@@ -693,3 +693,58 @@ def test_downstream_dispatches_with_a_contents_token(self):
693693 downstream = job (self .WORKFLOW , "downstream" )
694694 self .assertNotIn ("checkout" , downstream )
695695 self .assertEqual (1 , downstream .count ("uses:" ))
696+
697+
698+ class TestAlertWorkflow (WorkflowTestCase ):
699+ WORKFLOW = "alert.yml"
700+
701+ def test_watches_the_automation_workflows_by_their_exact_names (self ):
702+ self .assertIn ("""\
703+ on:
704+ workflow_run:
705+ workflows: [Release, Release PR, Upstream check]
706+ types: [completed]
707+
708+ permissions: {}
709+ """ , self .text ())
710+ names = {path .name : re .search (r"^name: (.+)$" , path .read_text (encoding = "utf-8" ), re .MULTILINE ).group (1 )
711+ for path in WORKFLOWS .glob ("*.yml" )}
712+ self .assertEqual ("Release" , names ["release.yml" ])
713+ self .assertEqual ("Release PR" , names ["release-pr.yml" ])
714+ self .assertEqual ("Upstream check" , names ["upstream.yml" ])
715+
716+ def test_comments_on_one_issue_with_github_token (self ):
717+ self .assert_in_job ("alert" , """\
718+ alert:
719+ if: github.event.workflow_run.conclusion != 'success' &&
720+ github.event.workflow_run.conclusion != 'skipped' &&
721+ github.event.workflow_run.conclusion != 'neutral' &&
722+ github.event.workflow_run.event != 'pull_request'
723+ runs-on: ubuntu-latest
724+ timeout-minutes: 5
725+ permissions:
726+ issues: write
727+ concurrency:
728+ group: automation-alert
729+ cancel-in-progress: false
730+ queue: max
731+ """ )
732+ self .assert_in_job ("alert" , """\
733+ run: |
734+ title='Automation needs a look'
735+ body="$WORKFLOW $CONCLUSION: $RUN_URL"
736+ number=$(TITLE=$title gh issue list --state open --limit 1000 --json number,title \\
737+ --jq 'map(select(.title == env.TITLE) | .number) | min // empty')
738+ if [[ -n $number ]]; then
739+ gh issue comment "$number" --body "$body"
740+ else
741+ gh issue create --title "$title" --assignee drptbl --body "$body"
742+ fi
743+ env:
744+ GH_TOKEN: ${{ github.token }}
745+ GH_REPO: ${{ github.repository }}
746+ WORKFLOW: ${{ github.event.workflow_run.name }}
747+ CONCLUSION: ${{ github.event.workflow_run.conclusion }}
748+ RUN_URL: ${{ github.event.workflow_run.html_url }}
749+ """ )
750+ self .assertNotIn ("uses:" , self .text ())
0 commit comments