You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by pi...@apache.org on 2022/10/11 22:13:37 UTC

[airflow] branch main updated: [DEV] add #protm tag to score calc in protm script (#26605)

This is an automated email from the ASF dual-hosted git repository.

pierrejeambrun pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 0d78ba560d [DEV] add #protm tag to score calc in protm script (#26605)
0d78ba560d is described below

commit 0d78ba560dec2e7ea2670744800864906622a4a4
Author: Michael Robinson <68...@users.noreply.github.com>
AuthorDate: Tue Oct 11 18:13:17 2022 -0400

    [DEV] add #protm tag to score calc in protm script (#26605)
    
    * add protm tag to score calc in protm script
    
    Signed-off-by: Michael Robinson <me...@gmail.com>
    
    * add protm tag search to review comments
    
    Signed-off-by: Michael Robinson <me...@gmail.com>
    
    * add tag variation to conditions for adding to count
    
    Signed-off-by: Michael Robinson <me...@gmail.com>
    
    * revise and add a tag variation to conditions for adding to count
    
    Signed-off-by: Michael Robinson <me...@gmail.com>
    
    * use merged_at date instead of created_at date as cut-ff
    
    Signed-off-by: Michael Robinson <me...@gmail.com>
    
    * add protm tag to score calc in protm script
    
    Signed-off-by: Michael Robinson <me...@gmail.com>
    
    * add protm tag search to review comments
    
    Signed-off-by: Michael Robinson <me...@gmail.com>
    
    * add tag variation to conditions for adding to count
    
    Signed-off-by: Michael Robinson <me...@gmail.com>
    
    * revise and add a tag variation to conditions for adding to count
    
    Signed-off-by: Michael Robinson <me...@gmail.com>
    
    * use merged_at date instead of created_at date as cut-ff
    
    Signed-off-by: Michael Robinson <me...@gmail.com>
    
    * Fix CI
    
    Signed-off-by: Michael Robinson <me...@gmail.com>
    Co-authored-by: pierrejeambrun <pi...@gmail.com>
---
 dev/stats/get_important_pr_candidates.py | 71 +++++++++++++++++++++-----------
 1 file changed, 48 insertions(+), 23 deletions(-)

diff --git a/dev/stats/get_important_pr_candidates.py b/dev/stats/get_important_pr_candidates.py
index 802b925a95..13690b07ae 100755
--- a/dev/stats/get_important_pr_candidates.py
+++ b/dev/stats/get_important_pr_candidates.py
@@ -71,32 +71,44 @@ class PrStat:
         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:
@@ -121,11 +133,11 @@ class PrStat:
     @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):
@@ -155,14 +167,14 @@ class PrStat:
     @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:
@@ -267,9 +279,12 @@ class PrStat:
         # 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
@@ -278,13 +293,23 @@ class PrStat:
         )
 
     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'
@@ -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