diff --git a/plugins/jira/jira.go b/plugins/jira/jira.go index dd3ab769a9f..828c0baf91f 100644 --- a/plugins/jira/jira.go +++ b/plugins/jira/jira.go @@ -168,6 +168,7 @@ func (plugin Jira) MigrationScripts() []migration.Script { new(migrationscripts.UpdateSchemas20220527), new(migrationscripts.UpdateSchemas20220601), new(migrationscripts.UpdateSchemas20220614), + new(migrationscripts.UpdateSchemas20220616), } } diff --git a/plugins/jira/models/issue_label.go b/plugins/jira/models/issue_label.go new file mode 100644 index 00000000000..0f9cfbdd801 --- /dev/null +++ b/plugins/jira/models/issue_label.go @@ -0,0 +1,19 @@ +package models + +import ( + "github.com/apache/incubator-devlake/models/common" +) + +// Please note that Issue Labels can also apply to Pull Requests. +// Pull Requests are considered Issues in GitHub. + +type JiraIssueLabel struct { + ConnectionId uint64 `gorm:"primaryKey;autoIncrement:false"` + IssueId uint64 `gorm:"primaryKey;autoIncrement:false"` + LabelName string `gorm:"primaryKey;type:varchar(255)"` + common.NoPKModel +} + +func (JiraIssueLabel) TableName() string { + return "_tool_jira_issue_labels" +} diff --git a/plugins/jira/models/migrationscripts/updateSchemas20220616.go b/plugins/jira/models/migrationscripts/updateSchemas20220616.go new file mode 100644 index 00000000000..a02f7fda6fe --- /dev/null +++ b/plugins/jira/models/migrationscripts/updateSchemas20220616.go @@ -0,0 +1,52 @@ +/* +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 ( + "context" + "github.com/apache/incubator-devlake/models/migrationscripts/archived" + + "gorm.io/gorm" +) + +type JiraIssueLabel0616 struct { + ConnectionId uint64 `gorm:"primaryKey;autoIncrement:false"` + IssueId uint64 `gorm:"primaryKey;autoIncrement:false"` + LabelName string `gorm:"primaryKey;type:varchar(255)"` + archived.NoPKModel +} + +func (JiraIssueLabel0616) TableName() string { + return "_tool_jira_issue_labels" +} + +type UpdateSchemas20220616 struct{} + +func (*UpdateSchemas20220616) Up(ctx context.Context, db *gorm.DB) error { + + err := db.Migrator().AutoMigrate(JiraIssueLabel0616{}) + return err +} + +func (*UpdateSchemas20220616) Version() uint64 { + return 20220616154646 +} + +func (*UpdateSchemas20220616) Name() string { + return "add jira issue labels" +} diff --git a/plugins/jira/tasks/apiv2models/issue.go b/plugins/jira/tasks/apiv2models/issue.go index cfd52916576..a110bbd6dfb 100644 --- a/plugins/jira/tasks/apiv2models/issue.go +++ b/plugins/jira/tasks/apiv2models/issue.go @@ -91,7 +91,7 @@ type Issue struct { Name string `json:"name"` ID uint64 `json:"id,string"` } `json:"priority"` - Labels []interface{} `json:"labels"` + Labels []string `json:"labels"` Timeestimate interface{} `json:"timeestimate"` Aggregatetimeoriginalestimate interface{} `json:"aggregatetimeoriginalestimate"` Versions []interface{} `json:"versions"` diff --git a/plugins/jira/tasks/issue_extractor.go b/plugins/jira/tasks/issue_extractor.go index 3c2cee56d94..98c0df49a05 100644 --- a/plugins/jira/tasks/issue_extractor.go +++ b/plugins/jira/tasks/issue_extractor.go @@ -141,6 +141,16 @@ func ExtractIssues(taskCtx core.SubTaskContext) error { BoardId: boardId, IssueId: issue.IssueId, }) + labels := apiIssue.Fields.Labels + for _, v := range labels { + issueLabel := &models.JiraIssueLabel{ + IssueId: issue.IssueId, + LabelName: v, + ConnectionId: data.Options.ConnectionId, + } + results = append(results, issueLabel) + } + return results, nil return results, nil }, })