[Patchew-devel] [PATCH] Support 'git push -o ci.skip' for gitlab CI

fam@euphon.net posted 1 patch 8 months, 2 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/patchew next tags/patchew/20210105114313.90141-1-fam@euphon.net
mods/git.py          | 16 +++++++++++++---
patchew-cli          | 17 +++++++++--------
tests/patchewtest.py | 14 +++++++++++---
tests/test_git.py    | 11 +++++++++++
4 files changed, 44 insertions(+), 14 deletions(-)

[Patchew-devel] [PATCH] Support 'git push -o ci.skip' for gitlab CI

Posted by fam@euphon.net 8 months, 2 weeks ago
From: Fam Zheng <fam@euphon.net>

When we update tags and re-apply series, don't trigger CI pipeline.
---
 mods/git.py          | 16 +++++++++++++---
 patchew-cli          | 17 +++++++++--------
 tests/patchewtest.py | 14 +++++++++++---
 tests/test_git.py    | 11 +++++++++++
 4 files changed, 44 insertions(+), 14 deletions(-)

diff --git a/mods/git.py b/mods/git.py
index d10cbeb..df9374b 100644
--- a/mods/git.py
+++ b/mods/git.py
@@ -75,6 +75,9 @@ class GitModule(PatchewModule):
             schema.StringSchema(
                 "public_repo", "Public repo", desc="Publicly visible repo URL"
             ),
+            schema.BooleanSchema(
+                "use_git_push_option", "Enable git push options", desc="Whether the push remote accepts git push options"
+            ),
             schema.StringSchema(
                 "url_template",
                 "URL template",
@@ -93,15 +96,21 @@ class GitModule(PatchewModule):
         declare_event("ProjectGitUpdate", project="the updated project name")
         declare_event("SeriesApplied", series="the object of applied series")
         register_handler("SeriesComplete", self.on_series_update)
-        register_handler("TagsUpdate", self.on_series_update)
+        register_handler("TagsUpdate", self.on_tags_update)
 
-    def mark_as_pending_apply(self, series):
+    def mark_as_pending_apply(self, series, data={}):
         r = series.git_result or series.create_result(name="git")
         r.log = None
         r.status = Result.PENDING
-        r.data = {}
+        r.data = data
         r.save()
 
+    def on_tags_update(self, event, series, **params):
+        if series.is_complete:
+            self.mark_as_pending_apply(series, {
+                'git.push_options': 'ci.skip',
+                })
+
     def on_series_update(self, event, series, **params):
         if series.is_complete:
             self.mark_as_pending_apply(series)
@@ -327,6 +336,7 @@ class ApplierGetView(APILoginRequiredView):
             request=request,
         )
         response["result_uri"] = reverse_detail(m.git_result, request)
+        response["git.push_options"] = m.git_result.data.get("git.push_options")
         return response
 
 
diff --git a/patchew-cli b/patchew-cli
index 8e3a357..ccef76b 100755
--- a/patchew-cli
+++ b/patchew-cli
@@ -934,19 +934,19 @@ class ApplyCommand(SubCommand):
             )
         return list(maintainers)
 
-    def _push(self, repo, remote, tag, logf):
+    def _push(self, repo, remote, tag, logf, push_options):
         subprocess.check_call(
             ["git", "remote", "add", "push_to", remote],
             cwd=repo,
             stdout=logf,
             stderr=logf,
         )
-        subprocess.check_call(
-            ["git", "push", "-f", "push_to", "%s:refs/tags/%s" % (tag, tag)],
-            cwd=repo,
-            stdout=logf,
-            stderr=logf,
-        )
+        push_options_args = ['-o', push_options] if push_options else []
+        cmd = ["git", "push", "-f", "push_to"] + \
+                push_options_args + \
+                ["%s:refs/tags/%s" % (tag, tag)]
+        logging.debug(" ".join(cmd))
+        subprocess.check_call(cmd, cwd=repo, stdout=logf, stderr=logf)
 
     def _applier_mode(self, args):
         applier_get_args = {}
@@ -981,7 +981,8 @@ class ApplyCommand(SubCommand):
             )
             maintainers = self._apply(wd, toapply, branch, force_branch, tag, logf)
             if push_repo:
-                self._push(wd, push_repo, tag, logf)
+                push_options = toapply.get('git.push_options') if toapply.get("git.use_git_push_option") else None
+                self._push(wd, push_repo, tag, logf, push_options)
             url = toapply.get("git.url_template", "").replace("%t", tag)
         except Exception as e:
             if not isinstance(e, ApplyFailedException):
