@@ -347,9 +347,43 @@ func (impl GitBitbucketClient) CommitValues(ctx context.Context, config *ChartCo
347
347
}
348
348
349
349
//extracting the latest commit hash from the paginated api response of above method, reference of api & response - https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/commits
350
- commitHash = commits .(map [string ]interface {})["values" ].([]interface {})[0 ].(map [string ]interface {})["hash" ].(string )
351
- commitTimeString := commits .(map [string ]interface {})["values" ].([]interface {})[0 ].(map [string ]interface {})["date" ].(string )
352
- commitTime , err = time .Parse (time .RFC3339 , commitTimeString )
350
+ commitsMap , ok := commits .(map [string ]interface {})
351
+ if ! ok {
352
+ impl .logger .Errorw ("unexpected response format from bitbucket" , "commits" , commits )
353
+ return "" , time.Time {}, fmt .Errorf ("unexpected response format from bitbucket" )
354
+ }
355
+
356
+ values , ok := commitsMap ["values" ]
357
+ if ! ok || values == nil {
358
+ impl .logger .Errorw ("no values found in bitbucket response" , "commits" , commits , "commitsMap" , commitsMap )
359
+ return "" , time.Time {}, fmt .Errorf ("no commits found in bitbucket response" )
360
+ }
361
+
362
+ valuesArray , ok := values .([]interface {})
363
+ if ! ok || len (valuesArray ) == 0 {
364
+ impl .logger .Errorw ("empty values array in bitbucket response" , "commits" , commits , "values" , values )
365
+ return "" , time.Time {}, fmt .Errorf ("empty commits array in bitbucket response" )
366
+ }
367
+
368
+ firstCommit , ok := valuesArray [0 ].(map [string ]interface {})
369
+ if ! ok {
370
+ impl .logger .Errorw ("invalid commit format in bitbucket response" , "commits" , commits , "firstCommit" , valuesArray [0 ])
371
+ return "" , time.Time {}, fmt .Errorf ("invalid commit format in bitbucket response" )
372
+ }
373
+
374
+ commitHash , ok = firstCommit ["hash" ].(string )
375
+ if ! ok || commitHash == "" {
376
+ impl .logger .Errorw ("no hash found in commit" , "commits" , commits , "firstCommit" , firstCommit )
377
+ return "" , time.Time {}, fmt .Errorf ("no hash found in commit" )
378
+ }
379
+
380
+ dateStr , ok := firstCommit ["date" ].(string )
381
+ if ! ok || dateStr == "" {
382
+ impl .logger .Errorw ("no date found in commit" , "firstCommit" , firstCommit )
383
+ return "" , time.Time {}, fmt .Errorf ("no date found in commit response" )
384
+ }
385
+
386
+ commitTime , err = time .Parse (time .RFC3339 , dateStr )
353
387
if err != nil {
354
388
util .TriggerGitOpsMetrics ("CommitValues" , "GitBitbucketClient" , start , err )
355
389
impl .logger .Errorw ("error in getting commitTime" , "err" , err )
0 commit comments