Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add matrix chat notifications to Actions #108

Merged
merged 1 commit into from
Sep 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/backlog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,22 @@ jobs:
- name: Install dependencies
run: sudo apt-get install curl jq
- name: Check SUSE QE Tools WIP-Limit
id: wip-limit
run: sh -ex backlog-check-wip-limit
- name: Check step status
id: step_check
if: always()
continue-on-error: true
run: |
. steps.sh ${{github.job}} ${{github.repository}} ${{github.run_id}}
env:
step_context: ${{ toJson(steps) }}
- name: send message
if: (success() || failure()) && steps.step_check.outcome == 'failure'
continue-on-error: true
run: |
. chat_notify.sh "matrix.org" "${{steps.step_check.outputs.result}}" \
"${{secrets.MATRIX_ACCESS_TOKEN}}" "${{secrets.MATRIX_ROOM_ID}}"
set_suse_qe_tools_due_dates:
name: Set SUSE QE Tools due dates
runs-on: ubuntu-latest
Expand Down
15 changes: 15 additions & 0 deletions chat_notify.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
send_message() {
out="$(curl -XPOST -d "$1" "https://$2/_matrix/client/r0/rooms/$3/send/m.room.message?access_token=$4")"
if [ "$(echo "$out" | jq .errcode)" = "null" ]; then
echo "[+] Message sent!"
else
echo '[!] Something went wrong sending the message'
echo "$out" | jq '.error'
fi
}

server=$1
body='{"msgtype": "m.text", "body": "'$2'", "format": "org.matrix.custom.html", "formatted_body": "'$2'"}'
access_token=$3
room_id=$4
send_message "$body" "$server" "$room_id" "$access_token"
38 changes: 38 additions & 0 deletions steps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
steps="${step_context}"
job=$1
repo_url="https://github.com/$2"
run_url="https://github.com/$2/actions/runs/$3"
sed_c='s/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g; s/"/\&quot;/g; s/'"'"'/\&#39;/g'
results=""
if [ -z "$steps" ]
then
exit 0
else
for k in $(jq -c 'keys[]' <<< "$steps"); do
outcome="$(jq -c ".${k}.outcome" <<< "$steps")"
if [[ $outcome != \"success\" ]]
then
if [ -z "$results" ]
then
repo_url="$(sed "$sed_c" <<< "$repo_url")"
repo="$(sed "$sed_c" <<< "$repo")"
results="<p><b>There are failures in the GitHub Actions pipeline for repo"
results="${results}<a href='${repo_url}'>${2}</a></b></p>"
results="${results}<table><tr><th>Job</th><th>Step</th><th>State</th></tr>"
fi
pipeline="$(sed -e 's/^"//' -e 's/"$//' <<<"$k")"
pipeline="$(sed "$sed_c" <<< "$pipeline")"
outcome="$(sed -e 's/^"//' -e 's/"$//' <<<"$outcome")"
run_url="$(sed "$sed_c" <<< "$run_url")"
job="$(sed "$sed_c" <<< "$job")"
results="${results}<tr><td><a href='${run_url}'>${job}</td><td>${pipeline}</td><td>${outcome}</td></tr>"
Martchus marked this conversation as resolved.
Show resolved Hide resolved
fi
if [ -n "$results" ]; then
results="${results}</table>"
else
exit 0
fi
done
fi
echo "::set-output name=result::${results}"
exit 1