Skip to content

Commit

Permalink
Bug 1323110 - Return taskcluster information in job detail endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
wlach committed Feb 21, 2017
1 parent f0eaf7f commit 6832102
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
16 changes: 16 additions & 0 deletions tests/webapp/api/test_jobs_api.py
Expand Up @@ -9,6 +9,7 @@
from treeherder.model.models import (ExclusionProfile,
Job,
JobExclusion,
TaskclusterMetadata,
TextLogError,
TextLogStep)
from treeherder.webapp.api.jobs import JobsViewSet
Expand Down Expand Up @@ -241,6 +242,21 @@ def test_job_detail(webapp, test_job):
assert resp.status_int == 200
assert isinstance(resp.json, dict)
assert resp.json["id"] == test_job.id
assert not resp.json.get("taskcluster_metadata")

# add some taskcluster metadata to the test job so we can test that too
tm = TaskclusterMetadata.objects.create(job=test_job,
task_id='IYyscnNMTLuxzna7PNqUJQ',
retry_id=0)
resp = webapp.get(
reverse("jobs-detail",
kwargs={"project": test_job.repository.name,
"pk": test_job.id})
)
assert resp.json["taskcluster_metadata"] == {
"task_id": tm.task_id,
"retry_id": tm.retry_id
}


def test_job_retrigger_unauthorized(webapp, test_repository):
Expand Down
10 changes: 9 additions & 1 deletion treeherder/webapp/api/jobs.py
Expand Up @@ -235,7 +235,7 @@ def retrieve(self, request, project, pk=None):
"""
try:
job = Job.objects.select_related(
*self._default_select_related).get(
*self._default_select_related + ['taskcluster_metadata']).get(
repository__name=project, id=pk)
except Job.DoesNotExist:
return Response("No job with id: {0}".format(pk), status=HTTP_404_NOT_FOUND)
Expand All @@ -253,6 +253,14 @@ def retrieve(self, request, project, pk=None):
if platform_option:
resp["platform_option"] = platform_option

try:
resp['taskcluster_metadata'] = {
'task_id': job.taskcluster_metadata.task_id,
'retry_id': job.taskcluster_metadata.retry_id
}
except ObjectDoesNotExist:
pass

return Response(resp)

def list(self, request, project):
Expand Down

0 comments on commit 6832102

Please sign in to comment.