Skip to content

Commit

Permalink
Limit number of diffs for large PRs
Browse files Browse the repository at this point in the history
  • Loading branch information
Micket committed Oct 31, 2024
1 parent 6a4e1fe commit f469159
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
39 changes: 28 additions & 11 deletions .github/workflows/tagbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def sort_by_added_date(repo, file_paths):

def similar_easyconfigs(repo, new_file):
possible_neighbours = [x for x in new_file.parent.glob('*.eb') if x != new_file]
return sort_by_added_date(repo, possible_neighbours)[:3] # top 3 choices
return sort_by_added_date(repo, possible_neighbours)


def diff(old, new):
Expand Down Expand Up @@ -79,28 +79,45 @@ def pr_ecs(pr_diff):
print("Changed ECs:", changed_ecs)
print("Newly added ECs:", new_ecs)

new_software = False
updated_software = False
comment = ''
new_software = 0
updated_software = 0
to_diff = dict()
for new_file in new_ecs:
neighbours = similar_easyconfigs(gitrepo, new_file)
print(f"Found {len(neighbours)} neighbours for {new_file}")
if neighbours:
updated_software = True
print(f"Diffs for {new_file}")
comment += f'#### Updated software `{new_file.name}`\n\n'
updated_software += 1
to_diff[new_file] = neighbours
else:
new_software += 1

print(f"Generating comment for {len(to_diff)} updates softwares")
# Limit comment size for large PRs:
if len(to_diff) > 20: # Too much, either bad PR or some broad change. Not diffing.
max_diffs_per_software = 0
elif len(to_diff) > 10:
max_diffs_per_software = 1
elif len(to_diff) > 5:
max_diffs_per_software = 2
else:
max_diffs_per_software = 3

for neighbour in neighbours:
comment = ''
if max_diffs_per_software > 0:
for new_file, neighbours in to_diff.items():
compare_neighbours = neighbours[:max_diffs_per_software]
if compare_neighbours:
print(f"Diffs for {new_file}")
comment += f'#### Updated software `{new_file.name}`\n\n'

for neighbour in compare_neighbours:
print(f"against {neighbour}")
comment += '<details>\n'
comment += f'<summary>Diff against <code>{neighbour.name}</code></summary>\n\n'
comment += f'[{neighbour}](https://github.com/{repo}/blob/{base_branch_name}/{neighbour})\n\n'
comment += '```diff\n'
comment += diff(neighbour, new_file)
comment += '```\n</details>\n\n'
else:
new_software = True


print("Adjusting labels")
current_labels = [label['name'] for label in data['pull_request']['labels']]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tagbot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

- run: |
# Make sure the script is unmodified
echo "9763efd8ceb7b8fb85573e8180e8b0dcac1a4d53d5b7a69fbbf0ac8d4584ccd9 .github/workflows/tagbot.py"|sha256sum --check --status
echo "8be2d295e8436ce557acc8a4d3b82a639913ae65de0d1a76871f21359b4e8d9f .github/workflows/tagbot.py"|sha256sum --check --status
- name: set up Python
uses: actions/setup-python@v5
Expand Down

0 comments on commit f469159

Please sign in to comment.