diff --git a/tests/patchewtest.py b/tests/patchewtest.py
index ab333ae..33923d1 100644
--- a/tests/patchewtest.py
+++ b/tests/patchewtest.py
@@ -70,8 +70,15 @@ class PatchewTestCase(dj_test.LiveServerTestCase):
         return user
 
     def cli(self, argv):
+        return self.do_cli(False, argv)
+
+    def cli_debug(self, argv):
+        return self.do_cli(True, argv)
+
+    def do_cli(self, debug, argv):
         """Run patchew-cli command and return (retcode, stdout, stderr)"""
-        cmd = [PATCHEW_CLI, "-D", "-s", self.live_server_url] + argv
+        dbgopt = "-d" if debug else "-D"
+        cmd = [PATCHEW_CLI, dbgopt, "-s", self.live_server_url] + argv
         p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
         a, b = p.communicate()
         a = a.decode("utf-8")
@@ -105,13 +112,14 @@ class PatchewTestCase(dj_test.LiveServerTestCase):
     def cli_import(self, mbox, rc=0):
         self.check_cli(["import", self.get_data_path(mbox)], rc)
 
-    def do_apply(self):
+    def do_apply(self, debug=False):
         while True:
-            r, out, err = self.cli(["apply", "--applier-mode"])
+            r, out, err = self.do_cli(debug, ["apply", "--applier-mode"])
             if r != 0:
                 break
         for s in Message.objects.series_heads():
             self.assertNotEqual(s.git_result.status, Result.PENDING)
+        return out, err
 
     def get_data_path(self, fname):
         r = tempfile.NamedTemporaryFile(dir=RUN_DIR, prefix="test-data-", delete=False)
diff --git a/tests/test_git.py b/tests/test_git.py
index 4718322..857454c 100755
--- a/tests/test_git.py
+++ b/tests/test_git.py
@@ -194,6 +194,17 @@ class GitTest(PatchewTestCase):
         self.assertEqual(resp.status_code, 200)
         self.assertEquals(len(resp.data["results"]), 0)
 
+    def test_git_push_options(self):
+        self.p.config['git']["use_git_push_option"] = True
+        self.p.save()
+        self.cli_import("0013-foo-patch.mbox.gz")
+        out, err = self.do_apply(True)
+        self.assertNotIn("ci.skip", out)
+
+        # Getting a new reviewed-by shouldn't trigger re-test
+        self.cli_import("0025-foo-patch-review.mbox.gz")
+        out, err = self.do_apply(True)
+        self.assertIn("ci.skip", out)
 
 if __name__ == "__main__":
     main()
-- 
2.25.1



_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel

Re: [Patchew-devel] [PATCH] Support 'git push -o ci.skip' for gitlab CI

Posted by Philippe Mathieu-Daudé 8 months, 2 weeks ago
On 1/5/21 12:43 PM, fam@euphon.net wrote:
> From: Fam Zheng <fam@euphon.net>
> 
> When we update tags and re-apply series, don't trigger CI pipeline.
> ---
>  mods/git.py          | 16 +++++++++++++---
>  patchew-cli          | 17 +++++++++--------
>  tests/patchewtest.py | 14 +++++++++++---
>  tests/test_git.py    | 11 +++++++++++
>  4 files changed, 44 insertions(+), 14 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel

Re: [Patchew-devel] [PATCH] Support 'git push -o ci.skip' for gitlab CI

Posted by Fam Zheng 8 months, 2 weeks ago
On Tue, 2021-01-05 at 13:15 +0100, Philippe Mathieu-Daudé wrote:
> On 1/5/21 12:43 PM, fam@euphon.net wrote:
> > From: Fam Zheng <fam@euphon.net>
> > 
> > When we update tags and re-apply series, don't trigger CI pipeline.
> > ---
> >  mods/git.py          | 16 +++++++++++++---
> >  patchew-cli          | 17 +++++++++--------
> >  tests/patchewtest.py | 14 +++++++++++---
> >  tests/test_git.py    | 11 +++++++++++
> >  4 files changed, 44 insertions(+), 14 deletions(-)
> 
> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> 
> _______________________________________________
> Patchew-devel mailing list
> Patchew-devel@redhat.com
> https://www.redhat.com/mailman/listinfo/patchew-devel

Pushed, thanks Phil.

Fam


_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel