[llvm] [Github Automation] Update Execute command (PR #81002)

Shourya Goel via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 4 19:44:36 PST 2024


https://github.com/Sh0g0-1758 updated https://github.com/llvm/llvm-project/pull/81002

>From 6ec2d323b8be4a2b6edd91ac6d6791d917bc29a2 Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Wed, 7 Feb 2024 20:54:17 +0530
Subject: [PATCH 1/7] Changed Regex to accept /branch: and /cherry-pick:
 commands

---
 llvm/utils/git/github-automation.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/llvm/utils/git/github-automation.py b/llvm/utils/git/github-automation.py
index e2b84aeca3ad7a..7eb76e435b3f34 100755
--- a/llvm/utils/git/github-automation.py
+++ b/llvm/utils/git/github-automation.py
@@ -603,16 +603,16 @@ def execute_command(self) -> bool:
         """
         This function reads lines from STDIN and executes the first command
         that it finds.  The 2 supported commands are:
-        /cherry-pick commit0 <commit1> <commit2> <...>
-        /branch <owner>/<repo>/<branch>
+        /cherry-pick<:> commit0 <commit1> <commit2> <...>
+        /branch<:> <owner>/<repo>/<branch>
         """
         for line in sys.stdin:
             line.rstrip()
-            m = re.search(r"/([a-z-]+)\s(.+)", line)
+            m = re.search(r"/([a-z-]+)(:?)(?:\s(.+))?", line)
             if not m:
                 continue
             command = m.group(1)
-            args = m.group(2)
+            args = m.group(3)
 
             if command == "cherry-pick":
                 arg_list = args.split()

>From f449793e759414109fa999a11a421cb245f40915 Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Wed, 7 Feb 2024 22:20:37 +0530
Subject: [PATCH 2/7] Changed Regex to include space also

---
 llvm/utils/git/github-automation.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/llvm/utils/git/github-automation.py b/llvm/utils/git/github-automation.py
index 7eb76e435b3f34..74e86a4fbdf2a3 100755
--- a/llvm/utils/git/github-automation.py
+++ b/llvm/utils/git/github-automation.py
@@ -603,16 +603,16 @@ def execute_command(self) -> bool:
         """
         This function reads lines from STDIN and executes the first command
         that it finds.  The 2 supported commands are:
-        /cherry-pick<:> commit0 <commit1> <commit2> <...>
-        /branch<:> <owner>/<repo>/<branch>
+        /cherry-pick< ><:> commit0 <commit1> <commit2> <...>
+        /branch< ><:> <owner>/<repo>/<branch>
         """
         for line in sys.stdin:
             line.rstrip()
-            m = re.search(r"/([a-z-]+)(:?)(?:\s(.+))?", line)
+            m = re.search(r"/([a-z-]+)\s*:? *(.*)", line)
             if not m:
                 continue
             command = m.group(1)
-            args = m.group(3)
+            args = m.group(2)
 
             if command == "cherry-pick":
                 arg_list = args.split()

>From 55e768b65b325aeab55607c2a4dda0216b906b81 Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Sat, 2 Mar 2024 14:04:37 +0530
Subject: [PATCH 3/7] Removed Branch command

---
 llvm/utils/git/github-automation.py | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/llvm/utils/git/github-automation.py b/llvm/utils/git/github-automation.py
index 6a9fe3f586896a..0dbc7b925dbc94 100755
--- a/llvm/utils/git/github-automation.py
+++ b/llvm/utils/git/github-automation.py
@@ -616,9 +616,8 @@ def create_pull_request(
     def execute_command(self) -> bool:
         """
         This function reads lines from STDIN and executes the first command
-        that it finds.  The 2 supported commands are:
+        that it finds.  The supported command is:
         /cherry-pick< ><:> commit0 <commit1> <commit2> <...>
-        /branch< ><:> <owner>/<repo>/<branch>
         """
         for line in sys.stdin:
             line.rstrip()
@@ -628,10 +627,9 @@ def execute_command(self) -> bool:
             command = m.group(1)
             args = m.group(2)
 
-            if command == "cherry-pick":
-                arg_list = args.split()
-                commits = list(map(lambda a: extract_commit_hash(a), arg_list))
-                return self.create_branch(commits)
+            arg_list = args.split()
+            commits = list(map(lambda a: extract_commit_hash(a), arg_list))
+            return self.create_branch(commits)
 
         print("Do not understand input:")
         print(sys.stdin.readlines())

>From 6b4a56c0b98b9428326dcac0f1b8eff9898fa573 Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Tue, 5 Mar 2024 08:54:23 +0530
Subject: [PATCH 4/7] Resolve Regex

---
 llvm/utils/git/github-automation.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/llvm/utils/git/github-automation.py b/llvm/utils/git/github-automation.py
index 0dbc7b925dbc94..a01d561b548dc3 100755
--- a/llvm/utils/git/github-automation.py
+++ b/llvm/utils/git/github-automation.py
@@ -621,11 +621,11 @@ def execute_command(self) -> bool:
         """
         for line in sys.stdin:
             line.rstrip()
-            m = re.search(r"/([a-z-]+)\s*:? *(.*)", line)
+            m = re.search(r"/cherry-pick\s*:? *(.*)", line)
             if not m:
                 continue
-            command = m.group(1)
-            args = m.group(2)
+            
+            args = m.group(1)
 
             arg_list = args.split()
             commits = list(map(lambda a: extract_commit_hash(a), arg_list))

>From ab6728bdea0486ef380d50aba4dc3e4c2879ea82 Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Tue, 5 Mar 2024 09:10:45 +0530
Subject: [PATCH 5/7] Ran Formatter

---
 llvm/utils/git/github-automation.py | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/llvm/utils/git/github-automation.py b/llvm/utils/git/github-automation.py
index a01d561b548dc3..dc5d96587e287e 100755
--- a/llvm/utils/git/github-automation.py
+++ b/llvm/utils/git/github-automation.py
@@ -64,7 +64,8 @@ def team_name(self) -> str:
 
     def __init__(self, token: str, repo: str, issue_number: int, label_name: str):
         self.repo = github.Github(token).get_repo(repo)
-        self.org = github.Github(token).get_organization(self.repo.organization.login)
+        self.org = github.Github(token).get_organization(
+            self.repo.organization.login)
         self.issue = self.repo.get_issue(issue_number)
         self._team_name = "issue-subscribers-{}".format(label_name).lower()
 
@@ -109,7 +110,8 @@ def team_name(self) -> str:
 
     def __init__(self, token: str, repo: str, pr_number: int, label_name: str):
         self.repo = github.Github(token).get_repo(repo)
-        self.org = github.Github(token).get_organization(self.repo.organization.login)
+        self.org = github.Github(token).get_organization(
+            self.repo.organization.login)
         self.pr = self.repo.get_issue(pr_number).as_pull_request()
         self._team_name = "pr-subscribers-{}".format(
             label_name.replace("+", "x")
@@ -318,7 +320,7 @@ def extract_commit_hash(arg: str):
     """
     github_prefix = "https://github.com/llvm/llvm-project/commit/"
     if arg.startswith(github_prefix):
-        return arg[len(github_prefix) :]
+        return arg[len(github_prefix):]
     return arg
 
 
@@ -538,7 +540,8 @@ def create_branch(self, commits: List[str]) -> bool:
 
         push_url = self.push_url
         print("Pushing to {} {}".format(push_url, branch_name))
-        local_repo.git.push(push_url, "HEAD:{}".format(branch_name), force=True)
+        local_repo.git.push(
+            push_url, "HEAD:{}".format(branch_name), force=True)
 
         self.issue_remove_cherry_pick_failed_label()
         return self.create_pull_request(
@@ -624,7 +627,7 @@ def execute_command(self) -> bool:
             m = re.search(r"/cherry-pick\s*:? *(.*)", line)
             if not m:
                 continue
-            
+
             args = m.group(1)
 
             arg_list = args.split()
@@ -659,9 +662,12 @@ def execute_command(self) -> bool:
 pr_greeter_parser = subparsers.add_parser("pr-greeter")
 pr_greeter_parser.add_argument("--issue-number", type=int, required=True)
 
-pr_buildbot_information_parser = subparsers.add_parser("pr-buildbot-information")
-pr_buildbot_information_parser.add_argument("--issue-number", type=int, required=True)
-pr_buildbot_information_parser.add_argument("--author", type=str, required=True)
+pr_buildbot_information_parser = subparsers.add_parser(
+    "pr-buildbot-information")
+pr_buildbot_information_parser.add_argument(
+    "--issue-number", type=int, required=True)
+pr_buildbot_information_parser.add_argument(
+    "--author", type=str, required=True)
 
 release_workflow_parser = subparsers.add_parser("release-workflow")
 release_workflow_parser.add_argument(

>From 8e3451e8e7192f8d301010cdbcdc152858cd99b1 Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Tue, 5 Mar 2024 09:13:18 +0530
Subject: [PATCH 6/7] Ran Formatter

---
 llvm/utils/git/github-automation.py | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)

diff --git a/llvm/utils/git/github-automation.py b/llvm/utils/git/github-automation.py
index dc5d96587e287e..a01d561b548dc3 100755
--- a/llvm/utils/git/github-automation.py
+++ b/llvm/utils/git/github-automation.py
@@ -64,8 +64,7 @@ def team_name(self) -> str:
 
     def __init__(self, token: str, repo: str, issue_number: int, label_name: str):
         self.repo = github.Github(token).get_repo(repo)
-        self.org = github.Github(token).get_organization(
-            self.repo.organization.login)
+        self.org = github.Github(token).get_organization(self.repo.organization.login)
         self.issue = self.repo.get_issue(issue_number)
         self._team_name = "issue-subscribers-{}".format(label_name).lower()
 
@@ -110,8 +109,7 @@ def team_name(self) -> str:
 
     def __init__(self, token: str, repo: str, pr_number: int, label_name: str):
         self.repo = github.Github(token).get_repo(repo)
-        self.org = github.Github(token).get_organization(
-            self.repo.organization.login)
+        self.org = github.Github(token).get_organization(self.repo.organization.login)
         self.pr = self.repo.get_issue(pr_number).as_pull_request()
         self._team_name = "pr-subscribers-{}".format(
             label_name.replace("+", "x")
@@ -320,7 +318,7 @@ def extract_commit_hash(arg: str):
     """
     github_prefix = "https://github.com/llvm/llvm-project/commit/"
     if arg.startswith(github_prefix):
-        return arg[len(github_prefix):]
+        return arg[len(github_prefix) :]
     return arg
 
 
@@ -540,8 +538,7 @@ def create_branch(self, commits: List[str]) -> bool:
 
         push_url = self.push_url
         print("Pushing to {} {}".format(push_url, branch_name))
-        local_repo.git.push(
-            push_url, "HEAD:{}".format(branch_name), force=True)
+        local_repo.git.push(push_url, "HEAD:{}".format(branch_name), force=True)
 
         self.issue_remove_cherry_pick_failed_label()
         return self.create_pull_request(
@@ -627,7 +624,7 @@ def execute_command(self) -> bool:
             m = re.search(r"/cherry-pick\s*:? *(.*)", line)
             if not m:
                 continue
-
+            
             args = m.group(1)
 
             arg_list = args.split()
@@ -662,12 +659,9 @@ def execute_command(self) -> bool:
 pr_greeter_parser = subparsers.add_parser("pr-greeter")
 pr_greeter_parser.add_argument("--issue-number", type=int, required=True)
 
-pr_buildbot_information_parser = subparsers.add_parser(
-    "pr-buildbot-information")
-pr_buildbot_information_parser.add_argument(
-    "--issue-number", type=int, required=True)
-pr_buildbot_information_parser.add_argument(
-    "--author", type=str, required=True)
+pr_buildbot_information_parser = subparsers.add_parser("pr-buildbot-information")
+pr_buildbot_information_parser.add_argument("--issue-number", type=int, required=True)
+pr_buildbot_information_parser.add_argument("--author", type=str, required=True)
 
 release_workflow_parser = subparsers.add_parser("release-workflow")
 release_workflow_parser.add_argument(

>From 82a9d11061e51e738e390eb83ecc5e64b746af61 Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Tue, 5 Mar 2024 09:14:19 +0530
Subject: [PATCH 7/7] Ran Formatter

---
 llvm/utils/git/github-automation.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/utils/git/github-automation.py b/llvm/utils/git/github-automation.py
index a01d561b548dc3..b2e6843eb9af17 100755
--- a/llvm/utils/git/github-automation.py
+++ b/llvm/utils/git/github-automation.py
@@ -624,7 +624,7 @@ def execute_command(self) -> bool:
             m = re.search(r"/cherry-pick\s*:? *(.*)", line)
             if not m:
                 continue
-            
+
             args = m.group(1)
 
             arg_list = args.split()



More information about the llvm-commits mailing list