Skip to content

Commit

Permalink
add script to redirect issues from datadog-agent (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanista authored Oct 14, 2021
1 parent 164740e commit 3f56c09
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/redirect_issues.yml
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions scripts/redirect_issues.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3f56c09

Please sign in to comment.