We will show you how to create a program that checks given repo's github issues periodically and posts it to Slack if issues are found.
First, just to make our lives easier, we will install github cli to our RapidForge instance. This will allow us to interact with GitHub API. Github cli requires token to authenticate with GitHub. You can create a token by going to your GitHub account settings and clicking on Developer settings. Then click on Personal access tokens and create a new token.
Secondly create a periodic task and configure frequency that you want your issues to be checked. After that copy the Github token and save it to Periodic Task as environment variable. (GH_TOKEN).
Final step is to create webhook for a channel in Slack. Follow their documentation to create webhook.
Now we are ready to create our script.
ISSUE_LIST=$(gh issue list --repo=rapidforge-io/release --state=open --json title,url)
if [[ $ISSUE_LIST == [] ]]
then
echo "No open ISSUES found."
exit 0
fi
MESSAGE="Here are the current open PRs in rapidforge-io:\n"
# Loop through the JSON data and format
for row in $(echo "${ISSUE_LIST}" | jq -r '.[] | @base64'); do
_jq() {
echo ${row} | base64 --decode | jq -r ${1}
}
TITLE=$(_jq '.title')
URL=$(_jq '.url')
MESSAGE="${MESSAGE}\n*${TITLE}*: ${URL}"
done
# SLACK_WEBHOOK_URL is environment variable set in Periodic Task
curl -X POST -H 'Content-type: application/json' --data "{\"text\": \"${MESSAGE}\"}" ${SLACK_WEBHOOK_URL}
Alternatively if you like to use Discord instead of Slack you can send message to Discord using webhooks.
curl -H "Content-Type: application/json" -X POST -d "{\"content\": \"${MESSAGE}\"}" ${DISCORD_WEBHOOK_URL}
This example focused on Github issues but we can also use it to check unattended pull requests and send notifications to Slack to notify team about new PRs.