[llvm] [Github] Add initial workflow to prune unused user branches (PR #175693)

Baranov Victor via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 20 06:07:37 PST 2026


================
@@ -0,0 +1,85 @@
+import subprocess
+import os
+
+import github
+
+
+def get_branches() -> list[str]:
+    git_process = subprocess.run(
+        ["git", "branch", "--all"], stdout=subprocess.PIPE, check=True
+    )
+    branches = [
+        branch.strip() for branch in git_process.stdout.decode("utf-8").split("\n")
+    ]
+
+    def branch_filter(branch_name):
+        return "users/" in branch_name or "revert-" in branch_name
+
+    filtered_branches = list(filter(branch_filter, branches))
+    return [branch.replace("remotes/origin/", "") for branch in filtered_branches]
+
+
+def get_branches_from_open_prs(github_token) -> list[str]:
+    gh = github.Github(auth=github.Auth.Token(github_token))
+    query = """
+  query ($after: String) {
+    search(query: "is:pr repo:llvm/llvm-project is:open head:users/", type: ISSUE, first: 100, after: $after) {
+      nodes {
+        ... on PullRequest {
+          baseRefName
+          headRefName
+          isCrossRepository
+          number
+        }
+      }
+      pageInfo {
+        hasNextPage
+        endCursor
+      }
+    }
+  }"""
+    pr_data = []
+    has_next_page = True
+    variables = {"after": None}
+    while has_next_page:
+        _, res_data = gh.requester.graphql_query(query, variables=variables)
----------------
vbvictor wrote:

script seem to fail in ci
```
Run python3 .github/workflows/prune-unused-branches.py
Traceback (most recent call last):
  File "/home/runner/work/llvm-project/llvm-project/.github/workflows/prune-unused-branches.py", line 85, in <module>
    main(os.environ["GITHUB_TOKEN"])
  File "/home/runner/work/llvm-project/llvm-project/.github/workflows/prune-unused-branches.py", line 74, in main
    user_branches_from_prs = get_branches_from_open_prs(github_token)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/llvm-project/llvm-project/.github/workflows/prune-unused-branches.py", line 45, in get_branches_from_open_prs
    _, res_data = gh.requester.graphql_query(query, variables=variables)
                  ^^^^^^^^^^^^
AttributeError: 'Github' object has no attribute 'requester'
```

https://github.com/llvm/llvm-project/pull/175693


More information about the llvm-commits mailing list