mr-ks commented on code in PR #7809:
URL:
https://github.com/apache/incubator-devlake/pull/7809#discussion_r1703315791
##########
backend/plugins/azuredevops_go/e2e/raw_tables/_raw_azuredevops_go_api_workitems.csv:
##########
@@ -0,0 +1,2 @@
+id,params,data,url,input
+1234,"{""OrganizationId"":""johndoe"",""RepositoryId"":""0d50ba13-f9ad-49b0-9b21-d29eda50ca33"",""ProjectId"":""test-project""}",com.intellij.database.extractors.TextInfo@d75361af,https://dev.azure.com/johndoe/test-project/_apis/wit/workitemsbatch?%24skip=0&%24top=0&api-version=7.1
Review Comment:
Could you please check the value of the `data` column?
`com.intellij.database.extractors.TextInfo@d75361af` appears to be an export
error to me.
##########
backend/plugins/azuredevops_go/tasks/workitem_collector.go:
##########
@@ -0,0 +1,121 @@
+/*
+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.
+*/
+
+package tasks
+
+import (
+ "encoding/json"
+ "github.com/apache/incubator-devlake/core/errors"
+ "github.com/apache/incubator-devlake/core/plugin"
+ "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
+ "github.com/tidwall/gjson"
+ "io"
+ "net/http"
+)
+
+func init() {
+ RegisterSubtaskMeta(&CollectWorkitemsMeta)
+}
+
+const RawWorkitemsTable = "azuredevops_go_api_workitems"
+
+var CollectWorkitemsMeta = plugin.SubTaskMeta{
Review Comment:
If I'm not mistaken, this task runs for each data scope linked to a DevLake
project, meaning we read all work items in an Azure DevOps project n times if n
data scopes are attached. This can quickly deplete the quota for large projects
with many work items.
##########
backend/plugins/azuredevops_go/tasks/workitem_collector.go:
##########
@@ -0,0 +1,121 @@
+/*
+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.
+*/
+
+package tasks
+
+import (
+ "encoding/json"
+ "github.com/apache/incubator-devlake/core/errors"
+ "github.com/apache/incubator-devlake/core/plugin"
+ "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
+ "github.com/tidwall/gjson"
+ "io"
+ "net/http"
+)
+
+func init() {
+ RegisterSubtaskMeta(&CollectWorkitemsMeta)
+}
+
+const RawWorkitemsTable = "azuredevops_go_api_workitems"
+
+var CollectWorkitemsMeta = plugin.SubTaskMeta{
+ Name: "collectApiWorkitems",
+ EntryPoint: CollectApiWorkitems,
+ EnabledByDefault: true,
+ Description: "Collect work items data from Azure DevOps API",
+ DomainTypes: []string{plugin.DOMAIN_TYPE_TICKET},
+ ProductTables: []string{RawWorkitemsTable},
+}
+
+func CollectApiWorkitems(taskCtx plugin.SubTaskContext) errors.Error {
+ rawDataSubTaskArgs, data := CreateRawDataSubTaskArgs(taskCtx,
RawWorkitemsTable)
+
+ var rawWorkItems gjson.Result
+ logger := taskCtx.GetLogger()
+ repoType := data.Options.RepositoryType
+
+ queryCollector, err := api.NewApiCollector(api.ApiCollectorArgs{
+ RawDataSubTaskArgs: *rawDataSubTaskArgs,
+ ApiClient: data.ApiClient,
+ Concurrency: 1,
+ PageSize: 100,
+ Incremental: false,
+ Method: http.MethodPost,
+ UrlTemplate: "{{ .Params.OrganizationId }}/{{
.Params.ProjectId }}/_apis/wit/wiql?api-version=7.1",
+ RequestBody: func(reqData *api.RequestData)
map[string]interface{} {
+
+ return map[string]interface{}{
+ "query": `SELECT [System.Id] FROM workitems
WHERE [System.TeamProject] = "` + data.Options.ProjectId + `" ORDER BY
[System.ChangedDate] DESC`,
Review Comment:
Integrating an additional time filter condition in the `WHERE clause` can
help us to integrate the project-level sync policy settings and provide an
incremental mode. There is a nice example in the jira implementation:
https://github.com/apache/incubator-devlake/blob/938e22c876f3002560b9002d645fd4d7cadf9a2b/backend/plugins/jira/tasks/issue_collector.go#L80
##########
backend/plugins/azuredevops_go/tasks/workitem_collector.go:
##########
@@ -0,0 +1,121 @@
+/*
+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.
+*/
+
+package tasks
+
+import (
+ "encoding/json"
+ "github.com/apache/incubator-devlake/core/errors"
+ "github.com/apache/incubator-devlake/core/plugin"
+ "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
+ "github.com/tidwall/gjson"
+ "io"
+ "net/http"
+)
+
+func init() {
+ RegisterSubtaskMeta(&CollectWorkitemsMeta)
+}
+
+const RawWorkitemsTable = "azuredevops_go_api_workitems"
+
+var CollectWorkitemsMeta = plugin.SubTaskMeta{
+ Name: "collectApiWorkitems",
+ EntryPoint: CollectApiWorkitems,
+ EnabledByDefault: true,
+ Description: "Collect work items data from Azure DevOps API",
+ DomainTypes: []string{plugin.DOMAIN_TYPE_TICKET},
+ ProductTables: []string{RawWorkitemsTable},
+}
+
+func CollectApiWorkitems(taskCtx plugin.SubTaskContext) errors.Error {
+ rawDataSubTaskArgs, data := CreateRawDataSubTaskArgs(taskCtx,
RawWorkitemsTable)
+
+ var rawWorkItems gjson.Result
+ logger := taskCtx.GetLogger()
+ repoType := data.Options.RepositoryType
+
+ queryCollector, err := api.NewApiCollector(api.ApiCollectorArgs{
+ RawDataSubTaskArgs: *rawDataSubTaskArgs,
+ ApiClient: data.ApiClient,
+ Concurrency: 1,
+ PageSize: 100,
+ Incremental: false,
+ Method: http.MethodPost,
+ UrlTemplate: "{{ .Params.OrganizationId }}/{{
.Params.ProjectId }}/_apis/wit/wiql?api-version=7.1",
+ RequestBody: func(reqData *api.RequestData)
map[string]interface{} {
+
+ return map[string]interface{}{
+ "query": `SELECT [System.Id] FROM workitems
WHERE [System.TeamProject] = "` + data.Options.ProjectId + `" ORDER BY
[System.ChangedDate] DESC`,
+ }
+ },
+ ResponseParser: func(res *http.Response) ([]json.RawMessage,
errors.Error) {
+ logger.Debug("Response body received is: ", res.Body)
+ resBody, _ := io.ReadAll(res.Body)
+ rawWorkItems = gjson.Get(string(resBody),
"workItems.#.id")
+ return nil, nil
+ },
+ AfterResponse: handleClientErrors(repoType, logger),
+ })
+
+ err = queryCollector.Execute()
+
+ logger.Debug("All Ids received: #%s", rawWorkItems.String())
+
+ logger.Info("Sum of workitems Ids received: %d",
len(rawWorkItems.Array()))
+
+ var currentWorkItems, emptyWorkItems []string
+
+ rawWorkItems.ForEach(func(key, value gjson.Result) bool {
+ currentWorkItems = append(currentWorkItems, value.String())
+
+ if len(currentWorkItems) == 9 || key.Int() ==
int64(len(rawWorkItems.Array())-1) {
+ logger.Info("Currently processed items: %d",
key.Int()+1)
+ logger.Debug("Current work items in list: #%s",
currentWorkItems)
+ thisRequestBody := func(reqData *api.RequestData)
map[string]interface{} {
+ return map[string]interface{}{
+ "ids": currentWorkItems,
+ "fields": []string{"System.Id",
"System.Title", "System.TeamProject", "System.Description", "System.Reason",
"System.AreaPath", "System.WorkItemType", "System.State", "System.CreatedDate",
"System.ChangedDate", "System.CreatedBy", "System.AssignedTo",
"Microsoft.VSTS.Scheduling.Effort", "Microsoft.VSTS.Common.Priority",
"Microsoft.VSTS.Common.Severity"},
Review Comment:
I think it makes sense to make this configurable for the end user. Due to
the dynamic nature of Azure DevOps, it is very hard to make assumptions about
which property is used and which is not. If I got it right,
`Microsoft.VSTS.Scheduling.StoryPoints` is used in the Agile template instead
of `Microsoft.VSTS.Scheduling.Effort`.
##########
backend/plugins/azuredevops_go/tasks/workitem_collector.go:
##########
@@ -0,0 +1,121 @@
+/*
+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.
+*/
+
+package tasks
+
+import (
+ "encoding/json"
+ "github.com/apache/incubator-devlake/core/errors"
+ "github.com/apache/incubator-devlake/core/plugin"
+ "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
+ "github.com/tidwall/gjson"
+ "io"
+ "net/http"
+)
+
+func init() {
+ RegisterSubtaskMeta(&CollectWorkitemsMeta)
+}
+
+const RawWorkitemsTable = "azuredevops_go_api_workitems"
+
+var CollectWorkitemsMeta = plugin.SubTaskMeta{
+ Name: "collectApiWorkitems",
+ EntryPoint: CollectApiWorkitems,
+ EnabledByDefault: true,
+ Description: "Collect work items data from Azure DevOps API",
+ DomainTypes: []string{plugin.DOMAIN_TYPE_TICKET},
+ ProductTables: []string{RawWorkitemsTable},
+}
+
+func CollectApiWorkitems(taskCtx plugin.SubTaskContext) errors.Error {
+ rawDataSubTaskArgs, data := CreateRawDataSubTaskArgs(taskCtx,
RawWorkitemsTable)
+
+ var rawWorkItems gjson.Result
+ logger := taskCtx.GetLogger()
+ repoType := data.Options.RepositoryType
+
+ queryCollector, err := api.NewApiCollector(api.ApiCollectorArgs{
+ RawDataSubTaskArgs: *rawDataSubTaskArgs,
+ ApiClient: data.ApiClient,
+ Concurrency: 1,
+ PageSize: 100,
+ Incremental: false,
+ Method: http.MethodPost,
+ UrlTemplate: "{{ .Params.OrganizationId }}/{{
.Params.ProjectId }}/_apis/wit/wiql?api-version=7.1",
+ RequestBody: func(reqData *api.RequestData)
map[string]interface{} {
+
+ return map[string]interface{}{
+ "query": `SELECT [System.Id] FROM workitems
WHERE [System.TeamProject] = "` + data.Options.ProjectId + `" ORDER BY
[System.ChangedDate] DESC`,
+ }
+ },
+ ResponseParser: func(res *http.Response) ([]json.RawMessage,
errors.Error) {
+ logger.Debug("Response body received is: ", res.Body)
+ resBody, _ := io.ReadAll(res.Body)
+ rawWorkItems = gjson.Get(string(resBody),
"workItems.#.id")
+ return nil, nil
+ },
+ AfterResponse: handleClientErrors(repoType, logger),
+ })
+
+ err = queryCollector.Execute()
+
+ logger.Debug("All Ids received: #%s", rawWorkItems.String())
+
+ logger.Info("Sum of workitems Ids received: %d",
len(rawWorkItems.Array()))
+
+ var currentWorkItems, emptyWorkItems []string
+
+ rawWorkItems.ForEach(func(key, value gjson.Result) bool {
+ currentWorkItems = append(currentWorkItems, value.String())
+
+ if len(currentWorkItems) == 9 || key.Int() ==
int64(len(rawWorkItems.Array())-1) {
Review Comment:
Can you please explain how you came up with this condition? Is this a
restriction of the `/workitemsbatch` API?
##########
backend/plugins/azuredevops_go/tasks/workitem_collector.go:
##########
@@ -0,0 +1,121 @@
+/*
+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.
+*/
+
+package tasks
+
+import (
+ "encoding/json"
+ "github.com/apache/incubator-devlake/core/errors"
+ "github.com/apache/incubator-devlake/core/plugin"
+ "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
+ "github.com/tidwall/gjson"
+ "io"
+ "net/http"
+)
+
+func init() {
+ RegisterSubtaskMeta(&CollectWorkitemsMeta)
+}
+
+const RawWorkitemsTable = "azuredevops_go_api_workitems"
+
+var CollectWorkitemsMeta = plugin.SubTaskMeta{
+ Name: "collectApiWorkitems",
+ EntryPoint: CollectApiWorkitems,
+ EnabledByDefault: true,
+ Description: "Collect work items data from Azure DevOps API",
+ DomainTypes: []string{plugin.DOMAIN_TYPE_TICKET},
+ ProductTables: []string{RawWorkitemsTable},
+}
+
+func CollectApiWorkitems(taskCtx plugin.SubTaskContext) errors.Error {
+ rawDataSubTaskArgs, data := CreateRawDataSubTaskArgs(taskCtx,
RawWorkitemsTable)
+
+ var rawWorkItems gjson.Result
+ logger := taskCtx.GetLogger()
+ repoType := data.Options.RepositoryType
+
+ queryCollector, err := api.NewApiCollector(api.ApiCollectorArgs{
+ RawDataSubTaskArgs: *rawDataSubTaskArgs,
+ ApiClient: data.ApiClient,
+ Concurrency: 1,
+ PageSize: 100,
+ Incremental: false,
+ Method: http.MethodPost,
+ UrlTemplate: "{{ .Params.OrganizationId }}/{{
.Params.ProjectId }}/_apis/wit/wiql?api-version=7.1",
+ RequestBody: func(reqData *api.RequestData)
map[string]interface{} {
+
+ return map[string]interface{}{
+ "query": `SELECT [System.Id] FROM workitems
WHERE [System.TeamProject] = "` + data.Options.ProjectId + `" ORDER BY
[System.ChangedDate] DESC`,
+ }
+ },
+ ResponseParser: func(res *http.Response) ([]json.RawMessage,
errors.Error) {
+ logger.Debug("Response body received is: ", res.Body)
+ resBody, _ := io.ReadAll(res.Body)
+ rawWorkItems = gjson.Get(string(resBody),
"workItems.#.id")
+ return nil, nil
+ },
+ AfterResponse: handleClientErrors(repoType, logger),
+ })
+
+ err = queryCollector.Execute()
+
+ logger.Debug("All Ids received: #%s", rawWorkItems.String())
+
+ logger.Info("Sum of workitems Ids received: %d",
len(rawWorkItems.Array()))
+
+ var currentWorkItems, emptyWorkItems []string
+
+ rawWorkItems.ForEach(func(key, value gjson.Result) bool {
+ currentWorkItems = append(currentWorkItems, value.String())
+
+ if len(currentWorkItems) == 9 || key.Int() ==
int64(len(rawWorkItems.Array())-1) {
+ logger.Info("Currently processed items: %d",
key.Int()+1)
+ logger.Debug("Current work items in list: #%s",
currentWorkItems)
+ thisRequestBody := func(reqData *api.RequestData)
map[string]interface{} {
+ return map[string]interface{}{
+ "ids": currentWorkItems,
+ "fields": []string{"System.Id",
"System.Title", "System.TeamProject", "System.Description", "System.Reason",
"System.AreaPath", "System.WorkItemType", "System.State", "System.CreatedDate",
"System.ChangedDate", "System.CreatedBy", "System.AssignedTo",
"Microsoft.VSTS.Scheduling.Effort", "Microsoft.VSTS.Common.Priority",
"Microsoft.VSTS.Common.Severity"},
Review Comment:
Can you please check if all of the required fields are actually being used?
`System.Reason` is a very special one that is also not mapped to the Devlake
Issue domain type.
--
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]