Skip to content

Commit 3de6d30

Browse files
committed
Implement a mark-as-merged action for shipitscript (bug 1890753)
1 parent 7a0ff2b commit 3de6d30

12 files changed

Lines changed: 124 additions & 1 deletion

File tree

shipitscript/docker.d/worker.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
work_dir: { "$eval": "WORK_DIR" }
22
mark_as_shipped_schema_file: { "$eval": "MARK_AS_SHIPPED_SCHEMA_FILE" }
3+
mark_as_merged_schema_file: { "$eval": "MARK_AS_MERGED_SCHEMA_FILE" }
34
create_new_release_schema_file: { "$eval": "CREATE_NEW_RELEASE_SCHEMA_FILE" }
45
update_product_channel_version_schema_file: { "$eval": "UPDATE_PRODUCT_CHANNEL_VERSION_SCHEMA_FILE" }
56
taskcluster_scope_prefix: { "$eval": "TASKCLUSTER_SCOPE_PREFIX" }

shipitscript/src/shipitscript/data/config_schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33
"type": "object",
44
"required": [
55
"mark_as_shipped_schema_file",
6+
"mark_as_merged_schema_file",
67
"taskcluster_scope_prefix",
78
"shipit_instance"
89
],
910
"properties": {
1011
"mark_as_shipped_schema_file": {
1112
"type": "string"
1213
},
14+
"mark_as_merged_schema_file": {
15+
"type": "string"
16+
},
1317
"taskcluster_scope_prefix": {
1418
"type": "string"
1519
},
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"title": "Taskcluster shipit mark-as-merged task schema",
3+
"type": "object",
4+
"properties": {
5+
"dependencies": {
6+
"type": "array",
7+
"minItems": 1,
8+
"uniqueItems": true,
9+
"items": {
10+
"type": "string"
11+
}
12+
},
13+
"scopes": {
14+
"type": "array",
15+
"minItems": 2,
16+
"uniqueItems": true,
17+
"items": {
18+
"type": "string"
19+
}
20+
},
21+
"payload": {
22+
"type": "object",
23+
"properties": {
24+
"automation_id": {
25+
"type": "integer"
26+
}
27+
},
28+
"required": ["automation_id"],
29+
"additionalProperties": false
30+
}
31+
},
32+
"required": ["dependencies", "scopes", "payload"]
33+
}

shipitscript/src/shipitscript/script.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ def mark_as_shipped_action(context):
3535
ship_actions.mark_as_shipped_v2(context.ship_it_instance_config, release_name)
3636

3737

38+
def mark_as_merged_action(context):
39+
"""Action to mark a merge automation as complete"""
40+
automation_id = context.task["payload"]["automation_id"]
41+
42+
log.info("Marking the merge automation as complete ...")
43+
ship_actions.mark_as_merged(context.ship_it_instance_config, automation_id)
44+
45+
3846
def create_new_release_action(context):
3947
"""Determine if there is a shippable release and create it if so in Shipit"""
4048
payload = context.task["payload"]
@@ -109,6 +117,7 @@ def update_product_channel_version_action(context):
109117
# ACTION_MAP {{{1
110118
ACTION_MAP = {
111119
"mark-as-shipped": mark_as_shipped_action,
120+
"mark-as-merged": mark_as_merged_action,
112121
"create-new-release": create_new_release_action,
113122
"update-product-channel-version": update_product_channel_version_action,
114123
}
@@ -123,6 +132,7 @@ def get_default_config():
123132
"work_dir": os.path.join(parent_dir, "work_dir"),
124133
"verbose": False,
125134
"mark_as_shipped_schema_file": os.path.join(data_dir, "mark_as_shipped_task_schema.json"),
135+
"mark_as_merged_schema_file": os.path.join(data_dir, "mark_as_merged_task_schema.json"),
126136
"create_new_release_schema_file": os.path.join(data_dir, "create_new_release_task_schema.json"),
127137
}
128138

shipitscript/src/shipitscript/ship_actions.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@ def mark_as_shipped_v2(shipit_config, release_name):
104104
check_release_has_values_v2(release_api, release_name, headers, status="shipped")
105105

106106

