def _get_commit_hashes(pull: PullRequest) -> List[str]: """ Get a list of the commit hashes associated with this PR :param pull: :return: """ return [c.sha for c in pull.get_commits()]
def hide_orphaned_commit_comments(self, pull: PullRequest) -> None: # rewriting history of branch removes commits # we do not want to show test results for those commits anymore # get commits of this pull request commit_shas = set([commit.sha for commit in pull.get_commits()]) # get comments of this pull request comments = self.get_pull_request_comments(pull) # get all comments that come from this action and are not hidden comments = self.get_action_comments(comments) # get comment node ids and their commit sha (possibly abbreviated) matches = [(comment.get('id'), re.search(r'^[Rr]esults for commit ([0-9a-f]{8,40})\.(?:\s.*)?$', comment.get('body'), re.MULTILINE)) for comment in comments] comment_commits = [(node_id, match.group(1)) for node_id, match in matches if match is not None] # get those comment node ids whose commit is not part of this pull request any more comment_ids = [(node_id, comment_commit_sha) for (node_id, comment_commit_sha) in comment_commits if not any([sha for sha in commit_shas if sha.startswith(comment_commit_sha)])] # hide all those comments for node_id, comment_commit_sha in comment_ids: self._logger.info('hiding unit test result comment for commit {}'.format(comment_commit_sha)) self.hide_comment(node_id)
def get_checks_summary_lines(self, pr: PullRequest) -> List[str]: lines = [] commit = pr.get_commits().reversed[0] for suite in commit.get_check_suites(): completed = suite.status == "completed" success = suite.conclusion in ["success", "neutral", "skipped"] if completed: result = CHECK_PASSED if success else CHECK_FAILED else: result = CHECK_PENDING lines.append(f"**{suite.app.name}** {result}") return lines
def pullreq_commits_authors(pullreq: PullRequest, cache: MutableMapping[int, CacheItem]) -> List[AuthorTuple]: """Return a list of git authors of all commits contained in the given pull request.""" cached_item = cache.get(pullreq.id) if cached_item and cached_item.updated_at >= pullreq.updated_at: LOG.debug("Using cached data for pull request #%s", pullreq.number) commits_authors = cached_item.value else: LOG.debug("Loading commits for pull request #%s", pullreq.number) commits_authors = [commit_git_author(c) for c in pullreq.get_commits()] cache[pullreq.id] = CacheItem(commits_authors, pullreq.updated_at) return commits_authors
def pullreq_commits_authors( pullreq: PullRequest, cache: MutableMapping[int, CacheItem]) -> List[AuthorTuple]: """Return a list of git authors of all commits contained in the given pull request.""" cached_item = cache.get(pullreq.id) if cached_item and cached_item.updated_at >= pullreq.updated_at: LOG.debug("Using cached data for pull request #%s", pullreq.number) commits_authors = cached_item.value else: LOG.debug("Loading commits for pull request #%s", pullreq.number) commits_authors = [commit_git_author(c) for c in pullreq.get_commits()] cache[pullreq.id] = CacheItem(commits_authors, pullreq.updated_at) return commits_authors
def store(self, pull_request: GithubPullRequest): """Override :func:`~Entity.store`.""" _LOGGER.info("Extracting PR #%d", pull_request.number) if pull_request.number in self.previous_knowledge.index: _LOGGER.debug("PullRequest %s already analysed, skipping") return created_at = int(pull_request.created_at.timestamp()) closed_at = int(pull_request.closed_at.timestamp() ) if pull_request.closed_at is not None else None merged_at = int(pull_request.merged_at.timestamp() ) if pull_request.merged_at is not None else None closed_by = pull_request.as_issue( ).closed_by.login if pull_request.as_issue( ).closed_by is not None else None merged_by = pull_request.merged_by.login if pull_request.merged_by is not None else None labels = [label.name for label in pull_request.get_labels()] # Evaluate size of PR pull_request_size = None if labels: pull_request_size = GitHubKnowledge.get_labeled_size(labels) if not pull_request_size: lines_changes = pull_request.additions + pull_request.deletions pull_request_size = GitHubKnowledge.assign_pull_request_size( lines_changes=lines_changes) reviews = self.extract_pull_request_reviews(pull_request) self.stored_entities[str(pull_request.number)] = { "title": pull_request.title, "body": pull_request.body, "size": pull_request_size, "created_by": pull_request.user.login, "created_at": created_at, "closed_at": closed_at, "closed_by": closed_by, "merged_at": merged_at, "merged_by": merged_by, "commits_number": pull_request.commits, "changed_files_number": pull_request.changed_files, "interactions": GitHubKnowledge.get_interactions( pull_request.get_issue_comments()), "reviews": reviews, "labels": labels, "commits": [c.sha for c in pull_request.get_commits()], "changed_files": [f.filename for f in pull_request.get_files()], "first_review_at": get_first_review_time(reviews), "first_approve_at": get_approve_time(reviews), }