diff options
author | Arthur Zamarin <arthurzam@gentoo.org> | 2023-08-24 20:25:48 +0300 |
---|---|---|
committer | Arthur Zamarin <arthurzam@gentoo.org> | 2023-08-24 20:48:51 +0300 |
commit | 047ac2bdcfe019107b13646825818a0bc5339b9d (patch) | |
tree | 3ae0ec47c9c59a14e076df02f6194ad33b9d0793 | |
parent | commit: add support to enable/disable gpg signing (diff) | |
download | pkgdev-047ac2bdcfe019107b13646825818a0bc5339b9d.tar.gz pkgdev-047ac2bdcfe019107b13646825818a0bc5339b9d.tar.bz2 pkgdev-047ac2bdcfe019107b13646825818a0bc5339b9d.zip |
push: `--ask` stops for confirmation on warnings
Resolves: https://github.com/pkgcore/pkgdev/issues/150
Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
-rw-r--r-- | src/pkgdev/scripts/pkgdev_push.py | 9 | ||||
-rw-r--r-- | tests/scripts/test_pkgdev_push.py | 23 |
2 files changed, 31 insertions, 1 deletions
diff --git a/src/pkgdev/scripts/pkgdev_push.py b/src/pkgdev/scripts/pkgdev_push.py index 7948336..cf510ab 100644 --- a/src/pkgdev/scripts/pkgdev_push.py +++ b/src/pkgdev/scripts/pkgdev_push.py @@ -2,6 +2,7 @@ import argparse import shlex from pkgcheck import reporters, scan +from pkgcheck.results import Warning as PkgcheckWarning from snakeoil.cli import arghparse from snakeoil.cli.input import userquery @@ -58,9 +59,12 @@ def _push(options, out, err): # scan commits for QA issues pipe = scan(options.scan_args) + has_warnings = False with reporters.FancyReporter(out) as reporter: for result in pipe: reporter.report(result) + if result.level == PkgcheckWarning.level: + has_warnings = True # fail on errors unless they're ignored if pipe.errors: @@ -68,7 +72,10 @@ def _push(options, out, err): out.write(out.bold, out.fg("red"), "\nFAILURES", out.reset) for result in sorted(pipe.errors): reporter.report(result) - if not (options.ask and userquery("Push commits anyway?", out, err)): + if not (options.ask and userquery("Push commits anyway?", out, err, default_answer=False)): + return 1 + elif has_warnings and options.ask: + if not userquery("warnings detected, push commits anyway?", out, err, default_answer=False): return 1 # push commits upstream diff --git a/tests/scripts/test_pkgdev_push.py b/tests/scripts/test_pkgdev_push.py index f1f0a0b..fb4faa3 100644 --- a/tests/scripts/test_pkgdev_push.py +++ b/tests/scripts/test_pkgdev_push.py @@ -124,3 +124,26 @@ class TestPkgdevPush: ), pytest.raises(SystemExit) as excinfo, chdir(self.child_git_repo.path): self.script() assert excinfo.value.code == 0 + + def test_warnings(self, capsys): + pkgdir = os.path.dirname(self.child_repo.create_ebuild("cat/pkg-1")) + os.makedirs((filesdir := pjoin(pkgdir, "files")), exist_ok=True) + with open(pjoin(filesdir, "foo"), "w") as f: + f.write("") + self.child_git_repo.add_all("cat/pkg-1") + + # scans with warnings ask for confirmation before pushing with "--ask" + with patch("sys.argv", self.args + ["--ask"]), patch( + "sys.stdin", StringIO("n\n") + ), pytest.raises(SystemExit) as excinfo, chdir(self.child_git_repo.path): + self.script() + assert excinfo.value.code == 1 + out, err = capsys.readouterr() + assert "EmptyFile" in out + + # but without "--ask" it still pushes + with patch("sys.argv", self.args), pytest.raises(SystemExit) as excinfo, chdir( + self.child_git_repo.path + ): + self.script() + assert excinfo.value.code == 0 |