From a7d43b857100b327c2d07e7daaabf32575fef850 Mon Sep 17 00:00:00 2001 From: ffeldmann Date: Wed, 10 Aug 2022 14:57:21 +0200 Subject: [PATCH] fix: complete changeSet list (#3951) * fixes: complete changeset list * Adds test cases for multiple changeSets * Adds PrNumber to ChangeSet * Changes timestamp to Timestamp --- pkg/orchestrator/jenkins.go | 6 ++-- pkg/orchestrator/jenkins_test.go | 60 +++++++++++++++++++++++++++++--- pkg/orchestrator/orchestrator.go | 3 +- 3 files changed, 59 insertions(+), 10 deletions(-) diff --git a/pkg/orchestrator/jenkins.go b/pkg/orchestrator/jenkins.go index e7134a90c..4ea235549 100644 --- a/pkg/orchestrator/jenkins.go +++ b/pkg/orchestrator/jenkins.go @@ -109,15 +109,13 @@ func (j *JenkinsConfigProvider) GetChangeSet() []ChangeSet { for _, item := range child.S("items").Children() { tmpChangeSet := ChangeSet{ CommitId: item.Path("commitId").Data().(string), - timestamp: item.Path("timestamp").String(), + Timestamp: item.Path("timestamp").String(), } changeSetList = append(changeSetList, tmpChangeSet) } - - return changeSetList } } - return []ChangeSet{} + return changeSetList } diff --git a/pkg/orchestrator/jenkins_test.go b/pkg/orchestrator/jenkins_test.go index a8445ab95..bcf07e5ce 100644 --- a/pkg/orchestrator/jenkins_test.go +++ b/pkg/orchestrator/jenkins_test.go @@ -524,7 +524,47 @@ func TestJenkinsConfigProvider_GetChangeSet(t *testing.T) { "kind": "git" } ] - }`) +}`) + + changeSetMultiple := []byte(`{ +"displayName": "#531", +"duration": 424269, +"changeSets": [ + { + "_class": "hudson.plugins.git.GitChangeSetList", + "items": [ + { + "_class": "hudson.plugins.git.GitChangeSet", + "commitId": "987654321", + "timestamp": 1655057520000 + }, + { + "_class": "hudson.plugins.git.GitChangeSet", + "commitId": "123456789", + "timestamp": 1656057520000 + } + ], + "kind": "git" + }, + { + "_class": "hudson.plugins.git.GitChangeSetList", + "items": [ + { + "_class": "hudson.plugins.git.GitChangeSet", + "commitId": "456789123", + "timestamp": 1659948036000 + }, + { + "_class": "hudson.plugins.git.GitChangeSet", + "commitId": "654717777", + "timestamp": 1660053494000 + } + ], + "kind": "git" + } +] +}`) + changeSetEmpty := []byte(`{ "displayName": "#531", "duration": 424269, @@ -542,19 +582,29 @@ func TestJenkinsConfigProvider_GetChangeSet(t *testing.T) { { name: "success", want: []ChangeSet{ - {CommitId: "987654321", timestamp: "1655057520000"}, - {CommitId: "123456789", timestamp: "1656057520000"}, + {CommitId: "987654321", Timestamp: "1655057520000"}, + {CommitId: "123456789", Timestamp: "1656057520000"}, }, testChangeSet: changeSetTwo, }, + { + name: "success multiple", + want: []ChangeSet{ + {CommitId: "987654321", Timestamp: "1655057520000"}, + {CommitId: "123456789", Timestamp: "1656057520000"}, + {CommitId: "456789123", Timestamp: "1659948036000"}, + {CommitId: "654717777", Timestamp: "1660053494000"}, + }, + testChangeSet: changeSetMultiple, + }, { name: "failure - changeSet empty", - want: []ChangeSet{}, + want: []ChangeSet(nil), testChangeSet: changeSetEmpty, }, { name: "failure - no changeSet found", - want: []ChangeSet{}, + want: []ChangeSet(nil), testChangeSet: changeSetNotAvailable, }, } diff --git a/pkg/orchestrator/orchestrator.go b/pkg/orchestrator/orchestrator.go index e3caa6882..f724a4736 100644 --- a/pkg/orchestrator/orchestrator.go +++ b/pkg/orchestrator/orchestrator.go @@ -47,7 +47,8 @@ type PullRequestConfig struct { type ChangeSet struct { CommitId string - timestamp string + Timestamp string + PrNumber int } // OrchestratorSettings struct to set orchestrator specific settings e.g. Jenkins credentials