Skip to content

Commit

Permalink
Merge pull request #435 from ebmdatalab/evansd/change-op-deploy-channel
Browse files Browse the repository at this point in the history
Configure OpenPrescribing deploy failures to go to #team-rap
  • Loading branch information
evansd committed Feb 7, 2024
2 parents 44f7018 + f9f28b2 commit a990f72
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
6 changes: 6 additions & 0 deletions ebmbot/job_configs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Defines which jobs may be run, and how they can be invoked via Slack.
"""

import re
from operator import itemgetter

Expand Down Expand Up @@ -78,6 +79,7 @@
"restricted": True,
"description": "OpenPrescribing deployment and tools",
"fabfile": "https://raw.githubusercontent.com/ebmdatalab/openprescribing/main/fabfile.py",
"default_channel": "#team-rap",
"jobs": {
"deploy": {
"run_args_template": "fab deploy:production",
Expand Down Expand Up @@ -401,6 +403,7 @@ def build_config(raw_config):
"fabfiles": {},
"workspace_dir": {},
"restricted": {},
"default_channel": {},
}

for namespace in raw_config:
Expand All @@ -409,6 +412,9 @@ def build_config(raw_config):

config["description"][namespace] = raw_config[namespace].get("description", "")
config["restricted"][namespace] = raw_config[namespace].get("restricted", False)
config["default_channel"][namespace] = raw_config[namespace].get(
"default_channel", "#tech"
)

helps = []

Expand Down
3 changes: 2 additions & 1 deletion ebmbot/webserver/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,5 @@ def schedule_deploy(project):
abort(Response(f"Unknown project: {project}", 400))

logger.info("Scheduling deploy", project=project)
scheduler.schedule_job(job, {}, "#general", "", delay_seconds=60)
channel = config["default_channel"][project]
scheduler.schedule_job(job, {}, channel, "", delay_seconds=60)
1 change: 1 addition & 0 deletions tests/mock_web_api_server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Based on https://github.com/slackapi/bolt-python/blob/v1.14.3/tests/mock_web_api_server.py
"""

import json
import logging
import threading
Expand Down
7 changes: 7 additions & 0 deletions tests/test_job_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def test_build_config():
"ns1": {
"description": "ns1 jobs",
"restricted": True,
"default_channel": "#some-channel",
"jobs": {
"good_job": {"run_args_template": "cat [poem]"},
"bad_job": {"run_args_template": "dog [poem]"},
Expand Down Expand Up @@ -171,6 +172,12 @@ def test_build_config():
"ns3": False,
"test": False,
},
"default_channel": {
"ns1": "#some-channel",
"ns2": "#tech",
"ns3": "#tech",
"test": "#tech",
},
}


Expand Down
13 changes: 11 additions & 2 deletions tests/webserver/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pytest

from ebmbot import scheduler
from ebmbot.job_configs import build_config

from ..assertions import assert_job_matches
from ..time_helpers import T0, T
Expand All @@ -18,7 +19,15 @@
PAYLOAD_ISSUE_OPENED = '{"action": "opened", "issue": {}}'


dummy_config = {"jobs": {"test_deploy": {}}}
dummy_config = build_config(
{
"test": {
"default_channel": "#some-team",
"jobs": {"deploy": {"run_args_template": "fab deploy:production"}},
"slack": [],
}
}
)


def test_no_auth_header(web_client):
Expand Down Expand Up @@ -56,7 +65,7 @@ def test_on_closed_merged_pr(web_client):
assert rsp.status_code == 200
jj = scheduler.get_jobs_of_type("test_deploy")
assert len(jj) == 1
assert_job_matches(jj[0], "test_deploy", {}, "#general", T(60), None)
assert_job_matches(jj[0], "test_deploy", {}, "#some-team", T(60), None)


def test_on_closed_unmerged_pr(web_client):
Expand Down

0 comments on commit a990f72

Please sign in to comment.