You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by GitBox <gi...@apache.org> on 2022/06/30 21:44:44 UTC

[GitHub] [incubator-devlake] keon94 opened a new pull request, #2401: feat(jira) Collect the epic issue in an issue's epic link (#1681)

keon94 opened a new pull request, #2401:
URL: https://github.com/apache/incubator-devlake/pull/2401

   ### ⚠️ &nbsp;&nbsp;Pre Checklist
   
   > Please complete _ALL_ items in this checklist, and remove before submitting
   
   - [ ] I have read through the [Contributing](https://devlake.apache.org/community/) Documentation & [PR Template](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue)
   - [ ] This PR is using a `label` (bug, feature etc.)
   - [ ] My code is has necessary documentation (if appropriate)
   - [ ] I have added any relevant tests
   - [ ] This section (**⚠️ &nbsp;&nbsp;Pre Checklist**) will be removed when submitting PR
   
   # Summary
   
   <!--
   Thanks for submitting a pull request!
   
   We appreciate you spending the time to work on these changes.
   Please fill out as many sections below as possible.
   -->
   
   ### Does this close any open issues?
   Please mention the issues here.
   
   ### Screenshots
   Include any relevant screenshots here.
   
   ### Other Information
   Any other information that is important to this PR.
   


-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] mindlesscloud commented on a diff in pull request #2401: [feat-1681][jira]: Collect the epic issue in an issue's epic link

Posted by GitBox <gi...@apache.org>.
mindlesscloud commented on code in PR #2401:
URL: https://github.com/apache/incubator-devlake/pull/2401#discussion_r927330041


