| |
@@ -27,14 +27,14 @@
|
| |
# python%{?fedora:2}-foo in requires if not available.
|
| |
|
| |
import logging
|
| |
- import pathlib
|
| |
- import tempfile
|
| |
|
| |
import click
|
| |
|
| |
- from fixrequires import LocalRepo, PagureFork
|
| |
from fixrequires.modifier import RequiresModifier
|
| |
- from qa import test_in_mock, test_in_koji
|
| |
+ from fixrequires.dnf_info import DNFInfo
|
| |
+ from qa import check_mock_build, check_koji_build
|
| |
+
|
| |
+ from mass_pagure_prs import BasePRsGenerator
|
| |
|
| |
|
| |
def get_logger(name=__name__, level=logging.DEBUG):
|
| |
@@ -70,20 +70,36 @@
|
| |
)
|
| |
|
| |
|
| |
- def fix_specfile(specfile, modifier):
|
| |
- """Fix deps in a spec file.
|
| |
+ class PagurePRsGenerator(BasePRsGenerator):
|
| |
|
| |
- Return: True if fixed, False if no changes were made
|
| |
+ """A class to generate Pagure PRs for
|
| |
+ ambiguous requires change.
|
| |
"""
|
| |
- with open(specfile, 'rt') as f:
|
| |
- spec = f.read()
|
| |
|
| |
- new_spec = modifier.run(spec)
|
| |
+ def modify_spec(self, specfile):
|
| |
+ """Modify a spec file and return a modified version.
|
| |
+
|
| |
+ Args:
|
| |
+ specfile (str): A spec file as a string.
|
| |
|
| |
- with open(specfile, 'wt') as out:
|
| |
- out.write(new_spec)
|
| |
+ Return:
|
| |
+ (str) A modified spec file.
|
| |
+ """
|
| |
+ modifier = RequiresModifier(self.logger)
|
| |
+ new_spec = modifier.run(specfile)
|
| |
+ self.set_pr_description(
|
| |
+ f'{PR_DESCRIPTION}\n\n'
|
| |
+ f'{modifier.check_for_other_fedora_branches()}'
|
| |
+ '*This PR was opened automatically, for source code see '
|
| |
+ '[here](https://pagure.io/python-fixrequires)*')
|
| |
+ return new_spec
|
| |
|
| |
- return spec != new_spec
|
| |
+ def check_mock_build_results(self, output):
|
| |
+ dnf_info = DNFInfo(self.logger)
|
| |
+ check_mock_build(output, dnf_info)
|
| |
+
|
| |
+ def check_koji_scratch_build_results(self, output):
|
| |
+ check_koji_build(output)
|
| |
|
| |
|
| |
@click.command(help=__doc__)
|
| |
@@ -127,117 +143,29 @@
|
| |
logger = get_logger(level=logging.DEBUG)
|
| |
else:
|
| |
logger = get_logger(level=logging.ERROR)
|
| |
- with open(packages, 'rt') as f:
|
| |
- require_misnamed = f.read().splitlines()
|
| |
-
|
| |
- if not require_misnamed:
|
| |
- logger.info('No packages with misnamed requires found')
|
| |
-
|
| |
- if not dirname:
|
| |
- dirname = tempfile.mkdtemp()
|
| |
-
|
| |
- modifier = RequiresModifier(logger)
|
| |
-
|
| |
- non_fedora_packages = []
|
| |
- fixed_packages = []
|
| |
- problem_packages = []
|
| |
- opened_pr_links = []
|
| |
-
|
| |
- logger.debug(f'Cloning packages into {dirname}')
|
| |
- for package_name in require_misnamed:
|
| |
-
|
| |
- try:
|
| |
- local_repo = LocalRepo(
|
| |
- package_name,
|
| |
- pathlib.Path(f'{dirname}/{package_name}'),
|
| |
- logger)
|
| |
- pagure_fork = PagureFork(
|
| |
- package_name, pagure_token, pagure_user, logger)
|
| |
-
|
| |
- local_repo.clone()
|
| |
- local_repo.create_branch(GIT_BRANCH)
|
| |
-
|
| |
- spec_fixed = fix_specfile(local_repo.specfile, modifier)
|
| |
- if not spec_fixed:
|
| |
- raise Exception(
|
| |
- 'No changes made to the spec file. '
|
| |
- 'The package might already be fixed')
|
| |
-
|
| |
- local_repo.bump_spec(COMMENT)
|
| |
- local_repo.show_diff(local_repo.specfile)
|
| |
-
|
| |
- if pagure:
|
| |
- # Create a fork before testing to avoid
|
| |
- # waiting the fork to be ready to be pushed to.
|
| |
- if not pagure_token or not pagure_user:
|
| |
- raise Exception("Please provide both pagure user and token")
|
| |
- break
|
| |
-
|
| |
- pagure_fork.do_fork()
|
| |
- fork_url = pagure_fork.get_ssh_git_url()
|
| |
-
|
| |
- # QA.
|
| |
- local_repo.create_srpm()
|
| |
- if not no_mock_build:
|
| |
- test_in_mock(local_repo, logger, dnf_info=modifier.dnf_info)
|
| |
-
|
| |
- if not no_koji_build:
|
| |
- test_in_koji(local_repo, logger)
|
| |
- modifier.check_for_other_fedora_branches()
|
| |
-
|
| |
- # All good at this point. Go ahead and push.
|
| |
- if pagure:
|
| |
- # Use username as a name for fork remote if not provided.
|
| |
- remote_name = pagure_user
|
| |
-
|
| |
- local_repo.add_to_git_remotes(remote_name, fork_url)
|
| |
- local_repo.git_add(local_repo.specfile)
|
| |
- local_repo.git_commit(COMMIT)
|
| |
- local_repo.git_push(remote_name, GIT_BRANCH)
|
| |
- # If the PR is already there, then the script is being run
|
| |
- # the second time, and just pushing to a fork is enough.
|
| |
- pr = pagure_fork.has_upstream_pr_with(
|
| |
- title=COMMIT, branch_from=GIT_BRANCH)
|
| |
- if pr:
|
| |
- logger.info(f"The PR was already opened: {pr}")
|
| |
- continue
|
| |
-
|
| |
- pagure_fork.create_pull_request(
|
| |
- from_branch=GIT_BRANCH,
|
| |
- to_branch='master',
|
| |
- title=COMMIT,
|
| |
- description=(
|
| |
- f'{PR_DESCRIPTION}\n\n'
|
| |
- f'{modifier.check_for_other_fedora_branches()}'
|
| |
- '*This PR was opened automatically, for source code see '
|
| |
- '[here](https://pagure.io/python-fixrequires)*'
|
| |
- ),
|
| |
- fas_user=fas_user, fas_password=fas_password)
|
| |
-
|
| |
- pr = pagure_fork.has_upstream_pr_with(
|
| |
- title=COMMIT, branch_from=GIT_BRANCH)
|
| |
- opened_pr_links.append(pr)
|
| |
-
|
| |
- except Exception as err:
|
| |
- logger.error(f"Failed to fix a package {package_name}. Error: {err}")
|
| |
- problem_packages.append(package_name)
|
| |
- continue
|
| |
-
|
| |
- fixed_packages.append(package_name)
|
| |
-
|
| |
- result = (
|
| |
- '\n\nRESULTS:\n'
|
| |
- f'The following {len(problem_packages)} packages had problem'
|
| |
- f' while testing and were not pushed:\n{problem_packages}\n.'
|
| |
- f'The following {len(fixed_packages)} packages were successfully fixed:\n'
|
| |
- f'{fixed_packages}\n.'
|
| |
- )
|
| |
- logger.info(result)
|
| |
-
|
| |
- if pagure:
|
| |
- logger.info('Opened PRs:')
|
| |
- for pr_link in opened_pr_links:
|
| |
- print(pr_link)
|
| |
+
|
| |
+ prs_generator = PagurePRsGenerator(
|
| |
+ packages_filename=packages,
|
| |
+ output_dirname=dirname,
|
| |
+ dry_run=not pagure,
|
| |
+ pagure_token=pagure_token,
|
| |
+ pagure_user=pagure_user,
|
| |
+ logger=logger,
|
| |
+ fas_user=fas_user,
|
| |
+ fas_password=fas_password)
|
| |
+
|
| |
+ prs_generator.configure(
|
| |
+ git_branch=GIT_BRANCH,
|
| |
+ changelog_entry=COMMENT,
|
| |
+ commit_message=COMMIT,
|
| |
+ pr_title=COMMIT,
|
| |
+ pr_description=PR_DESCRIPTION)
|
| |
+
|
| |
+ prs = prs_generator.run(
|
| |
+ do_mock_build=not no_mock_build,
|
| |
+ do_koji_scratch_build=not no_koji_build)
|
| |
+ for pr in prs:
|
| |
+ print(pr)
|
| |
|
| |
|
| |
if __name__ == '__main__':
|
| |