Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve format of notifications returned by the API #16152

Conversation

eduardoj
Copy link
Member

@eduardoj eduardoj commented May 17, 2024

Before

XML result of http://localhost:3000/my/notifications for the user Admin in the development environment:

Click to expand
<notifications count="22">
  <total_pages>1</total_pages>
  <current_page>1</current_page>
  <notification id="3">
    <title>Build Service Notification</title>
    <event_type>report_for_comment</event_type>
  </notification>
  <notification id="4">
    <title>Build Service Notification</title>
    <event_type>report_for_package</event_type>
  </notification>
  <notification id="5">
    <title>Build Service Notification</title>
    <event_type>report_for_project</event_type>
  </notification>
  <notification id="6">
    <title>Build Service Notification</title>
    <event_type>report_for_user</event_type>
  </notification>
  <notification id="14">
    <title>Build Service Notification</title>
    <event_type>report_for_comment</event_type>
  </notification>
  <notification id="15">
    <title>Workflow run failed on Pull request</title>
    <event_type>workflow_run_fail</event_type>
  </notification>
  <notification id="16">
    <title>Workflow run failed on Merge request hook</title>
    <event_type>workflow_run_fail</event_type>
  </notification>
  <notification id="18">
    <title>Build Service Notification</title>
    <event_type>relationship_create</event_type>
    <who>Iggy</who>
  </notification>
  <notification id="25">
    <title>New comment in package home:Admin/package_1713525994_0 by Requestor</title>
    <event_type>comment_for_package</event_type>
    <when>2024-04-19T11:26:35</when>
  </notification>
  <notification id="31">
    <title>New comment in project home:Admin by Requestor</title>
    <event_type>comment_for_project</event_type>
    <when>2024-04-19T11:26:45</when>
  </notification>
  <notification id="32">
    <title>New comment in package home:Admin/package_1713526004_1 by Requestor</title>
    <event_type>comment_for_package</event_type>
    <when>2024-04-19T11:26:45</when>
  </notification>
  <notification id="37">
    <title>Request 1 created by Iggy (submit home:Admin/ruby)</title>
    <event_type>request_create</event_type>
    <description>Aut praesentium vel. Non omnis accusantium. Provident itaque perspiciatis.</description>
    <state>new</state>
    <when>2024-04-19T11:25:56</when>
    <who>Iggy</who>
    <request_number>1</request_number>
  </notification>
  <notification id="38">
    <title>Request 7 created by Iggy (submit home:Admin/another_package_with_diff_1713525977, submit home:Admin/another_package_with_diff_1713525979)</title>
    <event_type>request_create</event_type>
    <description>Minus illum pariatur. Qui a atque. Enim eos quam.</description>
    <state>new</state>
    <when>2024-04-19T11:26:19</when>
    <who>Iggy</who>
    <request_number>7</request_number>
  </notification>
  <notification id="39">
    <title>Request 8 created by Iggy (maintenance_incident openSUSE:Maintenance)</title>
    <event_type>request_create</event_type>
    <description>Request with incident actions</description>
    <state>new</state>
    <when>2024-04-19T11:26:23</when>
    <who>Iggy</who>
    <request_number>8</request_number>
  </notification>
  <notification id="40">
    <title>Request 9 created by Iggy (maintenance_incident openSUSE:Maintenance, maintenance_incident openSUSE:Maintenance, maintenance_incident openSUSE:Maintenance, maintenance_incident openSUSE:Maintenance, maintenance_incident openSUSE:Maintenance)</title>
    <event_type>request_create</event_type>
    <description>Request with incident actions</description>
    <state>new</state>
    <when>2024-04-19T11:26:26</when>
    <who>Iggy</who>
    <request_number>9</request_number>
  </notification>
  <notification id="41">
    <title>Request 11 created by Iggy (maintenance_incident openSUSE:Maintenance)</title>
    <event_type>request_create</event_type>
    <description>Request with incident actions</description>
    <state>new</state>
    <when>2024-04-19T11:26:32</when>
    <who>Iggy</who>
    <request_number>11</request_number>
  </notification>
  <notification id="42">
    <title>Request 13 created by Iggy (delete home:Admin/sed_1713525993)</title>
    <event_type>request_create</event_type>
    <description>Odio et dolorum. Perferendis est voluptatem. Deleniti saepe illum.</description>
    <state>new</state>
    <when>2024-04-19T11:26:33</when>
    <who>Iggy</who>
    <request_number>13</request_number>
  </notification>
  <notification id="43">
    <title>Request 15 changed from declined to declined (submit requestor_project/package_1713525994_0)</title>
    <event_type>request_statechange</event_type>
    <comment>Declined by requestor</comment>
    <description>Ut reprehenderit aut. Laudantium reprehenderit culpa. Aspernatur nesciunt beatae.</description>
    <state>declined</state>
    <when>2024-04-19T11:26:35</when>
    <who>Requestor</who>
    <request_number>15</request_number>
  </notification>
  <notification id="44">
    <title>Request 17 changed from declined to declined (submit requestor_project/package_1713526004_1)</title>
    <event_type>request_statechange</event_type>
    <comment>Declined by requestor</comment>
    <description>Voluptatem saepe et. Culpa praesentium similique. Sed id alias.</description>
    <state>declined</state>
    <when>2024-04-19T11:26:45</when>
    <who>Requestor</who>
    <request_number>17</request_number>
  </notification>
  <notification id="45">
    <title>Request 4 requires review (submit openSUSE:Factory/apache2)</title>
    <event_type>review_wanted</event_type>
    <comment>is this really fine?</comment>
    <description>Repellat non voluptatem. Minus laborum vel. Nemo ut non.</description>
    <state>new</state>
    <when>2024-04-19T11:26:01</when>
    <who>Iggy</who>
    <request_number>4</request_number>
  </notification>
  <notification id="47">
    <title>Request 14 requires review (submit home:Admin/package_1713525994_0)</title>
    <event_type>review_wanted</event_type>
    <comment>Et dignissimos quisquam. Velit repudiandae voluptas. Consequatur consequatur porro.</comment>
    <description>Distinctio incidunt eos. Esse quaerat dolorum. Enim quas et.</description>
    <state>new</state>
    <when>2024-04-19T11:26:35</when>
    <who>Requestor</who>
    <request_number>14</request_number>
  </notification>
  <notification id="49">
    <title>Request 16 requires review (submit home:Admin/package_1713526004_1)</title>
    <event_type>review_wanted</event_type>
    <comment>Aperiam sint expedita. Nihil incidunt est. Cumque magni sunt.</comment>
    <description>Perferendis dignissimos quia. Quas nisi quo. Pariatur qui veritatis.</description>
    <state>new</state>
    <when>2024-04-19T11:26:45</when>
    <who>Requestor</who>
    <request_number>16</request_number>
  </notification>
