This is an automated email from the ASF dual-hosted git repository.
mintsweet pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/main by this push:
new f234f584c fix: fix jira remote api (#5468)
f234f584c is described below
commit f234f584c897d874dd793fec9d280befe19b8e06
Author: mappjzc <[email protected]>
AuthorDate: Wed Jun 14 15:35:21 2023 +0800
fix: fix jira remote api (#5468)
Add analyzingQuery to get real PerPage and Page.
Because some jira server limit the maxResults.
Nddtfjiang <[email protected]>
---
backend/helpers/pluginhelper/api/remote_api_helper.go | 6 +++---
backend/plugins/jira/api/remote.go | 16 +++++++++++++++-
2 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/backend/helpers/pluginhelper/api/remote_api_helper.go
b/backend/helpers/pluginhelper/api/remote_api_helper.go
index b9d874a68..a85dd8ff8 100644
--- a/backend/helpers/pluginhelper/api/remote_api_helper.go
+++ b/backend/helpers/pluginhelper/api/remote_api_helper.go
@@ -21,12 +21,13 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
+ "net/http"
+ "strconv"
+
coreContext "github.com/apache/incubator-devlake/core/context"
"github.com/apache/incubator-devlake/core/errors"
"github.com/apache/incubator-devlake/core/plugin"
"github.com/go-playground/validator/v10"
- "net/http"
- "strconv"
)
type RemoteScopesChild struct {
@@ -233,7 +234,6 @@ func (r *RemoteApiHelper[Conn, Scope, ApiScope, Group])
GetScopesFromRemote(inpu
outputBody.NextPageToken = ""
if queryData != nil {
queryData.Page += 1
- queryData.PerPage = remoteScopesPerPage
outputBody.NextPageToken, err =
getPageTokenFromPageData(queryData)
if err != nil {
diff --git a/backend/plugins/jira/api/remote.go
b/backend/plugins/jira/api/remote.go
index 5f38b6737..90883b97b 100644
--- a/backend/plugins/jira/api/remote.go
+++ b/backend/plugins/jira/api/remote.go
@@ -58,7 +58,9 @@ func RemoteScopes(input *plugin.ApiResourceInput)
(*plugin.ApiResourceOutput, er
}
resBody := struct {
- Values []apiv2models.Board `json:"values"`
+ MaxResults int
`json:"maxResults"`
+ StartAt int `json:"startAt"`
+ Values []apiv2models.Board `json:"values"`
}{}
err = api.UnmarshalResponse(res, &resBody)
@@ -66,6 +68,11 @@ func RemoteScopes(input *plugin.ApiResourceInput)
(*plugin.ApiResourceOutput, er
return nil, err
}
+ if (queryData.PerPage != resBody.MaxResults) ||
+ (((queryData.Page - 1) * queryData.PerPage) !=
resBody.StartAt) {
+ analyzingQuery(resBody.MaxResults,
resBody.StartAt, queryData)
+ }
+
return resBody.Values, err
})
}
@@ -76,3 +83,10 @@ func initialQuery(queryData *api.RemoteQueryData) url.Values
{
query.Set("startAt", fmt.Sprintf("%v",
(queryData.Page-1)*queryData.PerPage))
return query
}
+
+func analyzingQuery(maxResults int, startAt int, queryData
*api.RemoteQueryData) {
+ if maxResults != 0 {
+ queryData.PerPage = maxResults
+ queryData.Page = startAt/maxResults + 1
+ }
+}