diff --git a/.github/workflows/slack-on-issue.yml b/.github/workflows/slack-on-issue.yml new file mode 100644 index 0000000..25dfe33 --- /dev/null +++ b/.github/workflows/slack-on-issue.yml @@ -0,0 +1,52 @@ +name: Notify Slack on New Issue or PR + +on: + issues: + types: [opened] + pull_request: + types: [opened] + +jobs: + notify: + runs-on: ubuntu-latest + steps: + - name: Send Slack notification + run: | + if [[ "${{ github.event_name }}" == "issues" ]]; then + TYPE="Issue" + TITLE="${{ github.event.issue.title }}" + URL="${{ github.event.issue.html_url }}" + USER="${{ github.event.issue.user.login }}" + else + TYPE="Pull Request" + TITLE="${{ github.event.pull_request.title }}" + URL="${{ github.event.pull_request.html_url }}" + USER="${{ github.event.pull_request.user.login }}" + fi + + PAYLOAD=$(jq -n \ + --arg type "$TYPE" \ + --arg title "$TITLE" \ + --arg url "$URL" \ + --arg user "$USER" \ + '{ + text: "*New GitHub \($type)* :sparkles:", + attachments: [ + { + color: "#36a64f", + title: $title, + title_link: $url, + fields: [ + { + title: "Author", + value: $user, + short: true + } + ] + } + ] + }') + + curl -X POST -H 'Content-type: application/json' --data "$PAYLOAD" $SLACK_WEBHOOK_URL + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}