@@ -295,7 +295,7 @@ func processSingleArtifactInput(artInput *Artifact, indexPrefix string, fileJCou
295
295
return artInput
296
296
}
297
297
298
- func buildCommitMap (filesCounter * int , locationMap * map [ string ][] string , filesMap * map [ string ] interface {} ) * Commit {
298
+ func buildCommitMap () * Commit {
299
299
var commitObj Commit
300
300
// TODO commit author and email is missing from here
301
301
commitObj .Uri = vcsUri
@@ -304,18 +304,6 @@ func buildCommitMap(filesCounter *int, locationMap *map[string][]string, filesMa
304
304
commitObj .CommitMessage = commitMessage
305
305
commitObj .VcsTag = vcsTag
306
306
commitObj .DateActual = dateActual
307
- if sceArts != "" {
308
- var sceArtifacts []Artifact
309
- err := json .Unmarshal ([]byte (sceArts ), & sceArtifacts )
310
- if err != nil {
311
- fmt .Println ("Error parsing Artifact Input: " , err )
312
- os .Exit (1 )
313
- } else {
314
- indexPrefix := "variables.releaseInputProg.sourceCodeEntry.artifacts."
315
- artifactsObject := * processArtifactsInput (& sceArtifacts , indexPrefix , filesCounter , locationMap , filesMap )
316
- commitObj .Artifacts = artifactsObject
317
- }
318
- }
319
307
return & commitObj
320
308
}
321
309
@@ -400,29 +388,53 @@ var addreleaseCmd = &cobra.Command{
400
388
body ["outboundDeliverables" ] = * buildOutboundDeliverables (& filesCounter , & locationMap , & filesMap )
401
389
}
402
390
391
+ // Create variable to hold future value for body["sourceCodeEntry"]
392
+ var sourceCodeEntry * Commit
393
+
403
394
if commit != "" {
404
- body [ " sourceCodeEntry" ] = * buildCommitMap (& filesCounter , & locationMap , & filesMap )
395
+ sourceCodeEntry = buildCommitMap ()
405
396
}
406
397
407
398
if len (commits ) > 0 {
408
399
// fmt.Println(commits)
409
400
bodyCommits := * buildCommitsInBody ()
410
- body ["commits" ] = bodyCommits
411
- // if commit is not present but we are here, use first line as commit
412
- if len (commit ) < 1 && len (bodyCommits ) > 0 {
413
- mainCommitFromBody := bodyCommits [0 ]
401
+
402
+ // Apply VCS properties to all commits in bodyCommits
403
+ for i := range bodyCommits {
414
404
if vcsTag != "" {
415
- mainCommitFromBody .VcsTag = vcsTag
405
+ bodyCommits [ i ] .VcsTag = vcsTag
416
406
}
417
407
if vcsUri != "" {
418
- mainCommitFromBody .Uri = vcsUri
408
+ bodyCommits [ i ] .Uri = vcsUri
419
409
}
420
410
if vcsType != "" {
421
- mainCommitFromBody .Type = vcsType
411
+ bodyCommits [ i ] .Type = vcsType
422
412
}
413
+ }
423
414
424
- body ["sourceCodeEntry" ] = mainCommitFromBody
415
+ body ["commits" ] = bodyCommits
416
+ // if commit is not set and there are bodyCommits, use first body commit
417
+ // or if commit is set but matches the first bodyCommit hash
418
+ if (len (commit ) < 1 && len (bodyCommits ) > 0 ) || (len (commit ) > 0 && len (bodyCommits ) > 0 && commit == bodyCommits [0 ].Commit ) {
419
+ sourceCodeEntry = & bodyCommits [0 ]
420
+ }
421
+ }
422
+
423
+ // Set body["sourceCodeEntry"] to the variable value if it was populated
424
+ if sourceCodeEntry != nil {
425
+ if sceArts != "" {
426
+ var sceArtifacts []Artifact
427
+ err := json .Unmarshal ([]byte (sceArts ), & sceArtifacts )
428
+ if err != nil {
429
+ fmt .Println ("Error parsing Artifact Input: " , err )
430
+ os .Exit (1 )
431
+ } else {
432
+ indexPrefix := "variables.releaseInputProg.sourceCodeEntry.artifacts."
433
+ artifactsObject := * processArtifactsInput (& sceArtifacts , indexPrefix , & filesCounter , & locationMap , & filesMap )
434
+ sourceCodeEntry .Artifacts = artifactsObject
435
+ }
425
436
}
437
+ body ["sourceCodeEntry" ] = sourceCodeEntry
426
438
}
427
439
if releaseArts != "" {
428
440
body ["artifacts" ] = * buildReleaseArts (& filesCounter , & locationMap , & filesMap )
0 commit comments