##########
plugins/jira/tasks/external_epic_collector.go:
##########
@@ -0,0 +1,152 @@
+/*
+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 (

Review Comment:
   would you mind merging the two import blocks?



##########
plugins/jira/e2e/external_epic_test.go:
##########
@@ -0,0 +1,83 @@
+package e2e

Review Comment:
   please add the Apache license header to this file



-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] klesh merged pull request #2401: [feat-1681][jira]: Collect the epic issue in an issue's epic link

Posted by GitBox <gi...@apache.org>.
klesh merged PR #2401:
URL: https://github.com/apache/incubator-devlake/pull/2401


-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] klesh commented on a diff in pull request #2401: [feat-1681][jira]: Collect the epic issue in an issue's epic link

Posted by GitBox <gi...@apache.org>.
klesh commented on code in PR #2401:
URL: https://github.com/apache/incubator-devlake/pull/2401#discussion_r931083458


##########
plugins/jira/tasks/epic_collector.go:
##########
@@ -0,0 +1,145 @@
+/*
+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 (
+	"fmt"
+	"github.com/apache/incubator-devlake/plugins/core"
+	"github.com/apache/incubator-devlake/plugins/core/dal"
+	"strings"
+
+	"encoding/json"
+	"github.com/apache/incubator-devlake/plugins/helper"
+	"io/ioutil"
+	"net/http"
+	"net/url"
+)
+
+const RAW_EPIC_TABLE = "jira_api_epics"
+
+type JiraEpicParams struct {

Review Comment:
   Why not use `JiraApiParams`? 



##########
plugins/jira/tasks/epic_collector.go:
##########
@@ -0,0 +1,145 @@
+/*
+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 (
+	"fmt"
+	"github.com/apache/incubator-devlake/plugins/core"
+	"github.com/apache/incubator-devlake/plugins/core/dal"
+	"strings"
+
+	"encoding/json"
+	"github.com/apache/incubator-devlake/plugins/helper"
+	"io/ioutil"
+	"net/http"
+	"net/url"
+)
+
+const RAW_EPIC_TABLE = "jira_api_epics"
+
+type JiraEpicParams struct {
+	ConnectionId uint64
+	BoardId      uint64
+}
+
+var _ core.SubTaskEntryPoint = CollectIssues
+
+var CollectEpicsMeta = core.SubTaskMeta{
+	Name:             "collectEpics",
+	EntryPoint:       CollectEpics,
+	EnabledByDefault: true,
+	Description:      "collect Jira epics from all boards",
+	DomainTypes:      []string{core.DOMAIN_TYPE_TICKET, core.DOMAIN_TYPE_CROSS},
+}
+
+func CollectEpics(taskCtx core.SubTaskContext) error {
+	db := taskCtx.GetDal()
+	data := taskCtx.GetData().(*JiraTaskData)
+	externalEpicKeys, err := GetEpicKeys(db, data)

Review Comment:
   Loading all epic_keys is fine in most cases, but it could be a problem when the total number of epics grows too big. say 1000? Not sure if Jira API would take that many keys.
   Besides, it is pointless to send all the keys every time, since the max records we can get is 100.
   I suggest that we create an `Iterator` as the `Input` that returns 100 keys max each time.



##########
plugins/jira/e2e/epic_test.go:
##########
@@ -0,0 +1,82 @@
+package e2e

Review Comment:
   Please add ASF header 



-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] keon94 commented on a diff in pull request #2401: [feat-1681][jira]: Collect the epic issue in an issue's epic link

Posted by GitBox <gi...@apache.org>.
keon94 commented on code in PR #2401:
URL: https://github.com/apache/incubator-devlake/pull/2401#discussion_r930611368


##########
plugins/jira/tasks/external_epic_collector.go:
##########
@@ -0,0 +1,152 @@
+/*
+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 (
+	"fmt"
+	"github.com/apache/incubator-devlake/plugins/core"
+	"github.com/apache/incubator-devlake/plugins/core/dal"
+	"strings"
+
+	"github.com/apache/incubator-devlake/plugins/helper"
+	"net/http"
+	"net/url"
+)
+
+import (
+	"encoding/json"
+	"io/ioutil"
+)
+
+const RAW_EXTERNAL_EPIC_TABLE = "jira_external_epics"
+
+// this struct should be moved to `jira_api_common.go`
+type JiraEpicParams struct {
+	ConnectionId uint64
+	BoardId      uint64
+}
+
+var _ core.SubTaskEntryPoint = CollectIssues
+
+var CollectExternalEpicsMeta = core.SubTaskMeta{
+	Name:             "collectExternalEpics",
+	EntryPoint:       CollectExternalEpics,
+	EnabledByDefault: true,
+	Description:      "collect Jira epics from other boards",
+	DomainTypes:      []string{core.DOMAIN_TYPE_TICKET, core.DOMAIN_TYPE_CROSS},
+}
+
+func CollectExternalEpics(taskCtx core.SubTaskContext) error {
+	db := taskCtx.GetDal()
+	data := taskCtx.GetData().(*JiraTaskData)
+	externalEpicKeys, err := GetExternalEpicKeys(db, data)
+	if err != nil {
+		return err
+	}
+	if len(externalEpicKeys) == 0 {
+		taskCtx.GetLogger().Info("no external epic keys found for Jira board %d", data.Options.BoardId)
+		return nil
+	}
+	since := data.Since
+	jql := "ORDER BY created ASC"
+	if since != nil {
+		// prepend a time range criteria if `since` was specified, either by user or from database
+		jql = fmt.Sprintf("updated >= '%s' %s", since.Format("2006/01/02 15:04"), jql)
+	}
+	jql = fmt.Sprintf("issue in (%s) %s", strings.Join(externalEpicKeys, ","), jql)
+
+	collector, err := helper.NewApiCollector(helper.ApiCollectorArgs{
+		RawDataSubTaskArgs: helper.RawDataSubTaskArgs{
+			Ctx: taskCtx,
+			Params: JiraEpicParams{
+				ConnectionId: data.Options.ConnectionId,
+				BoardId:      data.Options.BoardId,
+			},
+			Table: RAW_EXTERNAL_EPIC_TABLE,
+		},
+		ApiClient:   data.ApiClient,
+		PageSize:    100,
+		Incremental: false,
+		UrlTemplate: "api/2/search",
+		Query: func(reqData *helper.RequestData) (url.Values, error) {
+			query := url.Values{}
+			query.Set("jql", jql)
+			query.Set("issue in", fmt.Sprintf("(%s)", strings.Join(externalEpicKeys, ",")))
+			query.Set("startAt", fmt.Sprintf("%v", reqData.Pager.Skip))
+			query.Set("maxResults", fmt.Sprintf("%v", reqData.Pager.Size))
+			query.Set("expand", "changelog")
+			return query, nil
+		},
+		GetTotalPages: GetTotalPagesFromResponse,
+		Concurrency:   10,
+		ResponseParser: func(res *http.Response) ([]json.RawMessage, error) {
+			var data struct {
+				Issues []json.RawMessage `json:"issues"`
+			}
+			blob, err := ioutil.ReadAll(res.Body)
+			if err != nil {
+				return nil, err
+			}
+			err = json.Unmarshal(blob, &data)
+			if err != nil {
+				return nil, err
+			}
+			return data.Issues, nil
+		},
+	})
+	if err != nil {
+		return err
+	}
+	return collector.Execute()
+}
+
+func GetExternalEpicKeys(db dal.Dal, data *JiraTaskData) ([]string, error) {
+	// union of
+	// 1. issues with epics not from this board and not in the issues table
+	// 2. issues with epics not from this board that ARE already in the issues table (from previous runs)
+	// the above two selections are mutually exclusive
+	cursor, err := db.RawCursor(fmt.Sprintf(`

Review Comment:
   done



##########
plugins/jira/tasks/external_epic_extractor.go:
##########
@@ -0,0 +1,136 @@
+/*
+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/plugins/core"
+	"github.com/apache/incubator-devlake/plugins/helper"
+	"github.com/apache/incubator-devlake/plugins/jira/models"
+	"github.com/apache/incubator-devlake/plugins/jira/tasks/apiv2models"
+	"strconv"
+	"strings"
+	"time"
+)
+
+var _ core.SubTaskEntryPoint = ExtractIssues
+
+var ExtractExternalEpicsMeta = core.SubTaskMeta{
+	Name:             "extractExternalEpics",
+	EntryPoint:       ExtractExternalEpics,
+	EnabledByDefault: true,
+	Description:      "extract Jira epics from other boards",
+	DomainTypes:      []string{core.DOMAIN_TYPE_TICKET, core.DOMAIN_TYPE_CROSS},
+}
+
+func ExtractExternalEpics(taskCtx core.SubTaskContext) error {
+	data := taskCtx.GetData().(*JiraTaskData)
+	db := taskCtx.GetDal()
+	connectionId := data.Options.ConnectionId
+	boardId := data.Options.BoardId
+	logger := taskCtx.GetLogger()
+	logger.Info("extract external epic Issues, connection_id=%d, board_id=%d", connectionId, boardId)
+	mappings, err := getTypeMappings(data, db)
+	if err != nil {
+		return err
+	}
+	extractor, err := helper.NewApiExtractor(helper.ApiExtractorArgs{
+		RawDataSubTaskArgs: helper.RawDataSubTaskArgs{
+			Ctx: taskCtx,
+			Params: JiraEpicParams{
+				ConnectionId: data.Options.ConnectionId,
+				BoardId:      data.Options.BoardId,
+			},
+			Table: RAW_EXTERNAL_EPIC_TABLE,
+		},
+		Extract: func(row *helper.RawData) ([]interface{}, error) {
+			var apiIssue apiv2models.Issue
+			err = json.Unmarshal(row.Data, &apiIssue)
+			if err != nil {
+				return nil, err
+			}
+			err = apiIssue.SetAllFields(row.Data)
+			if err != nil {
+				return nil, err
+			}
+			var results []interface{}
+			sprints, issue, worklogs, changelogs, changelogItems, users := apiIssue.ExtractEntities(data.Options.ConnectionId)
+			for _, sprintId := range sprints {

Review Comment:
   done



-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] keon94 commented on a diff in pull request #2401: [feat-1681][jira]: Collect the epic issue in an issue's epic link

Posted by GitBox <gi...@apache.org>.
keon94 commented on code in PR #2401:
URL: https://github.com/apache/incubator-devlake/pull/2401#discussion_r927206808


##########
plugins/jira/tasks/external_epic_extractor.go:
##########
@@ -0,0 +1,136 @@
+/*
+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/plugins/core"
+	"github.com/apache/incubator-devlake/plugins/helper"
+	"github.com/apache/incubator-devlake/plugins/jira/models"
+	"github.com/apache/incubator-devlake/plugins/jira/tasks/apiv2models"
+	"strconv"
+	"strings"
+	"time"
+)
+
+var _ core.SubTaskEntryPoint = ExtractIssues
+
+var ExtractExternalEpicsMeta = core.SubTaskMeta{
+	Name:             "extractExternalEpics",
+	EntryPoint:       ExtractExternalEpics,
+	EnabledByDefault: true,
+	Description:      "extract Jira epics from other boards",
+	DomainTypes:      []string{core.DOMAIN_TYPE_TICKET, core.DOMAIN_TYPE_CROSS},
+}
+
+func ExtractExternalEpics(taskCtx core.SubTaskContext) error {
+	data := taskCtx.GetData().(*JiraTaskData)
+	db := taskCtx.GetDal()
+	connectionId := data.Options.ConnectionId
+	boardId := data.Options.BoardId
+	logger := taskCtx.GetLogger()
+	logger.Info("extract external epic Issues, connection_id=%d, board_id=%d", connectionId, boardId)
+	mappings, err := getTypeMappings(data, db)
+	if err != nil {
+		return err
+	}
+	extractor, err := helper.NewApiExtractor(helper.ApiExtractorArgs{
+		RawDataSubTaskArgs: helper.RawDataSubTaskArgs{
+			Ctx: taskCtx,
+			Params: JiraEpicParams{
+				ConnectionId: data.Options.ConnectionId,
+				BoardId:      data.Options.BoardId,
+			},
+			Table: RAW_EXTERNAL_EPIC_TABLE,
+		},
+		Extract: func(row *helper.RawData) ([]interface{}, error) {
+			var apiIssue apiv2models.Issue

Review Comment:
   Most of this code is identical to the one in the issue extractor. I can try to refactor it, like I did with getTypeMappings(), Let me know if you want that



-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] klesh commented on a diff in pull request #2401: [feat-1681][jira]: Collect the epic issue in an issue's epic link

Posted by GitBox <gi...@apache.org>.
klesh commented on code in PR #2401:
URL: https://github.com/apache/incubator-devlake/pull/2401#discussion_r927252440


##########
api/docs/docs.go:
##########
@@ -0,0 +1,1233 @@
+// Package docs GENERATED BY SWAG; DO NOT EDIT

Review Comment:
   Why is this file gets committed? it should be removed and ignored.



##########
plugins/jira/tasks/external_epic_extractor.go:
##########
@@ -0,0 +1,136 @@
+/*
+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/plugins/core"
+	"github.com/apache/incubator-devlake/plugins/helper"
+	"github.com/apache/incubator-devlake/plugins/jira/models"
+	"github.com/apache/incubator-devlake/plugins/jira/tasks/apiv2models"
+	"strconv"
+	"strings"
+	"time"
+)
+
+var _ core.SubTaskEntryPoint = ExtractIssues
+
+var ExtractExternalEpicsMeta = core.SubTaskMeta{
+	Name:             "extractExternalEpics",
+	EntryPoint:       ExtractExternalEpics,
+	EnabledByDefault: true,
+	Description:      "extract Jira epics from other boards",
+	DomainTypes:      []string{core.DOMAIN_TYPE_TICKET, core.DOMAIN_TYPE_CROSS},
+}
+
+func ExtractExternalEpics(taskCtx core.SubTaskContext) error {
+	data := taskCtx.GetData().(*JiraTaskData)
+	db := taskCtx.GetDal()
+	connectionId := data.Options.ConnectionId
+	boardId := data.Options.BoardId
+	logger := taskCtx.GetLogger()
+	logger.Info("extract external epic Issues, connection_id=%d, board_id=%d", connectionId, boardId)
+	mappings, err := getTypeMappings(data, db)
+	if err != nil {
+		return err
+	}
+	extractor, err := helper.NewApiExtractor(helper.ApiExtractorArgs{
+		RawDataSubTaskArgs: helper.RawDataSubTaskArgs{
+			Ctx: taskCtx,
+			Params: JiraEpicParams{
+				ConnectionId: data.Options.ConnectionId,
+				BoardId:      data.Options.BoardId,
+			},
+			Table: RAW_EXTERNAL_EPIC_TABLE,
+		},
+		Extract: func(row *helper.RawData) ([]interface{}, error) {
+			var apiIssue apiv2models.Issue
+			err = json.Unmarshal(row.Data, &apiIssue)
+			if err != nil {
+				return nil, err
+			}
+			err = apiIssue.SetAllFields(row.Data)
+			if err != nil {
+				return nil, err
+			}
+			var results []interface{}
+			sprints, issue, worklogs, changelogs, changelogItems, users := apiIssue.ExtractEntities(data.Options.ConnectionId)
+			for _, sprintId := range sprints {
+				sprintIssue := &models.JiraSprintIssue{
+					ConnectionId:     data.Options.ConnectionId,
+					SprintId:         sprintId,
+					IssueId:          issue.IssueId,
+					IssueCreatedDate: &issue.Created,
+					ResolutionDate:   issue.ResolutionDate,
+				}
+				results = append(results, sprintIssue)
+			}
+			if issue.ResolutionDate != nil {
+				issue.LeadTimeMinutes = uint(issue.ResolutionDate.Unix()-issue.Created.Unix()) / 60
+			}
+			if data.Options.TransformationRules.StoryPointField != "" {
+				strStoryPoint, _ := apiIssue.Fields.AllFields[data.Options.TransformationRules.StoryPointField].(string)
+				if strStoryPoint != "" {
+					issue.StoryPoint, _ = strconv.ParseFloat(strStoryPoint, 32)
+				}
+			}
+			issue.Type = mappings.typeIdMappings[issue.Type]
+			issue.StdStoryPoint = int64(issue.StoryPoint)
+			issue.StdType = mappings.stdTypeMappings[issue.Type]

Review Comment:
   I think it should be hardcoded as "EPIC"



##########
plugins/jira/tasks/external_epic_collector.go:
##########
@@ -0,0 +1,152 @@
+/*
+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 (
+	"fmt"
+	"github.com/apache/incubator-devlake/plugins/core"
+	"github.com/apache/incubator-devlake/plugins/core/dal"
+	"strings"
+
+	"github.com/apache/incubator-devlake/plugins/helper"
+	"net/http"
+	"net/url"
+)
+
+import (
+	"encoding/json"
+	"io/ioutil"
+)
+
+const RAW_EXTERNAL_EPIC_TABLE = "jira_external_epics"
+
+// this struct should be moved to `jira_api_common.go`
+type JiraEpicParams struct {
+	ConnectionId uint64
+	BoardId      uint64
+}
+
+var _ core.SubTaskEntryPoint = CollectIssues
+
+var CollectExternalEpicsMeta = core.SubTaskMeta{
+	Name:             "collectExternalEpics",
+	EntryPoint:       CollectExternalEpics,
+	EnabledByDefault: true,
+	Description:      "collect Jira epics from other boards",
+	DomainTypes:      []string{core.DOMAIN_TYPE_TICKET, core.DOMAIN_TYPE_CROSS},
+}
+
+func CollectExternalEpics(taskCtx core.SubTaskContext) error {
+	db := taskCtx.GetDal()
+	data := taskCtx.GetData().(*JiraTaskData)
+	externalEpicKeys, err := GetExternalEpicKeys(db, data)
+	if err != nil {
+		return err
+	}
+	if len(externalEpicKeys) == 0 {
+		taskCtx.GetLogger().Info("no external epic keys found for Jira board %d", data.Options.BoardId)
+		return nil
+	}
+	since := data.Since
+	jql := "ORDER BY created ASC"
+	if since != nil {
+		// prepend a time range criteria if `since` was specified, either by user or from database
+		jql = fmt.Sprintf("updated >= '%s' %s", since.Format("2006/01/02 15:04"), jql)
+	}
+	jql = fmt.Sprintf("issue in (%s) %s", strings.Join(externalEpicKeys, ","), jql)
+
+	collector, err := helper.NewApiCollector(helper.ApiCollectorArgs{
+		RawDataSubTaskArgs: helper.RawDataSubTaskArgs{
+			Ctx: taskCtx,
+			Params: JiraEpicParams{
+				ConnectionId: data.Options.ConnectionId,
+				BoardId:      data.Options.BoardId,
+			},
+			Table: RAW_EXTERNAL_EPIC_TABLE,
+		},
+		ApiClient:   data.ApiClient,
+		PageSize:    100,
+		Incremental: false,
+		UrlTemplate: "api/2/search",
+		Query: func(reqData *helper.RequestData) (url.Values, error) {
+			query := url.Values{}
+			query.Set("jql", jql)
+			query.Set("issue in", fmt.Sprintf("(%s)", strings.Join(externalEpicKeys, ",")))
+			query.Set("startAt", fmt.Sprintf("%v", reqData.Pager.Skip))
+			query.Set("maxResults", fmt.Sprintf("%v", reqData.Pager.Size))
+			query.Set("expand", "changelog")
+			return query, nil
+		},
+		GetTotalPages: GetTotalPagesFromResponse,
+		Concurrency:   10,
+		ResponseParser: func(res *http.Response) ([]json.RawMessage, error) {
+			var data struct {
+				Issues []json.RawMessage `json:"issues"`
+			}
+			blob, err := ioutil.ReadAll(res.Body)
+			if err != nil {
+				return nil, err
+			}
+			err = json.Unmarshal(blob, &data)
+			if err != nil {
+				return nil, err
+			}
+			return data.Issues, nil
+		},
+	})
+	if err != nil {
+		return err
+	}
+	return collector.Execute()
+}
+
+func GetExternalEpicKeys(db dal.Dal, data *JiraTaskData) ([]string, error) {
+	// union of
+	// 1. issues with epics not from this board and not in the issues table
+	// 2. issues with epics not from this board that ARE already in the issues table (from previous runs)
+	// the above two selections are mutually exclusive
+	cursor, err := db.RawCursor(fmt.Sprintf(`
+			SELECT tji.epic_key as epicKey FROM _tool_jira_issues tji

Review Comment:
   1. the `connection_id` is missing
   2. second, why union? shouldn't it be 
   ```sql
   select
   	distinct epic_key
   from
   	_tool_jira_issues i
   left join `_tool_jira_board_issues` bi on
   	(i.connection_id = bi.connection_id
   		and i.issue_id = bi.issue_id)
   where
   	i.epic_key != ''
   	and bi.board_id = 8
   ```



##########
plugins/jira/tasks/external_epic_extractor.go:
##########
@@ -0,0 +1,136 @@
+/*
+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/plugins/core"
+	"github.com/apache/incubator-devlake/plugins/helper"
+	"github.com/apache/incubator-devlake/plugins/jira/models"
+	"github.com/apache/incubator-devlake/plugins/jira/tasks/apiv2models"
+	"strconv"
+	"strings"
+	"time"
+)
+
+var _ core.SubTaskEntryPoint = ExtractIssues
+
+var ExtractExternalEpicsMeta = core.SubTaskMeta{
+	Name:             "extractExternalEpics",
+	EntryPoint:       ExtractExternalEpics,
+	EnabledByDefault: true,
+	Description:      "extract Jira epics from other boards",
+	DomainTypes:      []string{core.DOMAIN_TYPE_TICKET, core.DOMAIN_TYPE_CROSS},
+}
+
+func ExtractExternalEpics(taskCtx core.SubTaskContext) error {
+	data := taskCtx.GetData().(*JiraTaskData)
+	db := taskCtx.GetDal()
+	connectionId := data.Options.ConnectionId
+	boardId := data.Options.BoardId
+	logger := taskCtx.GetLogger()
+	logger.Info("extract external epic Issues, connection_id=%d, board_id=%d", connectionId, boardId)
+	mappings, err := getTypeMappings(data, db)
+	if err != nil {
+		return err
+	}
+	extractor, err := helper.NewApiExtractor(helper.ApiExtractorArgs{
+		RawDataSubTaskArgs: helper.RawDataSubTaskArgs{
+			Ctx: taskCtx,
+			Params: JiraEpicParams{
+				ConnectionId: data.Options.ConnectionId,
+				BoardId:      data.Options.BoardId,
+			},
+			Table: RAW_EXTERNAL_EPIC_TABLE,
+		},
+		Extract: func(row *helper.RawData) ([]interface{}, error) {
+			var apiIssue apiv2models.Issue
+			err = json.Unmarshal(row.Data, &apiIssue)
+			if err != nil {
+				return nil, err
+			}
+			err = apiIssue.SetAllFields(row.Data)
+			if err != nil {
+				return nil, err
+			}
+			var results []interface{}
+			sprints, issue, worklogs, changelogs, changelogItems, users := apiIssue.ExtractEntities(data.Options.ConnectionId)
+			for _, sprintId := range sprints {

Review Comment:
   Can we share these code with jira_issue_collector?



-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] keon94 commented on a diff in pull request #2401: [feat-1681][jira]: Collect the epic issue in an issue's epic link

Posted by GitBox <gi...@apache.org>.
keon94 commented on code in PR #2401:
URL: https://github.com/apache/incubator-devlake/pull/2401#discussion_r927544534


##########
plugins/jira/tasks/external_epic_collector.go:
##########
@@ -0,0 +1,152 @@
+/*
+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 (
+	"fmt"
+	"github.com/apache/incubator-devlake/plugins/core"
+	"github.com/apache/incubator-devlake/plugins/core/dal"
+	"strings"
+
+	"github.com/apache/incubator-devlake/plugins/helper"
+	"net/http"
+	"net/url"
+)
+
+import (
+	"encoding/json"
+	"io/ioutil"
+)
+
+const RAW_EXTERNAL_EPIC_TABLE = "jira_external_epics"
+
+// this struct should be moved to `jira_api_common.go`
+type JiraEpicParams struct {
+	ConnectionId uint64
+	BoardId      uint64
+}
+
+var _ core.SubTaskEntryPoint = CollectIssues
+
+var CollectExternalEpicsMeta = core.SubTaskMeta{
+	Name:             "collectExternalEpics",
+	EntryPoint:       CollectExternalEpics,
+	EnabledByDefault: true,
+	Description:      "collect Jira epics from other boards",
+	DomainTypes:      []string{core.DOMAIN_TYPE_TICKET, core.DOMAIN_TYPE_CROSS},
+}
+
+func CollectExternalEpics(taskCtx core.SubTaskContext) error {
+	db := taskCtx.GetDal()
+	data := taskCtx.GetData().(*JiraTaskData)
+	externalEpicKeys, err := GetExternalEpicKeys(db, data)
+	if err != nil {
+		return err
+	}
+	if len(externalEpicKeys) == 0 {
+		taskCtx.GetLogger().Info("no external epic keys found for Jira board %d", data.Options.BoardId)
+		return nil
+	}
+	since := data.Since
+	jql := "ORDER BY created ASC"
+	if since != nil {
+		// prepend a time range criteria if `since` was specified, either by user or from database
+		jql = fmt.Sprintf("updated >= '%s' %s", since.Format("2006/01/02 15:04"), jql)
+	}
+	jql = fmt.Sprintf("issue in (%s) %s", strings.Join(externalEpicKeys, ","), jql)
+
+	collector, err := helper.NewApiCollector(helper.ApiCollectorArgs{
+		RawDataSubTaskArgs: helper.RawDataSubTaskArgs{
+			Ctx: taskCtx,
+			Params: JiraEpicParams{
+				ConnectionId: data.Options.ConnectionId,
+				BoardId:      data.Options.BoardId,
+			},
+			Table: RAW_EXTERNAL_EPIC_TABLE,
+		},
+		ApiClient:   data.ApiClient,
+		PageSize:    100,
+		Incremental: false,
+		UrlTemplate: "api/2/search",
+		Query: func(reqData *helper.RequestData) (url.Values, error) {
+			query := url.Values{}
+			query.Set("jql", jql)
+			query.Set("issue in", fmt.Sprintf("(%s)", strings.Join(externalEpicKeys, ",")))
+			query.Set("startAt", fmt.Sprintf("%v", reqData.Pager.Skip))
+			query.Set("maxResults", fmt.Sprintf("%v", reqData.Pager.Size))
+			query.Set("expand", "changelog")
+			return query, nil
+		},
+		GetTotalPages: GetTotalPagesFromResponse,
+		Concurrency:   10,
+		ResponseParser: func(res *http.Response) ([]json.RawMessage, error) {
+			var data struct {
+				Issues []json.RawMessage `json:"issues"`
+			}
+			blob, err := ioutil.ReadAll(res.Body)
+			if err != nil {
+				return nil, err
+			}
+			err = json.Unmarshal(blob, &data)
+			if err != nil {
+				return nil, err
+			}
+			return data.Issues, nil
+		},
+	})
+	if err != nil {
+		return err
+	}
+	return collector.Execute()
+}
+
+func GetExternalEpicKeys(db dal.Dal, data *JiraTaskData) ([]string, error) {
+	// union of
+	// 1. issues with epics not from this board and not in the issues table
+	// 2. issues with epics not from this board that ARE already in the issues table (from previous runs)
+	// the above two selections are mutually exclusive
+	cursor, err := db.RawCursor(fmt.Sprintf(`
+			SELECT tji.epic_key as epicKey FROM _tool_jira_issues tji

Review Comment:
   The union is needed to also account for external epics we already collected. They are gonna be in the issues table but not in the board_issues table. Also, the first select statement ensures that we are only grabbing epic keys that are not issue keys in the issues table. For instance EE-1 could be an epic key in one row, and an issue key in another. We wouldn't want to be picking that up. But I know it's an ugly query and can probably be reduced.



-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] keon94 commented on a diff in pull request #2401: [feat-1681][jira]: Collect the epic issue in an issue's epic link

Posted by GitBox <gi...@apache.org>.
keon94 commented on code in PR #2401:
URL: https://github.com/apache/incubator-devlake/pull/2401#discussion_r927206023


##########
plugins/jira/tasks/external_epic_collector.go:
##########
@@ -0,0 +1,152 @@
+/*
+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 (
+	"fmt"
+	"github.com/apache/incubator-devlake/plugins/core"
+	"github.com/apache/incubator-devlake/plugins/core/dal"
+	"strings"
+
+	"github.com/apache/incubator-devlake/plugins/helper"
+	"net/http"
+	"net/url"
+)
+
+import (
+	"encoding/json"
+	"io/ioutil"
+)
+
+const RAW_EXTERNAL_EPIC_TABLE = "jira_external_epics"
+
+// this struct should be moved to `jira_api_common.go`
+type JiraEpicParams struct {
+	ConnectionId uint64
+	BoardId      uint64
+}
+
+var _ core.SubTaskEntryPoint = CollectIssues
+
+var CollectExternalEpicsMeta = core.SubTaskMeta{
+	Name:             "collectExternalEpics",
+	EntryPoint:       CollectExternalEpics,
+	EnabledByDefault: true,
+	Description:      "collect Jira epics from other boards",
+	DomainTypes:      []string{core.DOMAIN_TYPE_TICKET, core.DOMAIN_TYPE_CROSS},
+}
+
+func CollectExternalEpics(taskCtx core.SubTaskContext) error {
+	db := taskCtx.GetDal()
+	data := taskCtx.GetData().(*JiraTaskData)
+	externalEpicKeys, err := GetExternalEpicKeys(db, data)
+	if err != nil {
+		return err
+	}
+	if len(externalEpicKeys) == 0 {
+		taskCtx.GetLogger().Info("no external epic keys found for Jira board %d", data.Options.BoardId)
+		return nil
+	}
+	since := data.Since
+	jql := "ORDER BY created ASC"
+	if since != nil {
+		// prepend a time range criteria if `since` was specified, either by user or from database
+		jql = fmt.Sprintf("updated >= '%s' %s", since.Format("2006/01/02 15:04"), jql)
+	}
+	jql = fmt.Sprintf("issue in (%s) %s", strings.Join(externalEpicKeys, ","), jql)
+
+	collector, err := helper.NewApiCollector(helper.ApiCollectorArgs{
+		RawDataSubTaskArgs: helper.RawDataSubTaskArgs{
+			Ctx: taskCtx,
+			Params: JiraEpicParams{
+				ConnectionId: data.Options.ConnectionId,
+				BoardId:      data.Options.BoardId,
+			},
+			Table: RAW_EXTERNAL_EPIC_TABLE,
+		},
+		ApiClient:   data.ApiClient,
+		PageSize:    100,
+		Incremental: false,
+		UrlTemplate: "api/2/search",
+		Query: func(reqData *helper.RequestData) (url.Values, error) {
+			query := url.Values{}
+			query.Set("jql", jql)
+			query.Set("issue in", fmt.Sprintf("(%s)", strings.Join(externalEpicKeys, ",")))
+			query.Set("startAt", fmt.Sprintf("%v", reqData.Pager.Skip))
+			query.Set("maxResults", fmt.Sprintf("%v", reqData.Pager.Size))
+			query.Set("expand", "changelog")
+			return query, nil
+		},
+		GetTotalPages: GetTotalPagesFromResponse,
+		Concurrency:   10,
+		ResponseParser: func(res *http.Response) ([]json.RawMessage, error) {
+			var data struct {
+				Issues []json.RawMessage `json:"issues"`
+			}
+			blob, err := ioutil.ReadAll(res.Body)
+			if err != nil {
+				return nil, err
+			}
+			err = json.Unmarshal(blob, &data)
+			if err != nil {
+				return nil, err
+			}
+			return data.Issues, nil
+		},
+	})
+	if err != nil {
+		return err
+	}
+	return collector.Execute()
+}
+
+func GetExternalEpicKeys(db dal.Dal, data *JiraTaskData) ([]string, error) {

Review Comment:
   I refactored this function out of the Collect function so I could test it from my e2e test



-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] keon94 commented on a diff in pull request #2401: [feat-1681][jira]: Collect the epic issue in an issue's epic link

Posted by GitBox <gi...@apache.org>.
keon94 commented on code in PR #2401:
URL: https://github.com/apache/incubator-devlake/pull/2401#discussion_r930586616


##########
plugins/jira/tasks/external_epic_collector.go:
##########
@@ -0,0 +1,152 @@
+/*
+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 (
+	"fmt"
+	"github.com/apache/incubator-devlake/plugins/core"
+	"github.com/apache/incubator-devlake/plugins/core/dal"
+	"strings"
+
+	"github.com/apache/incubator-devlake/plugins/helper"
+	"net/http"
+	"net/url"
+)
+
+import (
+	"encoding/json"
+	"io/ioutil"
+)
+
+const RAW_EXTERNAL_EPIC_TABLE = "jira_external_epics"
+
+// this struct should be moved to `jira_api_common.go`
+type JiraEpicParams struct {
+	ConnectionId uint64
+	BoardId      uint64
+}
+
+var _ core.SubTaskEntryPoint = CollectIssues
+
+var CollectExternalEpicsMeta = core.SubTaskMeta{
+	Name:             "collectExternalEpics",
+	EntryPoint:       CollectExternalEpics,
+	EnabledByDefault: true,
+	Description:      "collect Jira epics from other boards",
+	DomainTypes:      []string{core.DOMAIN_TYPE_TICKET, core.DOMAIN_TYPE_CROSS},
+}
+
+func CollectExternalEpics(taskCtx core.SubTaskContext) error {
+	db := taskCtx.GetDal()
+	data := taskCtx.GetData().(*JiraTaskData)
+	externalEpicKeys, err := GetExternalEpicKeys(db, data)
+	if err != nil {
+		return err
+	}
+	if len(externalEpicKeys) == 0 {
+		taskCtx.GetLogger().Info("no external epic keys found for Jira board %d", data.Options.BoardId)
+		return nil
+	}
+	since := data.Since
+	jql := "ORDER BY created ASC"
+	if since != nil {
+		// prepend a time range criteria if `since` was specified, either by user or from database
+		jql = fmt.Sprintf("updated >= '%s' %s", since.Format("2006/01/02 15:04"), jql)
+	}
+	jql = fmt.Sprintf("issue in (%s) %s", strings.Join(externalEpicKeys, ","), jql)
+
+	collector, err := helper.NewApiCollector(helper.ApiCollectorArgs{
+		RawDataSubTaskArgs: helper.RawDataSubTaskArgs{
+			Ctx: taskCtx,
+			Params: JiraEpicParams{
+				ConnectionId: data.Options.ConnectionId,
+				BoardId:      data.Options.BoardId,
+			},
+			Table: RAW_EXTERNAL_EPIC_TABLE,
+		},
+		ApiClient:   data.ApiClient,
+		PageSize:    100,
+		Incremental: false,
+		UrlTemplate: "api/2/search",
+		Query: func(reqData *helper.RequestData) (url.Values, error) {
+			query := url.Values{}
+			query.Set("jql", jql)
+			query.Set("issue in", fmt.Sprintf("(%s)", strings.Join(externalEpicKeys, ",")))
+			query.Set("startAt", fmt.Sprintf("%v", reqData.Pager.Skip))
+			query.Set("maxResults", fmt.Sprintf("%v", reqData.Pager.Size))
+			query.Set("expand", "changelog")
+			return query, nil
+		},
+		GetTotalPages: GetTotalPagesFromResponse,
+		Concurrency:   10,
+		ResponseParser: func(res *http.Response) ([]json.RawMessage, error) {
+			var data struct {
+				Issues []json.RawMessage `json:"issues"`
+			}
+			blob, err := ioutil.ReadAll(res.Body)
+			if err != nil {
+				return nil, err
+			}
+			err = json.Unmarshal(blob, &data)
+			if err != nil {
+				return nil, err
+			}
+			return data.Issues, nil
+		},
+	})
+	if err != nil {
+		return err
+	}
+	return collector.Execute()
+}
+
+func GetExternalEpicKeys(db dal.Dal, data *JiraTaskData) ([]string, error) {
+	// union of
+	// 1. issues with epics not from this board and not in the issues table
+	// 2. issues with epics not from this board that ARE already in the issues table (from previous runs)
+	// the above two selections are mutually exclusive
+	cursor, err := db.RawCursor(fmt.Sprintf(`
+			SELECT tji.epic_key as epicKey FROM _tool_jira_issues tji

Review Comment:
   We discussed offline - we'll simplify the query to Klesh's suggestion at the expense of pulling in extra epics for the sake of simplicity



-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] mindlesscloud commented on a diff in pull request #2401: [feat-1681][jira]: Collect the epic issue in an issue's epic link

Posted by GitBox <gi...@apache.org>.
mindlesscloud commented on code in PR #2401:
URL: https://github.com/apache/incubator-devlake/pull/2401#discussion_r927352364


##########
plugins/jira/tasks/external_epic_collector.go:
##########
@@ -0,0 +1,152 @@
+/*
+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 (
+	"fmt"
+	"github.com/apache/incubator-devlake/plugins/core"
+	"github.com/apache/incubator-devlake/plugins/core/dal"
+	"strings"
+
+	"github.com/apache/incubator-devlake/plugins/helper"
+	"net/http"
+	"net/url"
+)
+
+import (
+	"encoding/json"
+	"io/ioutil"
+)
+
+const RAW_EXTERNAL_EPIC_TABLE = "jira_external_epics"
+
+// this struct should be moved to `jira_api_common.go`
+type JiraEpicParams struct {
+	ConnectionId uint64
+	BoardId      uint64
+}
+
+var _ core.SubTaskEntryPoint = CollectIssues
+
+var CollectExternalEpicsMeta = core.SubTaskMeta{
+	Name:             "collectExternalEpics",
+	EntryPoint:       CollectExternalEpics,
+	EnabledByDefault: true,
+	Description:      "collect Jira epics from other boards",
+	DomainTypes:      []string{core.DOMAIN_TYPE_TICKET, core.DOMAIN_TYPE_CROSS},
+}
+
+func CollectExternalEpics(taskCtx core.SubTaskContext) error {
+	db := taskCtx.GetDal()
+	data := taskCtx.GetData().(*JiraTaskData)
+	externalEpicKeys, err := GetExternalEpicKeys(db, data)
+	if err != nil {
+		return err
+	}
+	if len(externalEpicKeys) == 0 {
+		taskCtx.GetLogger().Info("no external epic keys found for Jira board %d", data.Options.BoardId)
+		return nil
+	}
+	since := data.Since
+	jql := "ORDER BY created ASC"
+	if since != nil {
+		// prepend a time range criteria if `since` was specified, either by user or from database
+		jql = fmt.Sprintf("updated >= '%s' %s", since.Format("2006/01/02 15:04"), jql)
+	}
+	jql = fmt.Sprintf("issue in (%s) %s", strings.Join(externalEpicKeys, ","), jql)
+
+	collector, err := helper.NewApiCollector(helper.ApiCollectorArgs{
+		RawDataSubTaskArgs: helper.RawDataSubTaskArgs{
+			Ctx: taskCtx,
+			Params: JiraEpicParams{
+				ConnectionId: data.Options.ConnectionId,
+				BoardId:      data.Options.BoardId,
+			},
+			Table: RAW_EXTERNAL_EPIC_TABLE,
+		},
+		ApiClient:   data.ApiClient,
+		PageSize:    100,
+		Incremental: false,
+		UrlTemplate: "api/2/search",
+		Query: func(reqData *helper.RequestData) (url.Values, error) {
+			query := url.Values{}
+			query.Set("jql", jql)
+			query.Set("issue in", fmt.Sprintf("(%s)", strings.Join(externalEpicKeys, ",")))
+			query.Set("startAt", fmt.Sprintf("%v", reqData.Pager.Skip))
+			query.Set("maxResults", fmt.Sprintf("%v", reqData.Pager.Size))
+			query.Set("expand", "changelog")
+			return query, nil
+		},
+		GetTotalPages: GetTotalPagesFromResponse,
+		Concurrency:   10,
+		ResponseParser: func(res *http.Response) ([]json.RawMessage, error) {
+			var data struct {
+				Issues []json.RawMessage `json:"issues"`
+			}
+			blob, err := ioutil.ReadAll(res.Body)
+			if err != nil {
+				return nil, err
+			}
+			err = json.Unmarshal(blob, &data)
+			if err != nil {
+				return nil, err
+			}
+			return data.Issues, nil
+		},
+	})
+	if err != nil {
+		return err
+	}
+	return collector.Execute()
+}
+
+func GetExternalEpicKeys(db dal.Dal, data *JiraTaskData) ([]string, error) {
+	// union of
+	// 1. issues with epics not from this board and not in the issues table
+	// 2. issues with epics not from this board that ARE already in the issues table (from previous runs)
+	// the above two selections are mutually exclusive
+	cursor, err := db.RawCursor(fmt.Sprintf(`

Review Comment:
   it's dangerous and not recommended to use `fmt.Sprintf` to generate SQL. consider prepared statements which are supported by `db.RawCursor`. It looks like:
   ```go
   db.RawCursor("SELECT * FROM _tool_jira_issues WHERE board_id = ? ", data.Options.BoardId)
   ```



-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] klesh commented on a diff in pull request #2401: [feat-1681][jira]: Collect the epic issue in an issue's epic link

Posted by GitBox <gi...@apache.org>.
klesh commented on code in PR #2401:
URL: https://github.com/apache/incubator-devlake/pull/2401#discussion_r931702617


##########
plugins/jira/tasks/epic_collector.go:
##########
@@ -0,0 +1,145 @@
+/*
+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 (
+	"fmt"
+	"github.com/apache/incubator-devlake/plugins/core"
+	"github.com/apache/incubator-devlake/plugins/core/dal"
+	"strings"
+
+	"encoding/json"
+	"github.com/apache/incubator-devlake/plugins/helper"
+	"io/ioutil"
+	"net/http"
+	"net/url"
+)
+
+const RAW_EPIC_TABLE = "jira_api_epics"
+
+type JiraEpicParams struct {
+	ConnectionId uint64
+	BoardId      uint64
+}
+
+var _ core.SubTaskEntryPoint = CollectIssues
+
+var CollectEpicsMeta = core.SubTaskMeta{
+	Name:             "collectEpics",
+	EntryPoint:       CollectEpics,
+	EnabledByDefault: true,
+	Description:      "collect Jira epics from all boards",
+	DomainTypes:      []string{core.DOMAIN_TYPE_TICKET, core.DOMAIN_TYPE_CROSS},
+}
+
+func CollectEpics(taskCtx core.SubTaskContext) error {
+	db := taskCtx.GetDal()
+	data := taskCtx.GetData().(*JiraTaskData)
+	externalEpicKeys, err := GetEpicKeys(db, data)

Review Comment:
   Yes, here is what I think it should be
   1. The `Iterator.Fetch` is returning a value of type `interface{}`, so, we may return `[]int` or `string` that contains up to 100 epic-keys at a time.
   2. Within `ApiCollector.Query` callback, we can access those `epic-keys` via `reqData.Input`, and concatenate them to the jql parameter



-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] keon94 commented on a diff in pull request #2401: [feat-1681][jira]: Collect the epic issue in an issue's epic link

Posted by GitBox <gi...@apache.org>.
keon94 commented on code in PR #2401:
URL: https://github.com/apache/incubator-devlake/pull/2401#discussion_r927546772


##########
plugins/jira/tasks/external_epic_extractor.go:
##########
@@ -0,0 +1,136 @@
+/*
+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/plugins/core"
+	"github.com/apache/incubator-devlake/plugins/helper"
+	"github.com/apache/incubator-devlake/plugins/jira/models"
+	"github.com/apache/incubator-devlake/plugins/jira/tasks/apiv2models"
+	"strconv"
+	"strings"
+	"time"
+)
+
+var _ core.SubTaskEntryPoint = ExtractIssues
+
+var ExtractExternalEpicsMeta = core.SubTaskMeta{
+	Name:             "extractExternalEpics",
+	EntryPoint:       ExtractExternalEpics,
+	EnabledByDefault: true,
+	Description:      "extract Jira epics from other boards",
+	DomainTypes:      []string{core.DOMAIN_TYPE_TICKET, core.DOMAIN_TYPE_CROSS},
+}
+
+func ExtractExternalEpics(taskCtx core.SubTaskContext) error {
+	data := taskCtx.GetData().(*JiraTaskData)
+	db := taskCtx.GetDal()
+	connectionId := data.Options.ConnectionId
+	boardId := data.Options.BoardId
+	logger := taskCtx.GetLogger()
+	logger.Info("extract external epic Issues, connection_id=%d, board_id=%d", connectionId, boardId)
+	mappings, err := getTypeMappings(data, db)
+	if err != nil {
+		return err
+	}
+	extractor, err := helper.NewApiExtractor(helper.ApiExtractorArgs{
+		RawDataSubTaskArgs: helper.RawDataSubTaskArgs{
+			Ctx: taskCtx,
+			Params: JiraEpicParams{
+				ConnectionId: data.Options.ConnectionId,
+				BoardId:      data.Options.BoardId,
+			},
+			Table: RAW_EXTERNAL_EPIC_TABLE,
+		},
+		Extract: func(row *helper.RawData) ([]interface{}, error) {
+			var apiIssue apiv2models.Issue
+			err = json.Unmarshal(row.Data, &apiIssue)
+			if err != nil {
+				return nil, err
+			}
+			err = apiIssue.SetAllFields(row.Data)
+			if err != nil {
+				return nil, err
+			}
+			var results []interface{}
+			sprints, issue, worklogs, changelogs, changelogItems, users := apiIssue.ExtractEntities(data.Options.ConnectionId)
+			for _, sprintId := range sprints {

Review Comment:
   you mean jira_issue_extractor? Already asked [here](https://github.com/apache/incubator-devlake/pull/2401/files/bcb7b10f0e7496227269ddf1529eb6d39128b2bc#r927206808). I can do that by moving most of the extract logic intoa shared function



-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] keon94 commented on a diff in pull request #2401: [feat-1681][jira]: Collect the epic issue in an issue's epic link

Posted by GitBox <gi...@apache.org>.
keon94 commented on code in PR #2401:
URL: https://github.com/apache/incubator-devlake/pull/2401#discussion_r931752987


##########
plugins/helper/queue.go:
##########
@@ -23,8 +23,9 @@ import (
 )

Review Comment:
   I was using queue iterators before realizing the Dal iterator was what I needed. I did find some issues and incompleteness with the QueueNode code though that I've tried to improve (e.g. being able to access a node's data). @klesh let me know what you think or if you want it reverted.



-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] keon94 commented on a diff in pull request #2401: [feat-1681][jira]: Collect the epic issue in an issue's epic link

Posted by GitBox <gi...@apache.org>.
keon94 commented on code in PR #2401:
URL: https://github.com/apache/incubator-devlake/pull/2401#discussion_r931678140


##########
plugins/jira/tasks/epic_collector.go:
##########
@@ -0,0 +1,145 @@
+/*
+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 (
+	"fmt"
+	"github.com/apache/incubator-devlake/plugins/core"
+	"github.com/apache/incubator-devlake/plugins/core/dal"
+	"strings"
+
+	"encoding/json"
+	"github.com/apache/incubator-devlake/plugins/helper"
+	"io/ioutil"
+	"net/http"
+	"net/url"
+)
+
+const RAW_EPIC_TABLE = "jira_api_epics"
+
+type JiraEpicParams struct {
+	ConnectionId uint64
+	BoardId      uint64
+}
+
+var _ core.SubTaskEntryPoint = CollectIssues
+
+var CollectEpicsMeta = core.SubTaskMeta{
+	Name:             "collectEpics",
+	EntryPoint:       CollectEpics,
+	EnabledByDefault: true,
+	Description:      "collect Jira epics from all boards",
+	DomainTypes:      []string{core.DOMAIN_TYPE_TICKET, core.DOMAIN_TYPE_CROSS},
+}
+
+func CollectEpics(taskCtx core.SubTaskContext) error {
+	db := taskCtx.GetDal()
+	data := taskCtx.GetData().(*JiraTaskData)
+	externalEpicKeys, err := GetEpicKeys(db, data)

Review Comment:
   Are you saying have a Dal iterator that returns up to 100 rows at a time? I'll have to make a batched iterator version of it, because the existing one gives just 1 row at a time. Also, how will the urlTemplate look like? The jql is a query param, so I dont know what the template syntax is going to become like. I couldnt find existing examples of us doing something like this



-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org