newModuleTagger: add --open|--merged|--closed
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
from tqdm import tqdm
|
||||
from pathlib import Path
|
||||
import argparse
|
||||
import subprocess
|
||||
import json
|
||||
import time
|
||||
@@ -15,7 +16,7 @@ RETRY_BACKOFF_SECONDS=3
|
||||
|
||||
|
||||
GRAPHQL_QUERY = """
|
||||
query($endCursor: String) {
|
||||
query($endCursor: String, $states: [PullRequestState!]) {
|
||||
repository(owner: "NixOS", name: "nixpkgs") {
|
||||
pullRequests(
|
||||
first: """ + str(PAGINATION_STEP) + """,
|
||||
@@ -25,6 +26,7 @@ query($endCursor: String) {
|
||||
direction: DESC
|
||||
},
|
||||
labels: ["8.has: module (update)"],
|
||||
states: $states,
|
||||
) {
|
||||
edges {
|
||||
node {
|
||||
@@ -74,13 +76,24 @@ def _gh(args: list[str]) -> str | None:
|
||||
return None
|
||||
|
||||
|
||||
def find_prs_without_new_module_tag():
|
||||
def parse_args():
|
||||
parser = argparse.ArgumentParser()
|
||||
state_group = parser.add_mutually_exclusive_group()
|
||||
state_group.add_argument('--open', action='store_true', help='Only show open PRs')
|
||||
state_group.add_argument('--merged', action='store_true', help='Only show merged PRs')
|
||||
state_group.add_argument('--closed', action='store_true', help='Only show closed (unmerged) PRs')
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def find_prs_without_new_module_tag(state_filter: str | None):
|
||||
hasNextPage = True
|
||||
endCursor = None
|
||||
|
||||
states_args = [] if state_filter is None else ['-F', f'states[]={state_filter}']
|
||||
|
||||
pbar = tqdm(total=PAGES*PAGINATION_STEP)
|
||||
for i in range(PAGES):
|
||||
prs = _gh(["api", "graphql", '-F', f'endCursor={'null' if endCursor is None else endCursor}', "-f", f"query={GRAPHQL_QUERY}"])
|
||||
prs = _gh(["api", "graphql", '-F', f'endCursor={'null' if endCursor is None else endCursor}', *states_args, "-f", f"query={GRAPHQL_QUERY}"])
|
||||
if prs is None:
|
||||
print("gh exited with error")
|
||||
exit(1)
|
||||
@@ -198,4 +211,6 @@ def print_pr(pr: dict[str, any]):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
find_prs_without_new_module_tag()
|
||||
args = parse_args()
|
||||
state_filter = 'OPEN' if args.open else 'MERGED' if args.merged else 'CLOSED' if args.closed else None
|
||||
find_prs_without_new_module_tag(state_filter)
|
||||
|
||||
Reference in New Issue
Block a user