Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Size reports: Don't comment on outdated builds #10565

Merged
merged 1 commit into from
Oct 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion scripts/tools/memory/gh_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@ def gh_get_comments_for_pr(gh: ghapi.core.GhApi, pr: int):
ghapi.all.paged(gh.issues.list_comments, pr))


def gh_get_commits_for_pr(gh: ghapi.core.GhApi, pr: int):
return itertools.chain.from_iterable(
ghapi.all.paged(gh.pulls.list_commits, pr))


def percent_change(a: int, b: int) -> float:
if a == 0:
return 0.0 if b == 0 else float('inf')
Expand Down Expand Up @@ -455,6 +460,20 @@ def gh_send_change_report(db: SizeDatabase, df: pd.DataFrame,
if not db.gh:
return False
pr = df.attrs['pr']

# Check the most recent commit on the PR, so that we don't comment on
# builds that are already outdated.
commit = df.attrs['commit']
commits = sorted(gh_get_commits_for_pr(db.gh, pr),
key=lambda c: c.commit.committer.date,
reverse=True)
if commits and commit != commits[0].sha:
logging.debug('SCS: PR #%s: not commenting for stale %s; newest is %s',
pr, commit, commits[0].sha)
return False

# Check for an existing size report comment. If one exists, we'll add
# the new report to it.
title = df.attrs['title']
existing_comment_id = 0
for comment in gh_get_comments_for_pr(db.gh, pr):
Expand Down Expand Up @@ -545,7 +564,6 @@ def report_matching_commits(db: SizeDatabase) -> Dict[str, pd.DataFrame]:

if (pr and comment_enabled
and (comment_limit == 0 or comment_limit > comment_count)):
comment_count += 1
if gh_send_change_report(db, df, tdf):
# Mark the originating builds, and remove the originating
# artifacts, so that they don't generate duplicate report
Expand All @@ -555,6 +573,7 @@ def report_matching_commits(db: SizeDatabase) -> Dict[str, pd.DataFrame]:
for artifact_id in df.attrs['artifacts']:
logging.info('RMC: deleting artifact %d', artifact_id)
db.delete_artifact(artifact_id)
comment_count += 1
return dfs


Expand Down