107+
def mark_as_merged(shipit_config, automation_id):
108+
release_api, headers = get_shipit_api_instance(shipit_config)
109+
110+
log.info("Marking merge automation as complete...")
111+
release_api.complete_merge_automation(automation_id, headers=headers)
112+
113+
107114
def get_product_channel_version(shipit_config, product, channel):
108115
release_api, headers = get_shipit_api_instance(shipit_config)
109116
log.info(f"Getting the current version of {product} {channel}...")

shipitscript/src/shipitscript/shipitapi.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,12 @@ def update_product_channel_version(self, product, channel, version, headers=None
180180
except Exception:
181181
log.error(f"Caught error while getting version for {product} {channel}!", exc_info=True)
182182
raise
183+
184+
def complete_merge_automation(self, automation_id, headers={}):
185+
"""Method to map over the PATCH /merge-automation/{automation_id} API in shipit
186+
187+
Parameters:
188+
* automation_id
189+
"""
190+
resp = self._request(api_endpoint=f"/merge-automation/{automation_id}", method="PATCH", data="", headers=headers).content
191+
return resp

shipitscript/src/shipitscript/task.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# SCHEMA_MAP {{{1
1010
SCHEMA_MAP = {
1111
"mark-as-shipped": "mark_as_shipped_schema_file",
12+
"mark-as-merged": "mark_as_merged_schema_file",
1213
"create-new-release": "create_new_release_schema_file",
1314
"update-product-channel-version": "update_product_channel_version_schema_file",
1415
}

shipitscript/tests/conftest.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
@pytest.fixture
1010
def context():
1111
context = Context()
12-
context.config = {"mark_as_shipped_schema_file": os.path.join(os.path.dirname(shipitscript.__file__), "data", "mark_as_shipped_task_schema.json")}
12+
context.config = {
13+
"mark_as_shipped_schema_file": os.path.join(os.path.dirname(shipitscript.__file__), "data", "mark_as_shipped_task_schema.json"),
14+
"mark_as_merged_schema_file": os.path.join(os.path.dirname(shipitscript.__file__), "data", "mark_as_merged_task_schema.json"),
15+
}
1316
context.config["shipit_instance"] = {
1417
"scope": "project:releng:ship-it:server:dev",
1518
"api_root_v2": "http://some-ship-it.url/v2",

shipitscript/tests/test_config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def test_config():
3333
"VERBOSE": "true",
3434
"TASKCLUSTER_SCOPE_PREFIX": "",
3535
"MARK_AS_SHIPPED_SCHEMA_FILE": "",
36+
"MARK_AS_MERGED_SCHEMA_FILE": "",
3637
"TASKCLUSTER_SCOPE": "",
3738
"API_ROOT_V2": "",
3839
"TASKCLUSTER_CLIENT_ID": "",

shipitscript/tests/test_script.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,28 @@ async def test_mark_as_shipped(context, monkeypatch, scopes):
3030
)
3131

3232

33+
@pytest.mark.parametrize("scopes", (["project:releng:ship-it:action:mark-as-merged", "project:releng:ship-it:server:dev"],))
34+
@pytest.mark.asyncio
35+
async def test_mark_as_merged(context, monkeypatch, scopes):
36+
context.task["scopes"] = scopes
37+
context.task["payload"] = {"automation_id": 123}
38+
39+
mark_as_merged_mock = MagicMock()
40+
monkeypatch.setattr(ship_actions, "mark_as_merged", mark_as_merged_mock)
41+
42+
await script.async_main(context)
43+
mark_as_merged_mock.assert_called_with(
44+
{
45+
"scope": scopes[-1],
46+
"api_root_v2": "http://some-ship-it.url/v2",
47+
"timeout_in_seconds": 1,
48+
"taskcluster_client_id": "some-id",
49+
"taskcluster_access_token": "some-token",
50+
},
51+
123,
52+
)
53+
54+
3355
@pytest.mark.parametrize(
3456
"task,raises",
3557
(
@@ -79,6 +101,7 @@ def test_get_default_config():
79101
"work_dir": os.path.join(parent_dir, "work_dir"),
80102
"verbose": False,
81103
"mark_as_shipped_schema_file": os.path.join(data_dir, "mark_as_shipped_task_schema.json"),
104+
"mark_as_merged_schema_file": os.path.join(data_dir, "mark_as_merged_task_schema.json"),
82105
"create_new_release_schema_file": os.path.join(data_dir, "create_new_release_task_schema.json"),
83106
}
84107

0 commit comments

Comments
 (0)