This is an automated email from the ASF dual-hosted git repository. warren pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
commit ab0dc9e8160c624d68fe5b33019f38b63768e5b3 Author: Yingchu Chen <[email protected]> AuthorDate: Wed Jun 1 18:43:12 2022 +0800 fix(jira): modify migrationscripts to spread basicAuthEncoded to username/password --- plugins/helper/connection.go | 6 +-- plugins/jira/jira.go | 2 +- ...Schemas20220524.go => updateSchemas20220601.go} | 59 ++++++++++++++++++---- 3 files changed, 52 insertions(+), 15 deletions(-) diff --git a/plugins/helper/connection.go b/plugins/helper/connection.go index 93974f73..85163068 100644 --- a/plugins/helper/connection.go +++ b/plugins/helper/connection.go @@ -190,10 +190,8 @@ func doDecrypt(dataVal reflect.Value, fieldName string) error { return err } if len(fieldName) > 0 { - decryptStr, err := core.Decrypt(encryptCode, dataVal.Elem().FieldByName(fieldName).String()) - if err != nil { - return err - } + decryptStr, _ := core.Decrypt(encryptCode, dataVal.Elem().FieldByName(fieldName).String()) + dataVal.Elem().FieldByName(fieldName).Set(reflect.ValueOf(decryptStr)) } return nil diff --git a/plugins/jira/jira.go b/plugins/jira/jira.go index 2a40b901..a36177da 100644 --- a/plugins/jira/jira.go +++ b/plugins/jira/jira.go @@ -150,10 +150,10 @@ func (plugin Jira) MigrationScripts() []migration.Script { new(migrationscripts.UpdateSchemas20220505), new(migrationscripts.UpdateSchemas20220507), new(migrationscripts.UpdateSchemas20220518), - new(migrationscripts.UpdateSchemas20220524), new(migrationscripts.UpdateSchemas20220525), new(migrationscripts.UpdateSchemas20220526), new(migrationscripts.UpdateSchemas20220527), + new(migrationscripts.UpdateSchemas20220601), } } diff --git a/plugins/jira/models/migrationscripts/updateSchemas20220524.go b/plugins/jira/models/migrationscripts/updateSchemas20220601.go similarity index 51% rename from plugins/jira/models/migrationscripts/updateSchemas20220524.go rename to plugins/jira/models/migrationscripts/updateSchemas20220601.go index 9c753610..ec528dcb 100644 --- a/plugins/jira/models/migrationscripts/updateSchemas20220524.go +++ b/plugins/jira/models/migrationscripts/updateSchemas20220601.go @@ -19,11 +19,14 @@ package migrationscripts import ( "context" + "encoding/base64" "github.com/apache/incubator-devlake/plugins/helper" "gorm.io/gorm" + "gorm.io/gorm/clause" + "strings" ) -type JiraConnection20220524 struct { +type JiraConnection20220601 struct { helper.RestConnection helper.BasicAuth EpicKeyField string `gorm:"type:varchar(50);" json:"epicKeyField"` @@ -31,29 +34,65 @@ type JiraConnection20220524 struct { RemotelinkCommitShaPattern string `gorm:"type:varchar(255);comment='golang regexp, the first group will be recognized as commit sha, ref https://github.com/google/re2/wiki/Syntax'" json:"remotelinkCommitShaPattern"` } -func (JiraConnection20220524) TableName() string { +func (JiraConnection20220601) TableName() string { return "_tool_jira_connections" } -type UpdateSchemas20220524 struct{} +type UpdateSchemas20220601 struct{} -func (*UpdateSchemas20220524) Up(ctx context.Context, db *gorm.DB) error { +func (*UpdateSchemas20220601) Up(ctx context.Context, db *gorm.DB) error { var err error if !db.Migrator().HasColumn(&JiraConnection20220505{}, "password") { - err = db.Migrator().AddColumn(&JiraConnection20220524{}, "password") + err = db.Migrator().AddColumn(&JiraConnection20220601{}, "password") if err != nil { return err } } if !db.Migrator().HasColumn(&JiraConnection20220505{}, "username") { - err = db.Migrator().AddColumn(&JiraConnection20220524{}, "username") + err = db.Migrator().AddColumn(&JiraConnection20220601{}, "username") if err != nil { return err } } if db.Migrator().HasColumn(&JiraConnection20220505{}, "basic_auth_encoded") { + connections := make([]*JiraConnection20220505, 0) + db.Find(&connections) + for i, _ := range connections { + err = helper.DecryptConnection(connections[i], "BasicAuthEncoded") + if err != nil { + return err + } + decodedStr, err := base64.StdEncoding.DecodeString(connections[i].BasicAuthEncoded) + if err != nil { + return err + } + strList := strings.Split(string(decodedStr), ":") + if len(strList) > 1 { + newConnection := JiraConnection20220601{ + RestConnection: helper.RestConnection{ + BaseConnection: helper.BaseConnection{ + Name: connections[i].Name, + Model: connections[i].Model, + }, + Endpoint: connections[i].Endpoint, + Proxy: connections[i].Proxy, + RateLimit: connections[i].RateLimit, + }, + BasicAuth: helper.BasicAuth{ + Username: strList[0], + Password: strList[1], + }, + EpicKeyField: connections[i].EpicKeyField, + StoryPointField: connections[i].StoryPointField, + RemotelinkCommitShaPattern: connections[i].RemotelinkCommitShaPattern, + } + db.Clauses(clause.OnConflict{UpdateAll: true}).Create(newConnection) + + } + connections[i].Name = strList[0] + } err = db.Migrator().DropColumn(&JiraConnection20220505{}, "basic_auth_encoded") if err != nil { return err @@ -63,10 +102,10 @@ func (*UpdateSchemas20220524) Up(ctx context.Context, db *gorm.DB) error { return nil } -func (*UpdateSchemas20220524) Version() uint64 { - return 20220507154646 +func (*UpdateSchemas20220601) Version() uint64 { + return 20220601154646 } -func (*UpdateSchemas20220524) Name() string { - return "Add icon_url column to JiraIssue" +func (*UpdateSchemas20220601) Name() string { + return "change basic_auth to username/password" }
