Thundercloud12 opened a new pull request, #9149:
URL: https://github.com/apache/devlake/pull/9149
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
### 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:
```text
=== 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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]