Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/plugins/jira/models/board.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type JiraBoard struct {
Self string `json:"self" mapstructure:"self" gorm:"type:varchar(255)"`
Type string `json:"type" mapstructure:"type" gorm:"type:varchar(100)"`
Jql string `json:"jql" mapstructure:"jql"`
SubQuery string `json:"subQuery" mapstructure:"subQuery"`
}

func (b JiraBoard) ScopeId() string {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
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 migrationscripts

import (
"github.com/apache/incubator-devlake/core/context"
"github.com/apache/incubator-devlake/core/errors"
"github.com/apache/incubator-devlake/helpers/migrationhelper"
)

type JiraBoard20260613 struct {
SubQuery string
}

func (JiraBoard20260613) TableName() string {
return "_tool_jira_boards"
}

type addBoardSubQuery20260613 struct{}

func (script *addBoardSubQuery20260613) Up(basicRes context.BasicRes) errors.Error {
return migrationhelper.AutoMigrateTables(basicRes, &JiraBoard20260613{})
}

func (*addBoardSubQuery20260613) Version() uint64 {
return 20260613120000
}

func (*addBoardSubQuery20260613) Name() string {
return "add sub_query to _tool_jira_boards"
}
1 change: 1 addition & 0 deletions backend/plugins/jira/models/migrationscripts/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@ func All() []plugin.MigrationScript {
new(flushJiraIssues),
new(updateScopeConfig),
new(addFixVersions20250619),
new(addBoardSubQuery20260613),
}
}
42 changes: 32 additions & 10 deletions backend/plugins/jira/tasks/board_filter_begin_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@ func CollectBoardFilterBegin(taskCtx plugin.SubTaskContext) errors.Error {
logger := taskCtx.GetLogger()
db := taskCtx.GetDal()
logger.Info("collect board in collectBoardFilterBegin: %d", data.Options.BoardId)
// get board filter id
filterId, err := getBoardFilterId(data)
// get board filter configuration
boardConfiguration, err := getBoardConfiguration(data)
if err != nil {
return errors.Default.Wrap(err, fmt.Sprintf("error getting board filter id for connection_id:%d board_id:%d", data.Options.ConnectionId, data.Options.BoardId))
return errors.Default.Wrap(err, fmt.Sprintf("error getting board filter configuration for connection_id:%d board_id:%d", data.Options.ConnectionId, data.Options.BoardId))
}
filterId := boardConfiguration.Filter.ID
subQuery := boardConfiguration.SubQuery
logger.Info("collect board filter:%s", filterId)
logger.Info("collect board subQuery:%s", subQuery)

// get board filter jql
filterInfo, err := getBoardFilterJql(data, filterId)
Expand All @@ -65,25 +68,27 @@ func CollectBoardFilterBegin(taskCtx plugin.SubTaskContext) errors.Error {
// full sync
syncPolicy := taskCtx.TaskContext().SyncPolicy()
if syncPolicy != nil && syncPolicy.FullSync {
if record.Jql != jql {
if record.Jql != jql || record.SubQuery != subQuery {
record.Jql = jql
record.SubQuery = subQuery
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))
}
logger.Info("full sync mode, update jql to %s", record.Jql)
logger.Info("full sync mode, update jql to %s, subQuery to %s", record.Jql, record.SubQuery)
}
return nil
}

// first run
if record.Jql == "" {
record.Jql = jql
record.SubQuery = subQuery
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))
}
logger.Info("first run, update jql to %s", record.Jql)
logger.Info("first run, update jql to %s, subQuery to %s", record.Jql, record.SubQuery)
return nil
}
// change
Expand All @@ -95,6 +100,7 @@ func CollectBoardFilterBegin(taskCtx plugin.SubTaskContext) errors.Error {
// set full sync
taskCtx.TaskContext().SetSyncPolicy(&coreModels.SyncPolicy{TriggerSyncPolicy: coreModels.TriggerSyncPolicy{FullSync: true}})
record.Jql = jql
record.SubQuery = subQuery
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))
Expand All @@ -103,23 +109,38 @@ func CollectBoardFilterBegin(taskCtx plugin.SubTaskContext) errors.Error {
return errors.Default.New(fmt.Sprintf("connection_id:%d board_id:%d filter jql has changed, please use fullSync mode. And the previous jql is %s, now jql is %s", data.Options.ConnectionId, data.Options.BoardId, record.Jql, jql))
}
}
if record.SubQuery != subQuery {
record.SubQuery = subQuery
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))
}
logger.Info("update board subQuery to %s", record.SubQuery)
}
// no change
return nil
}

func getBoardFilterId(data *JiraTaskData) (string, error) {
boardConfiguration, err := getBoardConfiguration(data)
if err != nil {
return "", err
}
return boardConfiguration.Filter.ID, nil
}

func getBoardConfiguration(data *JiraTaskData) (*BoardConfiguration, error) {
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
return nil, err
}
bc := &BoardConfiguration{}
err = helper.UnmarshalResponse(boardConfiguration, bc)
if err != nil {
return "", err
return nil, err
}
filterId := bc.Filter.ID
return filterId, nil
return bc, nil
}

func getBoardFilterJql(data *JiraTaskData, filterId string) (*FilterInfo, error) {
Expand Down Expand Up @@ -152,6 +173,7 @@ type BoardConfiguration struct {
ID string `json:"id"`
Self string `json:"self"`
} `json:"filter"`
SubQuery string `json:"subQuery"`
ColumnConfig struct {
Columns []struct {
Name string `json:"name"`
Expand Down
15 changes: 12 additions & 3 deletions backend/plugins/jira/tasks/board_filter_end_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ func CollectBoardFilterEnd(taskCtx plugin.SubTaskContext) errors.Error {
db := taskCtx.GetDal()
logger.Info("collect board in collectBoardFilterEnd: %d", data.Options.BoardId)

// get board filter id
filterId, err := getBoardFilterId(data)
// get board filter configuration
boardConfiguration, err := getBoardConfiguration(data)
if err != nil {
return errors.Default.Wrap(err, fmt.Sprintf("error getting board filter id for connection_id:%d board_id:%d", data.Options.ConnectionId, data.Options.BoardId))
return errors.Default.Wrap(err, fmt.Sprintf("error getting board filter configuration for connection_id:%d board_id:%d", data.Options.ConnectionId, data.Options.BoardId))
}
filterId := boardConfiguration.Filter.ID
logger.Info("collect board filter:%s", filterId)

// get board filter jql
Expand All @@ -70,6 +71,14 @@ func CollectBoardFilterEnd(taskCtx plugin.SubTaskContext) errors.Error {
return errors.Default.New(fmt.Sprintf("connection_id:%d board_id:%d filter jql has changed, please use fullSync mode. And the previous jql is %s, now jql is %s", data.Options.ConnectionId, data.Options.BoardId, record.Jql, jql))
}
}
if record.SubQuery != boardConfiguration.SubQuery {
record.SubQuery = boardConfiguration.SubQuery
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))
}
logger.Info("update board subQuery to %s", record.SubQuery)
}

return nil
}
Loading