likyh commented on code in PR #1994: URL: https://github.com/apache/incubator-devlake/pull/1994#discussion_r887683092
########## plugins/jira/models/migrationscripts/updateSchemas20220601.go: ########## @@ -0,0 +1,111 @@ +/* +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" + "encoding/base64" + "github.com/apache/incubator-devlake/plugins/helper" + "gorm.io/gorm" + "gorm.io/gorm/clause" + "strings" +) + +type JiraConnection20220601 struct { + helper.RestConnection + helper.BasicAuth + EpicKeyField string `gorm:"type:varchar(50);" json:"epicKeyField"` + StoryPointField string `gorm:"type:varchar(50);" json:"storyPointField"` + 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 (JiraConnection20220601) TableName() string { + return "_tool_jira_connections" +} + +type UpdateSchemas20220601 struct{} + +func (*UpdateSchemas20220601) Up(ctx context.Context, db *gorm.DB) error { + var err error + if !db.Migrator().HasColumn(&JiraConnection20220505{}, "password") { + err = db.Migrator().AddColumn(&JiraConnection20220601{}, "password") + if err != nil { + return err + } + } + + if !db.Migrator().HasColumn(&JiraConnection20220505{}, "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) Review Comment: It cannot run and I got: ``` panic: reflect: reflect.Value.SetUint using unaddressable value goroutine 1 [running]: reflect.flag.mustBeAssignableSlow(0x1059cc5b8?) /usr/local/go/src/reflect/value.go:262 +0x78 reflect.flag.mustBeAssignable(...) /usr/local/go/src/reflect/value.go:249 reflect.Value.SetUint({0x1035f9680?, 0x140002a4f10?, 0x114a47a20?}, 0x1) /usr/local/go/src/reflect/value.go:2261 +0x44 gorm.io/gorm/schema.(*Field).setupValuerAndSetter.func9({0x1037f8d20, 0x140000420e0}, {0x114a47a20?, 0x140002a4f00?, 0x14000370928?}, {0x1035b7700?, 0x140001f8490?}) /Users/lin/go/pkg/mod/gorm.io/[email protected]/schema/field.go:669 +0x2e4 gorm.io/gorm.(*DB).scanIntoStruct(0x140004a2720, {0x1037fb7a0, 0x1400027e580}, {0x114a47a20?, 0x140002a4f00?, 0x140001bef90?}, {0x140001103e0?, 0x1, 0x1}, {0x140001f8618, ...}, ...) /Users/lin/go/pkg/mod/gorm.io/[email protected]/scan.go:72 +0x32c gorm.io/gorm.Scan({0x1037fb7a0, 0x1400027e580}, 0x140004a2720, 0x2) /Users/lin/go/pkg/mod/gorm.io/[email protected]/scan.go:276 +0xa90 gorm.io/gorm/callbacks.Create.func1(0x140004a2720) /Users/lin/go/pkg/mod/gorm.io/[email protected]/callbacks/create.go:90 +0x504 gorm.io/gorm.(*processor).Execute(0x140001246e0, 0x140002a4f00?) /Users/lin/go/pkg/mod/gorm.io/[email protected]/callbacks.go:130 +0x3f0 gorm.io/gorm.(*DB).Create(0x114a47a20?, {0x114a47a20?, 0x140002a4f00}) /Users/lin/go/pkg/mod/gorm.io/[email protected]/finisher_api.go:24 +0xac github.com/apache/incubator-devlake/plugins/jira/models/migrationscripts.(*UpdateSchemas20220601).Up(0x1035d8800, {0x14000141818?, 0x1?}, 0x60?) /Users/lin/projects/lake/plugins/jira/models/migrationscripts/updateSchemas20220601.go:91 +0x4f0 github.com/apache/incubator-devlake/migration.(*migrator).execute(0x10525c2c0, {0x1037f8d20, 0x140000420e0}) /Users/lin/projects/lake/migration/migrator.go:80 +0x298 github.com/apache/incubator-devlake/migration.Execute(...) /Users/lin/projects/lake/migration/migrator.go:114 github.com/apache/incubator-devlake/services.init.0() /Users/lin/projects/lake/services/init.go:59 +0x244 exit status 2 make: *** [run] Error 1 ``` ########## config-ui/src/pages/configure/connections/ConnectionForm.jsx: ########## @@ -353,39 +355,42 @@ export default function ConnectionForm (props) { )} /> )} - { - activeProvider.id === Providers.JIRA && - <Popover - className='popover-generate-token' - position={Position.RIGHT} - autoFocus={false} - enforceFocus={false} - isOpen={showTokenCreator} - onInteraction={handleTokenInteraction} - onClosed={() => setShowTokenCreator(false)} - usePortal={false} - > - <Button - disabled={isTesting || isSaving || isLocked} - type='button' icon='key' intent={Intent.PRIMARY} style={{ marginLeft: '5px' }} - /> - <> - <div style={{ padding: '15px 20px 15px 15px' }}> - <GenerateTokenForm Review Comment: maybe we can delete this form -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
