Update patchset build submission to use GQL API

This commit is contained in:
Drew DeVault 2022-11-09 11:53:43 +01:00
parent e2dbb6c316
commit f37b9e6e18
3 changed files with 45 additions and 14 deletions

View File

@ -429,8 +429,8 @@ def build_complete(details):
buildsrht = get_origin("builds.sr.ht", external=True)
build_url = f"{buildsrht}/{project.owner.canonical_name}/job/{payload['id']}"
lists.patchset_set_tool(ml.owner, ml.name, details["patchset_id"],
details['key'], payload["status"],
f"[#{payload['id']}]({build_url}) {details['name']} {payload['status']}")
tool_details = f"[#{payload['id']}]({build_url}) {details['name']} {payload['status']}"
lists.patchset_update_tool(ml.owner, details["tool_id"],
payload["status"], tool_details)
return "Thanks!"

View File

@ -63,9 +63,8 @@ def submit_patchset(ml, payload):
[1]: mailto:{submitter[1]}"""
for key, value in manifests.items():
tool_key = f"hub.sr.ht:builds.sr.ht:{key}"
lists.patchset_set_tool(ml.owner, ml.name, payload["id"],
tool_key, "pending", f"build pending: {key}")
tool_id = lists.patchset_create_tool(ml.owner, payload["id"],
"PENDING", f"build pending: {key}")
try:
manifest = Manifest(yaml.safe_load(value))
@ -97,7 +96,7 @@ git am -3 /tmp/{payload["id"]}.patch"""
details = fernet.encrypt(json.dumps({
"mailing_list": ml.id,
"patchset_id": payload["id"],
"key": tool_key,
"tool_id": tool_id,
"name": key,
"user": project.owner.canonical_name,
}).encode()).decode()
@ -111,8 +110,8 @@ git am -3 /tmp/{payload["id"]}.patch"""
tags=[repo.name, "patches", key], execute=False)
ids.append(b["id"])
build_url = f"{buildsrht}/{project.owner.canonical_name}/job/{b['id']}"
lists.patchset_set_tool(ml.owner, ml.name, payload["id"],
tool_key, "waiting", f"[#{b['id']}]({build_url}) running {key}")
lists.patchset_update_tool(ml.owner, tool_id, "WAITING",
f"[#{b['id']}]({build_url}) running {key}")
trigger = Trigger({
"action": TriggerAction.email,

View File

@ -408,13 +408,45 @@ class ListService(SrhtService):
if r.status_code != 204 and r.status_code != 404:
raise Exception(r.text)
def patchset_set_tool(self, user, list_name, patchset_id, key, icon, details):
return self.put(user, None,
f"{_listsrht}/api/lists/{list_name}/patchsets/{patchset_id}/tools", {
"key": key,
def patchset_create_tool(self, user, patchset_id, icon, details):
query = """
mutation CreateTool($id: Int!, $details: String!, $icon: ToolIcon!) {
createTool(patchsetID: $id, details: $details, icon: $icon) {
id
}
}
"""
r = self.post(user, None, f"{_listsrht_api}/query", {
"query": query,
"variables": {
"id": patchset_id,
"icon": icon,
"details": details,
})
},
})
if not r["data"] or not r["data"]["createTool"]:
return None
return r["data"]["createTool"]["id"]
def patchset_update_tool(self, user, tool_id, icon, details):
query = """
mutation UpdateTool($id: Int!, $details: String!, $icon: ToolIcon!) {
updateTool(id: $id, details: $details, icon: $icon) {
id
}
}
"""
r = self.post(user, None, f"{_listsrht_api}/query", {
"query": query,
"variables": {
"id": tool_id,
"icon": icon,
"details": details,
},
})
if not r["data"] or not r["data"]["updateTool"]:
return None
return r["data"]["updateTool"]["id"]
class TodoService(SrhtService):
def get_trackers(self, user):