1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-02-23 02:32:13 +01:00

60 lines
1.8 KiB
Python
Raw Normal View History

2025-01-14 16:16:20 +01:00
import sys
import osc.commandline_git
class PullRequestGetCommand(osc.commandline_git.GitObsCommand):
"""
Get details about the specified pull requests
"""
name = "get"
aliases = ["show"] # for compatibility with osc
parent = "PullRequestCommand"
def init_arguments(self):
self.add_argument_owner_repo_pull(nargs="+")
2025-01-14 16:16:20 +01:00
self.add_argument(
"-p",
"--patch",
action="store_true",
help="Show patches associated with the pull requests",
)
def run(self, args):
from osc import gitea_api
from osc.core import highlight_diff
from osc.output import tty
self.print_gitea_settings()
num_entries = 0
failed_entries = []
for owner, repo, pull in args.owner_repo_pull:
2025-01-14 16:16:20 +01:00
try:
2025-01-23 09:17:33 +01:00
pr = gitea_api.PullRequest.get(self.gitea_conn, owner, repo, int(pull)).json()
2025-01-14 16:16:20 +01:00
num_entries += 1
except gitea_api.GiteaException as e:
if e.status == 404:
failed_entries.append(f"{owner}/{repo}#{pull}")
2025-01-14 16:16:20 +01:00
continue
raise
print(gitea_api.PullRequest.to_human_readable_string(pr))
if args.patch:
print("")
print(tty.colorize("Patch:", "bold"))
patch = gitea_api.PullRequest.get_patch(self.gitea_conn, owner, repo, pull).data
2025-01-14 16:16:20 +01:00
patch = highlight_diff(patch)
print(patch.decode("utf-8"))
print()
2025-01-14 16:16:20 +01:00
print(f"Total entries: {num_entries}", file=sys.stderr)
if failed_entries:
print(
f"{tty.colorize('ERROR', 'red,bold')}: Couldn't retrieve the following pull requests: {', '.join(failed_entries)}",
file=sys.stderr,
)
sys.exit(1)