Skip to content

Commit

Permalink
Add the check-links job
Browse files Browse the repository at this point in the history
  • Loading branch information
alarthast committed Oct 21, 2024
1 parent 963cab7 commit ef56fe2
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 1 deletion.
12 changes: 12 additions & 0 deletions bennettbot/job_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,11 @@
"restricted": True,
"description": "Report GitHub Actions workflow runs",
"jobs": {
"check_links": {
"run_args_template": "python jobs.py custom --job-name check-links",
"report_stdout": True,
"report_format": "blocks",
},
"display_emoji_key": {
"run_args_template": "python jobs.py key",
"report_stdout": True,
Expand All @@ -325,6 +330,12 @@
},
},
"slack": [
{
"command": "check-links",
"help": "Summarise GitHub Actions workflow runs for link-checking workflows in website repos.",
"action": "schedule_job",
"job_type": "check_links",
},
{
"command": "key",
"help": "Show the emoji key being used in the workflow summaries.",
Expand All @@ -350,6 +361,7 @@
"action": "schedule_job",
"job_type": "show",
},

]
},
"techsupport": {
Expand Down
86 changes: 86 additions & 0 deletions tests/workspace/test_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,3 +689,89 @@ def test_main_show_invalid_target():
},
},
]


@patch(
"workspace.workflows.config.CUSTOM_JOBS",
{
"check-links": {
"header_text": "Link-checking workflows",
"workflows": {
"opensafely/documentation": [82728346],
"ebmdatalab/bennett.ox.ac.uk": [82728346],
"ebmdatalab/opensafely.org": [82728346],
"ebmdatalab/team-manual": [82728346],
},
}
},
)
@use_mock_results(
[
{
"org": "opensafely",
"repo": "documentation",
"team": "Tech shared",
"conclusions": ["success"] * 5,
},
{
"org": "ebmdatalab",
"repo": "team-manual",
"team": "Tech shared",
"conclusions": ["failure"] * 5,
},
{
"org": "ebmdatalab",
"repo": "bennett.ox.ac.uk",
"team": "Tech shared",
"conclusions": ["success"] * 5,
},
{
"org": "ebmdatalab",
"repo": "opensafely.org",
"team": "Tech shared",
"conclusions": ["failure"] * 5,
},
]
)
def test_check_links():
args = jobs.get_command_line_parser().parse_args(
"custom --job-name check-links".split()
)
blocks = json.loads(jobs.get_blocks_for_custom_workflow_list(args))
assert blocks == [
{ # Only 1 emoji should appear for each repo
"type": "header",
"text": {
"type": "plain_text",
"text": "Link-checking workflows",
},
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "<https://github.com/opensafely/documentation/actions?query=branch%3Amain|opensafely/documentation>: :large_green_circle:",
},
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "<https://github.com/ebmdatalab/bennett.ox.ac.uk/actions?query=branch%3Amain|ebmdatalab/bennett.ox.ac.uk>: :large_green_circle:",
},
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "<https://github.com/ebmdatalab/opensafely.org/actions?query=branch%3Amain|ebmdatalab/opensafely.org>: :red_circle:",
},
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "<https://github.com/ebmdatalab/team-manual/actions?query=branch%3Amain|ebmdatalab/team-manual>: :red_circle:",
},
},
]
14 changes: 13 additions & 1 deletion workspace/workflows/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
},
"opensafely.org": {
"org": "ebmdatalab",
"team": "Team REX",
"team": "Tech shared",
},
"opencodelists": {
"org": "opensafely-core",
Expand Down Expand Up @@ -153,3 +153,15 @@
31178226, # Check links (expected to break, notifications handled elsewhere)
],
}

CUSTOM_JOBS = {
"check-links": {
"header_text": "Link-checking workflows",
"workflows": {
"opensafely/documentation": [25878886],
"ebmdatalab/bennett.ox.ac.uk": [42498719],
"ebmdatalab/opensafely.org": [26433647],
"ebmdatalab/team-manual": [31178226],
},
}
}
22 changes: 22 additions & 0 deletions workspace/workflows/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,23 @@ def _main(org, repo, skip_successful=False) -> str:
return report_invalid_org(org)


def get_blocks_for_custom_workflow_list(args):
job_config = config.CUSTOM_JOBS[args.job_name]
header_text = job_config["header_text"]
workflows = job_config["workflows"]
conclusions = {}
for location, workflow_ids in workflows.items():
wf_conclusions = RepoWorkflowReporter(location).get_latest_conclusions()
conclusions[location] = [
wf_conclusions.get(wf_id, "missing") for wf_id in workflow_ids
]
blocks = [
get_header_block(header_text),
*[get_summary_block(loc, conc) for loc, conc in conclusions.items()],
]
return json.dumps(blocks)


def get_text_blocks_for_key(args) -> str:
blocks = get_basic_header_and_text_blocks(
header_text="Workflow status emoji key",
Expand All @@ -331,6 +348,11 @@ def get_command_line_parser(): # pragma: no cover
show_parser.add_argument("--skip-successful", action="store_true", default=False)
show_parser.set_defaults(func=main)

# Custom tasks
custom_parser = subparsers.add_parser("custom")
custom_parser.add_argument("--job-name", required=True)
custom_parser.set_defaults(func=get_blocks_for_custom_workflow_list)

# Display key
key_parser = subparsers.add_parser("key")
key_parser.set_defaults(func=get_text_blocks_for_key)
Expand Down

0 comments on commit ef56fe2

Please sign in to comment.