Skip to content

Commit afe5f4e

Browse files
authored
fix(review): Fix primary-secondary determination (#47967)
### What does this PR do? Count the ownership of all PR files to properly decide the `primary`/`secondary` role indicator in code review message. ### Motivation This indicator must help reviewers understand their role in code review. The computation was wrong as only computing the number of files related to the current review_request, thus emitting `primary` nearly all the time. ### Describe how you validated your changes Local tests on existing PR with modified code: ``` GITHUB_TOKEN=$(ddtool auth github token) inv issue.ask-reviews -p 47890 -a review_request -t agent-log-pipelines Requested reviewers: ['agent-log-pipelines'] PR size: large lines, 10 files defaultdict(<class 'int'>, {'agent-devx': 9, 'agent-health': 1, 'agent-log-pipelines': 1, 'agent-runtime s': 2, 'ebpf-platform': 1, 'ndm-integrations': 1, 'network-device-monitoring-core': 1, 'cloud-network-monitoring': 4, 'windows-products ': 1, 'ecs-experiences': 1}) *Pierre-Louis Veyrenc* is asking review for PR <https://github.com/DataDog/datadog-agent/pull/47890/s|[ACIX-1365] refactor(e2e): auto-i nstall ECR credentials helper in docker.NewManager>. This is a `large` PR. agent-log-pipelines has 1 file(s) to review, as a secondary reviewer. Could you please have a look? Thanks in advance! #agent-log-pipelines ``` ### Additional Notes [ACIX-1365]: https://datadoghq.atlassian.net/browse/ACIX-1365?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ Co-authored-by: nicolas.schweitzer <nicolas.schweitzer@datadoghq.com>
1 parent 4fb24e1 commit afe5f4e

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

tasks/issue.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def ask_reviews(_, pr_id, action, team_slugs):
5050
waves = [emoji for emoji in emojis.data['emoji'] if 'wave' in emoji and 'microwave' not in emoji]
5151

5252
# Compute per-team file counts and PR size
53-
file_counts = _get_team_file_counts(pr, requested)
53+
file_counts = _get_team_file_counts(pr)
5454
size = get_pr_size(pr)
5555
max_files = max(file_counts.values()) if file_counts else 0
5656

@@ -112,17 +112,15 @@ def _is_revert(pr) -> bool:
112112
return False
113113

114114

115-
def _get_team_file_counts(pr, team_slugs, owners_file='.github/CODEOWNERS'):
115+
def _get_team_file_counts(pr, owners_file='.github/CODEOWNERS'):
116116
"""Return a dict mapping each team slug to the number of PR files it owns."""
117117
owners = read_owners(owners_file)
118-
counts = {slug: 0 for slug in team_slugs}
118+
counts = defaultdict(int)
119119
for f in pr.get_files():
120120
file_owners = owners.of(f.filename)
121-
for _kind, owner_handle in file_owners:
121+
for _, owner_handle in file_owners:
122122
normalized = owner_handle.casefold().removeprefix("@datadog/")
123-
for slug in team_slugs:
124-
if slug.casefold() == normalized:
125-
counts[slug] += 1
123+
counts[normalized] += 1
126124
return counts
127125

128126

0 commit comments

Comments
 (0)