Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for pull_request_target #6

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 45 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h1 align="center">Github Telegram Notify</h1>
<h1 align="center">GitHub Telegram Notify</h1>
<h4 align="center">Actions that sends commit updates of a repository to any chat in Telegram</h4>
<p align="center"><a href="https://github.com/marketplace/actions/github-telegram-notifier">🏪 View on Github Marketplace</a>&emsp;🏷️ <a href="https://github.com/EverythingSuckz/github-telegram-notify/releases/tag/v1.1.2">v1.1.2</a></p>

Expand All @@ -20,16 +20,56 @@ 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.

```sh
```yml
- 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

You can also replace the content of your YML file with the following lines of code.


```yml
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
Expand Down
2 changes: 2 additions & 0 deletions types/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ func (e *Metadata) ParseEvent() (event_type interface{}, err error) {
event_type = &IssuesEvent{}
case "pull_request":
event_type = &PullRequestEvent{}
case "pull_request_target":
event_type = &PullRequestEvent{}
case "pull_request_review_comment":
event_type = &PullRequestReviewCommentEvent{}
case "push":
Expand Down
13 changes: 13 additions & 0 deletions utils/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ func CreateContents(meta *types.Metadata) (text string, markupText string, marku
return
}

text = createPullRequestText(event)
markupText = "Open Pull Request"
markupUrl = event.PullRequest.HTMLURL
case "pull_request_target":
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
Expand Down