</notifications>

After

XML result of http://localhost:3000/my/notifications for the user Admin in the development environment:

Click to expand
<notifications count="22">
  <total_pages>1</total_pages>
  <current_page>1</current_page>
  <notification id="3">
    <title>Build Service Notification</title>
    <type>report_for_comment</type>
    <time>2024-04-19 11:26:39 UTC</time>
    <description>'Iggy' created a report for a comment from Admin. This is the reason:</description>
  </notification>
  <notification id="4">
    <title>Build Service Notification</title>
    <type>report_for_package</type>
    <time>2024-04-19 11:26:39 UTC</time>
    <description>'Iggy' created a report for a package. This is the reason:</description>
  </notification>
  <notification id="5">
    <title>Build Service Notification</title>
    <type>report_for_project</type>
    <time>2024-04-19 11:26:39 UTC</time>
    <description>'Iggy' created a report for a project. This is the reason:</description>
  </notification>
  <notification id="6">
    <title>Build Service Notification</title>
    <type>report_for_user</type>
    <time>2024-04-19 11:26:39 UTC</time>
    <description>'Iggy' created a report for a user. This is the reason:</description>
  </notification>
  <notification id="14">
    <title>Build Service Notification</title>
    <type>report_for_comment</type>
    <time>2024-04-19 11:26:40 UTC</time>
    <description>'Requestor' created a report for a comment from Admin. This is the reason:</description>
  </notification>
  <notification id="15">
    <title>Workflow run failed on Pull request</title>
    <type>workflow_run_fail</type>
    <time>2024-04-19 11:26:40 UTC</time>
    <state>fail</state>
  </notification>
  <notification id="16">
    <title>Workflow run failed on Merge request hook</title>
    <type>workflow_run_fail</type>
    <time>2024-04-19 11:26:40 UTC</time>
    <state>fail</state>
  </notification>
  <notification id="18">
    <title>Build Service Notification</title>
    <type>relationship_create</type>
    <time>2024-04-19 11:26:41 UTC</time>
    <who>Iggy</who>
    <description>Iggy made you maintainer of openSUSE:Maintenance</description>
  </notification>
  <notification id="25">
    <title>New comment in package home:Admin/package_1713525994_0 by Requestor</title>
    <type>comment_for_package</type>
    <time>2024-04-19 11:26:35 UTC</time>
    <description>home:Admin / package_1713525994_0</description>
  </notification>
  <notification id="31">
    <title>New comment in project home:Admin by Requestor</title>
    <type>comment_for_project</type>
    <time>2024-04-19 11:26:45 UTC</time>
    <description>home:Admin</description>
  </notification>
  <notification id="32">
    <title>New comment in package home:Admin/package_1713526004_1 by Requestor</title>
    <type>comment_for_package</type>
    <time>2024-04-19 11:26:45 UTC</time>
    <description>home:Admin / package_1713526004_1</description>
  </notification>
  <notification id="37">
    <title>Request 1 created by Iggy (submit home:Admin/ruby)</title>
    <type>request_create</type>
    <time>2024-04-19 11:25:56 UTC</time>
    <state>new</state>
    <who>Iggy</who>
    <description>home:Iggy:branches:home:Admin / ruby to home:Admin / ruby</description>
    <request_number>1</request_number>
  </notification>
  <notification id="38">
    <title>Request 7 created by Iggy (submit home:Admin/another_package_with_diff_1713525977, submit home:Admin/another_package_with_diff_1713525979)</title>
    <type>request_create</type>
    <time>2024-04-19 11:26:19 UTC</time>
    <state>new</state>
    <who>Iggy</who>
    <description>home:Admin</description>
    <request_number>7</request_number>
  </notification>
  <notification id="39">
    <title>Request 8 created by Iggy (maintenance_incident openSUSE:Maintenance)</title>
    <type>request_create</type>
    <time>2024-04-19 11:26:23 UTC</time>
    <state>new</state>
    <who>Iggy</who>
    <description>home:Iggy:branches:OBS_Maintained:bash / bash.openSUSE_Leap_15.4_Update to openSUSE:Maintenance</description>
    <request_number>8</request_number>
  </notification>
  <notification id="40">
    <title>Request 9 created by Iggy (maintenance_incident openSUSE:Maintenance, maintenance_incident openSUSE:Maintenance, maintenance_incident openSUSE:Maintenance, maintenance_incident openSUSE:Maintenance, maintenance_incident openSUSE:Maintenance)</title>
    <type>request_create</type>
    <time>2024-04-19 11:26:26 UTC</time>
    <state>new</state>
    <who>Iggy</who>
    <description>openSUSE:Maintenance</description>
    <request_number>9</request_number>
  </notification>
  <notification id="41">
    <title>Request 11 created by Iggy (maintenance_incident openSUSE:Maintenance)</title>
    <type>request_create</type>
    <time>2024-04-19 11:26:32 UTC</time>
    <state>new</state>
    <who>Iggy</who>
    <description>servers / apache2 to openSUSE:Maintenance</description>
    <request_number>11</request_number>
  </notification>
  <notification id="42">
    <title>Request 13 created by Iggy (delete home:Admin/sed_1713525993)</title>
    <type>request_create</type>
    <time>2024-04-19 11:26:33 UTC</time>
    <state>new</state>
    <who>Iggy</who>
    <description>home:Admin / sed_1713525993</description>
    <request_number>13</request_number>
  </notification>
  <notification id="43">
    <title>Request 15 changed from declined to declined (submit requestor_project/package_1713525994_0)</title>
    <type>request_statechange</type>
    <time>2024-04-19 11:26:35 UTC</time>
    <state>declined</state>
    <who>Requestor</who>
    <description>home:Admin / package_1713525994_0 to requestor_project / package_1713525994_0</description>
    <request_number>15</request_number>
  </notification>
  <notification id="44">
    <title>Request 17 changed from declined to declined (submit requestor_project/package_1713526004_1)</title>
    <type>request_statechange</type>
    <time>2024-04-19 11:26:45 UTC</time>
    <state>declined</state>
    <who>Requestor</who>
    <description>home:Admin / package_1713526004_1 to requestor_project / package_1713526004_1</description>
    <request_number>17</request_number>
  </notification>
  <notification id="45">
    <title>Request 4 requires review (submit openSUSE:Factory/apache2)</title>
    <type>review_wanted</type>
    <time>2024-04-19 11:26:01 UTC</time>
    <state>review</state>
    <who>Iggy</who>
    <description>openSUSE:Leap:15.0 / apache2 to openSUSE:Factory / apache2</description>
    <request_number>4</request_number>
  </notification>
  <notification id="47">
    <title>Request 14 requires review (submit home:Admin/package_1713525994_0)</title>
    <type>review_wanted</type>
    <time>2024-04-19 11:26:35 UTC</time>
    <state>review</state>
    <who>Requestor</who>
    <description>requestor_project / package_1713525994_0 to home:Admin / package_1713525994_0</description>
    <request_number>14</request_number>
  </notification>
  <notification id="49">
    <title>Request 16 requires review (submit home:Admin/package_1713526004_1)</title>
    <type>review_wanted</type>
    <time>2024-04-19 11:26:45 UTC</time>
    <state>review</state>
    <who>Requestor</who>
    <description>requestor_project / package_1713526004_1 to home:Admin / package_1713526004_1</description>
    <request_number>16</request_number>
  </notification>
