Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Mark phase as completed #521

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"title": "Taskcluster ShipIt mark-phase-as-completed task minimal schema",
"type": "object",
"properties": {
"dependencies": {
"type": "array",
"minItems": 1,
"uniqueItems": true,
"items": {
"type": "string"
}
},
"scopes": {
"type": "array",
"minItems": 2,
"uniqueItems": true,
"items": {
"type": "string"
}
},
"payload": {
"type": "object",
"properties": {
"release_name": {
"type": "string"
},
"phase": {
"type": "string"
}
},
"required": [
"release_name",
"phase"
],
"additionalProperties": false
}
},
"required": [
"dependencies",
"scopes",
"payload"
]
}
16 changes: 15 additions & 1 deletion shipitscript/src/shipitscript/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ async def async_main(context):
log.info("Success!")


def mark_phase_as_completed_action(context):
"""Action to perform is to tell Ship-it API that a phase can be marked
as completed"""
release_name = context.task["payload"]["release_name"]
phase = context.task["payload"]["phase"]

log.info("Marking the release's phase as completed ...")
ship_actions.mark_phase_as_completed(context.ship_it_instance_config, release_name, phase)


def mark_as_shipped_action(context):
"""Action to perform is to tell Ship-it API that a release can be marked
as shipped"""
Expand Down Expand Up @@ -63,7 +73,11 @@ def create_new_release_action(context):


# ACTION_MAP {{{1
ACTION_MAP = {"mark-as-shipped": mark_as_shipped_action, "create-new-release": create_new_release_action}
ACTION_MAP = {
"mark-as-shipped": mark_as_shipped_action,
"create-new-release": create_new_release_action,
"mark-phase-as-completed": mark_phase_as_completed_action,
}


def get_default_config():
Expand Down
7 changes: 7 additions & 0 deletions shipitscript/src/shipitscript/ship_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,10 @@ def mark_as_shipped_v2(shipit_config, release_name):
log.info("Marking the release as shipped...")
release_api.update_status(release_name, status="shipped", headers=headers)
check_release_has_values_v2(release_api, release_name, headers, status="shipped")


def mark_phase_as_completed(shipit_config, release_name, phase):
release_api, headers = get_shipit_api_instance(shipit_config)

log.info("Marking the release's phase as completed ...")
release_api.update_phase_status(release_name, phase, status="completed", headers=headers)
12 changes: 12 additions & 0 deletions shipitscript/src/shipitscript/shipitapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,15 @@ def trigger_release_phase(self, release_name, phase, headers={}):
log.error(resp.content)
log.error(f"Response code: {resp.status_code}")
raise

def update_phase_status(self, release_name, phase, status, headers={}):
data = json.dumps({"status": status})
response = None
try:
response = self._request(api_endpoint=f"/releases/{release_name}/{phase}", method="PATCH", data=data, headers=headers)
except Exception:
log.error(f"Caught error while triggering {phase} for {release_name}", exc_info=True)
if response:
log.error(response.content)
log.error(f"Response code: {response.status_code}")
raise