def get_items_from_common_tc_task(common_task_id, tc_config): tc_task_items = {} queue = Queue(tc_config) task = queue.task(common_task_id) tc_task_items["version"] = task["extra"]["build_props"]["version"] tc_task_items["build_number"] = task["extra"]["build_props"]["build_number"] tc_task_items["mozilla_revision"] = task["extra"]["build_props"]["revision"] tc_task_items["partials"] = task["extra"]["build_props"]["partials"] tc_task_items["mozharness_changeset"] = task["extra"]["build_props"]["mozharness_changeset"] return tc_task_items
class TaskDefinition: """Data and queries about a task definition.""" def __init__(self, json=None, task_id=None, queue=None): """Init.""" # taskId is not provided in the definition if task_id: self.task_id = task_id if json: self.def_json = json.get('task', json) return if not task_id: raise ValueError('No task definition or taskId provided') self.queue = queue if not self.queue: self.queue = Queue(tc_options()) self._fetch_definition() def _fetch_definition(self): self.def_json = self.queue.task(self.task_id) def __repr__(self): """repr.""" return "<TaskDefinition {}>".format(self.task_id) def __str__(self): """Str representation.""" return "<TaskDefinition {}>".format(self.task_id) @property def json(self): """Return json as originally presented.""" return {'task': self.def_json} @property def label(self): """Extract label.""" return self.def_json.get('tags', {}).get( 'label', self.def_json.get('metadata').get('name', '') ) @property def kind(self): """Return the task's kind.""" return self.def_json['tags'].get('kind', '') @property def scopes(self): """Return a list of the scopes used, if any.""" return self.def_json.get('scopes', []) @property def name(self): """Return the name of the task.""" return self.def_json['metadata']['name']
def get_items_from_common_tc_task(common_task_id, tc_config): tc_task_items = {} queue = Queue(tc_config) task = queue.task(common_task_id) tc_task_items["version"] = task["extra"]["build_props"]["version"] tc_task_items["build_number"] = task["extra"]["build_props"][ "build_number"] tc_task_items["mozilla_revision"] = task["extra"]["build_props"][ "revision"] tc_task_items["partials"] = task["extra"]["build_props"]["partials"] tc_task_items["mozharness_changeset"] = task["extra"]["build_props"][ "mozharness_changeset"] return tc_task_items