This is an automated email from the ASF dual-hosted git repository.

amolina pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new 8411fedeb8 ARROW-16508: [Archery][Dev] Add possibility to extend chat 
report message based on success or failures of jobs
8411fedeb8 is described below

commit 8411fedeb85120e889d3d134066c223b04955083
Author: Raúl Cumplido <[email protected]>
AuthorDate: Thu May 12 11:58:45 2022 +0200

    ARROW-16508: [Archery][Dev] Add possibility to extend chat report message 
based on success or failures of jobs
    
    Closes #13102 from raulcd/ARROW-16508
    
    Authored-by: Raúl Cumplido <[email protected]>
    Signed-off-by: Alessandro Molina <[email protected]>
---
 dev/archery/archery/crossbow/cli.py                | 13 +++--
 dev/archery/archery/crossbow/reports.py            |  8 ++-
 ...e.txt => chat-report-extra-message-failure.txt} |  2 +-
 .../fixtures/chat-report-extra-message-success.txt |  7 +++
 .../crossbow/tests/fixtures/chat-report.txt        |  2 +-
 .../tests/fixtures/crossbow-job-no-failure.yaml    | 67 ++++++++++++++++++++++
 dev/archery/archery/crossbow/tests/test_reports.py | 22 +++++--
 .../archery/templates/chat_nightly_report.txt.j2   | 21 +++++--
 8 files changed, 127 insertions(+), 15 deletions(-)

diff --git a/dev/archery/archery/crossbow/cli.py 
b/dev/archery/archery/crossbow/cli.py
index 30b10b6685..c8ae55903c 100644
--- a/dev/archery/archery/crossbow/cli.py
+++ b/dev/archery/archery/crossbow/cli.py
@@ -311,12 +311,15 @@ def report(obj, job_name, sender_name, sender_email, 
recipient_email,
               help='Just display the report, don\'t send it')
 @click.option('--webhook', '-w',
               help='Zulip/Slack Webhook address to send the report to')
[email protected]('--extra-message', '-s', default=None,
-              help='Extra message information, will be appended.')
[email protected]('--extra-message-success', '-s', default=None,
+              help='Extra message, will be appended if no failures.')
[email protected]('--extra-message-failure', '-f', default=None,
+              help='Extra message, will be appended if there are failures.')
 @click.option('--fetch/--no-fetch', default=True,
               help='Fetch references (branches and tags) from the remote')
 @click.pass_obj