</notifications>

@github-actions github-actions bot added the Frontend Things related to the OBS RoR app label May 17, 2024
@eduardoj eduardoj force-pushed the fix/api_notifications_improve_xml_format branch 2 times, most recently from fac278b to 6b226a2 Compare May 17, 2024 07:34
@eduardoj eduardoj marked this pull request as ready for review May 17, 2024 07:35
@eduardoj eduardoj force-pushed the fix/api_notifications_improve_xml_format branch from 6b226a2 to 9cddcb8 Compare May 17, 2024 07:36
Comment on lines +5 to +11
if (state = if notification.notifiable_type == 'BsRequest'
notification.notifiable.state
elsif notification.notifiable_type == 'WorkflowRun'
notification.notifiable.status
end)
builder.state state
end
Copy link
Contributor

@danidoni danidoni May 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too many ifs and assignments in the same line for my taste 😅 Can we make this simpler to read and understand?

@saraycp saraycp force-pushed the fix/api_notifications_improve_xml_format branch from 9cddcb8 to 3be2a21 Compare May 23, 2024 13:53
@hennevogel
Copy link
Member

Why are there changes to the components in this PR? Are we using components in the XML views?

@saraycp saraycp marked this pull request as draft May 24, 2024 09:23
@saraycp
Copy link
Contributor

saraycp commented May 27, 2024

We better do a refactoring to make it easier to use the information like excerpt, title/summary, involved users, etc in different places: UI, API XML and RSS. Otherwise, we'll need to do a trick to extract that info from the ViewComponents and use them in places different from UI.

Closing this PR.

@saraycp saraycp closed this May 27, 2024
@eduardoj eduardoj deleted the fix/api_notifications_improve_xml_format branch May 27, 2024 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Frontend Things related to the OBS RoR app
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants