Beispiel #1
0
 def _validate_branch(self):
     try:
         self.repo.branch(self.options["source_branch"])
     except github3.exceptions.NotFoundError:
         message = "Branch {} not found".format(self.options["source_branch"])
         self.logger.error(message)
         raise GithubApiNotFoundError(message)
Beispiel #2
0
 def _validate_branch(self):
     head_branch = self.repo.branch(self.options["source_branch"])
     if not head_branch:
         message = "Branch {} not found".format(
             self.options["source_branch"])
         self.logger.error(message)
         raise GithubApiNotFoundError(message)
Beispiel #3
0
 def _validate_source_branch(self, source_branch):
     """Validates that the source branch exists in the repository"""
     try:
         self.repo.branch(source_branch)
     except github3.exceptions.NotFoundError:
         message = f"Branch {source_branch} not found"
         raise GithubApiNotFoundError(message)
Beispiel #4
0
    def call_api(self, subpath, data=None):
        """ Takes a subpath under the repository (ex: /releases) and returns
        the json data from the api """
        api_url = '{}/repos/{}/{}{}'.format(
            self.github_api_base_url, self.github_owner, self.github_repo,
            subpath)

        # Use Github Authentication if available for the repo
        kwargs = {}
        if self.github_owner and self.github_owner:
            kwargs['auth'] = (self.github_owner, self.github_password)

        if data:
            resp = requests.post(api_url, data=json.dumps(data), **kwargs)
        else:
            resp = requests.get(api_url, **kwargs)

        if resp.status_code == httplib.NOT_FOUND:
            raise GithubApiNotFoundError(resp.content)
        elif resp.status_code == httplib.UNAUTHORIZED:
            raise GithubApiUnauthorized(resp.content)

        try:
            data = json.loads(resp.content)
            return data
        except:
            return resp.status_code
Beispiel #5
0
 def _get_tag_info(self, tag_name):
     tag = self.repo.ref('tags/{}'.format(tag_name))
     if not tag:
         raise GithubApiNotFoundError('Tag not found: {}'.format(tag_name))
     if tag.object.type != 'tag':
         raise GithubApiError(
             'Tag {} is lightweight, must be annotated.'.format(tag_name))
     return self.repo.tag(tag.object.sha)
Beispiel #6
0
 def _get_tag_info(self, tag_name):
     try:
         tag = self.repo.ref("tags/{}".format(tag_name))
     except github3.exceptions.NotFoundError:
         raise GithubApiNotFoundError("Tag not found: {}".format(tag_name))
     if tag.object.type != "tag":
         raise GithubApiError(
             "Tag {} is lightweight, must be annotated.".format(tag_name))
     return self.repo.tag(tag.object.sha)
Beispiel #7
0
 def _get_issue(self, issue_number):
     try:
         issue = self.github.issue(
             self.release_notes_generator.github_info["github_owner"],
             self.release_notes_generator.github_info["github_repo"],
             issue_number,
         )
     except github3.exceptions.NotFoundError:
         raise GithubApiNotFoundError("Issue #{} not found".format(issue_number))
     return issue
Beispiel #8
0
 def _get_issue(self, issue_number):
     issue = self.github.issue(
         self.release_notes_generator.github_info['github_owner'],
         self.release_notes_generator.github_info['github_repo'],
         issue_number,
     )
     if not issue:
         raise GithubApiNotFoundError(
             'Issue #{} not found'.format(issue_number))
     return issue