grafana/.github/workflows/issue-labeled.yml

72 lines
2.8 KiB
YAML

name: Notify Slack channel based on new issue label
on:
issues:
types: [labeled]
jobs:
notify:
runs-on: ubuntu-latest
steps:
- name: "Download teams.yml to know which label is for which team"
run: wget https://raw.githubusercontent.com/grafana/grafana/main/.github/teams.yml
- name: "Determine which team to notify"
run: |
# Default to null values.
CHANNEL="null"
TEAM="null"
echo "${{ github.event.label.name }} label added"
export CURRENT_LABEL="${{ github.event.label.name }}" # Enable the use of the label in yq evaluations
# yq is installed by default in ubuntu-latest
if [[ $(yq e 'keys | .[] | select(. == env(CURRENT_LABEL))' teams.yml ) ]]; then
# Check if we have a channel set to notify on comments.
if [[ $(yq '.[env(CURRENT_LABEL)] | has("channel-label")' teams.yml ) == true ]]; then
CHANNEL=$(yq '.[env(CURRENT_LABEL)].channel-label' teams.yml)
echo "Ready to send issue to channel ID ${CHANNEL}"
fi
if [[ $(yq '.[env(CURRENT_LABEL)] | has("exclude-github-team")' teams.yml ) == true ]]; then
TEAM=$(yq '.[env(CURRENT_LABEL)].exclude-github-team' teams.yml)
echo "Will not send issue to channel if issue author is part of the team ${TEAM}"
fi
fi
# set environment for next steps
echo "CHANNEL=${CHANNEL}" >> $GITHUB_ENV
echo "TEAM=${TEAM}" >> $GITHUB_ENV
- name: "Prepare payload"
uses: frabert/replace-string-action@v2.0
id: preparePayload
with:
# replace double quotes with single quotes to avoid breaking the JSON payload sent to Slack
string: ${{ github.event.issue.title }}
pattern: '"'
replace-with: "'"
flags: 'g'
- name: "Check that issue author is not part of the team"
if: ${{ env.TEAM != 'null' }}
uses: tspascoal/get-user-teams-membership@v2
id: checkUserMember
with:
username: ${{ github.event.issue.user.login }}
team: "${{ env.TEAM }}"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: "Send Slack notification"
if: ${{ (env.CHANNEL != 'null') && ((steps.checkUserMember.outputs.isTeamMember == 'false') || (env.TEAM != 'null')) }}
uses: slackapi/slack-github-action@v1.24.0
with:
payload: >
{
"icon_emoji": ":grafana:",
"username": "Grafana issue labeled",
"text": "Issue \"${{ steps.preparePayload.outputs.replaced }}\" labeled \"${{ github.event.label.name }}\": ${{ github.event.issue.html_url }}, please triage.",
"channel": "${{ env.CHANNEL }}"
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}