-def report_chat(obj, job_name, send, webhook, extra_message, fetch):
+def report_chat(obj, job_name, send, webhook, extra_message_success,
+                extra_message_failure, fetch):
     """
     Send a chat report to a webhook showing success/failure
     of tasks in a Crossbow run.
@@ -327,7 +330,9 @@ def report_chat(obj, job_name, send, webhook, 
extra_message, fetch):
         queue.fetch()
 
     job = queue.get(job_name)
-    report_chat = ChatReport(report=Report(job), extra_message=extra_message)
+    report_chat = ChatReport(report=Report(job),
+                             extra_message_success=extra_message_success,
+                             extra_message_failure=extra_message_failure)
     if send:
         ReportUtils.send_message(webhook, report_chat.render("text"))
     else:
diff --git a/dev/archery/archery/crossbow/reports.py 
b/dev/archery/archery/crossbow/reports.py
index b4a963fd8b..111a11d043 100644
--- a/dev/archery/archery/crossbow/reports.py
+++ b/dev/archery/archery/crossbow/reports.py
@@ -71,6 +71,11 @@ class Report:
             tasks_by_state[state][task_name] = task
         return tasks_by_state
 
+    @property
+    def contains_failures(self):
+        return any(self.tasks_by_state[state] for state in (
+            "error", "failure"))
+
     @property
     def tasks(self):
         return self._tasks
@@ -171,7 +176,8 @@ class ChatReport(JinjaReport):
     }
     fields = [
         'report',
-        'extra_message',
+        'extra_message_success',
+        'extra_message_failure',
     ]
 
 
diff --git 
a/dev/archery/archery/crossbow/tests/fixtures/chat-report-extra-message.txt 
b/dev/archery/archery/crossbow/tests/fixtures/chat-report-extra-message-failure.txt
similarity index 92%
rename from 
dev/archery/archery/crossbow/tests/fixtures/chat-report-extra-message.txt
rename to 
dev/archery/archery/crossbow/tests/fixtures/chat-report-extra-message-failure.txt
index 2d3fdeac81..95fc2efd8c 100644
--- a/dev/archery/archery/crossbow/tests/fixtures/chat-report-extra-message.txt
+++ 
b/dev/archery/archery/crossbow/tests/fixtures/chat-report-extra-message-failure.txt
@@ -11,4 +11,4 @@
 
 :tada: *1 successful jobs*
 
-This message is extended
+Failure present
diff --git 
a/dev/archery/archery/crossbow/tests/fixtures/chat-report-extra-message-success.txt
 
b/dev/archery/archery/crossbow/tests/fixtures/chat-report-extra-message-success.txt
new file mode 100644
index 0000000000..fb99f2d4c7
--- /dev/null
+++ 
b/dev/archery/archery/crossbow/tests/fixtures/chat-report-extra-message-success.txt
@@ -0,0 +1,7 @@
+
+*Archery crossbow report for 
<https://github.com/apache/crossbow/branches/all?query=ursabot-1|ursabot-1>*
+
+
+:tada: *4 successful jobs*
+
+Success present
\ No newline at end of file
diff --git a/dev/archery/archery/crossbow/tests/fixtures/chat-report.txt 
b/dev/archery/archery/crossbow/tests/fixtures/chat-report.txt
index 120564a755..3ee807d12a 100644
--- a/dev/archery/archery/crossbow/tests/fixtures/chat-report.txt
+++ b/dev/archery/archery/crossbow/tests/fixtures/chat-report.txt
@@ -9,4 +9,4 @@
 
 :warning: *1 pending jobs*
 
-:tada: *1 successful jobs*
+:tada: *1 successful jobs*
\ No newline at end of file
diff --git 
a/dev/archery/archery/crossbow/tests/fixtures/crossbow-job-no-failure.yaml 
b/dev/archery/archery/crossbow/tests/fixtures/crossbow-job-no-failure.yaml
new file mode 100644
index 0000000000..15e8ca3ff5
--- /dev/null
+++ b/dev/archery/archery/crossbow/tests/fixtures/crossbow-job-no-failure.yaml
@@ -0,0 +1,67 @@
+!Job
+target: !Target
+  head: f766a1d615dd1b7ee706d05102e579195951a61c
+  email: unkown
+  branch: refs/pull/4435/merge
+  remote: https://github.com/apache/arrow
+  version: 0.13.0.dev306
+  no_rc_version: 0.13.0.dev306
+tasks:
+  docker-cpp-cmake32: !Task
+    ci: circle
+    platform: linux
+    template: docker-tests/circle.linux.yml
+    artifacts: []
+    params:
+      commands:
+      - docker-compose build cpp-cmake32
+      - docker-compose run cpp-cmake32
+    branch: ursabot-1-circle-docker-cpp-cmake32
+    commit: a56b077c8d1b891a7935048e5672bf6fc07599ec
+    _status: !TaskStatus
+      combined_state: success
+      build_links: ["https://github.com/apache/crossbow/runs/1";]
+  wheel-osx-cp37m: !Task
+    ci: travis
+    platform: osx
+    template: python-wheels/travis.osx.yml
+    artifacts:
+    - pyarrow-0.13.0.dev306-cp37-cp37m-macosx_10_6_intel.whl
+    params:
+      python_version: 3.7
+    branch: ursabot-1-travis-wheel-osx-cp37m
+    commit: a56b077c8d1b891a7935048e5672bf6fc07599ec
+    _status: !TaskStatus
+      combined_state: success
+      build_links: ["https://github.com/apache/crossbow/runs/2";]
+  wheel-osx-cp36m: !Task
+    ci: travis
+    platform: osx
+    template: python-wheels/travis.osx.yml
+    artifacts:
+    - pyarrow-0.13.0.dev306-cp36-cp36m-macosx_10_6_intel.whl
+    params:
+      python_version: 3.6
+    branch: ursabot-1-travis-wheel-osx-cp36m
+    commit: a56b077c8d1b891a7935048e5672bf6fc07599ec
+    _status: !TaskStatus
+      combined_state: success
+      build_links: ["https://github.com/apache/crossbow/runs/3";]
+  wheel-win-cp36m: !Task
+    ci: appveyor
+    platform: win
+    template: python-wheels/appveyor.yml
+    artifacts:
+    - pyarrow-0.13.0.dev306-cp36-cp36m-win_amd64.whl
+    params:
+      python_version: 3.6
+    branch: ursabot-1-appveyor-wheel-win-cp36m
+    commit: a56b077c8d1b891a7935048e5672bf6fc07599ec
+    _status: !TaskStatus
+      combined_state: success
+      build_links: ["https://github.com/apache/crossbow/runs/4";]
+branch: ursabot-1
+_queue: !Queue
+  path: the_path
+  github_token: xxxxxxxxx
+  _remote_url: https://github.com/apache/crossbow
\ No newline at end of file
diff --git a/dev/archery/archery/crossbow/tests/test_reports.py 
b/dev/archery/archery/crossbow/tests/test_reports.py
index a45c80ca01..19e52b8b46 100644
--- a/dev/archery/archery/crossbow/tests/test_reports.py
+++ b/dev/archery/archery/crossbow/tests/test_reports.py
@@ -41,18 +41,32 @@ def test_crossbow_chat_report(load_fixture):
     job = load_fixture('crossbow-job.yaml', decoder=yaml.load)
     report = Report(job)
     assert report.tasks_by_state is not None
-    report_chat = ChatReport(report=report, extra_message=None)
+    report_chat = ChatReport(report=report, extra_message_success=None,
+                             extra_message_failure=None)
 
     assert report_chat.render("text") == textwrap.dedent(expected_msg)
 
 
-def test_crossbow_chat_report_extra_message(load_fixture):
-    expected_msg = load_fixture('chat-report-extra-message.txt')
+def test_crossbow_chat_report_extra_message_failure(load_fixture):
+    expected_msg = load_fixture('chat-report-extra-message-failure.txt')
     job = load_fixture('crossbow-job.yaml', decoder=yaml.load)
     report = Report(job)
     assert report.tasks_by_state is not None
     report_chat = ChatReport(report=report,
-                             extra_message="This message is extended")
+                             extra_message_success="Should not be present",
+                             extra_message_failure="Failure present")
+
+    assert report_chat.render("text") == textwrap.dedent(expected_msg)
+
+
+def test_crossbow_chat_report_extra_message_success(load_fixture):
+    expected_msg = load_fixture('chat-report-extra-message-success.txt')
+    job = load_fixture('crossbow-job-no-failure.yaml', decoder=yaml.load)
+    report = Report(job)
+    assert report.tasks_by_state is not None
+    report_chat = ChatReport(report=report,
+                             extra_message_success="Success present",
+                             extra_message_failure="Should not be present")
 
     assert report_chat.render("text") == textwrap.dedent(expected_msg)
 
diff --git a/dev/archery/archery/templates/chat_nightly_report.txt.j2 
b/dev/archery/archery/templates/chat_nightly_report.txt.j2
index 577ae04707..e15bedcdad 100644
--- a/dev/archery/archery/templates/chat_nightly_report.txt.j2
+++ b/dev/archery/archery/templates/chat_nightly_report.txt.j2
@@ -17,18 +17,31 @@
 # under the License.
 #}
 *Archery crossbow report for <{{ report.url(report.job.branch) }}|{{ 
report.job.branch }}>*
-
+{% if report.tasks_by_state["failure"] %}
 :x: *{{ report.tasks_by_state["failure"] | length }} failed jobs*
 {% for task_name, task in report.tasks_by_state["failure"] | dictsort -%}
 - <{{ report.task_url(task) }}|{{ task_name }}>
 {% endfor %}
+{%- endif -%}
+{% if report.tasks_by_state["error"] %}
 :x: *{{ report.tasks_by_state["error"] | length }} errored jobs*
 {% for task_name, task in report.tasks_by_state["error"] | dictsort -%}
 - <{{ report.task_url(task) }}|{{ task_name }}>
 {% endfor %}
+{%- endif -%}
+{% if report.tasks_by_state["pending"] %}
 :warning: *{{ report.tasks_by_state["pending"] | length }} pending jobs*
+{%- endif -%}
+{% if report.tasks_by_state["success"] %}
 
 :tada: *{{ report.tasks_by_state["success"] | length }} successful jobs*
-{% if extra_message %}
-{{ extra_message }}
-{% endif %}
+{%- endif -%}
+
+{% if extra_message_success and not report.contains_failures %}
+
+{{ extra_message_success }}
+{%- endif -%}
+{% if extra_message_failure and report.contains_failures %}
+
+{{ extra_message_failure }}
+{% endif %}
\ No newline at end of file

Reply via email to