@@ -19,7 +19,9 @@ package git
1919import (
2020 "context"
2121 "crypto/tls"
22+ "errors"
2223 "fmt"
24+ "github.com/devtron-labs/common-lib/utils/runTime"
2325 bean2 "github.com/devtron-labs/devtron/api/bean/gitOps"
2426 globalUtil "github.com/devtron-labs/devtron/util"
2527 "github.com/devtron-labs/devtron/util/retryFunc"
@@ -91,6 +93,15 @@ func (impl GitHubClient) DeleteRepository(config *bean2.GitOpsConfigDto) error {
9193 return nil
9294}
9395
96+ func IsRepoNotFound (err error ) bool {
97+ if err == nil {
98+ return false
99+ }
100+ var responseErr * github.ErrorResponse
101+ ok := errors .As (err , & responseErr )
102+ return ok && responseErr .Response .StatusCode == 404
103+ }
104+
94105func (impl GitHubClient ) CreateRepository (ctx context.Context , config * bean2.GitOpsConfigDto ) (url string , isNew bool , detailedErrorGitOpsConfigActions DetailedErrorGitOpsConfigActions ) {
95106 var err error
96107 start := time .Now ()
@@ -100,15 +111,14 @@ func (impl GitHubClient) CreateRepository(ctx context.Context, config *bean2.Git
100111
101112 detailedErrorGitOpsConfigActions .StageErrorMap = make (map [string ]error )
102113 repoExists := true
103- url , err = impl .GetRepoUrl ( config )
114+ url , err = impl .getRepoUrl ( ctx , config , IsRepoNotFound )
104115 if err != nil {
105- responseErr , ok := err .(* github.ErrorResponse )
106- if ! ok || responseErr .Response .StatusCode != 404 {
116+ if IsRepoNotFound (err ) {
117+ repoExists = false
118+ } else {
107119 impl .logger .Errorw ("error in creating github repo" , "err" , err )
108120 detailedErrorGitOpsConfigActions .StageErrorMap [GetRepoUrlStage ] = err
109121 return "" , false , detailedErrorGitOpsConfigActions
110- } else {
111- repoExists = false
112122 }
113123 }
114124 if repoExists {
@@ -251,12 +261,21 @@ func (impl GitHubClient) CommitValues(ctx context.Context, config *ChartConfig,
251261}
252262
253263func (impl GitHubClient ) GetRepoUrl (config * bean2.GitOpsConfigDto ) (repoUrl string , err error ) {
264+ ctx := context .Background ()
265+ return impl .getRepoUrl (ctx , config , globalUtil .AllPublishableError ())
266+ }
267+
268+ func (impl GitHubClient ) getRepoUrl (ctx context.Context , config * bean2.GitOpsConfigDto ,
269+ isNonPublishableError globalUtil.EvalIsNonPublishableErr ) (repoUrl string , err error ) {
254270 start := time .Now ()
255271 defer func () {
272+ if isNonPublishableError (err ) {
273+ impl .logger .Debugw ("found non publishable error. skipping metrics publish!" , "caller method" , runTime .GetCallerFunctionName (), "err" , err )
274+ return
275+ }
256276 globalUtil .TriggerGitOpsMetrics ("GetRepoUrl" , "GitHubClient" , start , err )
257277 }()
258278
259- ctx := context .Background ()
260279 repo , _ , err := impl .client .Repositories .Get (ctx , impl .org , config .GitRepoName )
261280 if err != nil {
262281 impl .logger .Errorw ("error in getting repo url by repo name" , "org" , impl .org , "gitRepoName" , config .GitRepoName , "err" , err )
0 commit comments