mirror of
https://github.com/openSUSE/osc.git
synced 2025-08-24 07:08:53 +02:00
support source validators as pre-checkin check
This commit is contained in:
1
NEWS
1
NEWS
@@ -5,6 +5,7 @@
|
|||||||
- fix creation of package link, when target project has the package via linked project
|
- fix creation of package link, when target project has the package via linked project
|
||||||
- add "osc rq approvenew $PROJECT" command to show and accept all request in new state.
|
- add "osc rq approvenew $PROJECT" command to show and accept all request in new state.
|
||||||
This makes sense esp. for projects which work with default reviewers before.
|
This makes sense esp. for projects which work with default reviewers before.
|
||||||
|
- support external source validator script before commiting
|
||||||
#
|
#
|
||||||
# Features which require OBS 2.0
|
# Features which require OBS 2.0
|
||||||
#
|
#
|
||||||
|
@@ -2370,6 +2370,8 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
help='read log message from FILE')
|
help='read log message from FILE')
|
||||||
@cmdln.option('-f', '--force', default=False, action="store_true",
|
@cmdln.option('-f', '--force', default=False, action="store_true",
|
||||||
help='force commit - do not tests a file list')
|
help='force commit - do not tests a file list')
|
||||||
|
@cmdln.option('--skip-validator', default=False, action="store_true",
|
||||||
|
help='Skip the source validator')
|
||||||
def do_commit(self, subcmd, opts, *args):
|
def do_commit(self, subcmd, opts, *args):
|
||||||
"""${cmd_name}: Upload content to the repository server
|
"""${cmd_name}: Upload content to the repository server
|
||||||
|
|
||||||
@@ -2398,6 +2400,13 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
args = parseargs(args)
|
args = parseargs(args)
|
||||||
|
|
||||||
msg = ''
|
msg = ''
|
||||||
|
validator = conf.config['source_validator']
|
||||||
|
if opts.skip_validator:
|
||||||
|
validator = None
|
||||||
|
elif not os.path.exists(validator):
|
||||||
|
print "WARNING: validator", validator, "configured, but not existing. Skipping ..."
|
||||||
|
validator = None
|
||||||
|
|
||||||
if opts.message:
|
if opts.message:
|
||||||
msg = opts.message
|
msg = opts.message
|
||||||
elif opts.file:
|
elif opts.file:
|
||||||
@@ -2409,9 +2418,13 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
arg_list = args[:]
|
arg_list = args[:]
|
||||||
for arg in arg_list:
|
for arg in arg_list:
|
||||||
if conf.config['do_package_tracking'] and is_project_dir(arg):
|
if conf.config['do_package_tracking'] and is_project_dir(arg):
|
||||||
Project(arg).commit(msg=msg)
|
|
||||||
if not msg:
|
if not msg:
|
||||||
msg = edit_message()
|
msg = edit_message()
|
||||||
|
try:
|
||||||
|
Project(arg).commit(msg=msg, validator=validator)
|
||||||
|
except oscerr.RuntimeError, e:
|
||||||
|
print >>sys.stderr, "ERROR: source_validator failed", e
|
||||||
|
return 1
|
||||||
args.remove(arg)
|
args.remove(arg)
|
||||||
|
|
||||||
pacs = findpacs(args)
|
pacs = findpacs(args)
|
||||||
@@ -2458,12 +2471,20 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
else:
|
else:
|
||||||
single_paths.append(pac.dir)
|
single_paths.append(pac.dir)
|
||||||
for prj, packages in prj_paths.iteritems():
|
for prj, packages in prj_paths.iteritems():
|
||||||
Project(prj).commit(tuple(packages), msg, files)
|
try:
|
||||||
|
Project(prj).commit(tuple(packages), msg, files, validator=validator)
|
||||||
|
except oscerr.RuntimeError, e:
|
||||||
|
print >>sys.stderr, "ERROR: source_validator failed", e
|
||||||
|
return 1
|
||||||
for pac in single_paths:
|
for pac in single_paths:
|
||||||
Package(pac).commit(msg)
|
try:
|
||||||
|
Package(pac).commit(msg, validator=validator)
|
||||||
|
except oscerr.RuntimeError, e:
|
||||||
|
print >>sys.stderr, "ERROR: source_validator failed", e
|
||||||
|
return 1
|
||||||
else:
|
else:
|
||||||
for p in pacs:
|
for p in pacs:
|
||||||
p.commit(msg)
|
p.commit(msg, validator=validator)
|
||||||
|
|
||||||
store_unlink_file(os.path.abspath('.'), '_commit_msg')
|
store_unlink_file(os.path.abspath('.'), '_commit_msg')
|
||||||
|
|
||||||
|
@@ -112,6 +112,8 @@ DEFAULTS = { 'apiurl': 'https://api.opensuse.org',
|
|||||||
'request_list_days': 30,
|
'request_list_days': 30,
|
||||||
# check for unversioned/removed files before commit
|
# check for unversioned/removed files before commit
|
||||||
'check_filelist': '1',
|
'check_filelist': '1',
|
||||||
|
# External script to validate sources, esp before commit
|
||||||
|
'source_validator': '/usr/lib/osc/source_validator',
|
||||||
# check for pending requests after executing an action (e.g. checkout, update, commit)
|
# check for pending requests after executing an action (e.g. checkout, update, commit)
|
||||||
'check_for_request_on_action': '0',
|
'check_for_request_on_action': '0',
|
||||||
# what to do with the source package if the submitrequest has been accepted
|
# what to do with the source package if the submitrequest has been accepted
|
||||||
@@ -251,6 +253,9 @@ apiurl = %(apiurl)s
|
|||||||
#review requests interactively (default: off)
|
#review requests interactively (default: off)
|
||||||
#request_show_review = 1
|
#request_show_review = 1
|
||||||
|
|
||||||
|
# Executable to validate sources, esp before committing
|
||||||
|
#source_validator = /usr/lib/osc/source_validator
|
||||||
|
|
||||||
[%(apiurl)s]
|
[%(apiurl)s]
|
||||||
user = %(user)s
|
user = %(user)s
|
||||||
pass = %(pass)s
|
pass = %(pass)s
|
||||||
|
14
osc/core.py
14
osc/core.py
@@ -624,7 +624,7 @@ class Project:
|
|||||||
finally:
|
finally:
|
||||||
self.write_packages()
|
self.write_packages()
|
||||||
|
|
||||||
def commit(self, pacs = (), msg = '', files = {}):
|
def commit(self, pacs = (), msg = '', files = {}, validator = None):
|
||||||
if len(pacs):
|
if len(pacs):
|
||||||
try:
|
try:
|
||||||
for pac in pacs:
|
for pac in pacs:
|
||||||
@@ -643,7 +643,7 @@ class Project:
|
|||||||
else:
|
else:
|
||||||
p = Package(os.path.join(self.dir, pac))
|
p = Package(os.path.join(self.dir, pac))
|
||||||
p.todo = todo
|
p.todo = todo
|
||||||
p.commit(msg)
|
p.commit(msg, validator=validator)
|
||||||
elif pac in self.pacs_unvers and not is_package_dir(os.path.join(self.dir, pac)):
|
elif pac in self.pacs_unvers and not is_package_dir(os.path.join(self.dir, pac)):
|
||||||
print 'osc: \'%s\' is not under version control' % pac
|
print 'osc: \'%s\' is not under version control' % pac
|
||||||
elif pac in self.pacs_broken:
|
elif pac in self.pacs_broken:
|
||||||
@@ -663,7 +663,7 @@ class Project:
|
|||||||
state = self.get_state(pac)
|
state = self.get_state(pac)
|
||||||
if state == ' ':
|
if state == ' ':
|
||||||
# do a simple commit
|
# do a simple commit
|
||||||
Package(os.path.join(self.dir, pac)).commit(msg)
|
Package(os.path.join(self.dir, pac)).commit(msg, validator=validator)
|
||||||
elif state == 'D':
|
elif state == 'D':
|
||||||
self.commitDelPackage(pac)
|
self.commitDelPackage(pac)
|
||||||
elif state == 'A':
|
elif state == 'A':
|
||||||
@@ -896,7 +896,7 @@ class Package:
|
|||||||
|
|
||||||
shutil.copyfile(os.path.join(self.dir, n), os.path.join(self.storedir, n))
|
shutil.copyfile(os.path.join(self.dir, n), os.path.join(self.storedir, n))
|
||||||
|
|
||||||
def commit(self, msg=''):
|
def commit(self, msg='', validator=None):
|
||||||
# commit only if the upstream revision is the same as the working copy's
|
# commit only if the upstream revision is the same as the working copy's
|
||||||
upstream_rev = self.latest_rev()
|
upstream_rev = self.latest_rev()
|
||||||
if self.rev != upstream_rev:
|
if self.rev != upstream_rev:
|
||||||
@@ -907,6 +907,12 @@ class Package:
|
|||||||
|
|
||||||
pathn = getTransActPath(self.dir)
|
pathn = getTransActPath(self.dir)
|
||||||
|
|
||||||
|
if validator:
|
||||||
|
import subprocess
|
||||||
|
p = subprocess.Popen([validator], close_fds=True)
|
||||||
|
if p.wait() != 0:
|
||||||
|
raise oscerr.RuntimeError(p.stdout, validator )
|
||||||
|
|
||||||
have_conflicts = False
|
have_conflicts = False
|
||||||
for filename in self.todo:
|
for filename in self.todo:
|
||||||
if not filename.startswith('_service:') and not filename.startswith('_service_'):
|
if not filename.startswith('_service:') and not filename.startswith('_service_'):
|
||||||
|
@@ -41,6 +41,13 @@ class NoConfigfile(OscBaseError):
|
|||||||
self.file = fname
|
self.file = fname
|
||||||
self.msg = msg
|
self.msg = msg
|
||||||
|
|
||||||
|
class RuntimeError(OscBaseError):
|
||||||
|
"""Exception raised when there is a runtime error of an external tool"""
|
||||||
|
def __init__(self, msg, fname):
|
||||||
|
OscBaseError.__init__(self)
|
||||||
|
self.msg = msg
|
||||||
|
self.file = fname
|
||||||
|
|
||||||
class WrongArgs(OscBaseError):
|
class WrongArgs(OscBaseError):
|
||||||
"""Exception raised by the cli for wrong arguments usage"""
|
"""Exception raised by the cli for wrong arguments usage"""
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user