Skip to content

Commit

Permalink
🚑 Fix pull-request-review event (#7)
Browse files Browse the repository at this point in the history
* add event

* Update main.py

* Update main.py

* Update main.py
  • Loading branch information
georgepstaylor authored May 5, 2024
1 parent 49c9667 commit ac36035
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
26 changes: 13 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ on:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: echo github event
run: echo "${{ toJson(github.event) }}"
- name: Test
uses: georgepstaylor/telegram-notify@feature/event-action-support
with:
telegram_bot_token: ${{ secrets.TELEGRAM_BOT_TOKEN }}
telegram_chat_id: ${{ secrets.TELEGRAM_CHAT_ID }}
gh_event: ${{ toJson(github.event) }}
gh_actor: ${{ github.actor }}
#jobs:
# test:
# runs-on: ubuntu-latest
# steps:
# - name: echo github event
# run: echo "${{ toJson(github.event) }}"
# - name: Test
# uses: georgepstaylor/telegram-notify@feature/event-action-support
# with:
# telegram_bot_token: ${{ secrets.TELEGRAM_BOT_TOKEN }}
# telegram_chat_id: ${{ secrets.TELEGRAM_CHAT_ID }}
# gh_event: ${{ toJson(github.event) }}
# gh_actor: ${{ github.actor }}
14 changes: 9 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def build_github_event_link():
"push": "commit"
}

if Env.GH_EVENT_NAME in ["pull_request_review_comment", "pull_request"]:
if Env.GH_EVENT_NAME in ["pull_request_review_comment", "pull_request", "pull_request_review"]:
return f"{github_base_url}/{event_name_url_map[Env.GH_EVENT_NAME]}/{Env.GH_EVENT['number']}"
elif Env.GH_EVENT_NAME in ["issue_comment", "issues"]:
return f"{github_base_url}/{event_name_url_map[Env.GH_EVENT_NAME]}/{Env.GH_EVENT['issue']['number']}"
Expand All @@ -58,11 +58,11 @@ def build_message(event_name):
event_link = build_github_event_link()
if event_name in ["issues", "issue_comment"]:
return (f"*Event:* [{event_name}]({event_link}) by [{Env.GH_ACTOR}](https://github.com/{Env.GH_ACTOR})\n"
f"*Action:* {event_name}\n"
f"*Action:* `{Env.GH_EVENT['action']}`\n"
f"*Repo:* [{Env.GH_REPO}](https://github.com/{Env.GH_REPO})")
elif event_name == "pull_request":
elif event_name in ["pull_request", "pull_request_review", "pull_request_review_comment"]:
return (f"*Event:* [{event_name}]({event_link}) by [{Env.GH_ACTOR}](https://github.com/{Env.GH_ACTOR})\n"
f"*Action:* {Env.GH_EVENT['action']}\n"
f"*Action:* `{Env.GH_EVENT['action']}`\n"
f"*Repo:* [{Env.GH_REPO}](https://github.com/{Env.GH_REPO})")
else:
return (f"*Event:* [{event_name}]({event_link}) by [{Env.GH_ACTOR}](https://github.com/{Env.GH_ACTOR})\n"
Expand All @@ -71,8 +71,12 @@ def main():
if telegram_check_token():
print("Token is valid")
event_link = build_github_event_link()
print(Env.GH_EVENT)
print(Env.GH_EVENT_NAME)
message = build_message(Env.GH_EVENT_NAME)
print(message)
telegram_send_message(
message=build_message(Env.GH_EVENT_NAME),
message=message,
inline_keyboard=[
[
{"text": "Event", "url": event_link},
Expand Down

0 comments on commit ac36035

Please sign in to comment.