mirror of
https://github.com/openSUSE/osc.git
synced 2025-11-26 14:39:50 +01:00
Add 'git-obs pr close' and 'git-obs pr reopen' commands
This commit is contained in:
49
osc/commands_git/pr_close.py
Normal file
49
osc/commands_git/pr_close.py
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
import osc.commandline_git
|
||||||
|
|
||||||
|
|
||||||
|
class PullRequestCloseCommand(osc.commandline_git.GitObsCommand):
|
||||||
|
"""
|
||||||
|
Close pull requests
|
||||||
|
"""
|
||||||
|
|
||||||
|
name = "close"
|
||||||
|
parent = "PullRequestCommand"
|
||||||
|
|
||||||
|
def init_arguments(self):
|
||||||
|
self.add_argument(
|
||||||
|
"id",
|
||||||
|
nargs="+",
|
||||||
|
help="Pull request ID in <owner>/<repo>#<number> format",
|
||||||
|
)
|
||||||
|
self.add_argument(
|
||||||
|
"-m",
|
||||||
|
"--message",
|
||||||
|
help="Text of the comment",
|
||||||
|
)
|
||||||
|
|
||||||
|
def run(self, args):
|
||||||
|
from osc import gitea_api
|
||||||
|
|
||||||
|
self.print_gitea_settings()
|
||||||
|
|
||||||
|
pull_request_ids = args.id
|
||||||
|
|
||||||
|
for pr_index, pr_id in enumerate(pull_request_ids):
|
||||||
|
print(f"Closing {pr_id} ...")
|
||||||
|
owner, repo, number = gitea_api.PullRequest.split_id(pr_id)
|
||||||
|
|
||||||
|
gitea_api.PullRequest.close(
|
||||||
|
self.gitea_conn,
|
||||||
|
owner,
|
||||||
|
repo,
|
||||||
|
number,
|
||||||
|
)
|
||||||
|
|
||||||
|
if args.message:
|
||||||
|
gitea_api.PullRequest.add_comment(
|
||||||
|
self.gitea_conn,
|
||||||
|
owner,
|
||||||
|
repo,
|
||||||
|
number,
|
||||||
|
msg=args.message,
|
||||||
|
)
|
||||||
49
osc/commands_git/pr_reopen.py
Normal file
49
osc/commands_git/pr_reopen.py
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
import osc.commandline_git
|
||||||
|
|
||||||
|
|
||||||
|
class PullRequestReopenCommand(osc.commandline_git.GitObsCommand):
|
||||||
|
"""
|
||||||
|
Reopen pull requests
|
||||||
|
"""
|
||||||
|
|
||||||
|
name = "reopen"
|
||||||
|
parent = "PullRequestCommand"
|
||||||
|
|
||||||
|
def init_arguments(self):
|
||||||
|
self.add_argument(
|
||||||
|
"id",
|
||||||
|
nargs="+",
|
||||||
|
help="Pull request ID in <owner>/<repo>#<number> format",
|
||||||
|
)
|
||||||
|
self.add_argument(
|
||||||
|
"-m",
|
||||||
|
"--message",
|
||||||
|
help="Text of the comment",
|
||||||
|
)
|
||||||
|
|
||||||
|
def run(self, args):
|
||||||
|
from osc import gitea_api
|
||||||
|
|
||||||
|
self.print_gitea_settings()
|
||||||
|
|
||||||
|
pull_request_ids = args.id
|
||||||
|
|
||||||
|
for pr_index, pr_id in enumerate(pull_request_ids):
|
||||||
|
print(f"Reopening {pr_id} ...")
|
||||||
|
owner, repo, number = gitea_api.PullRequest.split_id(pr_id)
|
||||||
|
|
||||||
|
gitea_api.PullRequest.reopen(
|
||||||
|
self.gitea_conn,
|
||||||
|
owner,
|
||||||
|
repo,
|
||||||
|
number,
|
||||||
|
)
|
||||||
|
|
||||||
|
if args.message:
|
||||||
|
gitea_api.PullRequest.add_comment(
|
||||||
|
self.gitea_conn,
|
||||||
|
owner,
|
||||||
|
repo,
|
||||||
|
number,
|
||||||
|
msg=args.message,
|
||||||
|
)
|
||||||
@@ -4,17 +4,14 @@ from typing import List
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
|
|
||||||
|
from .common import GiteaModel
|
||||||
from .connection import Connection
|
from .connection import Connection
|
||||||
from .connection import GiteaHTTPResponse
|
from .connection import GiteaHTTPResponse
|
||||||
from .user import User
|
from .user import User
|
||||||
|
|
||||||
|
|
||||||
@functools.total_ordering
|
@functools.total_ordering
|
||||||
class PullRequest:
|
class PullRequest(GiteaModel):
|
||||||
def __init__(self, data, *, response: Optional[GiteaHTTPResponse] = None):
|
|
||||||
self._data = data
|
|
||||||
self._response = response
|
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
(self.base_owner, self.base_repo, self.number) == (other.base_owner, other.base_repo, other.number)
|
(self.base_owner, self.base_repo, self.number) == (other.base_owner, other.base_repo, other.number)
|
||||||
|
|
||||||
@@ -558,3 +555,41 @@ class PullRequest:
|
|||||||
# the error message is the same and it's not possible to distinguish between the two cases.
|
# the error message is the same and it's not possible to distinguish between the two cases.
|
||||||
if e.status != 404:
|
if e.status != 404:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def close(
|
||||||
|
cls,
|
||||||
|
conn: Connection,
|
||||||
|
owner: str,
|
||||||
|
repo: str,
|
||||||
|
number: int,
|
||||||
|
) -> "PullRequest":
|
||||||
|
"""
|
||||||
|
Close a pull request.
|
||||||
|
"""
|
||||||
|
url = conn.makeurl("repos", owner, repo, "pulls", str(number))
|
||||||
|
json_data = {
|
||||||
|
"state": "closed",
|
||||||
|
}
|
||||||
|
response = conn.request("PATCH", url, json_data=json_data, context={"owner": owner, "repo": repo})
|
||||||
|
obj = cls(response.json(), response=response, conn=conn)
|
||||||
|
return obj
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def reopen(
|
||||||
|
cls,
|
||||||
|
conn: Connection,
|
||||||
|
owner: str,
|
||||||
|
repo: str,
|
||||||
|
number: int,
|
||||||
|
) -> "PullRequest":
|
||||||
|
"""
|
||||||
|
Reopen a pull request.
|
||||||
|
"""
|
||||||
|
url = conn.makeurl("repos", owner, repo, "pulls", str(number))
|
||||||
|
json_data = {
|
||||||
|
"state": "open",
|
||||||
|
}
|
||||||
|
response = conn.request("PATCH", url, json_data=json_data, context={"owner": owner, "repo": repo})
|
||||||
|
obj = cls(response.json(), response=response, conn=conn)
|
||||||
|
return obj
|
||||||
|
|||||||
Reference in New Issue
Block a user