]>
git.ipfire.org Git - pbs.git/blob - src/web/builds.py
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
)
43 repo
= self
.current_user
.get_repo(package
.distro
, repo_name
)
45 raise tornado
.web
.HTTPError(404, "Could not find repository")
48 build
= await self
.backend
.builds
.create(repo
, package
,
49 owner
=self
.current_user
, disable_test_builds
=disable_test_builds
)
54 # Send some data about the build
57 "name" : "%s" % build
,
60 # Launch all jobs (in the background)
61 self
.backend
.run_task(self
.backend
.builds
.launch
, [build
])
64 class IndexHandler(base
.BaseHandler
):
67 offset
= self
.get_argument_int("offset", None) or 0
68 limit
= self
.get_argument_int("limit", None) or 25
71 user
= self
.get_argument_user("user", None)
73 # Fetch the most recent builds
75 builds
= self
.backend
.builds
.get_by_user(user
, limit
=limit
, offset
=offset
)
77 builds
= self
.backend
.builds
.get_recent(limit
=limit
, offset
=offset
)
79 # Group builds by date
80 builds
= misc
.group(builds
, lambda build
: build
.created_at
.date())
82 self
.render("builds/index.html", builds
=builds
, user
=user
,
83 limit
=limit
, offset
=offset
)
86 class ShowHandler(base
.BaseHandler
):
87 async def get(self
, uuid
):
88 build
= self
.backend
.builds
.get_by_uuid(uuid
)
90 raise tornado
.web
.HTTPError(404, "Could not find build %s" % uuid
)
92 # Fetch any fixed Bugs
93 bugs
= await build
.get_bugs()
95 self
.render("builds/show.html", build
=build
, pkg
=build
.pkg
,
96 distro
=build
.distro
, bugs
=bugs
)
99 class DeleteHandler(base
.BaseHandler
):
100 @tornado.web
.authenticated
102 build
= self
.backend
.builds
.get_by_uuid(uuid
)
104 raise tornado
.web
.HTTPError(404, "Could not find build %s" % uuid
)
107 if not build
.can_be_deleted(self
.current_user
):
108 raise tornado
.web
.HTTPError(403, "%s cannot delete build %s" \
109 % (self
.current_user
, build
))
111 self
.render("builds/delete.html", build
=build
)
113 @tornado.web
.authenticated
114 async def post(self
, uuid
):
115 build
= self
.backend
.builds
.get_by_uuid(uuid
)
117 raise tornado
.web
.HTTPError(404, "Could not find build %s" % uuid
)
120 if not build
.can_be_deleted(self
.current_user
):
121 raise tornado
.web
.HTTPError(403, "%s cannot delete build %s" \
122 % (self
.current_user
, build
))
125 with self
.db
.transaction():
126 await build
.delete(self
.current_user
)
128 self
.redirect("/builds")
131 class WatchHandler(base
.BaseHandler
):
132 @tornado.web
.authenticated
133 def post(self
, uuid
):
134 build
= self
.backend
.builds
.get_by_uuid(uuid
)
136 raise tornado
.web
.HTTPError(404, "Could not find build %s" % uuid
)
138 with self
.db
.transaction():
139 build
.add_watcher(self
.current_user
)
141 self
.redirect("/builds/%s" % build
.uuid
)
144 class UnwatchHandler(base
.BaseHandler
):
145 @tornado.web
.authenticated
146 def post(self
, uuid
):
147 build
= self
.backend
.builds
.get_by_uuid(uuid
)
149 raise tornado
.web
.HTTPError(404, "Could not find build %s" % uuid
)
151 with self
.db
.transaction():
152 build
.remove_watcher(self
.current_user
)
154 self
.redirect("/builds/%s" % build
.uuid
)
157 class CommentHandler(base
.BaseHandler
):
158 @tornado.web
.authenticated
159 def post(self
, uuid
):
160 build
= self
.backend
.builds
.get_by_uuid(uuid
)
162 raise tornado
.web
.HTTPError(404, "Could not find build %s" % uuid
)
164 text
= self
.get_argument("text")
166 # Add a new comment to the build
167 with self
.db
.transaction():
168 build
.comment(self
.current_user
, text
)
170 # Redirect to the build
171 self
.redirect("/builds/%s" % build
.uuid
)
174 class BugHandler(base
.BaseHandler
):
175 @tornado.web
.authenticated
176 async def get(self
, uuid
):
177 build
= self
.backend
.builds
.get_by_uuid(uuid
)
179 raise tornado
.web
.HTTPError(404, "Could not find build %s" % uuid
)
182 fields
= await self
.backend
.bugzilla
.fields
184 self
.render("builds/bug.html", build
=build
, fields
=fields
)
186 @tornado.web
.authenticated
187 async def post(self
, uuid
):
188 build
= self
.backend
.builds
.get_by_uuid(uuid
)
190 raise tornado
.web
.HTTPError(404, "Could not find build %s" % uuid
)
192 # Is the user connected to Bugzilla?
193 if not self
.current_user
.bugzilla
:
194 raise tornado
.web
.HTTPError(400, "%s is not connected to Bugzilla" \
198 # Summary & Description
199 "summary" : self
.get_argument("summary"),
200 "description" : self
.get_argument("description", None),
201 } | build
.bugzilla_fields
204 bug
= await self
.current_user
.bugzilla
.create_bug(**kwargs
)
206 # Send the attachments
207 for job
in build
.jobs
:
208 if not self
.get_argument_bool("attach_log_%s" % job
.uuid
):
213 log
= await job
.open_log()
214 except FileNotFoundError
as e
:
215 log
.warning("Could not open log file for %s" % job
)
218 # Attach it to the bug
219 await bug
.attach(summary
="Log file for %s" % job
, filename
="%s.log" % job
,
220 data
=log
, content_type
="text/plain")
222 self
.render("builds/bug-created.html", build
=build
, bug
=bug
)
225 class GroupShowHandler(base
.BaseHandler
):
227 group
= self
.backend
.builds
.groups
.get_by_uuid(uuid
)
229 raise tornado
.web
.HTTPError(404, "Could not find build group %s" % uuid
)
231 self
.render("builds/groups/show.html", group
=group
)
234 class ListModule(ui_modules
.UIModule
):
235 def render(self
, builds
):
236 return self
.render_string("builds/modules/list.html", builds
=builds
)
239 class GroupListModule(ui_modules
.UIModule
):
240 def render(self
, group
, limit
=None):
241 return self
.render_string("builds/groups/modules/list.html",
242 group
=group
, limit
=limit
)
245 class WatchersModule(ui_modules
.UIModule
):
246 def render(self
, build
, watchers
=None):
248 watchers
= build
.watchers
250 return self
.render_string("builds/modules/watchers.html",
251 build
=build
, watchers
=watchers
)