Merge "zuul-web: fix traceback in "job" endpoint if a job doesn't exist"

This commit is contained in:
Zuul
2025-04-22 14:22:38 +00:00
committed by Gerrit Code Review
2 changed files with 6 additions and 0 deletions

View File

@ -1206,6 +1206,10 @@ class TestWeb(BaseTestWeb):
self.assertIsNotNone(post_job)
self.assertEqual(['post'], post_job.get('tags'))
def test_web_nonexistent_job(self):
resp = self.get_url("api/tenant/tenant-one/job/nopenopenope")
self.assertEqual(404, resp.status_code)
def test_web_job_noop(self):
job = self.get_url("api/tenant/tenant-one/job/noop").json()
self.assertEqual("noop", job[0]["name"])

View File

@ -1887,6 +1887,8 @@ class ZuulWebAPI(object):
def job(self, tenant_name, tenant, auth, job_name):
job_name = urllib.parse.unquote_plus(job_name)
job_variants = tenant.layout.jobs.get(job_name)
if job_variants is None:
raise cherrypy.HTTPError(404, "Job not found")
result = []
for job in job_variants:
result.append(job.toDict(tenant))