Skip to content

Commit

Permalink
SWF: Add Github workflow eXo Tasks notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
hbenali committed Feb 22, 2022
1 parent 9c7b45c commit 527d027
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions .github/workflows/webhooktasks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: eXo PR Task Webhook

on:
pull_request:
types: [opened, reopened, closed, review_requested]
pull_request_review:
types: [submitted]

env:
message: ${{ github.event.pull_request.title }}
state: ${{ github.event.pull_request.state }}
pull_number: ${{ github.event.pull_request.number }}
requested_reviewer: ${{ github.event.requested_reviewer.login }}
creator: ${{ github.event.pull_request.user.login }}
repo_name: ${{ github.event.repository.full_name }}
base_branch_name: ${{ github.event.pull_request.base.ref }}
jobs:
check_tasks:
name: Check for eXo tasks identifiers
runs-on: ubuntu-latest
steps:
- name: eXo Tasks Webhook
run: |
TASKS_IDS="$(echo ${message:-}| grep -oP '[0-9]{4,}' | xargs)"
if [ -z "${TASKS_IDS}" ]; then
echo "No tasks found! Abort."
exit 0
fi
echo "OK Task(s) found! Starting notifications..."
link="PR <a href=\"https://github.com/${repo_name}/pull/${pull_number}\">${repo_name}#${pull_number}</a>"
if [ "${{ github.event_name }}" = "pull_request" ]; then
if [ "${{ github.event.action }}" = "review_requested" ]; then
tribeUser=$(curl -s -f -L -u ${TRIBE_USERNAME}:${TRIBE_PASSWORD} -XGET "${TRIBE_GAMGH_CONNECTOR_REST_URL}/users/${requested_reviewer}" || echo "")
if [ ! -z "${tribeUser}" ]; then
echo "Requested reviewer is: ${tribeUser}."
msg="💭 $link requested a review from @${tribeUser} "
else
echo "Could not get Tribe user identifier! Abort"
exit 0
fi
elif [ "${{ github.event.pull_request.merged }}" = "true" ]; then
msg="🌟 $link has been merged into ${base_branch_name}."
else
msg="ℹ️ $link has been ${{ github.event.action }}."
fi
elif [ "${{ github.event_name }}" = "pull_request_review" ] && [ "${{ github.event.action }}" = "submitted" ]; then
mentionCreator=""
response=$(curl -s -f -L -u ${TRIBE_USERNAME}:${TRIBE_PASSWORD} -XGET "${TRIBE_GAMGH_CONNECTOR_REST_URL}/users/${creator}" || echo "")
[ -z "${response}" ] || mentionCreator=" FYI @${response} "
if [ "${{ github.event.review.state }}" = "changes_requested" ]; then
msg="🛠️ $link requires some changes.${mentionCreator}"
elif [ "${{ github.event.review.state }}" = "approved" ]; then
msg="✅ $link has been ${{ github.event.review.state }}.${mentionCreator}"
else
msg="ℹ️ $link has been ${{ github.event.review.state }}."
fi
fi
echo "*** Message is:"
echo ${msg}
echo "***"
for TASK_ID in ${TASKS_IDS}; do
echo "Commenting to Task #${TASK_ID}..."
curl -s -L -u ${TRIBE_USERNAME}:${TRIBE_PASSWORD} -XPOST --data-urlencode "<p>${msg}</p>" "${TRIBE_TASK_REST_PREFIXE_URL}/comments/${TASK_ID}"
done
env:
TRIBE_USERNAME: ${{ secrets.TRIBE_USERNAME }}
TRIBE_PASSWORD: ${{ secrets.TRIBE_PASSWORD }}
TRIBE_TASK_REST_PREFIXE_URL: ${{ secrets.TRIBE_TASK_REST_PREFIXE_URL }}
TRIBE_GAMGH_CONNECTOR_REST_URL: ${{ secrets.TRIBE_GAMGH_CONNECTOR_REST_URL }}

0 comments on commit 527d027

Please # to comment.