2019-05-16 06:39:08 +02:00
|
|
|
#!/usr/bin/python3
|
2016-12-29 00:34:56 -06:00
|
|
|
|
2022-03-24 21:19:45 +01:00
|
|
|
import difflib
|
2022-03-24 08:39:20 +01:00
|
|
|
import glob
|
2016-12-29 00:34:56 -06:00
|
|
|
import os
|
2018-08-13 22:47:01 -05:00
|
|
|
import re
|
2016-12-29 00:34:56 -06:00
|
|
|
import shutil
|
|
|
|
import subprocess
|
|
|
|
import sys
|
2022-03-25 07:56:35 +01:00
|
|
|
import tempfile
|
2023-06-21 14:11:18 +02:00
|
|
|
from typing import Optional, Set
|
|
|
|
from cmdln import CmdlnOptionParser
|
2016-12-29 00:34:56 -06:00
|
|
|
|
2022-02-18 10:16:17 +01:00
|
|
|
from lxml import etree as ET
|
2021-07-14 10:45:11 +01:00
|
|
|
|
2017-10-11 22:19:24 -05:00
|
|
|
import osc.conf
|
2016-12-29 00:34:56 -06:00
|
|
|
import osc.core
|
2018-08-16 23:35:10 -05:00
|
|
|
from osclib.conf import Config
|
2018-01-17 18:08:40 -06:00
|
|
|
from osclib.core import devel_project_get
|
2018-01-17 20:36:03 -06:00
|
|
|
from osclib.core import devel_project_fallback
|
2022-08-29 23:54:11 +08:00
|
|
|
from osclib.core import entity_exists
|
2018-11-06 16:15:20 -06:00
|
|
|
from osclib.core import group_members
|
2019-09-24 11:25:47 -05:00
|
|
|
from osclib.core import package_kind
|
2021-07-07 17:17:52 +02:00
|
|
|
from osclib.core import create_add_role_request
|
2023-12-12 16:30:55 +01:00
|
|
|
from osclib.core import package_role_expand
|
2023-06-22 10:39:21 +02:00
|
|
|
from osc.core import show_package_meta, show_project_meta
|
2021-07-26 22:21:06 +02:00
|
|
|
from osc.core import get_request_list
|
2019-05-16 06:39:08 +02:00
|
|
|
from urllib.error import HTTPError
|
2018-11-16 08:32:25 +01:00
|
|
|
|
2016-12-29 00:34:56 -06:00
|
|
|
import ReviewBot
|
2018-03-09 13:37:23 +01:00
|
|
|
from osclib.conf import str2bool
|
2016-12-29 00:34:56 -06:00
|
|
|
|
2022-02-18 17:15:48 +01:00
|
|
|
|
2016-12-29 00:34:56 -06:00
|
|
|
class CheckSource(ReviewBot.ReviewBot):
|
|
|
|
|
|
|
|
SCRIPT_PATH = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
ReviewBot.ReviewBot.__init__(self, *args, **kwargs)
|
|
|
|
|
2017-06-20 16:29:19 -05:00
|
|
|
# ReviewBot options.
|
2018-03-16 14:21:41 -05:00
|
|
|
self.request_default_return = True
|
2017-06-20 16:29:19 -05:00
|
|
|
|
2016-12-29 00:34:56 -06:00
|
|
|
self.skip_add_reviews = False
|
|
|
|
|
2023-06-21 14:11:18 +02:00
|
|
|
def target_project_config(self, project: str) -> None:
|
2017-10-11 22:19:24 -05:00
|
|
|
# Load project config and allow for remote entries.
|
2018-08-16 23:35:10 -05:00
|
|
|
config = Config.get(self.apiurl, project)
|
2017-10-11 22:19:24 -05:00
|
|
|
|
2018-06-28 12:13:26 -05:00
|
|
|
self.single_action_require = str2bool(config.get('check-source-single-action-require', 'False'))
|
2023-06-21 14:11:18 +02:00
|
|
|
self.ignore_devel: bool = not str2bool(config.get('devel-project-enforce', 'False'))
|
2018-03-16 14:09:02 -05:00
|
|
|
self.in_air_rename_allow = str2bool(config.get('check-source-in-air-rename-allow', 'False'))
|
2018-03-09 13:45:14 +01:00
|
|
|
self.add_review_team = str2bool(config.get('check-source-add-review-team', 'True'))
|
2017-10-11 22:19:24 -05:00
|
|
|
self.review_team = config.get('review-team')
|
2019-09-09 16:51:54 -05:00
|
|
|
self.mail_release_list = config.get('mail-release-list')
|
2018-08-16 23:29:25 -05:00
|
|
|
self.staging_group = config.get('staging-group')
|
2021-07-07 17:17:52 +02:00
|
|
|
self.required_maintainer = config.get('required-source-maintainer', '')
|
2017-10-11 22:19:24 -05:00
|
|
|
self.devel_whitelist = config.get('devel-whitelist', '').split()
|
2018-09-12 11:48:23 +02:00
|
|
|
self.skip_add_reviews = False
|
2022-08-29 23:54:11 +08:00
|
|
|
self.ensure_source_exist_in_baseproject = str2bool(config.get('check-source-ensure-source-exist-in-baseproject', 'False'))
|
2023-06-21 14:11:18 +02:00
|
|
|
self.devel_baseproject: str = config.get('check-source-devel-baseproject', '')
|
2022-08-29 23:54:11 +08:00
|
|
|
self.allow_source_in_sle = str2bool(config.get('check-source-allow-source-in-sle', 'True'))
|
|
|
|
self.sle_project_to_check = config.get('check-source-sle-project', '')
|
|
|
|
self.allow_valid_source_origin = str2bool(config.get('check-source-allow-valid-source-origin', 'False'))
|
2023-06-21 14:11:18 +02:00
|
|
|
self.valid_source_origins: Set[str] = set(config.get('check-source-valid-source-origins', '').split(' '))
|
2022-08-29 23:54:11 +08:00
|
|
|
self.add_devel_project_review = str2bool(config.get('check-source-add-devel-project-review', 'False'))
|
2023-06-28 15:38:01 +02:00
|
|
|
self.allowed_scm_submission_sources = config.get('allowed-scm-submission-sources', '').split()
|
2017-10-11 22:19:24 -05:00
|
|
|
|
2018-06-28 12:11:24 -05:00
|
|
|
if self.action.type == 'maintenance_incident':
|
|
|
|
# The workflow effectively enforces the names to match and the
|
|
|
|
# parent code sets target_package from source_package so this check
|
|
|
|
# becomes useless and awkward to perform.
|
|
|
|
self.in_air_rename_allow = True
|
|
|
|
|
2018-06-28 12:13:26 -05:00
|
|
|
# The target project will be set to product and thus inherit
|
|
|
|
# settings, but override since real target is not product.
|
|
|
|
self.single_action_require = False
|
|
|
|
|
2018-06-28 12:25:24 -05:00
|
|
|
# It might make sense to supersede maintbot, but for now.
|
|
|
|
self.skip_add_reviews = True
|
|
|
|
|
2023-06-21 14:11:18 +02:00
|
|
|
def is_good_name(self, package: Optional[str], target_package: Optional[str]) -> bool:
|
2020-03-20 14:40:01 +01:00
|
|
|
self.logger.debug(f"is_good_name {package} <-> {target_package}")
|
|
|
|
if target_package is None:
|
|
|
|
# if the name doesn't matter, existance is all
|
|
|
|
return package is not None
|
|
|
|
|
|
|
|
return target_package == package
|
|
|
|
|
|
|
|
def package_source_parse(self, project, package, revision=None, target_package=None):
|
|
|
|
ret = self._package_source_parse(project, package, revision)
|
|
|
|
|
|
|
|
if self.is_good_name(ret['name'], target_package):
|
|
|
|
return ret
|
|
|
|
|
|
|
|
d = {}
|
|
|
|
for repo in osc.core.get_repositories_of_project(self.apiurl, project):
|
|
|
|
r = self._package_source_parse(project, package, revision, repo)
|
|
|
|
if r['name'] is not None:
|
|
|
|
d[r['name']] = r
|
|
|
|
|
|
|
|
if len(d) == 1:
|
|
|
|
# here is only one so use that
|
|
|
|
ret = d[next(iter(d))]
|
|
|
|
else:
|
|
|
|
# check if any name matches
|
|
|
|
self.logger.debug("found multiple names %s", ', '.join(d.keys()))
|
|
|
|
for n, r in d.items():
|
|
|
|
if n == target_package:
|
|
|
|
ret = r
|
|
|
|
break
|
|
|
|
|
|
|
|
if not self.is_good_name(ret['name'], target_package):
|
|
|
|
self.logger.error("none of the names matched")
|
|
|
|
|
|
|
|
return ret
|
|
|
|
|
2023-06-21 14:11:18 +02:00
|
|
|
def check_source_submission(
|
|
|
|
self,
|
|
|
|
source_project: str,
|
|
|
|
source_package: str,
|
|
|
|
source_revision: str,
|
|
|
|
target_project: str,
|
|
|
|
target_package: str
|
|
|
|
) -> bool:
|
2022-02-18 17:44:32 +01:00
|
|
|
super(CheckSource, self).check_source_submission(source_project,
|
|
|
|
source_package, source_revision, target_project, target_package)
|
2017-10-11 22:19:24 -05:00
|
|
|
self.target_project_config(target_project)
|
2016-12-29 00:34:56 -06:00
|
|
|
|
2018-06-28 12:13:26 -05:00
|
|
|
if self.single_action_require and len(self.request.actions) != 1:
|
|
|
|
self.review_messages['declined'] = 'Only one action per request allowed'
|
|
|
|
return False
|
|
|
|
|
2021-05-26 15:08:59 +02:00
|
|
|
if source_revision is None:
|
|
|
|
self.review_messages['declined'] = 'Submission not from a pinned source revision'
|
|
|
|
return False
|
|
|
|
|
2019-09-24 11:25:47 -05:00
|
|
|
kind = package_kind(self.apiurl, target_project, target_package)
|
|
|
|
if kind == 'meta':
|
2023-09-20 08:56:16 +02:00
|
|
|
self.review_messages['accepted'] = 'Skipping most checks for meta packages'
|
|
|
|
if not self.skip_add_reviews and self.add_review_team and self.review_team is not None:
|
|
|
|
if not (self.allow_valid_source_origin and source_project in self.valid_source_origins):
|
|
|
|
self.add_review(self.request, by_group=self.review_team, msg='Please review sources')
|
|
|
|
|
2018-03-15 15:43:37 +01:00
|
|
|
return True
|
2019-09-25 19:36:52 +08:00
|
|
|
elif (kind is not None and kind != 'source'):
|
2024-05-07 17:55:17 +02:00
|
|
|
self.review_messages['declined'] = f'May not modify a non-source package of type {kind}'
|
2019-09-24 11:26:52 -05:00
|
|
|
return False
|
2018-03-15 15:43:37 +01:00
|
|
|
|
2022-08-29 23:54:11 +08:00
|
|
|
if not self.allow_source_in_sle and self.sle_project_to_check:
|
|
|
|
if entity_exists(self.apiurl, self.sle_project_to_check, target_package):
|
|
|
|
self.review_messages['declined'] = ("SLE-base package, please submit to the corresponding SLE project."
|
|
|
|
"Or let us know the reason why needs to rebuild SLE-base package.")
|
|
|
|
return False
|
|
|
|
|
|
|
|
if self.ensure_source_exist_in_baseproject and self.devel_baseproject:
|
|
|
|
if not entity_exists(self.apiurl, self.devel_baseproject, target_package) and source_project not in self.valid_source_origins:
|
2023-06-28 15:38:01 +02:00
|
|
|
self.review_messages['declined'] = f"Per our development policy, please submit to {self.devel_baseproject} first."
|
2022-08-29 23:54:11 +08:00
|
|
|
return False
|
|
|
|
|
2018-06-28 12:10:19 -05:00
|
|
|
inair_renamed = target_package != source_package
|
|
|
|
|
2016-12-29 00:34:56 -06:00
|
|
|
if not self.ignore_devel:
|
2017-10-11 22:14:42 -05:00
|
|
|
self.logger.info('checking if target package exists and has devel project')
|
2018-01-17 18:08:40 -06:00
|
|
|
devel_project, devel_package = devel_project_get(self.apiurl, target_project, target_package)
|
2016-12-29 00:34:56 -06:00
|
|
|
if devel_project:
|
2023-06-22 10:39:21 +02:00
|
|
|
if (
|
|
|
|
(source_project != devel_project or source_package != devel_package)
|
|
|
|
and not (source_project == target_project and source_package == target_package)):
|
|
|
|
# check if the devel project & package are using scmsync & match the allowed prj prefix
|
|
|
|
# => waive the devel project source submission requirement
|
|
|
|
meta = ET.fromstringlist(show_package_meta(self.apiurl, devel_project, devel_package))
|
|
|
|
scm_sync = meta.find('scmsync')
|
2023-06-28 15:38:01 +02:00
|
|
|
if scm_sync is None:
|
2023-06-22 10:39:21 +02:00
|
|
|
# Not from proper devel project/package and not self-submission and not scmsync.
|
|
|
|
self.review_messages['declined'] = 'Expected submission from devel package %s/%s' % (
|
|
|
|
devel_project, devel_package)
|
|
|
|
return False
|
2023-06-28 15:38:01 +02:00
|
|
|
|
|
|
|
scm_pool_repository = f"https://src.opensuse.org/pool/{source_package}"
|
|
|
|
if not scm_sync.text.startswith(scm_pool_repository):
|
|
|
|
# devel project uses scm sync not from the trusted src location
|
2024-08-02 09:37:32 +02:00
|
|
|
self.review_messages['declined'] = (
|
|
|
|
f"devel project scmsync setting is {scm_sync.text}. Must be {scm_pool_repository} instead.")
|
2023-06-28 15:38:01 +02:00
|
|
|
return False
|
|
|
|
if not self.source_is_scm_staging_submission(source_project):
|
|
|
|
# Not a submission coming from the scm-sync bot
|
2024-06-17 09:12:40 +02:00
|
|
|
self.review_messages['declined'] = "Expected a submitrequest coming from scm-sync project"
|
2023-06-28 15:38:01 +02:00
|
|
|
return False
|
|
|
|
|
2016-12-29 00:34:56 -06:00
|
|
|
else:
|
|
|
|
# Check to see if other packages exist with the same source project
|
|
|
|
# which indicates that the project has already been used as devel.
|
|
|
|
if not self.is_devel_project(source_project, target_project):
|
2018-01-02 13:27:10 +01:00
|
|
|
self.review_messages['declined'] = (
|
|
|
|
'%s is not a devel project of %s, submit the package to a devel project first. '
|
|
|
|
'See https://en.opensuse.org/openSUSE:How_to_contribute_to_Factory#How_to_request_a_new_devel_project for details.'
|
|
|
|
) % (source_project, target_project)
|
2016-12-29 00:34:56 -06:00
|
|
|
return False
|
2018-06-28 12:10:19 -05:00
|
|
|
else:
|
|
|
|
if source_project.endswith(':Update'):
|
|
|
|
# Allow for submission like:
|
|
|
|
# - source: openSUSE:Leap:15.0:Update/google-compute-engine.8258
|
|
|
|
# - target: openSUSE:Leap:15.1/google-compute-engine
|
|
|
|
# Note: home:jberry:Update would also be allowed via this condition,
|
|
|
|
# but that should be handled by leaper and human review.
|
2018-08-13 22:47:01 -05:00
|
|
|
# Ignore a dot in package name (ex. tpm2.0-abrmd) and instead
|
|
|
|
# only look for ending in dot number.
|
|
|
|
match = re.match(r'(.*)\.\d+$', source_package)
|
|
|
|
if match:
|
|
|
|
inair_renamed = target_package != match.group(1)
|
2018-06-28 12:10:19 -05:00
|
|
|
|
2023-06-28 15:38:01 +02:00
|
|
|
# TODO(dmllr): ensure requird maintainers are set in the temporary project that is created
|
|
|
|
# by the scm-staging bot
|
|
|
|
if not self.source_is_scm_staging_submission(source_project) and not self.source_has_required_maintainers(source_project):
|
2021-07-07 17:17:52 +02:00
|
|
|
declined_msg = (
|
|
|
|
'This request cannot be accepted unless %s is a maintainer of %s.' %
|
|
|
|
(self.required_maintainer, source_project)
|
|
|
|
)
|
|
|
|
|
2021-07-29 10:37:44 +02:00
|
|
|
req = self.__ensure_add_role_request(source_project)
|
|
|
|
if req:
|
2024-05-07 17:55:17 +02:00
|
|
|
declined_msg += f' Created the add_role request {req} for addressing this problem.'
|
2021-07-07 17:17:52 +02:00
|
|
|
|
|
|
|
self.review_messages['declined'] = declined_msg
|
|
|
|
return False
|
|
|
|
|
2018-06-28 12:10:19 -05:00
|
|
|
if not self.in_air_rename_allow and inair_renamed:
|
|
|
|
self.review_messages['declined'] = 'Source and target package names must match'
|
|
|
|
return False
|
2016-12-29 00:34:56 -06:00
|
|
|
|
|
|
|
# Checkout and see if renaming package screws up version parsing.
|
2024-05-07 17:55:17 +02:00
|
|
|
copath = os.path.expanduser(f'~/co/{self.request.reqid}')
|
2023-06-28 15:38:01 +02:00
|
|
|
if os.path.exists(copath):
|
2024-05-07 17:55:17 +02:00
|
|
|
self.logger.warning(f'directory {copath} already exists')
|
2023-06-28 15:38:01 +02:00
|
|
|
shutil.rmtree(copath)
|
|
|
|
os.makedirs(copath)
|
|
|
|
os.chdir(copath)
|
2016-12-29 00:34:56 -06:00
|
|
|
|
|
|
|
try:
|
2023-06-28 15:38:01 +02:00
|
|
|
CheckSource.checkout_package(self.apiurl, target_project, target_package, pathname=copath,
|
2022-02-18 17:35:33 +01:00
|
|
|
server_service_files=True, expand_link=True)
|
2016-12-29 00:34:56 -06:00
|
|
|
shutil.rmtree(os.path.join(target_package, '.osc'))
|
|
|
|
os.rename(target_package, '_old')
|
2019-08-27 14:49:17 -05:00
|
|
|
except HTTPError as e:
|
|
|
|
if e.code == 404:
|
2024-05-07 17:55:17 +02:00
|
|
|
self.logger.info(f'target package does not exist {target_project}/{target_package}')
|
2019-08-27 14:49:17 -05:00
|
|
|
else:
|
|
|
|
raise e
|
2016-12-29 00:34:56 -06:00
|
|
|
|
|
|
|
CheckSource.checkout_package(self.apiurl, source_project, source_package, revision=source_revision,
|
2023-06-28 15:38:01 +02:00
|
|
|
pathname=copath, server_service_files=True, expand_link=True)
|
2016-12-29 00:34:56 -06:00
|
|
|
os.rename(source_package, target_package)
|
|
|
|
shutil.rmtree(os.path.join(target_package, '.osc'))
|
|
|
|
|
2020-03-20 14:40:01 +01:00
|
|
|
new_info = self.package_source_parse(source_project, source_package, source_revision, target_package)
|
2020-11-18 09:54:10 +01:00
|
|
|
filename = new_info.get('filename', '')
|
2023-03-02 19:52:50 +01:00
|
|
|
expected_name = target_package
|
|
|
|
if filename == '_preinstallimage':
|
|
|
|
expected_name = 'preinstallimage'
|
2023-07-20 12:36:34 +02:00
|
|
|
if not (filename.endswith('.kiwi') or filename == 'Dockerfile') and new_info['name'] != expected_name:
|
|
|
|
shutil.rmtree(copath)
|
|
|
|
self.review_messages['declined'] = "A package submitted as %s has to build as 'Name: %s' - found Name '%s'" % (
|
|
|
|
target_package, expected_name, new_info['name'])
|
|
|
|
return False
|
2016-12-29 00:34:56 -06:00
|
|
|
|
2022-03-24 08:25:32 +01:00
|
|
|
if not self.check_service_file(target_package):
|
|
|
|
return False
|
|
|
|
|
2022-03-24 08:39:20 +01:00
|
|
|
if not self.check_rpmlint(target_package):
|
|
|
|
return False
|
|
|
|
|
2022-03-24 13:35:23 +01:00
|
|
|
specs = [os.path.basename(x) for x in glob.glob(os.path.join(target_package, "*.spec"))]
|
2023-09-15 15:20:03 +02:00
|
|
|
if specs and not self.check_spec_policy('_old', target_package, specs):
|
2022-03-24 13:35:23 +01:00
|
|
|
return False
|
|
|
|
|
2022-03-24 15:23:16 +01:00
|
|
|
if not self.run_source_validator('_old', target_package):
|
|
|
|
return False
|
|
|
|
|
2023-09-15 15:20:03 +02:00
|
|
|
if specs and not self.detect_mentioned_patches('_old', target_package, specs):
|
2022-03-24 21:19:45 +01:00
|
|
|
return False
|
|
|
|
|
2022-03-25 07:56:35 +01:00
|
|
|
if not self.check_urls('_old', target_package, specs):
|
2022-03-25 12:11:35 +01:00
|
|
|
osc.core.change_review_state(apiurl=self.apiurl,
|
|
|
|
reqid=self.request.reqid, newstate='new',
|
|
|
|
by_group=self.review_group,
|
|
|
|
by_user=self.review_user, message=self.review_messages['new'])
|
|
|
|
return None
|
2016-12-29 00:34:56 -06:00
|
|
|
|
2023-06-28 15:38:01 +02:00
|
|
|
shutil.rmtree(copath)
|
2016-12-29 00:34:56 -06:00
|
|
|
self.review_messages['accepted'] = 'Check script succeeded'
|
|
|
|
|
2022-03-25 07:56:35 +01:00
|
|
|
if self.skip_add_reviews:
|
|
|
|
return True
|
2016-12-29 00:34:56 -06:00
|
|
|
|
2022-03-25 07:56:35 +01:00
|
|
|
if self.add_review_team and self.review_team is not None:
|
2022-08-29 23:54:11 +08:00
|
|
|
if not (self.allow_valid_source_origin and source_project in self.valid_source_origins):
|
|
|
|
self.add_review(self.request, by_group=self.review_team, msg='Please review sources')
|
|
|
|
|
|
|
|
if self.add_devel_project_review:
|
|
|
|
devel_project, devel_package = devel_project_fallback(self.apiurl, target_project, target_package)
|
|
|
|
if devel_project and devel_package:
|
2023-01-31 12:34:10 +01:00
|
|
|
submitter = self.request.creator
|
2023-12-12 16:30:55 +01:00
|
|
|
maintainers = set(package_role_expand(self.apiurl, devel_project, devel_package))
|
2022-08-29 23:54:11 +08:00
|
|
|
known_maintainer = False
|
|
|
|
if maintainers:
|
|
|
|
if submitter in maintainers:
|
2024-05-07 17:55:17 +02:00
|
|
|
self.logger.debug(f"{submitter} is maintainer")
|
2022-08-29 23:54:11 +08:00
|
|
|
known_maintainer = True
|
|
|
|
if not known_maintainer:
|
|
|
|
for r in self.request.reviews:
|
|
|
|
if r.by_user in maintainers:
|
2024-05-07 17:55:17 +02:00
|
|
|
self.logger.debug(f"found {r.by_user} as reviewer")
|
2022-08-29 23:54:11 +08:00
|
|
|
known_maintainer = True
|
|
|
|
if not known_maintainer:
|
2024-05-07 17:55:17 +02:00
|
|
|
self.logger.warning(f"submitter: {submitter}, maintainers: {','.join(maintainers)} => need review")
|
|
|
|
self.logger.debug(f"adding review to {devel_project}/{devel_package}")
|
2022-08-29 23:54:11 +08:00
|
|
|
msg = ('Submission for {} by someone who is not maintainer in '
|
|
|
|
'the devel project ({}). Please review').format(target_package, devel_project)
|
|
|
|
self.add_review(self.request, by_project=devel_project, by_package=devel_package, msg=msg)
|
|
|
|
else:
|
2024-05-07 17:55:17 +02:00
|
|
|
self.logger.warning(f"{target_package} doesn't have devel project")
|
2016-12-29 00:34:56 -06:00
|
|
|
|
2022-03-25 07:56:35 +01:00
|
|
|
if self.only_changes():
|
|
|
|
self.logger.debug('only .changes modifications')
|
|
|
|
if self.staging_group and self.review_user in group_members(self.apiurl, self.staging_group):
|
|
|
|
if not self.dryrun:
|
|
|
|
osc.core.change_review_state(self.apiurl, str(self.request.reqid), 'accepted',
|
|
|
|
by_group=self.staging_group,
|
|
|
|
message='skipping the staging process since only .changes modifications')
|
|
|
|
else:
|
|
|
|
self.logger.debug('unable to skip staging review since not a member of staging group')
|
2016-12-29 00:34:56 -06:00
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
def is_devel_project(self, source_project, target_project):
|
2017-10-11 22:19:24 -05:00
|
|
|
if source_project in self.devel_whitelist:
|
2016-12-29 00:34:56 -06:00
|
|
|
return True
|
|
|
|
|
2017-07-18 17:08:02 -05:00
|
|
|
# Allow any projects already used as devel projects for other packages.
|
2016-12-29 00:34:56 -06:00
|
|
|
search = {
|
2024-05-07 17:55:17 +02:00
|
|
|
'package': f"@project='{target_project}' and devel/@project='{source_project}'",
|
2016-12-29 00:34:56 -06:00
|
|
|
}
|
|
|
|
result = osc.core.search(self.apiurl, **search)
|
|
|
|
return result['package'].attrib['matches'] != '0'
|
|
|
|
|
2022-03-24 08:25:32 +01:00
|
|
|
def check_service_file(self, directory):
|
|
|
|
ALLOWED_MODES = ['localonly', 'disabled', 'buildtime', 'manual']
|
|
|
|
|
|
|
|
servicefile = os.path.join(directory, '_service')
|
|
|
|
if os.path.exists(servicefile):
|
|
|
|
services = ET.parse(servicefile)
|
|
|
|
for service in services.findall('service'):
|
|
|
|
mode = service.get('mode')
|
|
|
|
if mode in ALLOWED_MODES:
|
|
|
|
continue
|
|
|
|
allowed = ', '.join(ALLOWED_MODES)
|
2022-03-24 10:17:55 +01:00
|
|
|
name = service.get('name')
|
2022-03-24 08:25:32 +01:00
|
|
|
self.review_messages[
|
2022-03-24 10:17:55 +01:00
|
|
|
'declined'] = f"Services are only allowed if their mode is one of {allowed}. " + \
|
|
|
|
f"Please change the mode of {name} and use `osc service localrun/disabledrun`."
|
2022-03-24 08:25:32 +01:00
|
|
|
return False
|
2022-03-24 08:32:08 +01:00
|
|
|
# remove it away to have full service from source validator
|
|
|
|
os.unlink(servicefile)
|
2022-03-24 08:48:06 +01:00
|
|
|
|
|
|
|
for file in glob.glob(os.path.join(directory, "_service:*")):
|
|
|
|
file = os.path.basename(file)
|
|
|
|
self.review_messages['declined'] = f"Found _service generated file {file} in checkout. Please clean this up first."
|
|
|
|
return False
|
|
|
|
|
2022-03-24 08:25:32 +01:00
|
|
|
return True
|
|
|
|
|
2022-03-24 08:39:20 +01:00
|
|
|
def check_rpmlint(self, directory):
|
|
|
|
for rpmlintrc in glob.glob(os.path.join(directory, "*rpmlintrc")):
|
|
|
|
with open(rpmlintrc, 'r') as f:
|
|
|
|
for line in f:
|
|
|
|
if not re.match(r'^\s*setBadness', line):
|
|
|
|
continue
|
|
|
|
self.review_messages['declined'] = f"For product submissions, you cannot use setBadness. Use filters in {rpmlintrc}."
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
2022-03-24 14:30:11 +01:00
|
|
|
def check_spec_policy(self, old, directory, specs):
|
2022-03-24 13:35:23 +01:00
|
|
|
bname = os.path.basename(directory)
|
|
|
|
if not os.path.exists(os.path.join(directory, bname + '.changes')):
|
|
|
|
text = f"{bname}.changes is missing. "
|
|
|
|
text += "A package submitted as FooBar needs to have a FooBar.changes file with a format created by `osc vc`."
|
|
|
|
self.review_messages['declined'] = text
|
|
|
|
return False
|
|
|
|
|
|
|
|
specfile = os.path.join(directory, bname + '.spec')
|
|
|
|
if not os.path.exists(specfile):
|
|
|
|
self.review_messages['declined'] = f"{bname}.spec is missing. A package submitted as FooBar needs to have a FooBar.spec file."
|
|
|
|
return False
|
|
|
|
|
2022-03-24 14:30:11 +01:00
|
|
|
changes_updated = False
|
2022-03-24 13:35:23 +01:00
|
|
|
for spec in specs:
|
|
|
|
with open(os.path.join(directory, spec), 'r') as f:
|
|
|
|
content = f.read()
|
|
|
|
if not re.search(r'#[*\s]+Copyright\s', content):
|
|
|
|
text = f"{spec} does not appear to contain a Copyright comment. Please stick to the format\n\n"
|
|
|
|
text += "# Copyright (c) 2022 Unsong Hero\n\n"
|
|
|
|
text += "or use osc service runall format_spec_file"
|
|
|
|
self.review_messages['declined'] = text
|
|
|
|
return False
|
|
|
|
|
|
|
|
if re.search(r'\nVendor:', content):
|
|
|
|
self.review_messages['declined'] = "{spec} contains a Vendor line, this is forbidden."
|
|
|
|
return False
|
|
|
|
|
2022-03-24 14:48:56 +01:00
|
|
|
if not re.search(r'\n%changelog\s', content) and not re.search(r'\n%changelog$', content):
|
|
|
|
text = f"{spec} does not contain a %changelog line. We don't want a changelog in the spec file"
|
|
|
|
text += ", but the %changelog section needs to be present\n"
|
|
|
|
self.review_messages['declined'] = text
|
|
|
|
return False
|
|
|
|
|
|
|
|
if not re.search('#[^\n]*license', content, flags=re.IGNORECASE):
|
|
|
|
text = f"{spec} does not appear to have a license. The file needs to contain a free software license\n"
|
|
|
|
text += "Suggestion: use \"osc service runall format_spec_file\" to get our default license or\n"
|
|
|
|
text += "the minimal license:\n\n"
|
|
|
|
text += "# This file is under MIT license\n"
|
|
|
|
self.review_messages['declined'] = text
|
|
|
|
return False
|
|
|
|
|
2022-03-24 14:30:11 +01:00
|
|
|
# Check that we have for each spec file a changes file - and that at least one
|
|
|
|
# contains changes
|
|
|
|
changes = spec.replace('.spec', '.changes')
|
|
|
|
|
|
|
|
# new or deleted .changes files also count
|
|
|
|
old_exists = os.path.exists(os.path.join(old, changes))
|
|
|
|
new_exists = os.path.exists(os.path.join(directory, changes))
|
|
|
|
if old_exists != new_exists:
|
|
|
|
changes_updated = True
|
|
|
|
elif old_exists and new_exists:
|
|
|
|
if subprocess.run(["cmp", "-s", os.path.join(old, changes), os.path.join(directory, changes)]).returncode:
|
|
|
|
changes_updated = True
|
|
|
|
|
|
|
|
if not changes_updated:
|
|
|
|
self.review_messages['declined'] = "No changelog. Please use 'osc vc' to update the changes file(s)."
|
|
|
|
return False
|
|
|
|
|
2022-03-24 13:35:23 +01:00
|
|
|
return True
|
|
|
|
|
2023-06-28 15:38:01 +02:00
|
|
|
def source_is_scm_staging_submission(self, source_project):
|
|
|
|
"""Checks whether the source project is a scm_submission source project"""
|
|
|
|
|
|
|
|
return any(source_project.startswith(allowed_src) for allowed_src in self.allowed_scm_submission_sources)
|
|
|
|
|
|
|
|
def source_has_required_maintainers(self, source_project):
|
2021-07-07 17:17:52 +02:00
|
|
|
"""Checks whether the source project has the required maintainer
|
|
|
|
|
|
|
|
If a 'required-source-maintainer' is set, it checks whether it is a
|
2021-07-26 22:25:05 +02:00
|
|
|
maintainer for the source project. Inherited maintainership is
|
2021-07-29 10:37:44 +02:00
|
|
|
intentionally ignored to have explicit maintainer set.
|
2021-07-07 17:17:52 +02:00
|
|
|
|
|
|
|
source_project - source project name
|
|
|
|
"""
|
|
|
|
self.logger.info(
|
2024-05-07 17:55:17 +02:00
|
|
|
f'Checking required maintainer from the source project ({self.required_maintainer})'
|
2021-07-07 17:17:52 +02:00
|
|
|
)
|
2022-02-18 13:42:57 +01:00
|
|
|
if not self.required_maintainer:
|
|
|
|
return True
|
2021-07-07 17:17:52 +02:00
|
|
|
|
2022-02-18 10:16:17 +01:00
|
|
|
meta = ET.fromstringlist(show_project_meta(self.apiurl, source_project))
|
2021-07-14 10:45:11 +01:00
|
|
|
maintainers = meta.xpath('//person[@role="maintainer"]/@userid')
|
|
|
|
maintainers += ['group:' + g for g in meta.xpath('//group[@role="maintainer"]/@groupid')]
|
|
|
|
|
2021-07-07 17:17:52 +02:00
|
|
|
return self.required_maintainer in maintainers
|
|
|
|
|
2021-07-29 10:37:44 +02:00
|
|
|
def __ensure_add_role_request(self, source_project):
|
|
|
|
"""Returns add_role request ID for given source project. Creates that add role if needed."""
|
|
|
|
try:
|
|
|
|
add_roles = get_request_list(self.apiurl, source_project,
|
2022-02-18 17:35:33 +01:00
|
|
|
req_state=['new', 'review'], req_type='add_role')
|
2021-07-29 10:37:44 +02:00
|
|
|
add_roles = list(filter(self.__is_required_maintainer, add_roles))
|
|
|
|
if len(add_roles) > 0:
|
|
|
|
return add_roles[0].reqid
|
|
|
|
else:
|
2024-05-07 17:55:17 +02:00
|
|
|
add_role_msg = f'Created automatically from request {self.request.reqid}'
|
2021-07-29 10:37:44 +02:00
|
|
|
return create_add_role_request(self.apiurl, source_project, self.required_maintainer,
|
2022-02-18 13:50:43 +01:00
|
|
|
'maintainer', message=add_role_msg)
|
2021-07-29 10:37:44 +02:00
|
|
|
except HTTPError as e:
|
|
|
|
self.logger.error(
|
2024-05-07 17:55:17 +02:00
|
|
|
f'Cannot create the corresponding add_role request for {self.request.reqid}: {e}'
|
2021-07-29 10:37:44 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
def __is_required_maintainer(self, request):
|
|
|
|
"""Returns true for add role requests that adds required maintainer user or group"""
|
2021-07-26 22:21:06 +02:00
|
|
|
action = request.actions[0]
|
|
|
|
user = self.required_maintainer
|
|
|
|
if user.startswith('group:'):
|
|
|
|
group = user.replace('group:', '')
|
|
|
|
return action.group_name == group and action.group_role == 'maintainer'
|
|
|
|
else:
|
|
|
|
return action.person_name == user and action.person_role == 'maintainer'
|
|
|
|
|
2016-12-29 00:34:56 -06:00
|
|
|
@staticmethod
|
|
|
|
def checkout_package(*args, **kwargs):
|
|
|
|
_stdout = sys.stdout
|
2019-05-16 13:13:25 +02:00
|
|
|
sys.stdout = open(os.devnull, 'w')
|
2016-12-29 00:34:56 -06:00
|
|
|
try:
|
|
|
|
result = osc.core.checkout_package(*args, **kwargs)
|
|
|
|
finally:
|
|
|
|
sys.stdout = _stdout
|
|
|
|
return result
|
|
|
|
|
2019-11-28 10:30:37 +01:00
|
|
|
def _package_source_parse(self, project, package, revision=None, repository=None):
|
2016-12-29 00:34:56 -06:00
|
|
|
query = {'view': 'info', 'parse': 1}
|
|
|
|
if revision:
|
|
|
|
query['rev'] = revision
|
2019-11-28 10:30:37 +01:00
|
|
|
if repository:
|
|
|
|
query['repository'] = repository
|
2016-12-29 00:34:56 -06:00
|
|
|
url = osc.core.makeurl(self.apiurl, ['source', project, package], query)
|
|
|
|
|
|
|
|
ret = {'name': None, 'version': None}
|
|
|
|
|
|
|
|
try:
|
|
|
|
xml = ET.parse(osc.core.http_GET(url)).getroot()
|
2018-11-16 08:32:25 +01:00
|
|
|
except HTTPError as e:
|
2024-05-07 17:55:17 +02:00
|
|
|
self.logger.error(f'ERROR in URL {url} [{e}]')
|
2016-12-29 00:34:56 -06:00
|
|
|
return ret
|
|
|
|
|
2019-11-28 10:30:37 +01:00
|
|
|
if xml.find('error') is not None:
|
|
|
|
self.logger.error("%s/%s/%s: %s", project, package, repository, xml.find('error').text)
|
|
|
|
return ret
|
|
|
|
|
2016-12-29 00:34:56 -06:00
|
|
|
# ET boolean check fails.
|
|
|
|
if xml.find('name') is not None:
|
|
|
|
ret['name'] = xml.find('name').text
|
|
|
|
|
|
|
|
if xml.find('version') is not None:
|
|
|
|
ret['version'] = xml.find('version').text
|
|
|
|
|
2019-09-20 14:37:46 +02:00
|
|
|
if xml.find('filename') is not None:
|
|
|
|
ret['filename'] = xml.find('filename').text
|
|
|
|
|
2019-11-28 10:30:37 +01:00
|
|
|
self.logger.debug("%s/%s/%s: %s", project, package, repository, ret)
|
|
|
|
|
|
|
|
return ret
|
|
|
|
|
2017-04-19 09:30:57 -05:00
|
|
|
def only_changes(self):
|
|
|
|
u = osc.core.makeurl(self.apiurl, ['request', self.request.reqid],
|
|
|
|
{'cmd': 'diff', 'view': 'xml'})
|
|
|
|
try:
|
|
|
|
diff = ET.parse(osc.core.http_POST(u)).getroot()
|
|
|
|
for f in diff.findall('action/sourcediff/files/file/*[@name]'):
|
|
|
|
if not f.get('name').endswith('.changes'):
|
|
|
|
return False
|
|
|
|
return True
|
2022-02-18 11:25:26 +01:00
|
|
|
except HTTPError:
|
2017-04-19 09:30:57 -05:00
|
|
|
pass
|
|
|
|
return False
|
|
|
|
|
2016-12-29 00:34:56 -06:00
|
|
|
def check_action_add_role(self, request, action):
|
|
|
|
# Decline add_role request (assumed the bot acting on requests to Factory or similar).
|
2024-05-07 17:55:17 +02:00
|
|
|
message = f'Roles to packages are granted in the devel project, not in {action.tgt_project}.'
|
2016-12-29 00:34:56 -06:00
|
|
|
|
|
|
|
if action.tgt_package is not None:
|
2018-01-17 20:36:03 -06:00
|
|
|
project, package = devel_project_fallback(self.apiurl, action.tgt_project, action.tgt_package)
|
2024-05-07 17:55:17 +02:00
|
|
|
message += f' Send this request to {project}/{package}.'
|
2016-12-29 00:34:56 -06:00
|
|
|
|
|
|
|
self.review_messages['declined'] = message
|
|
|
|
return False
|
|
|
|
|
2018-09-17 17:11:33 -05:00
|
|
|
def check_action_delete_package(self, request, action):
|
2018-01-03 20:01:12 -06:00
|
|
|
self.target_project_config(action.tgt_project)
|
|
|
|
|
2016-12-29 00:34:56 -06:00
|
|
|
try:
|
|
|
|
result = osc.core.show_project_sourceinfo(self.apiurl, action.tgt_project, True, (action.tgt_package))
|
|
|
|
root = ET.fromstring(result)
|
2018-11-16 08:32:25 +01:00
|
|
|
except HTTPError:
|
2016-12-29 00:34:56 -06:00
|
|
|
return None
|
|
|
|
|
2017-10-12 19:11:01 +08:00
|
|
|
# Decline the delete request if there is another delete/submit request against the same package
|
|
|
|
query = "match=state/@name='new'+and+(action/target/@project='{}'+and+action/target/@package='{}')"\
|
|
|
|
"+and+(action/@type='delete'+or+action/@type='submit')".format(action.tgt_project, action.tgt_package)
|
|
|
|
url = osc.core.makeurl(self.apiurl, ['search', 'request'], query)
|
|
|
|
matches = ET.parse(osc.core.http_GET(url)).getroot()
|
|
|
|
if int(matches.attrib['matches']) > 1:
|
|
|
|
ids = [rq.attrib['id'] for rq in matches.findall('request')]
|
2022-02-18 17:44:32 +01:00
|
|
|
self.review_messages['declined'] = "There is a pending request %s to %s/%s in process." % (
|
|
|
|
','.join(ids), action.tgt_project, action.tgt_package)
|
2017-10-12 19:11:01 +08:00
|
|
|
return False
|
|
|
|
|
2019-01-09 12:58:54 +01:00
|
|
|
# Decline delete requests against linked flavor package
|
|
|
|
linked = root.find('sourceinfo/linked')
|
|
|
|
if not (linked is None or self.check_linked_package(action, linked)):
|
2016-12-29 00:34:56 -06:00
|
|
|
return False
|
|
|
|
|
2019-01-09 12:58:54 +01:00
|
|
|
if not self.ignore_devel:
|
|
|
|
self.devel_project_review_ensure(request, action.tgt_project, action.tgt_package)
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
def check_linked_package(self, action, linked):
|
|
|
|
if linked.get('project', action.tgt_project) != action.tgt_project:
|
|
|
|
return True
|
|
|
|
linked_package = linked.get('package')
|
2024-05-07 17:55:17 +02:00
|
|
|
self.review_messages['declined'] = f"Delete the package {linked_package} instead"
|
2019-01-09 12:58:54 +01:00
|
|
|
return False
|
|
|
|
|
2018-09-17 17:06:18 -05:00
|
|
|
def check_action_delete_project(self, request, action):
|
|
|
|
# Presumably if the request is valid the bot should be disabled or
|
|
|
|
# overridden, but seems like no valid case for allowing this (see #1696).
|
2024-05-07 17:55:17 +02:00
|
|
|
self.review_messages['declined'] = f'Deleting the {action.tgt_project} project is not allowed.'
|
2018-09-17 17:06:18 -05:00
|
|
|
return False
|
|
|
|
|
2018-09-17 17:10:01 -05:00
|
|
|
def check_action_delete_repository(self, request, action):
|
2019-09-09 16:51:54 -05:00
|
|
|
self.target_project_config(action.tgt_project)
|
|
|
|
|
|
|
|
if self.mail_release_list:
|
2019-09-09 16:57:26 -05:00
|
|
|
self.review_messages['declined'] = 'Deleting repositories is not allowed. ' \
|
|
|
|
'Contact {} to discuss further.'.format(self.mail_release_list)
|
2018-09-17 17:10:01 -05:00
|
|
|
return False
|
|
|
|
|
|
|
|
self.review_messages['accepted'] = 'unhandled: removing repository'
|
|
|
|
return True
|
|
|
|
|
2022-03-24 15:23:16 +01:00
|
|
|
def run_source_validator(self, old, directory):
|
|
|
|
scripts = glob.glob("/usr/lib/obs/service/source_validators/*")
|
|
|
|
if not scripts:
|
|
|
|
raise RuntimeError.new('Missing source validator')
|
|
|
|
for script in scripts:
|
|
|
|
if os.path.isdir(script):
|
|
|
|
continue
|
2022-10-25 12:19:54 +02:00
|
|
|
res = subprocess.run([script, '--batchmode', directory, old], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
2022-03-24 15:23:16 +01:00
|
|
|
if res.returncode:
|
|
|
|
text = "Source validator failed. Try \"osc service runall source_validator\"\n"
|
|
|
|
text += res.stdout.decode('utf-8')
|
|
|
|
self.review_messages['declined'] = text
|
|
|
|
return False
|
|
|
|
|
|
|
|
for line in res.stdout.decode('utf-8').split("\n"):
|
|
|
|
# pimp up some warnings
|
|
|
|
if re.search(r'Attention.*not mentioned', line):
|
|
|
|
line = re.sub(r'\(W\) ', '', line)
|
|
|
|
self.review_messages['declined'] = line
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
2022-03-25 07:56:35 +01:00
|
|
|
def _snipe_out_existing_urls(self, old, directory, specs):
|
|
|
|
if not os.path.isdir(old):
|
|
|
|
return
|
|
|
|
oldsources = self._mentioned_sources(old, specs)
|
|
|
|
for spec in specs:
|
|
|
|
specfn = os.path.join(directory, spec)
|
|
|
|
nspecfn = specfn + '.new'
|
|
|
|
wf = open(nspecfn, 'w')
|
|
|
|
with open(specfn) as rf:
|
|
|
|
for line in rf:
|
|
|
|
m = re.match(r'(Source[0-9]*\s*):\s*(.*)$', line)
|
|
|
|
if m and m.group(2) in oldsources:
|
|
|
|
wf.write(m.group(1) + ":" + os.path.basename(m.group(2)) + "\n")
|
|
|
|
continue
|
|
|
|
wf.write(line)
|
|
|
|
wf.close()
|
|
|
|
os.rename(nspecfn, specfn)
|
|
|
|
|
|
|
|
def check_urls(self, old, directory, specs):
|
|
|
|
self._snipe_out_existing_urls(old, directory, specs)
|
|
|
|
oldcwd = os.getcwd()
|
|
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
|
|
os.chdir(directory)
|
|
|
|
res = subprocess.run(["/usr/lib/obs/service/download_files", "--enforceupstream",
|
|
|
|
"yes", "--enforcelocal", "yes", "--outdir", tmpdir], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
|
|
|
if res.returncode:
|
2022-03-25 12:11:35 +01:00
|
|
|
self.review_messages['new'] = "Source URLs are not valid. Try `osc service runall download_files`.\n" + \
|
2022-03-25 07:56:35 +01:00
|
|
|
res.stdout.decode('utf-8')
|
|
|
|
os.chdir(oldcwd)
|
|
|
|
return False
|
|
|
|
os.chdir(oldcwd)
|
|
|
|
return True
|
|
|
|
|
2022-03-24 21:19:45 +01:00
|
|
|
def difflines(self, oldf, newf):
|
|
|
|
with open(oldf, 'r') as f:
|
|
|
|
oldl = f.readlines()
|
|
|
|
with open(newf, 'r') as f:
|
|
|
|
newl = f.readlines()
|
|
|
|
return list(difflib.unified_diff(oldl, newl))
|
|
|
|
|
2022-03-25 07:39:17 +01:00
|
|
|
def _mentioned_sources(self, directory, specs):
|
|
|
|
sources = set()
|
|
|
|
for spec in specs:
|
2022-03-25 07:56:35 +01:00
|
|
|
specfn = os.path.join(directory, spec)
|
|
|
|
if not os.path.exists(specfn):
|
|
|
|
continue
|
|
|
|
with open(specfn) as f:
|
2022-03-25 07:39:17 +01:00
|
|
|
for line in f:
|
|
|
|
m = re.match(r'Source[0-9]*\s*:\s*(.*)$', line)
|
|
|
|
if not m:
|
|
|
|
continue
|
|
|
|
sources.add(m.group(1))
|
|
|
|
return sources
|
|
|
|
|
|
|
|
def detect_mentioned_patches(self, old, directory, specs):
|
2022-03-24 21:19:45 +01:00
|
|
|
# new packages have different rules
|
|
|
|
if not os.path.isdir(old):
|
|
|
|
return True
|
|
|
|
opatches = self.list_patches(old)
|
|
|
|
npatches = self.list_patches(directory)
|
|
|
|
|
|
|
|
cpatches = opatches.intersection(npatches)
|
|
|
|
opatches -= cpatches
|
|
|
|
npatches -= cpatches
|
|
|
|
|
|
|
|
if not npatches and not opatches:
|
|
|
|
return True
|
|
|
|
|
2023-06-28 15:38:01 +02:00
|
|
|
patches_to_mention = {}
|
2022-03-24 21:19:45 +01:00
|
|
|
for p in opatches:
|
|
|
|
patches_to_mention[p] = 'old'
|
|
|
|
for p in npatches:
|
|
|
|
patches_to_mention[p] = 'new'
|
|
|
|
for changes in glob.glob(os.path.join(directory, '*.changes')):
|
|
|
|
base = os.path.basename(changes)
|
|
|
|
oldchanges = os.path.join(old, base)
|
|
|
|
if os.path.exists(oldchanges):
|
|
|
|
diff = self.difflines(oldchanges, changes)
|
|
|
|
else:
|
|
|
|
with open(changes, 'r') as f:
|
2022-03-25 07:56:35 +01:00
|
|
|
diff = ['+' + line for line in f.readlines()]
|
2022-03-24 21:19:45 +01:00
|
|
|
for line in diff:
|
|
|
|
pass
|
|
|
|
# Check if the line mentions a patch being added (starts with +)
|
|
|
|
# or removed (starts with -)
|
|
|
|
if not re.match(r'[+-]', line):
|
|
|
|
continue
|
|
|
|
# In any of those cases, remove the patch from the list
|
|
|
|
line = line[1:].strip()
|
2022-03-25 11:26:53 +01:00
|
|
|
for patch in list(patches_to_mention):
|
2022-03-24 21:19:45 +01:00
|
|
|
if line.find(patch) >= 0:
|
|
|
|
del patches_to_mention[patch]
|
|
|
|
|
2022-03-25 07:39:17 +01:00
|
|
|
# if a patch is mentioned as source, we ignore it
|
|
|
|
sources = self._mentioned_sources(directory, specs)
|
|
|
|
sources |= self._mentioned_sources(old, specs)
|
|
|
|
|
|
|
|
for s in sources:
|
|
|
|
patches_to_mention.pop(s, None)
|
|
|
|
|
2022-03-24 21:19:45 +01:00
|
|
|
if not patches_to_mention:
|
|
|
|
return True
|
|
|
|
|
|
|
|
lines = []
|
|
|
|
for patch, state in patches_to_mention.items():
|
|
|
|
# wording stolen from Raymond's declines :)
|
|
|
|
if state == 'new':
|
|
|
|
lines.append(f"A patch ({patch}) is being added without this addition being mentioned in the changelog.")
|
|
|
|
else:
|
|
|
|
lines.append(f"A patch ({patch}) is being deleted without this removal being mentioned in the changelog.")
|
|
|
|
self.review_messages['declined'] = '\n'.join(lines)
|
|
|
|
return False
|
|
|
|
|
|
|
|
def list_patches(self, directory):
|
|
|
|
ret = set()
|
|
|
|
for ext in ['*.diff', '*.patch', '*.dif']:
|
|
|
|
for file in glob.glob(os.path.join(directory, ext)):
|
|
|
|
ret.add(os.path.basename(file))
|
|
|
|
return ret
|
|
|
|
|
2022-02-18 17:15:48 +01:00
|
|
|
|
2016-12-29 00:34:56 -06:00
|
|
|
class CommandLineInterface(ReviewBot.CommandLineInterface):
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
ReviewBot.CommandLineInterface.__init__(self, args, kwargs)
|
|
|
|
self.clazz = CheckSource
|
|
|
|
|
2023-06-21 14:11:18 +02:00
|
|
|
def get_optparser(self) -> CmdlnOptionParser:
|
2016-12-29 00:34:56 -06:00
|
|
|
parser = ReviewBot.CommandLineInterface.get_optparser(self)
|
|
|
|
|
2022-02-18 17:44:32 +01:00
|
|
|
parser.add_option('--skip-add-reviews', action='store_true', default=False,
|
|
|
|
help='skip adding review after completing checks')
|
2016-12-29 00:34:56 -06:00
|
|
|
|
|
|
|
return parser
|
|
|
|
|
|
|
|
def setup_checker(self):
|
|
|
|
bot = ReviewBot.CommandLineInterface.setup_checker(self)
|
|
|
|
|
|
|
|
bot.skip_add_reviews = self.options.skip_add_reviews
|
|
|
|
|
|
|
|
return bot
|
|
|
|
|
2022-02-18 17:11:46 +01:00
|
|
|
|
2016-12-29 00:34:56 -06:00
|
|
|
if __name__ == "__main__":
|
|
|
|
app = CommandLineInterface()
|
|
|
|
sys.exit(app.main())
|