Skip to content

Commit 90239e1

Browse files
committed
feat(jira): expose DevLake project name as ExtraJQL template variable
Users often want to filter a shared Jira board per Devlake project using the devlake project name. The ExtraJQL field supports Go text/templates, but only BoardId and BoardName are available. Look up the Devlake project name from the project_mapping table at task setup time and expose it as {{.ProjectName}} in ExtraJQL templates. Example scope config ExtraJQL: component = {{.ProjectName}}
1 parent 14a4e5b commit 90239e1

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

backend/plugins/jira/impl/impl.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import (
2525
"github.com/apache/incubator-devlake/core/dal"
2626
"github.com/apache/incubator-devlake/core/errors"
2727
coreModels "github.com/apache/incubator-devlake/core/models"
28+
"github.com/apache/incubator-devlake/core/models/domainlayer/crossdomain"
29+
"github.com/apache/incubator-devlake/core/models/domainlayer/didgen"
2830
"github.com/apache/incubator-devlake/core/plugin"
2931
helper "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
3032
"github.com/apache/incubator-devlake/plugins/jira/api"
@@ -257,6 +259,19 @@ func (p Jira) PrepareTaskData(taskCtx plugin.TaskContext, options map[string]int
257259
Board: scope,
258260
}
259261

262+
// Resolve the Devlake project name from the project_mapping table so it can
263+
// be used as a template variable in ExtraJQL
264+
if scope != nil {
265+
rowId := didgen.NewDomainIdGenerator(&models.JiraBoard{}).Generate(scope.ConnectionId, scope.BoardId)
266+
var mapping crossdomain.ProjectMapping
267+
err = db.First(&mapping, dal.Where("`table` = ? AND `row_id` = ?", "boards", rowId))
268+
if err == nil {
269+
taskData.ProjectName = mapping.ProjectName
270+
} else if !db.IsErrorNotFound(err) {
271+
logger.Error(err, "failed to load project mapping for board %s", rowId)
272+
}
273+
}
274+
260275
return taskData, nil
261276
}
262277

backend/plugins/jira/tasks/issue_collector.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@ func CollectIssues(taskCtx plugin.SubTaskContext) errors.Error {
112112
// JqlTemplateData holds the variables available inside an ExtraJQL template.
113113
// Users reference these with Go template syntax, e.g. `{{.BoardName}}`.
114114
type JqlTemplateData struct {
115-
BoardId uint64 // numeric ID of the connected Jira board
116-
BoardName string // display name of the connected Jira board
115+
BoardId uint64 // numeric ID of the connected Jira board
116+
BoardName string // display name of the connected Jira board
117+
ProjectName string // Devlake project name associated with the Jira board scope
117118
}
118119

119120
// renderExtraJQL executes the ExtraJQL scope-config field as a Go text/template,
@@ -133,7 +134,8 @@ func renderExtraJQL(tmplStr string, data *JiraTaskData) (string, errors.Error) {
133134
}
134135

135136
vars := JqlTemplateData{
136-
BoardId: data.Options.BoardId,
137+
BoardId: data.Options.BoardId,
138+
ProjectName: data.ProjectName,
137139
}
138140
if data.Board != nil {
139141
vars.BoardName = data.Board.Name

backend/plugins/jira/tasks/task_data.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type JiraTaskData struct {
3939
JiraServerInfo models.JiraServerInfo
4040
FilterId string
4141
Board *models.JiraBoard
42+
ProjectName string
4243
}
4344

4445
type JiraApiParams models.JiraApiParams

0 commit comments

Comments
 (0)