Compare commits
8 Commits
8-backport
...
4bc78716ee
Author | SHA1 | Date | |
---|---|---|---|
4bc78716ee | |||
a27f88a62b | |||
2d94c8b561 | |||
b4b2b2ec5d | |||
ec8e3e491e | |||
2245698405 | |||
9ee3ec2018 | |||
356da4d8ec |
25
README.md
25
README.md
@@ -5,15 +5,26 @@ Nixpkgs PR status checker.
|
|||||||
## Example
|
## Example
|
||||||
|
|
||||||
```console
|
```console
|
||||||
$ nixprstatus 345501
|
$ nixprstatus pr 345501
|
||||||
|
ktailctl: 0.18.0 -> 0.18.1
|
||||||
|
|
||||||
|
✅ merged
|
||||||
✅ master
|
✅ master
|
||||||
❌ nixos-unstable-small
|
✅ nixos-unstable-small
|
||||||
❌ nixos-unstable
|
✅ nixos-unstable
|
||||||
❌ nixos-24.05
|
❌ nixos-24.05
|
||||||
|
|
||||||
|
$ nixprstatus --help
|
||||||
|
Usage: python -m nixprstatus [OPTIONS] COMMAND [ARGS]...
|
||||||
|
|
||||||
|
Options:
|
||||||
|
--install-completion Install completion for the current shell.
|
||||||
|
--show-completion Show completion for the current shell, to copy it or
|
||||||
|
customize the installation.
|
||||||
|
--help Show this message and exit.
|
||||||
|
|
||||||
|
Commands:
|
||||||
|
pr Get merge status of pull request.
|
||||||
|
since Return the count of commits that has happened between the two refs.
|
||||||
```
|
```
|
||||||
|
|
||||||
## TODO
|
|
||||||
|
|
||||||
* Support backported commits
|
|
||||||
* JSON output
|
|
||||||
|
@@ -5,7 +5,7 @@ from rich.console import Console
|
|||||||
from nixprstatus.pr import pr_merge_status
|
from nixprstatus.pr import pr_merge_status
|
||||||
from nixprstatus.pr import commits_since
|
from nixprstatus.pr import commits_since
|
||||||
|
|
||||||
app = typer.Typer()
|
app = typer.Typer(rich_markup_mode=None)
|
||||||
|
|
||||||
DEFAULT_HEADERS = {
|
DEFAULT_HEADERS = {
|
||||||
"Accept": "application/vnd.github.text+json",
|
"Accept": "application/vnd.github.text+json",
|
||||||
@@ -21,13 +21,15 @@ def pr(
|
|||||||
list[str] | None, typer.Option(help="Check specific branch")
|
list[str] | None, typer.Option(help="Check specific branch")
|
||||||
] = None,
|
] = None,
|
||||||
):
|
):
|
||||||
"""Get status of pull request"""
|
"""Get merge status of pull request."""
|
||||||
console = Console()
|
console = Console()
|
||||||
|
|
||||||
if branches:
|
if branches:
|
||||||
status = pr_merge_status(pr, branches)
|
status = pr_merge_status(pr, branches)
|
||||||
else:
|
else:
|
||||||
status = pr_merge_status(pr)
|
status = pr_merge_status(pr)
|
||||||
|
|
||||||
|
console.print(f"{status.title}\n", highlight=False)
|
||||||
merged = ":white_check_mark: merged" if status.merged else ":x: merged"
|
merged = ":white_check_mark: merged" if status.merged else ":x: merged"
|
||||||
console.print(merged, highlight=False)
|
console.print(merged, highlight=False)
|
||||||
|
|
||||||
|
@@ -9,6 +9,7 @@ BACKPORT_LABEL = "backport release-24.05"
|
|||||||
|
|
||||||
|
|
||||||
class PRStatus(BaseModel):
|
class PRStatus(BaseModel):
|
||||||
|
title: str
|
||||||
merged: bool
|
merged: bool
|
||||||
branches: dict[str, bool]
|
branches: dict[str, bool]
|
||||||
|
|
||||||
@@ -40,10 +41,13 @@ def pr_merge_status(
|
|||||||
pr_response.raise_for_status()
|
pr_response.raise_for_status()
|
||||||
|
|
||||||
pr_data = pr_response.json()
|
pr_data = pr_response.json()
|
||||||
|
title = pr_data["title"]
|
||||||
|
|
||||||
merged = pr_data["merged"]
|
merged = pr_data["merged"]
|
||||||
if merged is False:
|
if merged is False:
|
||||||
return PRStatus(merged=False, branches={branch: False for branch in branches})
|
return PRStatus(
|
||||||
|
title=title, merged=False, branches={branch: False for branch in branches}
|
||||||
|
)
|
||||||
|
|
||||||
commit_sha = pr_data.get("merge_commit_sha")
|
commit_sha = pr_data.get("merge_commit_sha")
|
||||||
|
|
||||||
@@ -54,6 +58,13 @@ def pr_merge_status(
|
|||||||
|
|
||||||
results = {}
|
results = {}
|
||||||
|
|
||||||
|
# Check if base branch is in our list, if it is
|
||||||
|
# no need to call commit_in_branch
|
||||||
|
merge_base_branch = pr_data.get("base", {}).get("ref")
|
||||||
|
if merge_base_branch in branches:
|
||||||
|
results[merge_base_branch] = True
|
||||||
|
branches.remove(merge_base_branch)
|
||||||
|
|
||||||
for branch in branches:
|
for branch in branches:
|
||||||
in_branch = commit_in_branch(commit_sha, branch)
|
in_branch = commit_in_branch(commit_sha, branch)
|
||||||
results[branch] = in_branch
|
results[branch] = in_branch
|
||||||
@@ -77,11 +88,11 @@ def pr_merge_status(
|
|||||||
backport_sha = backport_response.json().get("merge_commit_sha")
|
backport_sha = backport_response.json().get("merge_commit_sha")
|
||||||
if backport_sha is None:
|
if backport_sha is None:
|
||||||
results[f"nixos-24.05 (#{backport_pr})"] = False
|
results[f"nixos-24.05 (#{backport_pr})"] = False
|
||||||
return PRStatus(merged=True, branches=results)
|
return PRStatus(title=title, merged=True, branches=results)
|
||||||
|
|
||||||
results.pop("nixos-24.05")
|
results.pop("nixos-24.05")
|
||||||
results[f"nixos-24.05 (#{backport_pr})"] = commit_in_branch(
|
results[f"nixos-24.05 (#{backport_pr})"] = commit_in_branch(
|
||||||
backport_sha, "nixos-24.05"
|
backport_sha, "nixos-24.05"
|
||||||
)
|
)
|
||||||
|
|
||||||
return PRStatus(merged=True, branches=results)
|
return PRStatus(title=title, merged=True, branches=results)
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "nixprstatus"
|
name = "nixprstatus"
|
||||||
version = "0.1.1"
|
version = "0.1.4"
|
||||||
description = "Nixpkgs PR status checker"
|
description = "Nixpkgs PR status checker"
|
||||||
authors = ["Torjus Håkestad <torjus@usit.uio.no>"]
|
authors = ["Torjus Håkestad <torjus@usit.uio.no>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
@@ -57,6 +57,28 @@ class TestPRMergeStatus(unittest.TestCase):
|
|||||||
self.assertTrue(res.merged)
|
self.assertTrue(res.merged)
|
||||||
self.assertTrue(res.branches["nixos-24.05 (#346022)"])
|
self.assertTrue(res.branches["nixos-24.05 (#346022)"])
|
||||||
|
|
||||||
|
@unittest.mock.patch("requests.get", side_effect=mocked_requests_get)
|
||||||
|
def test_pr_merge_status_title_345769(self, mock_get):
|
||||||
|
pr = 345769
|
||||||
|
branches = ["nixos-24.05"]
|
||||||
|
expected_title = "Firefox: 130.0.1 -> 131.0; 128.2.0esr -> 128.3.0esr; 115.15.0esr -> 115.16.0esr"
|
||||||
|
|
||||||
|
res = pr_merge_status(pr, branches, check_backport=True)
|
||||||
|
self.assertEqual(res.title, expected_title)
|
||||||
|
|
||||||
|
@unittest.mock.patch("requests.get", side_effect=mocked_requests_get)
|
||||||
|
def test_pr_merge_status_no_check_master_345583(self, mock_get):
|
||||||
|
pr = 345583
|
||||||
|
branches = ["master", "nixos-unstable", "nixos-24.05"]
|
||||||
|
master_compare_url = "https://api.github.com/repos/NixOS/nixpkgs/compare/master...2c5fac3edf2d00d948253e392ec1604b29b38f14"
|
||||||
|
|
||||||
|
res = pr_merge_status(pr, branches, check_backport=False)
|
||||||
|
self.assertTrue(res.merged)
|
||||||
|
self.assertTrue(res.branches["master"])
|
||||||
|
|
||||||
|
urls_called = [call[0][0] for call in mock_get.call_args_list]
|
||||||
|
self.assertFalse(master_compare_url in urls_called)
|
||||||
|
|
||||||
|
|
||||||
class TestCommitInBranch(unittest.TestCase):
|
class TestCommitInBranch(unittest.TestCase):
|
||||||
@unittest.mock.patch("requests.get", side_effect=mocked_requests_get)
|
@unittest.mock.patch("requests.get", side_effect=mocked_requests_get)
|
||||||
|
Reference in New Issue
Block a user