2022-03-10 10:34:16 +01:00
|
|
|
#!/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)
|
2022-03-11 11:15:36 +01:00
|
|
|
self.request_default_return = True
|
2022-04-05 16:41:26 +02:00
|
|
|
self.override_allow = False
|
2022-03-10 10:34:16 +01:00
|
|
|
|
|
|
|
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))
|
2022-03-10 12:01:19 +01:00
|
|
|
if src_package.startswith('patchinfo'):
|
2022-03-10 10:34:16 +01:00
|
|
|
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
|
2022-08-30 09:39:03 +02:00
|
|
|
m = re.match(r'\s*bugowner:\s*(\S*)\s*$', line)
|
2022-03-10 10:34:16 +01:00
|
|
|
if m:
|
|
|
|
matched_maintainer = m.group(1)
|
2022-08-30 09:39:03 +02:00
|
|
|
m = re.match(r'\s*bugowner:\s(\S*)\s(\S*)\s*$', line)
|
2022-03-10 10:34:16 +01:00
|
|
|
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):
|
2022-08-29 11:10:21 +02:00
|
|
|
self.review_messages['declined'] += f"\n{matched_maintainer} could not be found on this instance."
|
2022-03-10 10:34:16 +01:00
|
|
|
return False
|
|
|
|
return True
|
|
|
|
self.review_messages['declined'] += f"\n{target_package } appears to be a new package and " + \
|
2022-04-05 16:41:26 +02:00
|
|
|
"no matching 'bugowner:' line could be found in the request description. See https://confluence.suse.com/x/WgH2OQ"
|
2022-03-10 10:34:16 +01:00
|
|
|
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())
|