Skip to content

Commit

Permalink
Simplifying description scanning phase. (#291)
Browse files Browse the repository at this point in the history
Reducing description scanning to one step and leveraging set
intersections to create lists of pull requests and issues to close.

closes #279
  • Loading branch information
mwaxmonsky authored Aug 23, 2024
1 parent 9a8766a commit 4663589
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions .github/scripts/branch_pr_issue_closer.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,6 @@ def _main_prog():
#Extract (lower case) Pull Request message:
pr_msg_lower = merged_pull.body.lower()

#End script if no keywords found:
if keyword_pattern.search(pr_msg_lower) is None:
endmsg = f"Pull request #{pr_num} was merged without using any of the keywords. "
endmsg += "Thus there are no issues to close."
end_script(endmsg)

#search for at least one keyword in PR message:
word_matches = keyword_pattern.finditer(pr_msg_lower, re.IGNORECASE)

#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#Extract issue and PR numbers associated with found keywords in merged PR message
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Expand All @@ -234,19 +225,25 @@ def _main_prog():
#Create new "closed" PR list:
close_pulls = []

#Create iterator of all keyword/id pairs:
word_matches = keyword_pattern.finditer(pr_msg_lower, re.IGNORECASE)

#Go through all matches to pull out PR and issue numbers:
found_ids = set()
for match in word_matches:

issue_dict = match.groupdict()
issue_num = int(issue_dict['id'].lstrip('0'))
found_ids.add(issue_num)

#End script if no keyword/id pairs were found:
if not found_ids:
endmsg = f"Pull request #{pr_num} was merged without using any of the keywords. "
endmsg += "Thus there are no issues to close."
end_script(endmsg)

close_pulls = list(found_ids.intersection(open_pulls))
close_issues = list(found_ids.intersection(open_issues))

#Check if number is actually for a PR (as opposed to an issue):
if issue_num in open_pulls:
#Add PR number to "close pulls" list:
close_pulls.append(issue_num)
elif issue_num in open_issues:
#If in fact an issue, then add to "close issues" list:
close_issues.append(issue_num)

#+++END REFERENCED PR LOOP+++

Expand Down

0 comments on commit 4663589

Please sign in to comment.