Example #1
0
    def find_open_release_issues(self):
        """
        Looks for opened release issues on github
        :return: True on found, False if not found
        """
        release_issues = {}
        latest_version = Version(self.github.latest_release())
        opened_issues = self.project.get_issue_list(IssueStatus.open)
        if not opened_issues:
            self.logger.debug(f'No more open issues found')
        else:
            for issue in opened_issues:
                match, version = process_version_from_title(
                    issue.title, latest_version)
                if match:
                    if self.project.can_close_issue(which_username(self.conf),
                                                    issue):
                        release_issues[version] = issue
                        self.logger.info(
                            f'Found new release issue with version: {version}')
                    else:
                        self.logger.warning(
                            f"User {which_username(self.conf)} "
                            f"has no permission to modify issue")

        if len(release_issues) > 1:
            msg = f'Multiple release issues are open {release_issues}, please reduce them to one'
            self.logger.error(msg)
            return False
        if len(release_issues) == 1:
            if which_service(self.project) == GitService.Github:
                labels = self.new_release.labels
            elif which_service(self.project) == GitService.Pagure:
                # Putting labels on Pagure issues is not implemented yet inside ogr-lib
                labels = None

            for version, issue in release_issues.items():
                self.new_pr.update_new_pr_details(version=version,
                                                  issue_id=None,
                                                  issue_number=issue.id,
                                                  labels=labels)
                return True
        else:
            return False
Example #2
0
 def __init__(self, configuration):
     self.conf = configuration
     self.git = Git(self.conf.clone_url, self.conf)
     self.github = Github(configuration, self.git)
     self.pypi = PyPi(configuration, self.git)
     self.logger = configuration.logger
     self.new_release = NewRelease()
     self.new_pr = NewPR()
     self.project = configuration.project
     self.git_service = which_service(self.project)  # Github/Pagure
Example #3
0
    def make_pr(
        self, branch, version, log, changed_version_files, base: str = None, labels=None
    ):
        """
        Makes a pull request with info on the new release
        :param branch: name of the branch to make PR from
        :param version: version that is being released
        :param log: changelog
        :param changed_version_files: list of files that have been changed
                                      in order to update version
        :param base: base of the PR. defaults to project's default branch
        :param labels: list of str, labels to be put on PR
        :return: url of the PR
        """
        message = (
            f"Hi,\n you have requested a release PR from me. Here it is!\n"
            f"This is the changelog I created:\n"
            f"### Changes\n{log}\n\nYou can change it by editing `CHANGELOG.md` "
            f"in the root of this repository and pushing to `{branch}` branch"
            f" before merging this PR.\n"
        )
        if len(changed_version_files) == 1:
            message += "I have also updated the  `__version__ ` in file:\n"
        elif len(changed_version_files) > 1:
            message += (
                "There were multiple files where  `__version__ ` was set, "
                "so I left updating them up to you. These are the files:\n"
            )
        elif not changed_version_files:
            message += "I didn't find any files where  `__version__` is set."

        for file in changed_version_files:
            message += f"* {file}\n"

        try:
            if base is None:
                base = self.project.default_branch
            new_pr = self.project.create_pr(
                title=f"{version} release",
                body=message,
                target_branch=base,
                source_branch=branch,
            )

            self.logger.info(f"Created PR: {new_pr}")
            if labels and which_service(self.project) == GitService.Github:
                # ogr-lib implements labeling only for Github labels
                self.project.add_pr_labels(new_pr.id, labels=labels)
            return new_pr.url
        except Exception:
            msg = (
                f"Something went wrong with creating "
                f"PR on {which_service(self.project).name}"
            )
            raise ReleaseException(msg)
Example #4
0
    def get_user_contact(self):
        """
        Get user's contact details
        :return: name and email
        """
        name = 'Release bot'
        mail = '*****@*****.**'

        # don't set in case of Github app instance, it uses defaults
        if not self.conf.github_app_id:
            if which_service(self.project) == GitService.Github:
                name = self.project.service.user.get_username()
                mail = self.project.service.user.get_email()
        return name, mail
Example #5
0
 def test_which_service(self):
     git_service = which_service(self.release_bot.project)
     assert git_service == GitService.Github