[Patchew-devel] [PATCH] testing: add a badge view

Paolo Bonzini posted 1 patch 5 years ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/patchew next tags/patchew/20190311174259.16129-1-pbonzini@redhat.com
mods/testing.py | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
[Patchew-devel] [PATCH] testing: add a badge view
Posted by Paolo Bonzini 5 years ago
Redirect to shields.io using the current set of failing builds to
determine whether to return success of failure.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 mods/testing.py | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/mods/testing.py b/mods/testing.py
index 650990e..0cea58a 100644
--- a/mods/testing.py
+++ b/mods/testing.py
@@ -142,6 +142,15 @@ class TestingModule(PatchewModule):
                 if isinstance(obj, Message):
                     obj.set_property("testing.tested-base",
                                      self.get_msg_base_tags(obj))
+            if isinstance(obj, Project):
+                # cache the last result so that badges are not affected by RUNNING state
+                failures = obj.get_property("testing.failures")
+                if result.status == result.SUCCESS and result.name in failures:
+                    failures.remove(result.name)
+                    po.set_property('testing.failures', list(failures))
+                if result.status == result.FAILURE and result.name not in failures:
+                    failures.add(result.name)
+                    po.set_property('testing.failures', list(failures))
 
         if result.name != "git":
             return
@@ -221,6 +230,13 @@ class TestingModule(PatchewModule):
         self.clear_and_start_testing(obj, request.GET.get("test", ""))
         return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
 
+    def www_view_badge(self, request, project):
+        po = Project.objects.filter(name=project).first()
+        if po.get_property('testing.failures'):
+            return HttpResponseRedirect('https://img.shields.io/badge/patchew-failing-critical.png')
+        else:
+            return HttpResponseRedirect('https://img.shields.io/badge/patchew-passing-success.png')
+
     def www_url_hook(self, urlpatterns):
         urlpatterns.append(url(r"^testing-reset/(?P<project_or_series>.*)/",
                                self.www_view_testing_reset,
@@ -228,6 +244,8 @@ class TestingModule(PatchewModule):
         urlpatterns.append(url(r"^logs/(?P<project_or_series>.*)/testing.(?P<testing_name>.*)/",
                                TestingLogViewer.as_view(),
                                name="testing-log"))
+        urlpatterns.append(url(r"^(?P<project>[^/]*)/badge.svg$", self.www_view_badge,
+                               name="testing-badge"))
 
     def reverse_testing_log(self, obj, test, request=None, html=False):
         if isinstance(obj, Message):
-- 
2.20.1

_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel
Re: [Patchew-devel] [PATCH] testing: add a badge view
Posted by Fam Zheng 5 years ago

> On Mar 12, 2019, at 01:42, Paolo Bonzini <pbonzini@redhat.com> wrote:
> 
> Redirect to shields.io using the current set of failing builds to
> determine whether to return success of failure.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> mods/testing.py | 18 ++++++++++++++++++
> 1 file changed, 18 insertions(+)
> 
> diff --git a/mods/testing.py b/mods/testing.py
> index 650990e..0cea58a 100644
> --- a/mods/testing.py
> +++ b/mods/testing.py
> @@ -142,6 +142,15 @@ class TestingModule(PatchewModule):
>                 if isinstance(obj, Message):
>                     obj.set_property("testing.tested-base",
>                                      self.get_msg_base_tags(obj))
> +            if isinstance(obj, Project):
> +                # cache the last result so that badges are not affected by RUNNING state
> +                failures = obj.get_property("testing.failures")
> +                if result.status == result.SUCCESS and result.name in failures:
> +                    failures.remove(result.name)
> +                    po.set_property('testing.failures', list(failures))
> +                if result.status == result.FAILURE and result.name not in failures:
> +                    failures.add(result.name)
> +                    po.set_property('testing.failures', list(failures))
> 
>         if result.name != "git":
>             return
> @@ -221,6 +230,13 @@ class TestingModule(PatchewModule):
>         self.clear_and_start_testing(obj, request.GET.get("test", ""))
>         return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
> 
> +    def www_view_badge(self, request, project):
> +        po = Project.objects.filter(name=project).first()
> +        if po.get_property('testing.failures'):
> +            return HttpResponseRedirect('https://img.shields.io/badge/patchew-failing-critical.png')
> +        else:
> +            return HttpResponseRedirect('https://img.shields.io/badge/patchew-passing-success.png')
> +

I really like these little badges. Thanks!

Fam

>     def www_url_hook(self, urlpatterns):
>         urlpatterns.append(url(r"^testing-reset/(?P<project_or_series>.*)/",
>                                self.www_view_testing_reset,
> @@ -228,6 +244,8 @@ class TestingModule(PatchewModule):
>         urlpatterns.append(url(r"^logs/(?P<project_or_series>.*)/testing.(?P<testing_name>.*)/",
>                                TestingLogViewer.as_view(),
>                                name="testing-log"))
> +        urlpatterns.append(url(r"^(?P<project>[^/]*)/badge.svg$", self.www_view_badge,
> +                               name="testing-badge"))
> 
>     def reverse_testing_log(self, obj, test, request=None, html=False):
>         if isinstance(obj, Message):
> -- 
> 2.20.1
> 
> _______________________________________________
> Patchew-devel mailing list
> Patchew-devel@redhat.com
> https://www.redhat.com/mailman/listinfo/patchew-devel



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