You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by "abeizn (via GitHub)" <gi...@apache.org> on 2024/01/11 09:13:02 UTC

[PR] feat: add filter jql checker [incubator-devlake]

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

   ### Summary
   feat: add filter jql checker
   
   ### Does this close any open issues?
   Closes #6765 
   
   ### Screenshots
   1. first run:
   ![img_v3_0270_b96e5332-de1a-4701-8a55-0ebb1c1cbaeg](https://github.com/apache/incubator-devlake/assets/101256042/167621fa-975b-406a-a391-d6d807007b16)
   ![img_v3_0270_d74df339-9f3b-43e0-a234-1fc36031dc9g](https://github.com/apache/incubator-devlake/assets/101256042/e5044fc9-75fc-4d65-9976-5525f1cdd204)
   
   
   2. collect data(not first):
   ![img_v3_0270_7283ff40-73c6-46b4-b2d4-b34b144042dg](https://github.com/apache/incubator-devlake/assets/101256042/a4936841-8df7-4f07-861f-010e7ea3d1f3)
   ![img_v3_0270_82d769ab-4f62-4f08-a56b-100d1be12fbg](https://github.com/apache/incubator-devlake/assets/101256042/99eeea2b-c821-4827-949b-9f2e5bd6c1cf)
   
   
   3. full sync(jql !=nil)
   
   ![img_v3_0270_0a8584b5-d4e8-4cf4-ae08-74f57e74a64g](https://github.com/apache/incubator-devlake/assets/101256042/d9994c8f-5c85-4032-80a6-466c074fa932)
   ![img_v3_0270_690ef28a-30f7-43ac-8987-cf6ef71438cg](https://github.com/apache/incubator-devlake/assets/101256042/46e63604-3b01-4998-900f-e6f819d49777)
   
   4. full sync(jql ==nil)
   ![img_v3_0270_2c2c0eb1-ce71-4fb9-8b38-9e8f8d4fa1dg](https://github.com/apache/incubator-devlake/assets/101256042/9b82c346-ecee-48ef-9146-8dde72e99fbb)
   ![img_v3_0270_f398c4e1-41a7-4b36-bc54-70936d36f87g](https://github.com/apache/incubator-devlake/assets/101256042/21dc8a03-f5b6-4db6-8295-93e55080b431)
   
   
   5. re-trans:
   ![img_v3_0270_8b498d5e-e16f-438a-81df-ed265c8fb2dg](https://github.com/apache/incubator-devlake/assets/101256042/11b64e8d-d8f3-48b5-b3ec-130c75a877e3)
   ![img_v3_0270_f815cd64-c518-4849-8f77-de870869203g](https://github.com/apache/incubator-devlake/assets/101256042/8f29a86f-7896-4870-b6df-73fbc6d2f44d)
   
   
   
   6. update JQL after last run:
   ![img_v3_0270_14fbec06-d009-4b14-b468-7b25bac97a8g](https://github.com/apache/incubator-devlake/assets/101256042/0ace182f-6688-4ed9-9772-cec55a9b7b84)
   
   
   7. update JQL and full sync:
   
   ![img_v3_0270_e6015862-f9be-4a40-9a46-0d8ae7d6fa3g](https://github.com/apache/incubator-devlake/assets/101256042/2d2d934b-5a3a-4111-aa9e-c9eb48573e6e)
   ![img_v3_0270_9f9486ef-e373-4d6e-a4ec-eedd9fe4ddcg](https://github.com/apache/incubator-devlake/assets/101256042/372bb59a-b922-44dc-a2f7-fd40780e03dd)
   
   8. update JQL when running:
   
   ![img_v3_0270_23b0a103-2301-41ef-8973-edc133ab537g](https://github.com/apache/incubator-devlake/assets/101256042/9e0d7536-d2b4-4f09-a05c-8c99d321e90b)
   
   
   ### 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


Re: [PR] feat: add filter jql checker [incubator-devlake]

Posted by "d4x1 (via GitHub)" <gi...@apache.org>.
d4x1 commented on code in PR #6789:
URL: https://github.com/apache/incubator-devlake/pull/6789#discussion_r1449806247


##########
backend/plugins/jira/tasks/board_filter_begin_collector.go:
##########
@@ -0,0 +1,222 @@
+/*
+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/core/dal"
+	"github.com/apache/incubator-devlake/core/errors"
+	"github.com/apache/incubator-devlake/core/plugin"
+	helper "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
+	"github.com/apache/incubator-devlake/plugins/jira/models"
+)
+
+var CollectBoardFilterBeginMeta = plugin.SubTaskMeta{
+	Name:             "collectBoardFilterBegin",
+	EntryPoint:       CollectBoardFilterBegin,
+	EnabledByDefault: true,
+	Description:      "Jira board filter jql checker before runnig",

Review Comment:
   I think it's a typo. `runnig`



##########
backend/plugins/jira/tasks/board_filter_end_collector.go:
##########
@@ -0,0 +1,72 @@
+/*
+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/core/dal"
+	"github.com/apache/incubator-devlake/core/errors"
+	"github.com/apache/incubator-devlake/core/plugin"
+	"github.com/apache/incubator-devlake/plugins/jira/models"
+)
+
+var CollectBoardFilterEndMeta = plugin.SubTaskMeta{
+	Name:             "collectBoardFilterEnd",
+	EntryPoint:       CollectBoardFilterEnd,
+	EnabledByDefault: true,
+	Description:      "Jira board filter jql checker after runnig",

Review Comment:
   Same as above.



-- 
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


Re: [PR] feat: add filter jql checker [incubator-devlake]

Posted by "klesh (via GitHub)" <gi...@apache.org>.
klesh commented on code in PR #6789:
URL: https://github.com/apache/incubator-devlake/pull/6789#discussion_r1449697370


##########
backend/plugins/jira/tasks/board_filter_begin_collector.go:
##########
@@ -0,0 +1,211 @@
+/*
+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/core/dal"
+	"github.com/apache/incubator-devlake/core/errors"
+	"github.com/apache/incubator-devlake/core/plugin"
+	helper "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
+	"github.com/apache/incubator-devlake/plugins/jira/models"
+)
+
+var CollectBoardFilterBeginMeta = plugin.SubTaskMeta{
+	Name:             "collectBoardFilterBegin",
+	EntryPoint:       CollectBoardFilterBegin,
+	EnabledByDefault: true,
+	Description:      "Jira board filter jql checker before runnig",
+	DomainTypes:      plugin.DOMAIN_TYPES,
+}
+
+func CollectBoardFilterBegin(taskCtx plugin.SubTaskContext) errors.Error {
+	data := taskCtx.GetData().(*JiraTaskData)
+	logger := taskCtx.GetLogger()
+	db := taskCtx.GetDal()
+	logger.Info("collect board in collectBoardFilterBegin: %d", data.Options.BoardId)
+
+	// get board filter id
+	url := fmt.Sprintf("agile/1.0/board/%d/configuration", data.Options.BoardId)
+	boardConfiguration, err := data.ApiClient.Get(url, nil, nil)
+	if err != nil {
+		return err
+	}
+	bc := &BoardConfiguration{}
+	err = helper.UnmarshalResponse(boardConfiguration, bc)
+	if err != nil {
+		return err
+	}
+	filterId := bc.Filter.ID
+	logger.Info("collect board filter:%s", filterId)
+
+	// get board filter jql
+	url = fmt.Sprintf("api/2/filter/%s", filterId)
+	filterInfo, err := data.ApiClient.Get(url, nil, nil)
+	if err != nil {
+		return err
+	}
+	fi := &FilterInfo{}
+	err = helper.UnmarshalResponse(filterInfo, fi)
+	if err != nil {
+		return err
+	}
+	jql := fi.Jql
+	logger.Info("collect board filter jql:%s", jql)
+
+	var record models.JiraBoard
+	err = db.First(&record, dal.Where("connection_id = ? AND board_id = ? ", data.Options.ConnectionId, data.Options.BoardId))
+	if err != nil {
+		return errors.Default.Wrap(err, fmt.Sprintf("error finding record in _tool_jira_boards table for connection_id:%d board_id:%d", data.Options.ConnectionId, data.Options.BoardId))
+	}
+
+	// full sync
+	syncPolicy := taskCtx.TaskContext().SyncPolicy()
+	if syncPolicy != nil && syncPolicy.FullSync {
+		if record.Jql != jql {
+			record.Jql = jql
+			err = db.Update(&record, dal.Where("connection_id = ? AND board_id = ? ", data.Options.ConnectionId, data.Options.BoardId))
+			if err != nil {
+				return errors.Default.Wrap(err, fmt.Sprintf("error updating record in _tool_jira_boards table for connection_id:%d board_id:%d", data.Options.ConnectionId, data.Options.BoardId))
+			}
+		}
+		return nil
+	}
+	// first run
+	if record.Jql == "" {
+		record.Jql = jql
+		err = db.Update(&record, dal.Where("connection_id = ? AND board_id = ? ", data.Options.ConnectionId, data.Options.BoardId))
+		if err != nil {
+			return errors.Default.Wrap(err, fmt.Sprintf("error updating record in _tool_jira_boards table for connection_id:%d board_id:%d", data.Options.ConnectionId, data.Options.BoardId))
+		}
+		return nil
+	}
+	// no change
+	if record.Jql == jql {

Review Comment:
   Not needed



##########
backend/plugins/jira/tasks/board_filter_end_collector.go:
##########
@@ -0,0 +1,84 @@
+/*
+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/core/dal"
+	"github.com/apache/incubator-devlake/core/errors"
+	"github.com/apache/incubator-devlake/core/plugin"
+	helper "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
+	"github.com/apache/incubator-devlake/plugins/jira/models"
+)
+
+var CollectBoardFilterEndMeta = plugin.SubTaskMeta{
+	Name:             "collectBoardFilterEnd",
+	EntryPoint:       CollectBoardFilterEnd,
+	EnabledByDefault: true,
+	Description:      "Jira board filter jql checker after runnig",
+	DomainTypes:      plugin.DOMAIN_TYPES,
+}
+
+func CollectBoardFilterEnd(taskCtx plugin.SubTaskContext) errors.Error {
+	data := taskCtx.GetData().(*JiraTaskData)
+	logger := taskCtx.GetLogger()
+	db := taskCtx.GetDal()
+	logger.Info("collect board in collectBoardFilterEnd: %d", data.Options.BoardId)
+
+	// get board filter id
+	url := fmt.Sprintf("agile/1.0/board/%d/configuration", data.Options.BoardId)
+	boardConfiguration, err := data.ApiClient.Get(url, nil, nil)
+	if err != nil {
+		return err
+	}
+	bc := &BoardConfiguration{}
+	err = helper.UnmarshalResponse(boardConfiguration, bc)
+	if err != nil {
+		return err
+	}
+	filterId := bc.Filter.ID
+	logger.Info("collect board filter:%s", filterId)
+
+	// get board filter jql
+	url = fmt.Sprintf("api/2/filter/%s", filterId)
+	filterInfo, err := data.ApiClient.Get(url, nil, nil)
+	if err != nil {
+		return err
+	}
+	fi := &FilterInfo{}
+	err = helper.UnmarshalResponse(filterInfo, fi)
+	if err != nil {
+		return err
+	}

Review Comment:
   It would be better to extract them into a new function called `getJqlForBoard(boardId)` and share it with the `CollectBoardFilterBegin`



-- 
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


Re: [PR] feat: add filter jql checker [incubator-devlake]

Posted by "klesh (via GitHub)" <gi...@apache.org>.
klesh merged PR #6789:
URL: https://github.com/apache/incubator-devlake/pull/6789


-- 
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