Skip to content

Commit

Permalink
Ciac 10185 (demisto#34402)
Browse files Browse the repository at this point in the history
* Ciac 10185

* Ciac 10185

* Ciac 10185

* Ciac 10185

* Ciac 10185

* Ciac 10185

* Ciac 10185

* Ciac 10185

* Ciac 10185

* Ciac 10185
  • Loading branch information
edik24 authored May 21, 2024
1 parent ef0fa46 commit cb53d9e
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion Utils/github_workflow_scripts/handle_external_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"Triggers"
]
PR_AUTHOR_PATTERN = '## Contributor\n@(.*)'
LABELS_TO_SKIP_PR_REVIEW = {'contribution on hold'}


def get_location_of_reviewer(assigned_prs_per_potential_reviewer: dict) -> int:
Expand Down Expand Up @@ -93,6 +94,24 @@ def get_location_of_reviewer(assigned_prs_per_potential_reviewer: dict) -> int:
return 0


def skip_pr_from_count_for_reviewer(pr: PullRequest, pr_labels: list[str]) -> bool:
""" Checks if the current PR has the label "contribution on hold" or pr is in draft state,
if so - the PR won't be counted for the PR count to determine reviewer
Args:
pr (PullRequest): The PR
pr_labels (list): The PR labels
Returns:
bool: if PR need to be skipped
"""
pr_labels_set = set(pr_labels)
if pr.draft or LABELS_TO_SKIP_PR_REVIEW.issubset(pr_labels_set):
print(f'PR number {pr.number} with draft status {pr.draft} and labels {pr_labels_set} will be skipped from count ')
return True
return False


def determine_random_reviewer(potential_reviewers: list[str], repo: Repository) -> str:
"""Checks the number of open 'Contribution' PRs that have been assigned to a user
for each potential reviewer and returns the user with the smallest amount.
Expand All @@ -111,7 +130,7 @@ def determine_random_reviewer(potential_reviewers: list[str], repo: Repository)
for pull in pulls:
# we only consider 'Contribution' prs when computing who to assign
pr_labels = [label.name.casefold() for label in pull.labels]
if label_to_consider not in pr_labels:
if label_to_consider not in pr_labels or skip_pr_from_count_for_reviewer(pull, pr_labels):
continue
assignees = {assignee.login for assignee in pull.assignees}
for reviewer in potential_reviewers:
Expand Down

0 comments on commit cb53d9e

Please sign in to comment.