1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-10-31 03:22:15 +01:00

Implement '--reviewer' and '--review-state' options for 'git-obs pr list'

This commit is contained in:
2025-05-06 13:47:24 +02:00
parent 79657c0e22
commit aa8a48b79b
2 changed files with 43 additions and 0 deletions

View File

@@ -19,6 +19,19 @@ class PullRequestListCommand(osc.commandline_git.GitObsCommand):
default="open",
help="State of the pull requests (default: open)",
)
self.add_argument(
"--reviewer",
dest="reviewers",
action="append",
help="Filter by reviewer. Team reviewers start with '@'.",
)
self.add_argument(
"--review-state",
dest="review_states",
action="append",
choices=("REQUEST_REVIEW", "APPROVED"),
help="Filter by review state. Needs to be used with ``--reviewer``.",
)
def run(self, args):
from osc import gitea_api
@@ -28,6 +41,25 @@ class PullRequestListCommand(osc.commandline_git.GitObsCommand):
total_entries = 0
for owner, repo in args.owner_repo:
data = gitea_api.PullRequest.list(self.gitea_conn, owner, repo, state=args.state).json()
review_states = args.review_states or ["REQUEST_REVIEW"]
if args.reviewers:
new_data = []
for entry in data:
all_reviews = gitea_api.PullRequest.get_reviews(self.gitea_conn, owner, repo, entry["number"]).json()
user_reviews = {i["user"]["login"]: i["state"] for i in all_reviews if i["user"] and i["state"] in review_states}
team_reviews = {i["team"]["name"]: i["state"] for i in all_reviews if i["team"] and i["state"] in review_states}
user_reviewers = [i for i in args.reviewers if not i.startswith("@")]
team_reviewers = [i[1:] for i in args.reviewers if i.startswith("@")]
if set(user_reviews) & set(user_reviewers) or set(team_reviews) & set(team_reviewers):
print(set(user_reviews) & set(user_reviewers), set(team_reviews) & set(team_reviewers))
new_data.append(entry)
data = new_data
total_entries += len(data)
text = gitea_api.PullRequest.list_to_human_readable_string(data, sort=True)

View File

@@ -261,6 +261,17 @@ class PullRequest:
}
return conn.request("POST", url, json_data=json_data)
@classmethod
def get_reviews(
cls,
conn: Connection,
owner: str,
repo: str,
number: int,
):
url = conn.makeurl("repos", owner, repo, "pulls", str(number), "reviews")
return conn.request("GET", url)
@classmethod
def approve_review(
cls,