1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-01-18 05:18:24 +02:00

fix: complete changeSet list (#3951)

* fixes: complete changeset list

* Adds test cases for multiple changeSets

* Adds PrNumber to ChangeSet

* Changes timestamp to Timestamp
This commit is contained in:
ffeldmann 2022-08-10 14:57:21 +02:00 committed by GitHub
parent 924ff6552f
commit a7d43b8571
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 59 additions and 10 deletions

View File

@ -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
}

View File

@ -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,
},
}

View File

@ -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