Skip to content

Commit 24a2777

Browse files
authored
Automatically react to the issue, and close the issue. (#1)
Also mention the GitHub username on Slack.
1 parent e87e11b commit 24a2777

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

webservice/issues.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@ async def issue_labeled(event, gh, *args, **kwargs):
2121
issue_title = event.data["issue"]["title"]
2222
issue_body = event.data["issue"]["body"]
2323
html_url = event.data["issue"]["html_url"]
24+
author = event.data["issue"]["user"]["login"]
25+
issue_number = event.data["issue"]["number"]
26+
repo_full_name = event.data["repository"]["full_name"]
2427

2528
# post it to Slack "events" channel
2629
slack_client = WebClient(token=os.getenv("SLACK_API_KEY"))
2730
try:
2831
response = slack_client.chat_postMessage(
2932
channel="#events",
30-
text=f"*New Event posted*\n\n*Title*: {issue_title}\n{issue_body}\n\n_source:_ _{html_url}_ ",
33+
text=f"*New Event posted* by *{author}*\n\n*Title*: {issue_title}\n{issue_body}\n\n_source:_ _{html_url}_ ",
3134
)
3235
except SlackApiError as e:
3336
# You will get a SlackApiError if "ok" is False
@@ -44,10 +47,26 @@ async def issue_labeled(event, gh, *args, **kwargs):
4447
private_key=os.environ.get("GH_PRIVATE_KEY"),
4548
)
4649

50+
# react with "hooray"
51+
await gh.post(
52+
f"/repos/{repo_full_name}/issues/{issue_number}/reactions",
53+
data={"content": "hooray"},
54+
accept="application/vnd.github.squirrel-girl-preview+json",
55+
oauth_token=installation_access_token["token"],
56+
)
57+
58+
# say thanks
4759
response = await gh.post(
4860
event.data["issue"]["comments_url"],
4961
data={
5062
"body": "Thanks for sharing this event with PyLadies!! We've shared this in PyLadies Slack #events channel."
5163
},
5264
oauth_token=installation_access_token["token"],
5365
)
66+
67+
# close the issue
68+
await gh.patch(
69+
f"/repos/{repo_full_name}/issues/{issue_number}",
70+
data={"state": "closed"},
71+
oauth_token=installation_access_token["token"],
72+
)

0 commit comments

Comments
 (0)