Skip to content
Merged
56 changes: 48 additions & 8 deletions .github/workflows/discord_issues.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,66 @@
name: Discuss on Discord

on:
issues:
types:
- labeled
pull_request:
types:
- labeled
workflow_dispatch:
inputs:
issue_number:
description: 'Issue number'
required: true

pull_request_number:
description: 'Pull request number'

permissions:
issues: write
pull-requests: write

jobs:
discord:
runs-on: ubuntu-latest
steps:
- name: Discuss on Discord
- name: Check if PR is from non-maintainer
id: check_maintainer
run: |
# Using https://docs.github.com/en/free-pro-team@latest/rest/collaborators/collaborators?apiVersion=2022-11-28#check-if-a-user-is-a-repository-collaborator

PR_NUMBER="${{ github.event.inputs.pull_request_number || github.event.pull_request.number }}"

GITHUB_API=$(curl -s -o response.txt -w "%{http_code}" -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: token ${{ secrets.REPO_SECRET }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
'https://api.github.com/repos/${{ github.repository }}/collaborators/${{ github.event.pull_request.user.login }}')

if [ "$GITHUB_API" -eq "204" ]; then
echo "PR is from a maintainer"
echo "is_maintainer=true" >> $GITHUB_OUTPUT
else
echo "PR is from a non-maintainer"
echo "is_maintainer=false" >> $GITHUB_OUTPUT
fi
shell: bash

- name: "Discuss on Discord-Issues"
if: github.event.issue && contains(github.event.issue.labels.*.name, 'help wanted')
uses: EndBug/[email protected]
with:
discord_bot_token: ${{ secrets.DISCORD_BOT_TOKEN }}
destination: https://discord.com/channels/1111902634220199988/1111902634220199988
issue_number: ${{ github.event.inputs.issue_number || github.event.issue.number }}
issue_comment: Hey 👋, I've just created a [thread]($THREAD_LINK$) for this issue on [PyTorch-Ignite Discord](https://pytorch-ignite.ai/chat) where you can quickly talk to the community on the topic.
discord_message: New issue created in `${{ github.repository }}`:<https://github.com/${{ github.repository }}/issues/${{ github.event.issue.number }}>

- name: "Discuss on Discord-PR (Non-maintainer only)"
if: github.event_name == 'pull_request' && steps.check_maintainer.outputs.is_maintainer == 'false' && contains(github.event.pull_request.labels.*.name, 'help wanted')
uses: EndBug/[email protected]
if: ${{ github.event.label.name == 'help wanted' }}
with:
discord_bot_token: ${{ secrets.DISCORD_BOT_TOKEN }}
destination: ${{ secrets.DISCORD_BOT_DESTINATION }}
issue_number: ${{ github.event.inputs.issue_number || github.event.issue.number }}
issue_comment: Hey 👋, I've just created a [thread]($THREAD_LINK$) for this issue on [PyTorch-Ignite Discord](https://pytorch-ignite.ai/chat) where you can quickly talk to the community on the topic.
discord_bot_token: ${{ secrets.DISCORD_BOT_TOKEN }}
destination: https://discord.com/channels/1111902634220199988/1111902634220199988
issue_number: ${{ github.event.inputs.pull_request_number || github.event.pull_request.number }}
issue_comment: Hey 👋, I've just created a [thread]($THREAD_LINK$) for this pull request on [PyTorch-Ignite Discord](https://pytorch-ignite.ai/chat) where you can quickly talk to the community on the topic.
discord_message: New PR created in `${{ github.repository }}`:<https://github.com/${{ github.repository }}/issues/${{ github.event.pull_request.number }}>