-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgithub_issue_count.py
66 lines (53 loc) · 2.17 KB
/
github_issue_count.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import os
import requests
import discord
from discord.ext import commands
from datetime import datetime
# Set GitHub API token and Discord bot token from environment variables
GITHUB_TOKEN = os.environ["GITHUB_TOKEN"]
DISCORD_BOT_TOKEN = os.environ["DISCORD_BOT_TOKEN"]
DISCORD_CHANNEL_ID = os.environ["DISCORD_CHANNEL_ID"]
# Create a Discord bot client with default intents
intents = discord.Intents.default()
client = discord.Client(intents=intents)
# Function to send GitHub issue count to Discord
async def send_github_issue_count_once():
# Retrieve GitHub issues
headers = {
"Authorization": f"token {GITHUB_TOKEN}"
}
response = requests.get("https://api.github.com/repos/fog-of-war/dev-be/issues", headers=headers)
if response.status_code == 200:
issues = response.json()
assignee_count = {}
current_date = datetime.now().strftime("%Y-%m-%d")
for issue in issues:
assignee = issue["assignee"]["login"] if issue["assignee"] else "담당자 없음"
if assignee in assignee_count:
assignee_count[assignee] += 1
else:
assignee_count[assignee] = 1
# Send the message to the Discord channel
channel = client.get_channel(int(DISCORD_CHANNEL_ID))
# Create the message
message = f"## 📅 **{current_date}**\n"
for assignee, count in assignee_count.items():
message += f"💡 **{assignee}**: {count}개의 이슈가 남아있습니다.\n"
code_block = "```md\n"
for issue in issues:
if issue["assignee"] and issue["assignee"]["login"] == assignee:
issue_title = issue["title"]
code_block += f"{issue_title}\n"
code_block += "```"
message += code_block
message += "\n"
await channel.send(message)
@client.event
async def on_ready():
print(f'Logged in as {client.user}')
# Run the function once when the bot starts
await send_github_issue_count_once()
# Close the bot when the task is done
await client.close()
# Run the bot
client.run(DISCORD_BOT_TOKEN)