def update_unaggregated_pr_header(self, pull_request_to_update, branch_name_to_add): """Updates the 'Unaggregated Pull Requests' section header with a link to the new child branch pull request""" body = pull_request_to_update.body if self.UNAGGREGATED_SECTION_HEADER not in body: body += self.UNAGGREGATED_SECTION_HEADER pull_requests = get_pull_requests_with_base_branch( self.repo, branch_name_to_add.split("__")[0], branch_name_to_add) if len(pull_requests) == 0: raise CumulusCIException( "No pull request for branch {} found.".format( branch_name_to_add)) elif len(pull_requests) > 1: raise CumulusCIException( "Expected one pull request, found {} for branch {}".format( len(pull_requests), branch_name_to_add)) pull_request_link = markdown_link_to_pr(pull_requests[0]) if pull_request_link not in body: body += "\r\n* " + pull_request_link pull_request_to_update.update(body=body) return
def _get_release(self): repo = self.get_repo() try: return repo.release_from_tag(self.current_tag) except github3.exceptions.NotFoundError: raise CumulusCIException("Release not found for tag: {}".format( self.current_tag))
def aggregate_child_change_notes(self, pull_request): """Given a pull request, aggregate all change notes from child pull requests. Child pull requests are pull requests that have a base branch equal to the the given pull request's head.""" self.change_notes = get_pull_requests_with_base_branch( self.repo, pull_request.head.ref, state="all") self.change_notes = [ note for note in self.change_notes if is_pull_request_merged(note) and note.head.ref != self.repo.default_branch ] if len(self.change_notes) == 0: return for change_note in self.change_notes: self._parse_change_note(change_note) body = [] for parser in self.parsers: if parser.title is None: parser.title = "Notes From Child PRs" parser_content = parser.render() if parser_content: body.append(parser_content) if self.empty_change_notes: body.extend(render_empty_pr_section(self.empty_change_notes)) new_body = "\r\n".join(body) if not pull_request.update(body=new_body): raise CumulusCIException( "Update of pull request #{} failed.".format( pull_request.number))
def __call__(self): release = self._get_release() if not release: raise CumulusCIException("Release not found for tag: {}".format( self.current_tag)) content = super(GithubReleaseNotesGenerator, self).__call__() content = self._update_release_content(release, content) if self.do_publish: release.edit(body=content) return content