Skip to content

Commit

Permalink
Replaced cURL slack workflows with slackapi (#3577)
Browse files Browse the repository at this point in the history
Co-authored-by: Olga Bulat <[email protected]>
Co-authored-by: Dhruv Bhanushali <[email protected]>
  • Loading branch information
3 people authored Jan 9, 2024
1 parent bd77fb5 commit fa632e6
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 33 deletions.
25 changes: 18 additions & 7 deletions .github/workflows/discussion_ping.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,28 @@ jobs:
name: Send Slack message
runs-on: ubuntu-latest
env:
slack_url: ${{ secrets.SLACK_WEBHOOK_URL }}
discussion_url: ${{ github.event.discussion.html_url }}
discussion_number: ${{ github.event.discussion.number }}
discussion_title: ${{ github.event.discussion.title }}
discussion_author: ${{ github.event.discussion.user.login }}
discussion_repo: ${{ github.event.repository.full_name }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
steps:
- name: Send notification for new discussion
run: |
curl \
"$slack_url" \
-X POST \
-H 'Content-Type: application/json' \
-d '{"text":"New discussion opened by '"$discussion_author"' in '"$discussion_repo"': #'"$discussion_number"' - '"$discussion_title"'","blocks":[{"type":"section","text":{"type":"mrkdwn","text":":github: New discussion opened by *'"$discussion_author"'* in `'"$discussion_repo"'`:\n<'"$discussion_url"'|#'"$discussion_number"' - '"$discussion_title"'>"}}]}'
id: slack
uses: slackapi/[email protected]
with:
payload: |
{
"text": "New discussion opened by ${{ env.discussion_author }} in ${{ env.discussion_repo }}: #${{ env.discussion_number }} - ${{ env.discussion_title }}",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":github: New discussion opened by *${{ env.discussion_author }}* in ${{ env.discussion_repo }}:\n<${{ env.discussion_url }}|#${{ env.discussion_number }} - ${{ env.discussion_title }}>"
}
}
]
}
22 changes: 10 additions & 12 deletions .github/workflows/pr_limit_reminders.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,17 @@ jobs:
if: ${{ needs.analyze-user-prs.outputs.pr_count >= 3 }}
runs-on: ubuntu-latest
env:
slack_url: ${{ secrets.SLACK_DM_WEBHOOK_URL }}
pr_count: ${{ needs.analyze-user-prs.outputs.pr_count }}
slack_id: ${{ needs.analyze-user-prs.outputs.slack_id }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
steps:
- name: Send notification
run: |
msg="Hi, Opener! \nYou currently have $pr_count Pull Request(s) open with requested reviews (totalling $((pr_count * 2)) required reviews). \nTo help ease the review burden, increase review velocity for older PRs, and improve the equitable distribution of project maintenance tasks across the team, please consider reviewing this list of ways to contribute instead of working on new code contributions: \nhttps://docs.openverse.org/meta/maintainer_tasks.html"
curl \
"$slack_url" \
-X POST \
-H 'Content-Type: application/json' \
-d '{
"user": "'"$slack_id"'",
"message": "'"$msg"'"
}'
id: slack
uses: slackapi/[email protected]
with:
payload: |
{
"user": "${{ env.slack_id }}",
"message": "Hi, Opener! \nYou currently have ${{ env.pr_count }} Pull Request(s) open with requested reviews (totalling $((${{ env.pr_count }} * 2)) required reviews). \nTo help ease the review burden, increase review velocity for older PRs, and improve the equitable distribution of project maintenance tasks across the team, please consider reviewing this list of ways to contribute instead of working on new code contributions: \nhttps://docs.openverse.org/meta/maintainer_tasks.html"
}
48 changes: 34 additions & 14 deletions .github/workflows/pr_ping.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,50 @@ jobs:
!startsWith(github.event.pull_request.title, '🔄')
runs-on: ubuntu-latest
env:
slack_url: ${{ secrets.SLACK_WEBHOOK_URL }}
pr_url: ${{ github.event.pull_request.html_url }}
pr_number: ${{ github.event.pull_request.number }}
pr_title: ${{ github.event.pull_request.title }}
pr_author: ${{ github.event.pull_request.user.login }}
pr_repo: ${{ github.event.pull_request.base.repo.full_name }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
steps:
- name: Send notification for new PR
if: github.event.action == 'opened'
id: slack
uses: slackapi/[email protected]
env:
pr_status: ${{ github.event.pull_request.draft && ' draft ' || ' ' }}
pr_icon: ${{ github.event.pull_request.draft && ':pr-draft:' || ':pull-request:' }}
run: |
curl \
"$slack_url" \
-X POST \
-H 'Content-Type: application/json' \
-d '{"text":"New'"$pr_status"'PR opened by '"$pr_author"' in '"$pr_repo"': #'"$pr_number"' - '"$pr_title"'","blocks":[{"type":"section","text":{"type":"mrkdwn","text":"'"$pr_icon"' New'"$pr_status"'PR opened by *'"$pr_author"'* in `'"$pr_repo"'`:\n<'"$pr_url"'|#'"$pr_number"' - '"$pr_title"'>"}}]}'
with:
payload: |
{
"text": "New \"${{ env.pr_status }}\" PR opened by \"${{ env.pr_author }}\" in \"${{ env.pr_repo }}\": #\"${{ env.pr_number }}\" - \"${{ env.pr_title }}\"",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "\"${{ env.pr_icon }}\" New\"${{ env.pr_status }}\"PR opened by *\"${{ env.pr_author }}\"* in `\"${{ env.pr_repo }}\"`:\n<\"${{ env.pr_url }}\"|#\"${{ env.pr_number }}\" - \"${{ env.pr_title }}\">"
}
}
]
}
- name: Send notification for PR marked ready
if: github.event.action == 'ready_for_review'
run: |
curl \
"$slack_url" \
-X POST \
-H 'Content-Type: application/json' \
-d '{"text":"PR by '"$pr_author"' in '"$pr_repo"' marked ready for review: #'"$pr_number"' - '"$pr_title"'","blocks":[{"type":"section","text":{"type":"mrkdwn","text":":pull-request: PR by *'"$pr_author"'* in `'"$pr_repo"'` marked ready for review:\n<'"$pr_url"'|#'"$pr_number"' - '"$pr_title"'>"}}]}'
id: slack-notifications
uses: slackapi/[email protected]
with:
payload: |
{
"text": "PR by \"${{ env.pr_author }}\" in \"${{ env.pr_repo }}\" marked ready for review: #${{ env.pr_number }} - \"${{ env.pr_title }}\"",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":pull-request: PR by *${{ env.pr_author }}* in `${{ env.pr_repo }}` marked ready for review:\n<${{ env.pr_url }}|#${{ env.pr_number }} - ${{ env.pr_title }}>"
}
}
]
}

0 comments on commit fa632e6

Please sign in to comment.