Skip to content

Commit 47b5e33

Browse files
committed
fix: resolution of commit details on add release
1 parent 14726cc commit 47b5e33

File tree

1 file changed

+34
-22
lines changed

1 file changed

+34
-22
lines changed

cmd/addRelease.go

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ func processSingleArtifactInput(artInput *Artifact, indexPrefix string, fileJCou
295295
return artInput
296296
}
297297

298-
func buildCommitMap(filesCounter *int, locationMap *map[string][]string, filesMap *map[string]interface{}) *Commit {
298+
func buildCommitMap() *Commit {
299299
var commitObj Commit
300300
// TODO commit author and email is missing from here
301301
commitObj.Uri = vcsUri
@@ -304,18 +304,6 @@ func buildCommitMap(filesCounter *int, locationMap *map[string][]string, filesMa
304304
commitObj.CommitMessage = commitMessage
305305
commitObj.VcsTag = vcsTag
306306
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-
}
319307
return &commitObj
320308
}
321309

@@ -400,29 +388,53 @@ var addreleaseCmd = &cobra.Command{
400388
body["outboundDeliverables"] = *buildOutboundDeliverables(&filesCounter, &locationMap, &filesMap)
401389
}
402390

391+
// Create variable to hold future value for body["sourceCodeEntry"]
392+
var sourceCodeEntry *Commit
393+
403394
if commit != "" {
404-
body["sourceCodeEntry"] = *buildCommitMap(&filesCounter, &locationMap, &filesMap)
395+
sourceCodeEntry = buildCommitMap()
405396
}
406397

407398
if len(commits) > 0 {
408399
// fmt.Println(commits)
409400
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 {
414404
if vcsTag != "" {
415-
mainCommitFromBody.VcsTag = vcsTag
405+
bodyCommits[i].VcsTag = vcsTag
416406
}
417407
if vcsUri != "" {
418-
mainCommitFromBody.Uri = vcsUri
408+
bodyCommits[i].Uri = vcsUri
419409
}
420410
if vcsType != "" {
421-
mainCommitFromBody.Type = vcsType
411+
bodyCommits[i].Type = vcsType
422412
}
413+
}
423414

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+
}
425436
}
437+
body["sourceCodeEntry"] = sourceCodeEntry
426438
}
427439
if releaseArts != "" {
428440
body["artifacts"] = *buildReleaseArts(&filesCounter, &locationMap, &filesMap)

0 commit comments

Comments
 (0)