@@ -39,20 +39,24 @@ type GitAzureClient struct {
39
39
gitOpsHelper * GitOpsHelper
40
40
}
41
41
42
- func (impl GitAzureClient ) GetRepoUrl (config * bean2.GitOpsConfigDto ) (repoUrl string , err error ) {
42
+ func (impl GitAzureClient ) GetRepoUrl (config * bean2.GitOpsConfigDto ) (repoUrl string , isRepoEmpty bool , err error ) {
43
43
44
44
start := time .Now ()
45
45
defer func () {
46
46
globalUtil .TriggerGitOpsMetrics ("GetRepoUrl" , "GitAzureClient" , start , err )
47
47
}()
48
48
49
- url , exists , err := impl .repoExists (config .GitRepoName , impl .project )
49
+ var (
50
+ url string
51
+ exists bool
52
+ )
53
+ url , exists , isRepoEmpty , err = impl .repoExists (config .GitRepoName , impl .project )
50
54
if err != nil {
51
- return "" , err
55
+ return "" , isRepoEmpty , err
52
56
} else if ! exists {
53
- return "" , fmt .Errorf ("%s :repo not found" , config .GitRepoName )
57
+ return "" , isRepoEmpty , fmt .Errorf ("%s :repo not found" , config .GitRepoName )
54
58
} else {
55
- return url , nil
59
+ return url , isRepoEmpty , nil
56
60
}
57
61
}
58
62
@@ -96,23 +100,26 @@ func (impl GitAzureClient) DeleteRepository(config *bean2.GitOpsConfigDto) (err
96
100
return err
97
101
}
98
102
99
- func (impl GitAzureClient ) CreateRepository (ctx context.Context , config * bean2.GitOpsConfigDto ) (url string , isNew bool , detailedErrorGitOpsConfigActions DetailedErrorGitOpsConfigActions ) {
100
- var err error
103
+ func (impl GitAzureClient ) CreateRepository (ctx context.Context , config * bean2.GitOpsConfigDto ) (url string , isNew bool , isEmpty bool , detailedErrorGitOpsConfigActions DetailedErrorGitOpsConfigActions ) {
104
+ var (
105
+ err error
106
+ repoExists bool
107
+ )
101
108
start := time .Now ()
102
109
defer func () {
103
110
globalUtil .TriggerGitOpsMetrics ("CreateRepository" , "GitAzureClient" , start , err )
104
111
}()
105
112
106
113
detailedErrorGitOpsConfigActions .StageErrorMap = make (map [string ]error )
107
- url , repoExists , err : = impl .repoExists (config .GitRepoName , impl .project )
114
+ url , repoExists , isEmpty , err = impl .repoExists (config .GitRepoName , impl .project )
108
115
if err != nil {
109
116
impl .logger .Errorw ("error in communication with azure" , "err" , err )
110
117
detailedErrorGitOpsConfigActions .StageErrorMap [GetRepoUrlStage ] = err
111
- return "" , false , detailedErrorGitOpsConfigActions
118
+ return "" , false , isEmpty , detailedErrorGitOpsConfigActions
112
119
}
113
120
if repoExists {
114
121
detailedErrorGitOpsConfigActions .SuccessfulStages = append (detailedErrorGitOpsConfigActions .SuccessfulStages , GetRepoUrlStage )
115
- return url , false , detailedErrorGitOpsConfigActions
122
+ return url , false , isEmpty , detailedErrorGitOpsConfigActions
116
123
}
117
124
gitRepositoryCreateOptions := git.GitRepositoryCreateOptions {
118
125
Name : & config .GitRepoName ,
@@ -125,12 +132,12 @@ func (impl GitAzureClient) CreateRepository(ctx context.Context, config *bean2.G
125
132
if err != nil {
126
133
impl .logger .Errorw ("error in creating repo azure" , "project" , config .GitRepoName , "err" , err )
127
134
detailedErrorGitOpsConfigActions .StageErrorMap [CreateRepoStage ] = err
128
- url , repoExists , err = impl .repoExists (config .GitRepoName , impl .project )
135
+ url , repoExists , isEmpty , err = impl .repoExists (config .GitRepoName , impl .project )
129
136
if err != nil {
130
137
impl .logger .Errorw ("error in communication with azure" , "err" , err )
131
138
}
132
139
if err != nil || ! repoExists {
133
- return "" , true , detailedErrorGitOpsConfigActions
140
+ return "" , true , isEmpty , detailedErrorGitOpsConfigActions
134
141
}
135
142
}
136
143
impl .logger .Infow ("repo created " , "r" , operationReference .WebUrl )
@@ -139,34 +146,35 @@ func (impl GitAzureClient) CreateRepository(ctx context.Context, config *bean2.G
139
146
if err != nil {
140
147
impl .logger .Errorw ("error in ensuring project availability azure" , "project" , config .GitRepoName , "err" , err )
141
148
detailedErrorGitOpsConfigActions .StageErrorMap [CloneHttpStage ] = err
142
- return * operationReference .WebUrl , true , detailedErrorGitOpsConfigActions
149
+ return * operationReference .WebUrl , true , isEmpty , detailedErrorGitOpsConfigActions
143
150
}
144
151
if ! validated {
145
152
detailedErrorGitOpsConfigActions .StageErrorMap [CloneHttpStage ] = fmt .Errorf ("unable to validate project:%s in given time" , config .GitRepoName )
146
- return "" , true , detailedErrorGitOpsConfigActions
153
+ return "" , true , isEmpty , detailedErrorGitOpsConfigActions
147
154
}
148
155
detailedErrorGitOpsConfigActions .SuccessfulStages = append (detailedErrorGitOpsConfigActions .SuccessfulStages , CloneHttpStage )
149
156
150
157
_ , err = impl .CreateReadme (ctx , config )
151
158
if err != nil {
152
159
impl .logger .Errorw ("error in creating readme azure" , "project" , config .GitRepoName , "err" , err )
153
160
detailedErrorGitOpsConfigActions .StageErrorMap [CreateReadmeStage ] = err
154
- return * operationReference .WebUrl , true , detailedErrorGitOpsConfigActions
161
+ return * operationReference .WebUrl , true , isEmpty , detailedErrorGitOpsConfigActions
155
162
}
163
+ isEmpty = false //As we have created readme, repo is no longer empty
156
164
detailedErrorGitOpsConfigActions .SuccessfulStages = append (detailedErrorGitOpsConfigActions .SuccessfulStages , CreateReadmeStage )
157
165
158
166
validated , err = impl .ensureProjectAvailabilityOnSsh (impl .project , * operationReference .WebUrl )
159
167
if err != nil {
160
168
impl .logger .Errorw ("error in ensuring project availability azure" , "project" , config .GitRepoName , "err" , err )
161
169
detailedErrorGitOpsConfigActions .StageErrorMap [CloneSshStage ] = err
162
- return * operationReference .WebUrl , true , detailedErrorGitOpsConfigActions
170
+ return * operationReference .WebUrl , true , isEmpty , detailedErrorGitOpsConfigActions
163
171
}
164
172
if ! validated {
165
173
detailedErrorGitOpsConfigActions .StageErrorMap [CloneSshStage ] = fmt .Errorf ("unable to validate project:%s in given time" , config .GitRepoName )
166
- return "" , true , detailedErrorGitOpsConfigActions
174
+ return "" , true , isEmpty , detailedErrorGitOpsConfigActions
167
175
}
168
176
detailedErrorGitOpsConfigActions .SuccessfulStages = append (detailedErrorGitOpsConfigActions .SuccessfulStages , CloneSshStage )
169
- return * operationReference .WebUrl , true , detailedErrorGitOpsConfigActions
177
+ return * operationReference .WebUrl , true , isEmpty , detailedErrorGitOpsConfigActions
170
178
}
171
179
172
180
func (impl GitAzureClient ) CreateReadme (ctx context.Context , config * bean2.GitOpsConfigDto ) (string , error ) {
@@ -296,7 +304,7 @@ func (impl GitAzureClient) CommitValues(ctx context.Context, config *ChartConfig
296
304
return commitId , commitAuthorTime , nil
297
305
}
298
306
299
- func (impl GitAzureClient ) repoExists (repoName , projectName string ) (repoUrl string , exists bool , err error ) {
307
+ func (impl GitAzureClient ) repoExists (repoName , projectName string ) (repoUrl string , exists , isRepoEmpty bool , err error ) {
300
308
301
309
start := time .Now ()
302
310
defer func () {
@@ -313,16 +321,17 @@ func (impl GitAzureClient) repoExists(repoName, projectName string) (repoUrl str
313
321
notFoundStatus := 404
314
322
if err != nil {
315
323
if e , ok := err .(azuredevops.WrappedError ); ok && * e .StatusCode == notFoundStatus {
316
- return "" , false , nil
324
+ return "" , false , isRepoEmpty , nil
317
325
} else {
318
- return "" , false , err
326
+ return "" , false , isRepoEmpty , err
319
327
}
320
328
321
329
}
322
330
for gitRepository == nil {
323
- return "" , false , nil
331
+ return "" , false , isRepoEmpty , nil
324
332
}
325
- return * gitRepository .WebUrl , true , nil
333
+
334
+ return * gitRepository .WebUrl , true , * gitRepository .Size == 0 , nil
326
335
}
327
336
328
337
func (impl GitAzureClient ) ensureProjectAvailabilityOnHttp (repoName string ) (bool , error ) {
@@ -333,7 +342,7 @@ func (impl GitAzureClient) ensureProjectAvailabilityOnHttp(repoName string) (boo
333
342
}()
334
343
335
344
for count := 0 ; count < 5 ; count ++ {
336
- _ , exists , err := impl .repoExists (repoName , impl .project )
345
+ _ , exists , _ , err := impl .repoExists (repoName , impl .project )
337
346
if err == nil && exists {
338
347
impl .logger .Infow ("repo validated successfully on https" )
339
348
return true , nil
0 commit comments