Skip to content

Commit

Permalink
Update change management workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
strobus committed Oct 10, 2022
1 parent e887540 commit b62120a
Showing 1 changed file with 46 additions and 12 deletions.
58 changes: 46 additions & 12 deletions .github/workflows/change-management.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,13 @@ jobs:
PROJECT_GID: "1202267217415053"
SECTION_GID: "1203075160692525"
steps:
- id: PR
uses: 8BitJonny/gh-get-current-pr@2.1.1
with:
sha: ${{ github.event.pull_request.head.sha }}

- name: Create Asana Task
if: contains(steps.PR.outputs.pr_body, 'Change management:') != true
if: contains(github.event.pull_request.body, 'Change management:') != true
shell: bash
run: |
echo "creating change management task"
repo_name="$(cut -d "/" -f2 <<< "${{ github.repository }}")"
task_name="${repo_name}: ${{ steps.PR.outputs.pr_title }}"
task_name="${repo_name}: ${{ github.event.pull_request.title }}"
post_data="$(jq --null-input --arg name "$task_name" --arg project_gid "$PROJECT_GID" '{
"data": {
"projects":[ $project_gid ],
Expand All @@ -39,7 +34,7 @@ jobs:
task_url=$(echo "$task_data" | jq -r '.data.permalink_url')
echo "adding pull request url as comment to task"
comment="PR created: ${{ steps.PR.outputs.pr_url }}"
comment="PR created: ${{ github.event.pull_request._links.html }}"
post_data="$(jq --null-input --arg comment "$comment" '{
"data": {
"text": $comment
Expand All @@ -59,10 +54,10 @@ jobs:
-d "$post_data"
echo "updating the PR description with the link to the task"
pr_body="$(echo -e "${{ steps.PR.outputs.pr_body }}\n---\nChange management: $task_url\n")"
pr_body="$(echo -e "${{ github.event.pull_request.body }}\n---\nChange management: $task_url\n")"
post_data="$(jq --null-input --arg body "$pr_body" '{"body": $body}')"
repo="${{ github.repository }}"
pr_num="${{ steps.PR.outputs.number }}"
pr_num="${{ github.event.number }}"
curl -s -f -X PATCH https://api.github.com/repos/$repo/pulls/$pr_num \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
Expand All @@ -72,20 +67,59 @@ jobs:
if: github.event.action == 'edited'
shell: bash
run: |
body="${{ steps.PR.outputs.pr_body }}"
body="${{ github.event.pull_request.body }}"
task_gid="$(echo -e "$body" | grep 'Change management:' | cut -d "/" -f6)"
echo $task_gid
if [ "$task_gid" == "" ]; then
exit 0
fi
repo_name="$(cut -d "/" -f2 <<< "${{ github.repository }}")"
task_name="${repo_name}: ${{ steps.PR.outputs.pr_title }}"
task_name="${repo_name}: ${{ github.event.pull_request.title }}"
post_data="$(jq --null-input --arg task_name "$task_name" '{"data":{"name":$task_name}}')"
curl -s -f -X PUT https://app.asana.com/api/1.0/tasks/$task_gid \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H "Authorization: Bearer ${{ secrets.ASANA_API_TOKEN }}" \
-d "$post_data"
- name: Merged
if: github.event.action == 'closed' && github.event.pull_request.merged == true
shell: bash
run: |
body="${{ github.event.pull_request.body }}"
task_gid="$(echo -e "$body" | grep 'Change management:' | cut -d "/" -f6)"
echo $task_gid
post_data='{"data":{"completed":true}}'
curl -s -f -X PUT https://app.asana.com/api/1.0/tasks/$task_gid \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H "Authorization: Bearer ${{ secrets.ASANA_API_TOKEN }}" \
-d "$post_data"
- name: Create a comment
uses: Asana/comment-on-task-github-action@latest
with:
asana-secret: ${{ secrets.ASANA_ACTION_SECRET }}
comment-text: "{{PR_NAME}} is {{PR_STATE}}: {{PR_URL}}"

- name: Closed
if: github.event.action == 'closed' && github.event.pull_request.merged == false
shell: bash
run: |
echo "updating the PR description to remove the link to the task"
pr_body="$(echo -e "${{ github.event.pull_request.body }}" | sed '/Change management:/,+2d' | sed '$d')"
post_data="$(jq --null-input --arg body "$pr_body" '{"body": $body}')"
repo="${{ github.repository }}"
pr_num="${{ github.event.number }}"
curl -s -f -X PATCH https://api.github.com/repos/$repo/pulls/$pr_num \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-d "$post_data"
echo "deleting Asana task"
body="${{ github.event.pull_request.body }}"
task_gid="$(echo -e "$body" | grep 'Change management:' | cut -d "/" -f6)"
echo $task_gid
curl -s -f -X DELETE https://app.asana.com/api/1.0/tasks/$task_gid \
-H 'Accept: application/json' \
-H "Authorization: Bearer ${{ secrets.ASANA_API_TOKEN }}"

0 comments on commit b62120a

Please sign in to comment.