]>
git.ipfire.org Git - pbs.git/blob - src/web/builds.py
1440f1c6ac9872261b2b30e00fd992bdadbcc93a
5 from ..errors
import NoSuchDistroError
9 from . import ui_modules
11 class APIv1IndexHandler(base
.APIMixin
, base
.BaseHandler
):
12 # Allow users to create builds
15 @tornado.web
.authenticated
18 upload
= self
.get_argument_upload("upload_id")
20 raise tornado
.web
.HTTPError(404, "Could not find upload")
22 # Check permissions of the upload
23 if not upload
.has_perm(self
.current_user
):
24 raise tornado
.web
.HTTPError(403, "No permission for using upload %s" % upload
)
26 # Fetch the repository
27 repo_name
= self
.get_argument("repo", None)
29 # Did the uploader request to disable test builds?
30 disable_test_builds
= self
.get_argument_bool("disable_test_builds")
32 with self
.db
.transaction():
35 package
= await self
.backend
.packages
.create(upload
)
37 # If the distribution that is coded into the package could not be found,
38 # we will send that error to the user...
39 except NoSuchDistroError
as e
:
40 raise tornado
.web
.HTTPError(404, "Could not find distribution: %s" % e
)
44 repo
= self
.current_user
.get_repo(package
.distro
, repo_name
)
46 raise tornado
.web
.HTTPError(404, "Could not find repository")
49 build
= await self
.backend
.builds
.create(repo
, package
,
50 owner
=self
.current_user
, disable_test_builds
=disable_test_builds
)
52 # If anything goes wrong, we will try to delete the package again
53 except Exception as e
:
54 await package
.delete(user
=self
.current_user
)
61 # Send some data about the build
64 "name" : "%s" % build
,
67 # Launch all jobs (in the background)
68 self
.backend
.run_task(self
.backend
.builds
.launch
, [build
])
71 class IndexHandler(base
.BaseHandler
):
74 offset
= self
.get_argument_int("offset", None) or 0
75 limit
= self
.get_argument_int("limit", None) or 25
78 name
= self
.get_argument("name", None)
79 user
= self
.get_argument_user("user", None)
81 # Fetch the most recent builds
83 builds
= user
.get_builds(name
, limit
=limit
, offset
=offset
)
85 builds
= self
.backend
.builds
.get_recent(name
=name
, limit
=limit
, offset
=offset
)
87 # Group builds by date
88 builds
= misc
.group(builds
, lambda build
: build
.created_at
.date())
90 self
.render("builds/index.html", builds
=builds
, name
=name
, user
=user
,
91 limit
=limit
, offset
=offset
)
94 class ShowHandler(base
.BaseHandler
):
95 async def get(self
, uuid
):
96 build
= self
.backend
.builds
.get_by_uuid(uuid
)
98 raise tornado
.web
.HTTPError(404, "Could not find build %s" % uuid
)
100 # Fetch any fixed Bugs
101 bugs
= await build
.get_bugs()
103 self
.render("builds/show.html", build
=build
, pkg
=build
.pkg
,
104 distro
=build
.distro
, bugs
=bugs
)
107 class CloneHandler(base
.BaseHandler
):
108 @tornado.web
.authenticated
110 build
= self
.backend
.builds
.get_by_uuid(uuid
)
112 raise tornado
.web
.HTTPError(404, "Could not find build %s" % uuid
)
116 repos
= self
.current_user
.repos
[build
.distro
]
120 self
.render("builds/clone.html", build
=build
, repos
=repos
)
122 @tornado.web
.authenticated
123 async def post(self
, uuid
):
124 build
= self
.backend
.builds
.get_by_uuid(uuid
)
126 raise tornado
.web
.HTTPError(404, "Could not find build %s" % uuid
)
128 # Fetch the repository
129 repo
= self
.current_user
.get_repo(build
.distro
, self
.get_argument("repo"))
132 with self
.db
.transaction():
133 clone
= await self
.backend
.builds
.create(
134 repo
=repo
, package
=build
.pkg
, owner
=self
.current_user
,
137 # Launch all jobs (in the background)
138 self
.backend
.run_task(self
.backend
.builds
.launch
, [clone
])
140 self
.redirect("/builds/%s" % clone
.uuid
)
143 class DeleteHandler(base
.BaseHandler
):
144 @tornado.web
.authenticated
146 build
= self
.backend
.builds
.get_by_uuid(uuid
)
148 raise tornado
.web
.HTTPError(404, "Could not find build %s" % uuid
)
151 if not build
.can_be_deleted(self
.current_user
):
152 raise tornado
.web
.HTTPError(403, "%s cannot delete build %s" \
153 % (self
.current_user
, build
))
155 self
.render("builds/delete.html", build
=build
)
157 @tornado.web
.authenticated
158 async def post(self
, uuid
):
159 build
= self
.backend
.builds
.get_by_uuid(uuid
)
161 raise tornado
.web
.HTTPError(404, "Could not find build %s" % uuid
)
164 if not build
.can_be_deleted(self
.current_user
):
165 raise tornado
.web
.HTTPError(403, "%s cannot delete build %s" \
166 % (self
.current_user
, build
))
169 with self
.db
.transaction():
170 await build
.delete(self
.current_user
)
172 self
.redirect("/builds")
175 class WatchHandler(base
.BaseHandler
):
176 @tornado.web
.authenticated
177 def post(self
, uuid
):
178 build
= self
.backend
.builds
.get_by_uuid(uuid
)
180 raise tornado
.web
.HTTPError(404, "Could not find build %s" % uuid
)
182 with self
.db
.transaction():
183 build
.add_watcher(self
.current_user
)
185 self
.redirect("/builds/%s" % build
.uuid
)
188 class UnwatchHandler(base
.BaseHandler
):
189 @tornado.web
.authenticated
190 def post(self
, uuid
):
191 build
= self
.backend
.builds
.get_by_uuid(uuid
)
193 raise tornado
.web
.HTTPError(404, "Could not find build %s" % uuid
)
195 with self
.db
.transaction():
196 build
.remove_watcher(self
.current_user
)
198 self
.redirect("/builds/%s" % build
.uuid
)
201 class CommentHandler(base
.BaseHandler
):
202 @tornado.web
.authenticated
203 async def post(self
, uuid
):
204 build
= self
.backend
.builds
.get_by_uuid(uuid
)
206 raise tornado
.web
.HTTPError(404, "Could not find build %s" % uuid
)
208 text
= self
.get_argument("text")
210 # Add a new comment to the build
211 with self
.db
.transaction():
212 await build
.comment(self
.current_user
, text
)
214 # Redirect to the build
215 self
.redirect("/builds/%s" % build
.uuid
)
218 class BugHandler(base
.BaseHandler
):
219 @tornado.web
.authenticated
220 async def get(self
, uuid
):
221 build
= self
.backend
.builds
.get_by_uuid(uuid
)
223 raise tornado
.web
.HTTPError(404, "Could not find build %s" % uuid
)
226 fields
= await self
.backend
.bugzilla
.fields
228 self
.render("builds/bug.html", build
=build
, fields
=fields
)
230 @tornado.web
.authenticated
231 async def post(self
, uuid
):
232 build
= self
.backend
.builds
.get_by_uuid(uuid
)
234 raise tornado
.web
.HTTPError(404, "Could not find build %s" % uuid
)
236 # Is the user connected to Bugzilla?
237 if not self
.current_user
.bugzilla
:
238 raise tornado
.web
.HTTPError(400, "%s is not connected to Bugzilla" \
242 # Summary & Description
243 "summary" : self
.get_argument("summary"),
244 "description" : self
.get_argument("description", None),
245 } | build
.bugzilla_fields
248 bug
= await self
.current_user
.bugzilla
.create_bug(**kwargs
)
250 # Send the attachments
251 for job
in build
.jobs
:
252 if not self
.get_argument_bool("attach_log_%s" % job
.uuid
):
257 log
= await job
.open_log()
258 except FileNotFoundError
as e
:
259 log
.warning("Could not open log file for %s" % job
)
262 # Attach it to the bug
263 await bug
.attach(summary
="Log file for %s" % job
, filename
="%s.log" % job
,
264 data
=log
, content_type
="text/plain")
266 self
.render("builds/bug-created.html", build
=build
, bug
=bug
)
269 class ReposAddHandler(base
.BaseHandler
):
270 @tornado.web
.authenticated
272 build
= self
.backend
.builds
.get_by_uuid(uuid
)
274 raise tornado
.web
.HTTPError(404, "Could not find build %s" % uuid
)
276 # Fetch all available repositories
278 repos
= self
.current_user
.repos
[build
.distro
]
282 self
.render("builds/repos/add.html", build
=build
, repos
=repos
)
284 @tornado.web
.authenticated
285 async def post(self
, uuid
):
286 build
= self
.backend
.builds
.get_by_uuid(uuid
)
288 raise tornado
.web
.HTTPError(404, "Could not find build %s" % uuid
)
290 slug
= self
.get_argument("repo")
292 # Fetch the repository
293 repo
= self
.current_user
.get_repo(build
.distro
, slug
)
295 raise tornado
.web
.HTTPError(400, "Could not find repository '%s'" % slug
)
297 # Add the build to the repository
298 with self
.db
.transaction():
299 await repo
.add_build(build
, user
=self
.current_user
)
301 self
.redirect("/builds/%s" % build
.uuid
)
304 class ReposRemoveHandler(base
.BaseHandler
):
305 @tornado.web
.authenticated
307 build
= self
.backend
.builds
.get_by_uuid(uuid
)
309 raise tornado
.web
.HTTPError(404, "Could not find build %s" % uuid
)
311 # Raise error when the build is in to repositories
313 raise tornado
.web
.HTTPError(400)
315 self
.render("builds/repos/remove.html", build
=build
)
317 @tornado.web
.authenticated
318 async def post(self
, uuid
):
319 build
= self
.backend
.builds
.get_by_uuid(uuid
)
321 raise tornado
.web
.HTTPError(404, "Could not find build %s" % uuid
)
323 # Fetch all selected repos
324 repos
= self
.get_arguments("repo")
326 # Raise an error if nothing has been selected
328 raise tornado
.web
.HTTPError(400, "No repositories selected")
330 # Find all selected repositories
331 repos
= [repo
for repo
in build
.repos
if repo
.slug
in repos
]
333 # Remove build from all repositories
334 with self
.db
.transaction():
336 await repo
.remove_build(build
, user
=self
.current_user
)
338 self
.redirect("/builds/%s" % build
.uuid
)
341 class GroupShowHandler(base
.BaseHandler
):
343 group
= self
.backend
.builds
.groups
.get_by_uuid(uuid
)
345 raise tornado
.web
.HTTPError(404, "Could not find build group %s" % uuid
)
347 self
.render("builds/groups/show.html", group
=group
)
350 class ListModule(ui_modules
.UIModule
):
351 def render(self
, builds
, limit
=None, shorter
=False, more_url
=None):
356 builds
, rest
= builds
[:limit
], builds
[limit
:]
358 return self
.render_string("builds/modules/list.html", builds
=builds
,
359 rest
=rest
, shorter
=shorter
, more_url
=more_url
)
362 class GroupListModule(ui_modules
.UIModule
):
363 def render(self
, group
, limit
=None):
364 return self
.render_string("builds/groups/modules/list.html",
365 group
=group
, limit
=limit
)
368 class WatchersModule(ui_modules
.UIModule
):
369 def render(self
, build
, watchers
=None):
371 watchers
= build
.watchers
373 return self
.render_string("builds/modules/watchers.html",
374 build
=build
, watchers
=watchers
)