betodealmeida commented on a change in pull request #13588:
URL: https://github.com/apache/superset/pull/13588#discussion_r595584341



##########
File path: RELEASING/changelog.py
##########
@@ -108,21 +120,108 @@ def _get_github_login(self, git_log: GitLog) -> 
Optional[str]:
         self._github_login_cache[author_name] = github_login
         return github_login
 
+    def _has_commit_migrations(self, git_sha: str) -> bool:
+        commit = self._superset_repo.get_commit(sha=git_sha)
+        for file in commit.files:
+            if "superset/migrations/versions/" in file.filename:
+                return True
+        return False

Review comment:
       Nit suggestion:
   
   ```suggestion
           return any("superset/migrations/versions/" in file.filename for file 
in commit.files)
   ```

##########
File path: RELEASING/changelog.py
##########
@@ -108,21 +120,108 @@ def _get_github_login(self, git_log: GitLog) -> 
Optional[str]:
         self._github_login_cache[author_name] = github_login
         return github_login
 
+    def _has_commit_migrations(self, git_sha: str) -> bool:
+        commit = self._superset_repo.get_commit(sha=git_sha)
+        for file in commit.files:
+            if "superset/migrations/versions/" in file.filename:
+                return True
+        return False
+
+    def _get_pull_request_details(self, git_log: GitLog) -> Dict[str, Any]:
+        pr_number = git_log.pr_number
+        if pr_number:
+            detail = self._pr_logs_with_details.get(pr_number)
+            if detail:
+                return detail
+            else:

Review comment:
       Nit: no need for `else` here

##########
File path: RELEASING/changelog.py
##########
@@ -108,21 +120,108 @@ def _get_github_login(self, git_log: GitLog) -> 
Optional[str]:
         self._github_login_cache[author_name] = github_login
         return github_login
 
+    def _has_commit_migrations(self, git_sha: str) -> bool:
+        commit = self._superset_repo.get_commit(sha=git_sha)
+        for file in commit.files:
+            if "superset/migrations/versions/" in file.filename:
+                return True
+        return False
+
+    def _get_pull_request_details(self, git_log: GitLog) -> Dict[str, Any]:
+        pr_number = git_log.pr_number
+        if pr_number:
+            detail = self._pr_logs_with_details.get(pr_number)
+            if detail:
+                return detail
+            else:
+                pr_info = self._fetch_github_pr(pr_number)
+
+        has_migrations = self._has_commit_migrations(git_log.sha)
+        title = pr_info.title if pr_info else git_log.message
+        pr_type = re.match(r"^(fix|feat|chore|refactor|docs|build|ci|/gmi)", 
title)
+        if pr_type:
+            pr_type = pr_type.group().strip('"')
+        else:
+            pr_type = None

Review comment:
       `pr_type` will already by `None` if it's false, so:
   
   ```suggestion
           if pr_type:
               pr_type = pr_type.group().strip('"')
   ```

##########
File path: RELEASING/changelog.py
##########
@@ -108,21 +120,108 @@ def _get_github_login(self, git_log: GitLog) -> 
Optional[str]:
         self._github_login_cache[author_name] = github_login
         return github_login
 
+    def _has_commit_migrations(self, git_sha: str) -> bool:
+        commit = self._superset_repo.get_commit(sha=git_sha)
+        for file in commit.files:
+            if "superset/migrations/versions/" in file.filename:
+                return True
+        return False
+
+    def _get_pull_request_details(self, git_log: GitLog) -> Dict[str, Any]:
+        pr_number = git_log.pr_number
+        if pr_number:
+            detail = self._pr_logs_with_details.get(pr_number)
+            if detail:
+                return detail
+            else:
+                pr_info = self._fetch_github_pr(pr_number)
+
+        has_migrations = self._has_commit_migrations(git_log.sha)
+        title = pr_info.title if pr_info else git_log.message
+        pr_type = re.match(r"^(fix|feat|chore|refactor|docs|build|ci|/gmi)", 
title)
+        if pr_type:
+            pr_type = pr_type.group().strip('"')
+        else:
+            pr_type = None
+
+        labels = (" | ").join([label.name for label in pr_info.labels])
+        is_risky = self._is_risk_pull_request(pr_info.labels)
+        detail = {
+            "id": pr_number,
+            "has_migrations": has_migrations,
+            "labels": labels,
+            "title": title,
+            "type": pr_type,
+            "is_risky": is_risky or has_migrations,
+        }
+
+        if pr_number:
+            self._pr_logs_with_details[pr_number] = detail
+
+        return detail
+
+    def _is_risk_pull_request(self, labels: List[Any]) -> bool:
+        for label in labels:
+            risk_label = re.match(
+                r"^(blocking|risk|hold|revert|security vulnerability)", 
label.name
+            )
+            if risk_label is not None:
+                return True
+        return False

Review comment:
       I wonder if we should move the regular expression 
`r"^(blocking|risk|hold|revert|security vulnerability)"` to a constant, then 
this could be written:
   
   ```suggestion
           return any(re.match(RISKY_LABEL, label.name) for label in labels)
   ```

##########
File path: RELEASING/changelog.py
##########
@@ -269,14 +368,20 @@ def compare(base_parameters: BaseParameters) -> None:
     help="The github access token,"
     " if not provided will try to fetch from GITHUB_TOKEN env var",
 )
[email protected]("--risk", is_flag=True, help="show all pull request with risky 
labels")

Review comment:
       ```suggestion
   @click.option("--risk", is_flag=True, help="show all pull requests with 
risky labels")
   ```




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to