Commit 6237237f authored by Arturo Herrero's avatar Arturo Herrero

Jira Issue: Fix comments' datetime

When we query the Jira API, we use renderedFields option to get some
values (description and comments) as HTML. That way we can render that
information in GitLab.  That way, we can get the Jira Issue data from
the Jira API response in two formats: fields and renderedFields.

"fields": {
  ...
  "comment": {
    "comments": [
      ...
          "displayName": "Arturo Herrero",
          "active": true,
          "timeZone": "Europe/London"
        },
        "created": "2021-03-10T10:05:51.199+0000",
        "updated": "2021-03-10T10:05:51.199+0000"
      },
  ...
}
"renderedFields": {
  ...
  "comment": {
    "comments": [
      ...
          "displayName": "Arturo Herrero",
          "active": true,
          "timeZone": "Europe/London"
        },
        "created": "2 days ago 10:05 AM",
        "updated": "2 days ago 10:05 AM"
      },
  ...
}

Using renderedFields we can get some of the following formats:

- "Just now"
- "2 days ago 10:05 AM"
- "24/Feb/21 7:19 AM"

Instead of the datetime with timezone from fields:

- "2021-03-10T10:05:51.199+0000"

We have to get the datetimes' fields from the fields key as it's more
reliable and easy to consume in our end.
parent ffcbbe06
......@@ -4,8 +4,7 @@ module Integrations
module Jira
class IssueDetailEntity < ::Integrations::Jira::IssueEntity
expose :description_html do |jira_issue|
Banzai::Pipeline::JiraGfmPipeline
.call(jira_issue.renderedFields['description'], project: project)[:output].to_html
jira_gfm_pipeline(jira_issue.renderedFields['description'])
end
expose :state do |jira_issue|
......@@ -17,16 +16,22 @@ module Integrations
end
expose :comments do |jira_issue|
jira_issue.renderedFields['comment']['comments'].map do |comment|
jira_issue.fields['comment']['comments'].map.with_index do |comment, index|
{
id: comment['id'],
body_html: Banzai::Pipeline::JiraGfmPipeline.call(comment['body'], project: project)[:output].to_html,
body_html: jira_gfm_pipeline(jira_issue.renderedFields['comment']['comments'][index]['body']),
created_at: comment['created'].to_datetime.utc,
updated_at: comment['updated'].to_datetime.utc,
author: jira_user(comment['author'])
}
end
end
private
def jira_gfm_pipeline(html)
Banzai::Pipeline::JiraGfmPipeline.call(html, project: project)[:output].to_html
end
end
end
end
......@@ -40,11 +40,7 @@ RSpec.describe Integrations::Jira::IssueDetailEntity do
'comment' => {
'comments' => [
{
'id' => '10022',
'author' => comment_author,
'body' => '<p>Comment</p>',
'created' => '2020-06-25T15:50:00.000+0000',
'updated' => '2020-06-25T15:51:00.000+0000'
'body' => '<p>Comment</p>'
}
]
}
......@@ -56,7 +52,18 @@ RSpec.describe Integrations::Jira::IssueDetailEntity do
labels: ['backend'],
fields: {
'reporter' => reporter,
'assignee' => assignee
'assignee' => assignee,
'comment' => {
'comments' => [
{
'id' => '10022',
'author' => comment_author,
'body' => '<p>Comment</p>',
'created' => '2020-06-25T15:50:00.000+0000',
'updated' => '2020-06-25T15:51:00.000+0000'
}
]
}
},
project: double(key: 'GL'),
key: 'GL-5',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment