You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/06/28 15:42:45 UTC

[GitHub] [airflow] ashb commented on a diff in pull request #24654: Script to filter candidates for PR of the month based on heuristics

ashb commented on code in PR #24654:
URL: https://github.com/apache/airflow/pull/24654#discussion_r908640536


##########
dev/stats/get_important_pr_candidates.py:
##########
@@ -0,0 +1,187 @@
+#!/usr/bin/env python3
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+import logging
+import math
+import sys
+import textwrap
+from copy import deepcopy
+from datetime import date, datetime, timedelta
+from typing import List, Set
+
+import rich_click as click
+from github import Github
+from github.PullRequest import PullRequest
+from rich.console import Console
+
+if sys.version_info >= (3, 8):
+    from functools import cached_property
+else:
+    from cached_property import cached_property
+
+PROVIDER_LABEL = "area:providers"
+
+logger = logging.getLogger(__name__)
+
+console = Console(width=400, color_system="standard")
+
+option_github_token = click.option(
+    "--github-token",
+    type=str,
+    required=True,
+    help=textwrap.dedent(
+        """
+        GitHub token used to authenticate.
+        You can set omit it if you have GITHUB_TOKEN env variable set
+        Can be generated with:
+        https://github.com/settings/tokens/new?description=Read%20issues&scopes=repo:status"""
+    ),
+    envvar='GITHUB_TOKEN',
+)
+
+PROVIDER_SCORE = 0.5
+REGULAR_SCORE = 1.0
+
+REVIEW_INTERACTION_VALUE = 1.0
+COMMENT_INTERACTION_VALUE = 1.0
+REACTION_INTERACTION_VALUE = 0.1
+
+
+class PrStat:
+    def __init__(self, pull_request: PullRequest):
+        self.pull_request = pull_request
+        self._users: Set[str] = set()
+
+    @cached_property
+    def label_score(self) -> float:
+        for label in self.pull_request.labels:
+            if "provider" in label.name:
+                return PROVIDER_SCORE
+        return REGULAR_SCORE
+
+    @cached_property
+    def num_interactions(self) -> float:
+        interactions = 0.0
+        for comment in self.pull_request.get_comments():
+            interactions += COMMENT_INTERACTION_VALUE
+            self._users.add(comment.user.login)
+            for _ in comment.get_reactions():
+                interactions += REACTION_INTERACTION_VALUE
+        for review in self.pull_request.get_reviews():
+            interactions += REVIEW_INTERACTION_VALUE
+            self._users.add(review.user.login)
+        return interactions
+
+    @cached_property
+    def num_interacting_users(self) -> int:
+        _ = self.num_interactions  # make sure the _users set is populated
+        return len(self._users)
+
+    @cached_property
+    def num_changed_files(self) -> float:
+        return self.pull_request.changed_files
+
+    @cached_property
+    def score(self):
+        return (
+            1.0
+            * self.num_interactions
+            * self.label_score
+            * self.num_interacting_users
+            / (math.log10(self.num_changed_files) if self.num_changed_files > 10 else 1.0)
+        )
+
+    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}"
+        )
+
+
+DAYS_BACK = 5
+# Current (or previous during first few days of the next month)
+DEFAULT_BEGINNING_OF_MONTH = (date.today() - timedelta(days=DAYS_BACK)).replace(day=1)
+DEFAULT_END_OF_MONTH = (
+    deepcopy(DEFAULT_BEGINNING_OF_MONTH)
+    .replace(month=1 if DEFAULT_BEGINNING_OF_MONTH == 12 else DEFAULT_BEGINNING_OF_MONTH.month + 1)
+    .replace(
+        year=DEFAULT_BEGINNING_OF_MONTH.year + 1
+        if DEFAULT_BEGINNING_OF_MONTH.month == 12
+        else DEFAULT_BEGINNING_OF_MONTH.year
+    )
+)

Review Comment:
   Lets use pendulum?
   
   ```suggestion
   DEFAULT_BEGINNING_OF_MONTH = pendulum.now().start_of('month")
   DEFAULT_END_OF_MONTH = DEFAULT_BEGINNING_OF_MONTH.add(months=1)
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org