diff --git a/.github/workflows/redirect_issues.yml b/.github/workflows/redirect_issues.yml new file mode 100644 index 00000000..654b52d2 --- /dev/null +++ b/.github/workflows/redirect_issues.yml @@ -0,0 +1,20 @@ +name: redirect + +on: + schedule: + - cron: "0 12 * * *" + + workflow_dispatch: # should be deleted after manual test + +jobs: + redirect-issues: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Ping on slack issues related to serverless in the datadog-agent repo + env: + GH_TOKEN: ${{ secrets.GH_TOKEN }} + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} + run: ./scripts/redirect_issues.sh diff --git a/scripts/redirect_issues.sh b/scripts/redirect_issues.sh new file mode 100755 index 00000000..dc078979 --- /dev/null +++ b/scripts/redirect_issues.sh @@ -0,0 +1,26 @@ +#!/bin/bash +set -euo pipefail +IFS=$'\n\t' +# Retrieve all issues from a repo + +yesterday=$(date --iso-8601=seconds --date="yesterday") + +GH_REPO_OWNER="DataDog" +GH_REPO="datadog-agent" +GH_URL="https://api.github.com/repos/$GH_REPO_OWNER/$GH_REPO/issues?since=$yesterday" + +SLACK_CHANNEL="#serverless" + +KEYWORDS="lambda|serverless|extension|layer" + +response=$(curl -H "Authorization: token $GH_TOKEN" -H "Accept: application/vnd.github.v3+json" -X GET "$GH_URL") +echo "$response" | jq -c '.[]' | while read -r issue; do + # Check if the retrieved issue is not a PR + if [[ $(echo "${issue}" | jq '.pull_request') == "null" && \ + ( ! -z $(echo "${issue}" | jq '.body' | grep -E "$KEYWORDS") || \ + ! -z $(echo "${issue}" | jq '.title' | grep -E "$KEYWORDS") ) \ + ]]; then + issue_url=$(echo "${issue}" | jq '.html_url') + curl -H "Content-type: application/json" -X POST "$SLACK_WEBHOOK" -d '{"channel": "'$SLACK_CHANNEL'", "text": ":sos: '$issue_url'"}' + fi +done