Add ReviewBot to check for bugowner lines in requests for new packages

This commit is contained in:
Stephan Kulow 2022-03-10 10:34:16 +01:00
parent 807b0f93a4
commit a80184d44e
3 changed files with 97 additions and 4 deletions

View File

@ -322,11 +322,20 @@ packagers and creating SR from FactoryCandidates to the Leap project on successf
#### issue-diff.py
Compares packages from a project against factory for differences in referenced issues and presents
changes to allow whitelisting before creating Bugzilla entries.
changes to allow whitelisting before creating Bugzilla entries. It's used to check Factory packages
have all the bug references fixed in SLE (i.e. if 'Factory First' policy was correctly applied).
* Sources: [issue-diff.py](issue-diff.py)
* Documentation: --
* Package: openSUSE-release-tools
* Usage: ???
* Usage: manually
### check_bugowner.py
Verifies requests for new packages have a bugowner line in the request description (used in SLE where we don't have
devel projects).
* Sources: [check_bugowner.py](check_bugowner.py)
* Documentation: --
* Package: openSUSE-release-tools
* Usage: gocd

View File

@ -289,8 +289,10 @@ class ReviewBot(object):
self.add_review(req, by_group=by_group, by_user=by_user, msg='Adding fallback reviewer')
if doit:
self.logger.debug("setting %s to %s" % (req.reqid, state))
if not self.dryrun:
if self.dryrun:
self.logger.info("(dryrun) would set %s to %s with message %s" % (req.reqid, state, msg))
else:
self.logger.debug("setting %s to %s" % (req.reqid, state))
try:
osc.core.change_review_state(apiurl=self.apiurl,
reqid=req.reqid, newstate=newstate,

82
check_bugowner.py Executable file
View File

@ -0,0 +1,82 @@
#!/usr/bin/python3
# SPDX-License-Identifier: MIT
import sys
import re
from urllib.error import HTTPError
import osc.conf
import osc.core
import ReviewBot
http_GET = osc.core.http_GET
class CheckerBugowner(ReviewBot.ReviewBot):
def __init__(self, *args, **kwargs):
ReviewBot.ReviewBot.__init__(self, *args, **kwargs)
def check_source_submission(self, src_project, src_package, src_rev, target_project, target_package):
self.logger.info("%s/%s@%s -> %s/%s" % (src_project,
src_package, src_rev, target_project, target_package))
if src_package == 'patchinfo':
return True
if self.exists_in(target_project, target_package):
return True
for line in self.request.description.splitlines():
matched_package = None
matched_maintainer = None
m = re.match(r'bugowner:\s*(\S*)\s*$', line)
if m:
matched_maintainer = m.group(1)
m = re.match(r'bugowner:\s(\S*)\s(\S*)\s*$', line)
if m:
matched_maintainer = m.group(2)
matched_package = m.group(1)
if not matched_maintainer:
continue
if matched_package and matched_package != target_package:
continue
if not self.valid_maintainer(matched_maintainer):
self.review_messages['declined'] += f"\n{matched_maintainer} could not be found on this instance."
return False
return True
self.review_messages['declined'] += f"\n{target_package } appears to be a new package and " + \
"no 'bugowner' line could be found in the request description."
return False
def existing_url(self, url):
"Return False if url returns 404"
try:
osc.core.http_GET(url)
except HTTPError as e:
if e.code == 404:
return False
return True
def valid_maintainer(self, maintainer):
if maintainer.startswith('group:'):
maintainer = maintainer.replace('group:', '')
url = osc.core.makeurl(self.apiurl, ['group', maintainer])
return self.existing_url(url)
url = osc.core.makeurl(self.apiurl, ['person', maintainer])
return self.existing_url(url)
def exists_in(self, project, package):
url = osc.core.makeurl(self.apiurl, ['source', project, package])
return self.existing_url(url)
class CommandLineInterface(ReviewBot.CommandLineInterface):
def __init__(self, *args, **kwargs):
ReviewBot.CommandLineInterface.__init__(self, args, kwargs)
self.clazz = CheckerBugowner
if __name__ == "__main__":
app = CommandLineInterface()
sys.exit(app.main())