diff options
author | Ed Bartosh <eduard.bartosh@intel.com> | 2015-02-12 16:05:00 +0200 |
---|---|---|
committer | Ed Bartosh <eduard.bartosh@intel.com> | 2015-02-13 14:04:22 +0200 |
commit | 096cc22035ecb46f538d0ed2b3dc062ddd5abf3b (patch) | |
tree | 9bb04f2cf89ad1960d72bb06a66b49b9a08c5902 | |
parent | 8a7cff9d19c89f025527eba426ec1dec29cf41d5 (diff) | |
download | repa-096cc22035ecb46f538d0ed2b3dc062ddd5abf3b.tar.gz repa-096cc22035ecb46f538d0ed2b3dc062ddd5abf3b.tar.bz2 repa-096cc22035ecb46f538d0ed2b3dc062ddd5abf3b.zip |
Use jenkins job to accept and reject submissions
Implemented -j --jenkins command line option for repa reject and
repa accept subcommands.
With this option repa will trigger 're' jenkins job instead of creating
SR directly on OBS. With this functionality RE doesn't need to be a mainainer
of OBS project to be able to accept and reject submissions.
Fixes: #2412
Change-Id: I7ad07ca18595083cb7a91ac0a4af7fc297c89119
Signed-off-by: Ed Bartosh <eduard.bartosh@intel.com>
-rw-r--r-- | repa.1 | 12 | ||||
-rw-r--r-- | repa/accept.py | 11 | ||||
-rw-r--r-- | repa/common.py | 43 | ||||
-rw-r--r-- | repa/reject.py | 11 |
4 files changed, 63 insertions, 14 deletions
@@ -249,6 +249,12 @@ Print short help text about the "accept" command and exit. Add acceptance comment for created SR. .RE +.PP +\-j \-\-jenkins +.RS 2 +Trigger Jenkins job to accept submission. +.RE + .\" .\" The "reject" command description .\" @@ -275,6 +281,12 @@ Print short help text about the "reject" command and exit. Add rejection comment for created SR. .RE +.PP +\-j \-\-jenkins +.RS 2 +Trigger Jenkins job to reject submission. +.RE + .\" .\" The "group" command description .\" diff --git a/repa/accept.py b/repa/accept.py index 7c561da..410952d 100644 --- a/repa/accept.py +++ b/repa/accept.py @@ -30,6 +30,7 @@ Accept submissions. """ import sys +from collections import namedtuple from repa.obs import OBS from repa.main import sub_main @@ -48,13 +49,21 @@ class Accept(object): """Adds arguments to the parser. Called from [sub_]main.""" parser.add_argument('submission', help='submission or group') parser.add_argument('-c', '--comment', help='comment', default='') + parser.add_argument('-j', '--jenkins', action='store_true', + help='trigger Jenkins job') @staticmethod def run(argv): """Command line entry point. Called from [sub_]main.""" obs = OBS(argv.apiurl, argv.apiuser, argv.apipasswd) + + cred = None + if argv.jenkins: + cred = namedtuple('cred', ['url', 'username', 'password'])(\ + argv.jenkins_url, argv.jenkins_user, argv.jenkins_passwd) + return accept_or_reject(obs, argv.submission, 'accepted', - argv.project, argv.comment) + argv.project, argv.comment, cred) if __name__ == '__main__': sys.exit(sub_main(sys.argv[1:], Accept())) diff --git a/repa/common.py b/repa/common.py index 20344aa..7829f52 100644 --- a/repa/common.py +++ b/repa/common.py @@ -35,6 +35,8 @@ import time import json from functools import wraps, partial +from repa.jenkins import trigger_build + OBS_PROJECT_PREFIX = "home:prerelease:" class RepaException(Exception): @@ -82,8 +84,14 @@ def delete_project(obs, name, target): obs.delete_project(project) -def accept_or_reject(obs, submission, state, target, comment=''): - """Create SRs and set their state for one submission or for a group.""" +def accept_or_reject(obs, submission, state, target, comment='', + jenkins_cred=None): + """ + Create SRs and set their state for one submission or for a group. + + This can be done 2 ways - directly using OBS API and by triggering + jenkins job + """ for name, project, meta in _resolve_submissions(obs, submission, target): # osc submitreq [OPTIONS] SOURCEPRJ SOURCEPKG DESTPRJ [DESTPKG] # osc request accept [-m TEXT] ID @@ -99,19 +107,30 @@ def accept_or_reject(obs, submission, state, target, comment=''): % (comment or "submission %s" % str(name), projects, meta['git_tag']) - # Create SR - reqid = obs.create_sr(project, obs.get_source_packages(project), - str(meta['obs_target_prj']), message=message) + target_prj = str(meta['obs_target_prj']) + + if jenkins_cred: + build, status, out = \ + trigger_build('re', {'action': state, + 'submission': str(name), + 'target_project': target_prj, + 'comment': comment}, jenkins_cred) + print "Jenkins job: re, build #%s, status: %s" % (build, status) + print out + else: + # Create SR + reqid = obs.create_sr(project, obs.get_source_packages(project), + target_prj, message=message) - print 'created SR %s' % reqid + print 'created SR %s' % reqid - # and immediately set its state - message = "SR %s is set to %s" % (reqid, state) - if comment: - message += comment - obs.set_sr_state(reqid, state=state, + # and immediately set its state + message = "SR %s is set to %s" % (reqid, state) + if comment: + message += comment + obs.set_sr_state(reqid, state=state, message=str(message), force=True) - print 'set SR state to', state + print 'set SR state to', state # delete submit group if submission.startswith('submitgroup'): diff --git a/repa/reject.py b/repa/reject.py index 89bcbbe..4f8290a 100644 --- a/repa/reject.py +++ b/repa/reject.py @@ -30,6 +30,7 @@ Accept submissions. """ import sys +from collections import namedtuple from repa.obs import OBS from repa.main import sub_main @@ -48,13 +49,21 @@ class Reject(object): """Adds arguments to the parser. Called from [sub_]main.""" parser.add_argument('submission', help='submission or group') parser.add_argument('-c', '--comment', help='comment', default='') + parser.add_argument('-j', '--jenkins', action='store_true', + help='trigger Jenkins job') @staticmethod def run(argv): """Command line entry point. Called from [sub_]main.""" obs = OBS(argv.apiurl, argv.apiuser, argv.apipasswd) + + cred = None + if argv.jenkins: + cred = namedtuple('cred', ['url', 'username', 'password'])(\ + argv.jenkins_url, argv.jenkins_user, argv.jenkins_passwd) + return accept_or_reject(obs, argv.submission, 'declined', - argv.project, argv.comment) + argv.project, argv.comment, cred) if __name__ == '__main__': sys.exit(sub_main(sys.argv[1:], Reject())) |