From 257fb0b09a9493633f14e539b045cc85e0652352 Mon Sep 17 00:00:00 2001 From: Gabriel Adrian Samfira Date: Wed, 17 Apr 2024 13:45:56 +0000 Subject: [PATCH] Take into account legacy config Signed-off-by: Gabriel Adrian Samfira --- config/config.go | 7 +++++++ database/sql/sql.go | 10 +++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/config/config.go b/config/config.go index baafcb8e..5a6fd0a2 100644 --- a/config/config.go +++ b/config/config.go @@ -299,6 +299,13 @@ type Github struct { App GithubApp `toml:"app" json:"app"` } +func (g *Github) GetAuthType() GithubAuthType { + if g.AuthType == "" { + return GithubAuthTypePAT + } + return g.AuthType +} + func (g *Github) APIEndpoint() string { if g.APIBaseURL != "" { return g.APIBaseURL diff --git a/database/sql/sql.go b/database/sql/sql.go index 1bc16e08..2436dc3d 100644 --- a/database/sql/sql.go +++ b/database/sql/sql.go @@ -297,7 +297,7 @@ func (s *sqlDatabase) migrateCredentialsToDB() (err error) { credParams := params.CreateGithubCredentialsParams{ Name: cred.Name, Description: cred.Description, - AuthType: params.GithubAuthType(cred.AuthType), + AuthType: params.GithubAuthType(cred.GetAuthType()), } switch credParams.AuthType { case params.GithubAuthTypeApp: @@ -315,11 +315,15 @@ func (s *sqlDatabase) migrateCredentialsToDB() (err error) { return errors.Wrap(err, "validating app credentials") } case params.GithubAuthTypePAT: - if cred.PAT.OAuth2Token == "" { + token := cred.PAT.OAuth2Token + if token == "" { + token = cred.OAuth2Token + } + if token == "" { return errors.New("missing OAuth2 token") } credParams.PAT = params.GithubPAT{ - OAuth2Token: cred.PAT.OAuth2Token, + OAuth2Token: token, } }