def abandon_release(name): session = current_app.db.session try: release = session.query(Release).filter(Release.name == name).one() # we must require scope which depends on product required_permission = f"{SCOPE_PREFIX}/abandon_release/{release.product}" if not current_user.has_permissions(required_permission): user_permissions = ", ".join(current_user.get_permissions()) abort( 401, f"required permission: {required_permission}, user permissions: {user_permissions}" ) # Cancel all submitted task groups first for phase in filter(lambda x: x.submitted and not x.skipped, release.phases): try: actions = fetch_artifact(phase.task_id, "public/actions.json") parameters = fetch_artifact(phase.task_id, "public/parameters.yml") except ArtifactNotFound: logger.info("Ignoring not completed action task %s", phase.task_id) continue hook = generate_action_hook(task_group_id=phase.task_id, action_name="cancel-all", actions=actions, parameters=parameters, input_={}) hooks = get_service("hooks") client_id = hooks.options["credentials"]["clientId"].decode( "utf-8") hook["context"]["clientId"] = client_id hook_payload_rendered = render_action_hook( payload=hook["hook_payload"], context=hook["context"], delete_params=[ "existing_tasks", "release_history", "release_partner_config" ]) logger.info("Cancel phase %s by hook %s with payload: %s", phase.name, hook["hook_id"], hook_payload_rendered) res = hooks.triggerHook(hook["hook_group_id"], hook["hook_id"], hook_payload_rendered) logger.debug("Done: %s", res) release.status = "aborted" session.commit() release_json = release.json except NoResultFound: abort(404) notify_via_irc( release.product, f"Release {release.product} {release.version} build{release.build_number} was just canceled." ) return release_json
def actions(self): return fetch_artifact(self.decision_task_id, 'public/actions.json')
def parameters(self): return fetch_artifact(self.decision_task_id, 'public/parameters.yml')
def abandon_release(name): session = current_app.db.session try: release = session.query(Release).filter(Release.name == name).one() # we must require scope which depends on product required_permission = f'{SCOPE_PREFIX}/abandon_release/{release.product}' if not current_user.has_permissions(required_permission): user_permissions = ', '.join(current_user.get_permissions()) abort( 401, f'required permission: {required_permission}, user permissions: {user_permissions}' ) # Cancel all submitted task groups first for phase in filter(lambda x: x.submitted, release.phases): try: actions = fetch_artifact(phase.task_id, 'public/actions.json') parameters = fetch_artifact(phase.task_id, 'public/parameters.yml') except ArtifactNotFound: logger.info('Ignoring not completed action task %s', phase.task_id) continue hook = generate_action_hook( task_group_id=phase.task_id, action_name='cancel-all', actions=actions, parameters=parameters, input_={}, ) hooks = get_service('hooks') client_id = hooks.options['credentials']['clientId'].decode( 'utf-8') hook['context']['clientId'] = client_id hook_payload_rendered = render_action_hook( payload=hook['hook_payload'], context=hook['context'], delete_params=[ 'existing_tasks', 'release_history', 'release_partner_config' ], ) logger.info('Cancel phase %s by hook %s with payload: %s', phase.name, hook['hook_id'], hook_payload_rendered) res = hooks.triggerHook(hook['hook_group_id'], hook['hook_id'], hook_payload_rendered) logger.debug('Done: %s', res) release.status = 'aborted' session.commit() release_json = release.json except NoResultFound: abort(404) notify_via_irc( release.product, f'Release {release.product} {release.version} build{release.build_number} was just canceled.' ) return release_json