From 0fc969cdd76a984754d3b7ea628736de8ed1ac1e Mon Sep 17 00:00:00 2001 From: Kazem Forghani Date: Mon, 28 Aug 2023 17:00:03 +0330 Subject: [PATCH 1/5] Added initial support for `pull_request_target` --- types/base.go | 2 +- utils/parser.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/types/base.go b/types/base.go index 2b53928..abf8ce5 100644 --- a/types/base.go +++ b/types/base.go @@ -21,7 +21,7 @@ func (e *Metadata) ParseEvent() (event_type interface{}, err error) { event_type = &IssueCommentEvent{} case "issues": event_type = &IssuesEvent{} - case "pull_request": + case "pull_request_target": event_type = &PullRequestEvent{} case "pull_request_review_comment": event_type = &PullRequestReviewCommentEvent{} diff --git a/utils/parser.go b/utils/parser.go index 02daaba..35aadfe 100644 --- a/utils/parser.go +++ b/utils/parser.go @@ -42,7 +42,7 @@ func CreateContents(meta *types.Metadata) (text string, markupText string, marku text = createIssuesText(event) markupText = "Open Issue" markupUrl = event.Issue.HTMLURL - case "pull_request": + case "pull_request_target": event := event.(*types.PullRequestEvent) if !Contains([]string{ From 7e40420c3632239e23a81819e06de20a3b9bc3d6 Mon Sep 17 00:00:00 2001 From: Kazem Forghani Date: Mon, 28 Aug 2023 17:16:04 +0330 Subject: [PATCH 2/5] Finalized support for `pull_request_target` --- types/base.go | 2 ++ utils/parser.go | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/types/base.go b/types/base.go index abf8ce5..b4382bd 100644 --- a/types/base.go +++ b/types/base.go @@ -21,6 +21,8 @@ func (e *Metadata) ParseEvent() (event_type interface{}, err error) { event_type = &IssueCommentEvent{} case "issues": event_type = &IssuesEvent{} + case "pull_request": + event_type = &PullRequestEvent{} case "pull_request_target": event_type = &PullRequestEvent{} case "pull_request_review_comment": diff --git a/utils/parser.go b/utils/parser.go index 35aadfe..ba529bd 100644 --- a/utils/parser.go +++ b/utils/parser.go @@ -42,6 +42,19 @@ func CreateContents(meta *types.Metadata) (text string, markupText string, marku text = createIssuesText(event) markupText = "Open Issue" markupUrl = event.Issue.HTMLURL + case "pull_request": + event := event.(*types.PullRequestEvent) + + if !Contains([]string{ + "created", "opened", "reopened", "locked", "unlocked", "closed", "synchronize", // More to be added. + }, event.Action) { + err = fmt.Errorf("unsupported event type '%s' for %s", event.Action, meta.EventName) + return + } + + text = createPullRequestText(event) + markupText = "Open Pull Request" + markupUrl = event.PullRequest.HTMLURL case "pull_request_target": event := event.(*types.PullRequestEvent) From 90e78987409d57caa6ca3e5ed0c0f911fff20cbd Mon Sep 17 00:00:00 2001 From: Kazem Forghani Date: Mon, 28 Aug 2023 17:16:48 +0330 Subject: [PATCH 3/5] Added advanced example into `README.md` --- README.md | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9365559..9e47ec5 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -

Github Telegram Notify

+

GitHub Telegram Notify

Actions that sends commit updates of a repository to any chat in Telegram

🏪 View on Github Marketplace 🏷️ v1.1.2

@@ -20,7 +20,9 @@ A Telegram Bot Token is required for using the Telegram bot from which the commi ### - `topic_id` (optional) Use this only if you have topics enabled. -## How to use +## How to use? + +### Basic example Add the following lines of code in your YML file. @@ -32,6 +34,44 @@ Add the following lines of code in your YML file. chat_id: '${{ secrets.CHAT_ID }}' ``` +### Advanced example + +You can also replace the content of your YML file with the following lines of code. + + +```sh +name: Telegram Notification +on: + push: + fork: + watch: + issues: + types: [created, closed, opended, reopened, locked, unlocked] + issue_comment: + types: [created, deleted] + pull_request: + types: [created, closed, opened, reopened, locked, unlocked, synchronize] + pull_request_target: + types: [created, closed, opened, reopened, locked, unlocked, synchronize] + pull_request_review_comment: + types: [created, deleted] + release: + types: [published, released] + +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Notify everything on Telegram + uses: EverythingSuckz/github-telegram-notify@main + with: + bot_token: '${{ secrets.TELEGRAM_BOT_TOKEN }}' + chat_id: '${{ secrets.TELEGRAM_CHAT_ID }}' + topic_id: '${{ secrets.TELEGRAM_TOPIC_ID }}' +``` + ## Supported events - [x] Commits From 7fe8431fc382ea04618ccf59321fc236e68131f4 Mon Sep 17 00:00:00 2001 From: Kazem Forghani Date: Mon, 28 Aug 2023 17:18:26 +0330 Subject: [PATCH 4/5] Edited `README.md` --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9e47ec5..583a9a8 100644 --- a/README.md +++ b/README.md @@ -30,8 +30,8 @@ Add the following lines of code in your YML file. - name: Notify the commit on Telegram uses: EverythingSuckz/github-telegram-notify@main with: - bot_token: '${{ secrets.BOT_TOKEN }}' - chat_id: '${{ secrets.CHAT_ID }}' + bot_token: '${{ secrets.TELEGRAM_BOT_TOKEN }}' + chat_id: '${{ secrets.TELEGRAM_CHAT_ID }}' ``` ### Advanced example From b40ab3a64be26a00cb608524336d2737f18573ce Mon Sep 17 00:00:00 2001 From: Kazem Forghani Date: Mon, 28 Aug 2023 17:19:38 +0330 Subject: [PATCH 5/5] Highlighted example codes in `README.md` --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 583a9a8..e49201b 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Use this only if you have topics enabled. Add the following lines of code in your YML file. -```sh +```yml - name: Notify the commit on Telegram uses: EverythingSuckz/github-telegram-notify@main with: @@ -39,7 +39,7 @@ Add the following lines of code in your YML file. You can also replace the content of your YML file with the following lines of code. -```sh +```yml name: Telegram Notification on: push: