[ADD] toggle labels on the runbot

This commit is contained in:
Martin Trigaux 2014-05-28 15:43:35 +02:00
parent d0e313cdfd
commit 08f2a10d84
2 changed files with 51 additions and 1 deletions

View File

@ -179,7 +179,7 @@ class runbot_repo(osv.osv):
p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits. p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits.
p2.communicate()[0] p2.communicate()[0]
def github(self, cr, uid, ids, url, payload=None, context=None): def github(self, cr, uid, ids, url, payload=None, delete=False, context=None):
for repo in self.browse(cr, uid, ids, context=context): for repo in self.browse(cr, uid, ids, context=context):
mo = re.search('([^/]+)/([^/]+)/([^/]+)', repo.base) mo = re.search('([^/]+)/([^/]+)/([^/]+)', repo.base)
if mo: if mo:
@ -191,6 +191,8 @@ class runbot_repo(osv.osv):
s.headers.update({'Accept': 'application/vnd.github.she-hulk-preview+json'}) s.headers.update({'Accept': 'application/vnd.github.she-hulk-preview+json'})
if payload: if payload:
r = s.post(url, data=simplejson.dumps(payload)) r = s.post(url, data=simplejson.dumps(payload))
elif delete:
r = s.delete(url)
else: else:
r = s.get(url) r = s.get(url)
return r.json() return r.json()
@ -854,6 +856,51 @@ class RunbotController(http.Controller):
repo_id = registry['runbot.build'].force(cr, 1, [int(build_id)]) repo_id = registry['runbot.build'].force(cr, 1, [int(build_id)])
return werkzeug.utils.redirect('/runbot/repo/%s' % repo_id) return werkzeug.utils.redirect('/runbot/repo/%s' % repo_id)
@http.route(['/runbot/build/<build_id>/label/<label_id>'], type='http', auth="public", method='POST')
def toggle_label(self, build_id=None, label_id=None, search=None, **post):
registry, cr, uid, context = request.registry, request.cr, 1, request.context
build = registry['runbot.build'].browse(cr, uid, [int(build_id)])[0]
issue_number = build.branch_id.name.split('/')
if len(issue_number) == 3 and issue_number[0] == 'refs' and issue_number[1] == 'pull':
issue_number = int(issue_number[2])
else:
# not a pull request
return False
if label_id not in LABELS:
_logger.exception("unknown label")
else:
label_name = LABELS[label_id]
found = False
try:
res = build.repo_id.github('/repos/:owner/:repo/issues/%s/labels' % issue_number)
found = any([label for label in res if label['name'] == label_name])
except Exception, e:
_logger.exception("github error while fetching labels")
if found:
# removing existing label
try:
build.repo_id.github('/repos/:owner/:repo/issues/%s/labels/%s' % (issue_number, label_name), delete=True)
_logger.debug("removed github label %s for %s: %s", (label_name, issue_number))
except Exception, e:
_logger.exception("github error while removing label %s" % label_name)
else:
# adding the label
try:
build.repo_id.github('/repos/:owner/:repo/issues/%s/labels' % issue_number, [label_name])
_logger.debug("added github label %s for %s: %s", (label_name, issue_number))
except Exception, e:
_logger.exception("github error while adding label %s" % label_name)
return True
LABELS = {
1: 'WIP',
2: 'RD',
}
# kill ` ps faux | grep ./static | awk '{print $2}' ` # kill ` ps faux | grep ./static | awk '{print $2}' `
# ps faux| grep Cron | grep -- '-all' | awk '{print $2}' | xargs kill # ps faux| grep Cron | grep -- '-all' | awk '{print $2}' | xargs kill
# psql -l | grep " 000" | awk '{print $1}' | xargs -n1 dropdb # psql -l | grep " 000" | awk '{print $1}' | xargs -n1 dropdb

View File

@ -240,6 +240,9 @@
<li><a t-attf-href="https://{{bu.repo_id.base}}/compare/{{bu.branch_id.branch_name}}">Compare <i class="fa fa-github"/></a></li> <li><a t-attf-href="https://{{bu.repo_id.base}}/compare/{{bu.branch_id.branch_name}}">Compare <i class="fa fa-github"/></a></li>
<!-- TODO branch.pull from --> <!-- TODO branch.pull from -->
<li class="divider"></li> <li class="divider"></li>
<li><a t-attf-href="#" t-attf-onclick="$.post('/runbot/build/{{bu.id}}/label/1')">Toggle WIP label</a></li>
<li><a t-attf-href="#" t-attf-onclick="$.post('/runbot/build/{{bu.id}}/label/2')">Toggle RD label</a></li>
<li class="divider"></li>
<li class="disabled"><a href="#">Runtime: <t t-esc="bu.job_time"/>s</a></li> <li class="disabled"><a href="#">Runtime: <t t-esc="bu.job_time"/>s</a></li>
<li class="disabled"><a href="#">Port: <t t-esc="bu.port"/></a></li> <li class="disabled"><a href="#">Port: <t t-esc="bu.port"/></a></li>
<li class="disabled"><a href="#">Age: <t t-esc="s2h(bu.job_age)"/></a></li> <li class="disabled"><a href="#">Age: <t t-esc="s2h(bu.job_age)"/></a></li>