Skip to content

Commit

Permalink
[DEV] add #protm tag to score calc in protm script (#26605)
Browse files Browse the repository at this point in the history
* add protm tag to score calc in protm script

Signed-off-by: Michael Robinson <merobi@gmail.com>

* add protm tag search to review comments

Signed-off-by: Michael Robinson <merobi@gmail.com>

* add tag variation to conditions for adding to count

Signed-off-by: Michael Robinson <merobi@gmail.com>

* revise and add a tag variation to conditions for adding to count

Signed-off-by: Michael Robinson <merobi@gmail.com>

* use merged_at date instead of created_at date as cut-ff

Signed-off-by: Michael Robinson <merobi@gmail.com>

* add protm tag to score calc in protm script

Signed-off-by: Michael Robinson <merobi@gmail.com>

* add protm tag search to review comments

Signed-off-by: Michael Robinson <merobi@gmail.com>

* add tag variation to conditions for adding to count

Signed-off-by: Michael Robinson <merobi@gmail.com>

* revise and add a tag variation to conditions for adding to count

Signed-off-by: Michael Robinson <merobi@gmail.com>

* use merged_at date instead of created_at date as cut-ff

Signed-off-by: Michael Robinson <merobi@gmail.com>

* Fix CI

Signed-off-by: Michael Robinson <merobi@gmail.com>
Co-authored-by: pierrejeambrun <pierrejbrun@gmail.com>
  • Loading branch information
merobi-hub and pierrejeambrun authored Oct 11, 2022
1 parent 8e2e80a commit 0d78ba5
Showing 1 changed file with 48 additions and 23 deletions.
71 changes: 48 additions & 23 deletions dev/stats/get_important_pr_candidates.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,32 +71,44 @@ def __init__(self, g, pull_request: PullRequest):
self.len_issue_comments = 0
self.num_issue_comments = 0
self.num_issue_reactions = 0
self.protm_score = 0

@property
def label_score(self) -> float:
"""assigns label score"""
for label in self.pull_request.labels:
labels = self.pull_request.labels
for label in labels:
if "provider" in label.name:
return PrStat.PROVIDER_SCORE
return PrStat.REGULAR_SCORE

@cached_property
def num_comments(self):
"""counts reviewer comments"""
comments = 0
"""counts reviewer comments & checks for #protm tag"""
num_comments = 0
num_protm = 0
for comment in self.pull_request.get_comments():
self._users.add(comment.user.login)
comments += 1
return comments
lowercase_body = comment.body.lower()
if 'protm' in lowercase_body:
num_protm += 1
num_comments += 1
self.protm_score = num_protm
return num_comments

@cached_property
def num_conv_comments(self) -> int:
"""counts conversational comments"""
conv_comments = 0
"""counts conversational comments & checks for #protm tag"""
num_conv_comments = 0
num_protm = 0
for conv_comment in self.pull_request.get_issue_comments():
self._users.add(conv_comment.user.login)
conv_comments += 1
return conv_comments
lowercase_body = conv_comment.body.lower()
if 'protm' in lowercase_body:
num_protm += 1
num_conv_comments += 1
self.protm_score = num_protm
return num_conv_comments

@cached_property
def num_reactions(self) -> int:
Expand All @@ -121,11 +133,11 @@ def num_conv_reactions(self) -> int:
@cached_property
def num_reviews(self) -> int:
"""counts reviews"""
reviews = 0
num_reviews = 0
for review in self.pull_request.get_reviews():
self._users.add(review.user.login)
reviews += 1
return reviews
num_reviews += 1
return num_reviews

@cached_property
def issues(self):
Expand Down Expand Up @@ -155,14 +167,14 @@ def issue_reactions(self) -> int:
@cached_property
def issue_comments(self) -> int:
"""counts issue comments and calculates comment length"""
issues = self.issues
if issues:
if self.issue_nums:
repo = self.g.get_repo("apache/airflow")
issue_comments = 0
len_issue_comments = 0
for num in issues:
for num in self.issue_nums:
issue = repo.get_issue(number=num)
for issue_comment in issue.get_comments():
issues = issue.get_comments()
for issue_comment in issues:
issue_comments += 1
self._users.add(issue_comment.user.login)
if issue_comment.body is not None:
Expand Down Expand Up @@ -267,9 +279,12 @@ def score(self):
# If the body contains over 2000 characters, the PR should matter 40% more.
# If the body contains fewer than 1000 characters, the PR should matter 20% less.
#
# Weight PRs with #protm tags more heavily:
# If there is at least one #protm tag, multiply the interaction score by the number of tags, up to 3.
interaction_score *= min(self.protm_score + 1, 3)
return round(
1.0
* self.interaction_score
* interaction_score
* self.label_score
* self.length_score
* self.change_score
Expand All @@ -278,13 +293,23 @@ def score(self):
)

def __str__(self) -> str:
return (
f"Score: {self.score:.2f}: PR{self.pull_request.number} by @{self.pull_request.user.login}: "
f"\"{self.pull_request.title}\". "
f"Merged at {self.pull_request.merged_at}: {self.pull_request.html_url}"
)
if self.protm_score > 0:
return (
'[magenta]##Tagged PR## [/]'
f"Score: {self.score:.2f}: PR{self.pull_request.number} by @{self.pull_request.user.login}: "
f"\"{self.pull_request.title}\". "
f"Merged at {self.pull_request.merged_at}: {self.pull_request.html_url}"
)
else:
return (
f"Score: {self.score:.2f}: PR{self.pull_request.number} by @{self.pull_request.user.login}: "
f"\"{self.pull_request.title}\". "
f"Merged at {self.pull_request.merged_at}: {self.pull_request.html_url}"
)

def verboseStr(self) -> str:
if self.protm_score > 0:
console.print("********************* Tagged with '#protm' *********************", style="magenta")
return (
f'-- Created at [bright_blue]{self.pull_request.created_at}[/], '
f'merged at [bright_blue]{self.pull_request.merged_at}[/]\n'
Expand Down Expand Up @@ -372,7 +397,7 @@ def main(
)
continue

if pr.created_at < date_start:
if pr.merged_at < date_start:
console.print("[bright_blue]Completed selecting candidates")
break

Expand Down

0 comments on commit 0d78ba5

Please sign in to comment.