Skip to content

fix(jira): include fields=*all in Jira Server issue search query (fixes #9122) - #9149

Open
Thundercloud12 wants to merge 2 commits into
apache:mainfrom
Thundercloud12:fix/jira-server-worklog-collection
Open

Thundercloud12 wants to merge 2 commits into
apache:mainfrom
Thundercloud12:fix/jira-server-worklog-collection

Conversation

@Thundercloud12

Copy link
Copy Markdown
Contributor

Summary

When collecting issues from Jira Server (on-premise) via /api/2/search in setupIssueV2Collector, the fields query parameter was omitted.

According to Atlassian's REST API specifications, when fields is omitted, /rest/api/2/search defaults to returning only *navigable fields. Since worklog is not a navigable field, Jira Server omits the embedded fields.worklog array from the search response payload.

This resulted in the following downstream collection failure:

  1. extractIssues could not extract the embedded worklogs, which contain the first page of up to 20 worklogs, leaving issue.worklog_total = 0.
  2. collectWorklogs only queries issues where worklog_total > 20, assuming issues with 20 or fewer worklogs were already collected during the first step.
  3. Consequently, Jira Server issues with 20 or fewer worklogs had 0 worklogs recorded in jira_issue_worklogs.

This PR fixes the issue by:

  • Adding query.Set("fields", "*all") to setupIssueV2Collector in issue_collector.go, bringing it in line with setupIssueV3Collector for Jira Cloud.
  • Adding the unit test TestExtractIssuesWorklog in issue_extractor_test.go to ensure embedded worklogs are correctly parsed and recorded.

Does this close any open issues?

Closes #9122

Screenshots

Unit tests passing:

=== RUN   TestExtractIssuesWorklog
=== RUN   TestExtractIssuesWorklog/extracts_embedded_worklog_when_fields_contain_worklog
=== RUN   TestExtractIssuesWorklog/no_worklog_extracted_when_worklog_field_is_absent
--- PASS: TestExtractIssuesWorklog (0.00s)
PASS
ok      github.com/apache/devlake/plugins/jira/tasks    0.020s

Other Information

  • Official Atlassian documentation for /rest/api/2/search states that the search resource returns only *navigable fields by default.
  • Fields such as comment and worklog can contain large amounts of data, so they are excluded from the default *navigable set to keep API responses performant.
  • These fields must be explicitly requested, either individually or by requesting *all.
  • setupIssueV3Collector for Jira Cloud already uses query.Set("fields", "*all"); this change aligns Jira Server with the same behavior.

@Thundercloud12

Copy link
Copy Markdown
Contributor Author

@klesh please have a look, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Jira worklogs not collected when issue has fewer than 20 worklogs

1 participant