Repository navigation
chore: add Discord notifications for PRs, issues, and discussions #612
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| name: Discord Discussion Notification | ||
|
|
||
| on: | ||
| discussion: | ||
| types: [created] | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| notify: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Post to Discord | ||
| env: | ||
| DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_DISCUSSIONS_WEBHOOK_URL }} | ||
| DISCUSSION_TITLE: ${{ github.event.discussion.title }} | ||
| DISCUSSION_URL: ${{ github.event.discussion.html_url }} | ||
| DISCUSSION_BODY: ${{ github.event.discussion.body }} | ||
| DISCUSSION_AUTHOR: ${{ github.event.discussion.user.login }} | ||
| DISCUSSION_AVATAR: ${{ github.event.discussion.user.avatar_url }} | ||
| DISCUSSION_NUMBER: ${{ github.event.discussion.number }} | ||
| DISCUSSION_CATEGORY: ${{ github.event.discussion.category.name }} | ||
| run: | | ||
| # Truncate body and close unclosed code blocks | ||
| BODY="${DISCUSSION_BODY:0:1500}" | ||
| BACKTICK_COUNT=$(echo "$BODY" | grep -o '```' | wc -l) | ||
| if (( BACKTICK_COUNT % 2 != 0 )); then | ||
| BODY="${DISCUSSION_BODY:0:1500}..."$'\n```' | ||
| fi | ||
|
|
||
| PAYLOAD=$(jq -n \ | ||
| --arg title "#$DISCUSSION_NUMBER $DISCUSSION_TITLE" \ | ||
| --arg url "$DISCUSSION_URL" \ | ||
| --arg desc "$BODY" \ | ||
| --arg author "$DISCUSSION_AUTHOR" \ | ||
| --arg avatar "$DISCUSSION_AVATAR" \ | ||
| --arg category "$DISCUSSION_CATEGORY" \ | ||
| --arg repo "$GITHUB_REPOSITORY" \ | ||
| '{embeds: [{title: $title, url: $url, description: $desc, color: 10181046, | ||
| author: {name: $author, url: ("https://github.com/" + $author), icon_url: $avatar}, | ||
| fields: [ | ||
| {name: "Category", value: $category, inline: true}, | ||
| {name: "Repo", value: $repo, inline: true} | ||
| ]}]}') | ||
|
joshuadarron marked this conversation as resolved.
Resolved
|
||
| curl -sS -f -H "Content-Type: application/json" -d "$PAYLOAD" "$DISCORD_WEBHOOK_URL" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| name: Discord Issue Notification | ||
|
|
||
| on: | ||
| issues: | ||
| types: [opened] | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| notify: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Post to Discord | ||
| env: | ||
| DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_ISSUES_WEBHOOK_URL }} | ||
| ISSUE_TITLE: ${{ github.event.issue.title }} | ||
| ISSUE_URL: ${{ github.event.issue.html_url }} | ||
| ISSUE_BODY: ${{ github.event.issue.body }} | ||
| ISSUE_AUTHOR: ${{ github.event.issue.user.login }} | ||
| ISSUE_AVATAR: ${{ github.event.issue.user.avatar_url }} | ||
| ISSUE_NUMBER: ${{ github.event.issue.number }} | ||
| run: | | ||
| # Truncate body and close unclosed code blocks | ||
| BODY="${ISSUE_BODY:0:1500}" | ||
| BACKTICK_COUNT=$(echo "$BODY" | grep -o '```' | wc -l) | ||
| if (( BACKTICK_COUNT % 2 != 0 )); then | ||
| BODY="${ISSUE_BODY:0:1500}..."$'\n```' | ||
| fi | ||
|
|
||
| PAYLOAD=$(jq -n \ | ||
| --arg title "#$ISSUE_NUMBER $ISSUE_TITLE" \ | ||
| --arg url "$ISSUE_URL" \ | ||
| --arg desc "$BODY" \ | ||
| --arg author "$ISSUE_AUTHOR" \ | ||
| --arg avatar "$ISSUE_AVATAR" \ | ||
| --arg repo "$GITHUB_REPOSITORY" \ | ||
| '{embeds: [{title: $title, url: $url, description: $desc, color: 15548997, | ||
| author: {name: $author, url: ("https://github.com/" + $author), icon_url: $avatar}, | ||
| fields: [ | ||
| {name: "Repo", value: $repo, inline: true} | ||
| ]}]}') | ||
| curl -sS -f -H "Content-Type: application/json" -d "$PAYLOAD" "$DISCORD_WEBHOOK_URL" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| name: Discord PR Notification | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened] | ||
|
joshuadarron marked this conversation as resolved.
Resolved
|
||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| notify: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Post to Discord | ||
| env: | ||
| DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_PR_WEBHOOK_URL }} | ||
| PR_TITLE: ${{ github.event.pull_request.title }} | ||
| PR_URL: ${{ github.event.pull_request.html_url }} | ||
| PR_BODY: ${{ github.event.pull_request.body }} | ||
| PR_AUTHOR: ${{ github.event.pull_request.user.login }} | ||
| PR_AVATAR: ${{ github.event.pull_request.user.avatar_url }} | ||
| HEAD_REF: ${{ github.event.pull_request.head.ref }} | ||
| BASE_REF: ${{ github.event.pull_request.base.ref }} | ||
| PR_NUMBER: ${{ github.event.pull_request.number }} | ||
| run: | | ||
| # Truncate body to 1500 chars (leave room for embed fields). | ||
| # Close any unclosed code blocks to prevent broken formatting. | ||
| BODY="${PR_BODY:0:1500}" | ||
| BACKTICK_COUNT=$(echo "$BODY" | grep -o '```' | wc -l) | ||
| if (( BACKTICK_COUNT % 2 != 0 )); then | ||
|
joshuadarron marked this conversation as resolved.
Resolved
|
||
| BODY="${BODY}..."$'\n'"$BODY"'```' | ||
| BODY="${PR_BODY:0:1500}..."$'\n```' | ||
|
joshuadarron marked this conversation as resolved.
Resolved
|
||
| fi | ||
|
|
||
| PAYLOAD=$(jq -n \ | ||
| --arg title "#$PR_NUMBER $PR_TITLE" \ | ||
| --arg url "$PR_URL" \ | ||
| --arg desc "$BODY" \ | ||
| --arg author "$PR_AUTHOR" \ | ||
| --arg avatar "$PR_AVATAR" \ | ||
| --arg branch "$HEAD_REF → $BASE_REF" \ | ||
| --arg repo "$GITHUB_REPOSITORY" \ | ||
| '{embeds: [{title: $title, url: $url, description: $desc, color: 5814783, | ||
| author: {name: $author, url: ("https://github.com/" + $author), icon_url: $avatar}, | ||
| fields: [ | ||
| {name: "Branch", value: $branch, inline: true}, | ||
| {name: "Repo", value: $repo, inline: true} | ||
| ]}]}') | ||
| curl -sS -f -H "Content-Type: application/json" -d "$PAYLOAD" "$DISCORD_WEBHOOK_URL" | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.