mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-02-13 10:05:15 +08:00
Add additional info to the module-build(s) API output
This commit is contained in:
committed by
Nils Philippsen
parent
864ba5104e
commit
c79139b82c
@@ -199,11 +199,41 @@ class ModuleBuild(RidaBase):
|
||||
'state': self.state,
|
||||
'state_name': INVERSE_BUILD_STATES[self.state],
|
||||
'scmurl': self.scmurl,
|
||||
'owner': self.owner,
|
||||
'time_submitted': self.time_submitted,
|
||||
'time_modified': self.time_modified,
|
||||
'time_completed': self.time_completed,
|
||||
|
||||
# TODO, show their entire .json() ?
|
||||
'component_builds': [build.id for build in self.component_builds],
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def _utc_datetime_to_iso(datetime_object):
|
||||
"""
|
||||
Takes a UTC datetime object and returns an ISO formatted string
|
||||
:param datetime_object: datetime.datetime
|
||||
:return: string with datetime in ISO format
|
||||
"""
|
||||
if datetime_object:
|
||||
# Converts the datetime to ISO 8601
|
||||
return datetime_object.strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||
|
||||
return None
|
||||
|
||||
def api_json(self):
|
||||
|
||||
return {
|
||||
"id": self.id,
|
||||
"state": self.state,
|
||||
"owner": self.owner,
|
||||
"name": self.name,
|
||||
"time_submitted": self._utc_datetime_to_iso(self.time_submitted),
|
||||
"time_modified": self._utc_datetime_to_iso(self.time_modified),
|
||||
"time_completed": self._utc_datetime_to_iso(self.time_completed),
|
||||
"tasks": self.tasks()
|
||||
}
|
||||
|
||||
def tasks(self):
|
||||
"""
|
||||
:return: dictionary containing the tasks associated with the build
|
||||
|
||||
@@ -175,8 +175,7 @@ def query_builds():
|
||||
}
|
||||
|
||||
if verbose_flag.lower() == 'true' or verbose_flag == '1':
|
||||
json_data['items'] = [{'id': item.id, 'state': item.state, 'tasks': item.tasks()}
|
||||
for item in p_query.items]
|
||||
json_data['items'] = [item.api_json() for item in p_query.items]
|
||||
else:
|
||||
json_data['items'] = [{'id': item.id, 'state': item.state} for item in p_query.items]
|
||||
|
||||
@@ -189,11 +188,6 @@ def query_build(id):
|
||||
module = models.ModuleBuild.query.filter_by(id=id).first()
|
||||
|
||||
if module:
|
||||
|
||||
return jsonify({
|
||||
"id": module.id,
|
||||
"state": module.state,
|
||||
"tasks": module.tasks()
|
||||
}), 200
|
||||
return jsonify(module.api_json()), 200
|
||||
else:
|
||||
return "No such module found.", 404
|
||||
|
||||
Reference in New Issue
Block a user