Beispiel #1
0
 def make_release_pr(self, new_pr, gitchangelog):
     """
     Makes the steps to prepare new branch for the release PR,
     like generating changelog and updating version
     :param new_pr: object of class new_pr with info about the new release
     :param gitchangelog: bool, use gitchangelog
     :return: True on success, False on fail
     """
     repo = new_pr.repo
     version = new_pr.version
     branch = f"{version}-release"
     if self.branch_exists(branch):
         self.logger.warning(
             f"Branch {branch} already exists, aborting creating PR."
         )
         return False
     if self.conf.dry_run:
         msg = (
             f"I would make a new PR for release of version "
             f"{version} based on the issue."
         )
         self.logger.info(msg)
         return False
     try:
         name, email = self.get_user_contact()
         repo.set_credentials(name, email)
         repo.set_credential_store()
         # The bot first checks out the default branch and from it
         # it creates the new branch, checks out to it and then perform the release
         # This makes sure that the new release_pr branch has all the commits
         # from the default branch for the latest release.
         repo.checkout(self.project.default_branch)
         changelog = repo.get_log_since_last_release(
             new_pr.previous_version, gitchangelog
         )
         repo.checkout_new_branch(branch)
         changed = look_for_version_files(repo.repo_path, new_pr.version)
         if insert_in_changelog(
             f"{repo.repo_path}/CHANGELOG.md", new_pr.version, changelog
         ):
             repo.add(["CHANGELOG.md"])
         if changed:
             repo.add(changed)
         repo.commit(f"{version} release", allow_empty=True)
         repo.push(branch)
         if not self.pr_exists(f"{version} release"):
             new_pr.pr_url = self.make_pr(
                 branch=branch,
                 version=f"{version}",
                 log=changelog,
                 changed_version_files=changed,
                 labels=new_pr.labels,
             )
             return True
     except GitException as exc:
         raise ReleaseException(exc)
     finally:
         repo.checkout(self.project.default_branch)
     return False
Beispiel #2
0
 def make_release_pr(self, new_pr):
     """
     Makes the steps to prepare new branch for the release PR,
     like generating changelog and updating version
     :param new_pr: dict with info about the new release
     :return: True on success, False on fail
     """
     repo = new_pr['repo']
     version = new_pr['version']
     branch = f'{version}-release'
     if self.branch_exists(branch):
         self.logger.warning(f'Branch {branch} already exists, aborting creating PR.')
         return False
     try:
         name, email = self.get_user_contact()
         repo.set_credentials(name, email)
         repo.set_credential_store()
         # The bot first checks out the master branch and from master
         # it creates the new branch, checks out to it and then perform the release
         # This makes sure that the new release_pr branch has all the commits
         # from the master branch for the lastest release.
         repo.checkout('master')
         changelog = repo.get_log_since_last_release(new_pr['previous_version'])
         repo.checkout_new_branch(branch)
         changed = look_for_version_files(repo.repo_path, new_pr['version'])
         if insert_in_changelog(f'{repo.repo_path}/CHANGELOG.md',
                                new_pr['version'], changelog):
             repo.add(['CHANGELOG.md'])
         if changed:
             repo.add(changed)
         repo.commit(f'{version} release', allow_empty=True)
         repo.push(branch)
         if not self.pr_exists(f'{version} release'):
             new_pr['pr_url'] = self.make_pr(branch, f'{version}', changelog, changed,
                                             labels=new_pr.get('labels'))
             return True
     except GitException as exc:
         raise ReleaseException(exc)
     finally:
         repo.checkout('master')
     return False