You've already forked sap-jenkins-library
mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-11-06 09:09:19 +02:00
ABAP environment: add tag support (#3376)
This commit is contained in:
@@ -143,13 +143,52 @@ func GetRepositories(config *RepositoriesConfig) ([]Repository, error) {
|
||||
return repositories, nil
|
||||
}
|
||||
|
||||
//GetCommitStrings for getting the commit_id property for the http request and a string for logging output
|
||||
func GetCommitStrings(commitID string) (commitQuery string, commitString string) {
|
||||
if commitID != "" {
|
||||
commitQuery = `, "commit_id":"` + commitID + `"`
|
||||
commitString = ", commit '" + commitID + "'"
|
||||
func (repo *Repository) GetRequestBodyForCommitOrTag() (requestBodyString string) {
|
||||
if repo.CommitID != "" {
|
||||
requestBodyString = `, "commit_id":"` + repo.CommitID + `"`
|
||||
} else if repo.Tag != "" {
|
||||
requestBodyString = `, "tag_name":"` + repo.Tag + `"`
|
||||
}
|
||||
return commitQuery, commitString
|
||||
return requestBodyString
|
||||
}
|
||||
|
||||
func (repo *Repository) GetLogStringForCommitOrTag() (logString string) {
|
||||
if repo.CommitID != "" {
|
||||
logString = ", commit '" + repo.CommitID + "'"
|
||||
} else if repo.Tag != "" {
|
||||
logString = ", tag '" + repo.Tag + "'"
|
||||
}
|
||||
return logString
|
||||
}
|
||||
|
||||
func (repo *Repository) GetCloneRequestBody() (body string) {
|
||||
if repo.CommitID != "" && repo.Tag != "" {
|
||||
log.Entry().WithField("Tag", repo.Tag).WithField("Commit ID", repo.CommitID).Info("The commit ID takes precedence over the tag")
|
||||
}
|
||||
requestBodyString := repo.GetRequestBodyForCommitOrTag()
|
||||
body = `{"sc_name":"` + repo.Name + `", "branch_name":"` + repo.Branch + `"` + requestBodyString + `}`
|
||||
return body
|
||||
}
|
||||
|
||||
func (repo *Repository) GetCloneLogString() (logString string) {
|
||||
commitOrTag := repo.GetLogStringForCommitOrTag()
|
||||
logString = "repository / software component '" + repo.Name + "', branch '" + repo.Branch + "'" + commitOrTag
|
||||
return logString
|
||||
}
|
||||
|
||||
func (repo *Repository) GetPullRequestBody() (body string) {
|
||||
if repo.CommitID != "" && repo.Tag != "" {
|
||||
log.Entry().WithField("Tag", repo.Tag).WithField("Commit ID", repo.CommitID).Info("The commit ID takes precedence over the tag")
|
||||
}
|
||||
requestBodyString := repo.GetRequestBodyForCommitOrTag()
|
||||
body = `{"sc_name":"` + repo.Name + `"` + requestBodyString + `}`
|
||||
return body
|
||||
}
|
||||
|
||||
func (repo *Repository) GetPullLogString() (logString string) {
|
||||
commitOrTag := repo.GetLogStringForCommitOrTag()
|
||||
logString = "repository / software component '" + repo.Name + "'" + commitOrTag
|
||||
return logString
|
||||
}
|
||||
|
||||
/****************************************
|
||||
|
||||
@@ -216,15 +216,84 @@ repositories:
|
||||
})
|
||||
}
|
||||
|
||||
func TestGetCommitStrings(t *testing.T) {
|
||||
t.Run("CommitID available", func(t *testing.T) {
|
||||
commitQuery, commitString := GetCommitStrings("ABCD1234")
|
||||
assert.Equal(t, `, "commit_id":"ABCD1234"`, commitQuery, "Expected different query")
|
||||
assert.Equal(t, `, commit 'ABCD1234'`, commitString, "Expected different string")
|
||||
func TestCreateLogStrings(t *testing.T) {
|
||||
t.Run("Clone LogString Tag and Commit", func(t *testing.T) {
|
||||
repo := Repository{
|
||||
Name: "/DMO/REPO",
|
||||
Branch: "main",
|
||||
CommitID: "1234567",
|
||||
Tag: "myTag",
|
||||
}
|
||||
logString := repo.GetCloneLogString()
|
||||
assert.Equal(t, "repository / software component '/DMO/REPO', branch 'main', commit '1234567'", logString, "Expected different string")
|
||||
})
|
||||
t.Run("CommitID available", func(t *testing.T) {
|
||||
commitQuery, commitString := GetCommitStrings("")
|
||||
assert.Equal(t, ``, commitQuery, "Expected empty query")
|
||||
assert.Equal(t, ``, commitString, "Expected empty string")
|
||||
t.Run("Clone LogString Tag", func(t *testing.T) {
|
||||
repo := Repository{
|
||||
Name: "/DMO/REPO",
|
||||
Branch: "main",
|
||||
Tag: "myTag",
|
||||
}
|
||||
logString := repo.GetCloneLogString()
|
||||
assert.Equal(t, "repository / software component '/DMO/REPO', branch 'main', tag 'myTag'", logString, "Expected different string")
|
||||
})
|
||||
t.Run("Pull LogString Tag and Commit", func(t *testing.T) {
|
||||
repo := Repository{
|
||||
Name: "/DMO/REPO",
|
||||
Branch: "main",
|
||||
CommitID: "1234567",
|
||||
Tag: "myTag",
|
||||
}
|
||||
logString := repo.GetPullLogString()
|
||||
assert.Equal(t, "repository / software component '/DMO/REPO', commit '1234567'", logString, "Expected different string")
|
||||
})
|
||||
t.Run("Pull LogString Tag", func(t *testing.T) {
|
||||
repo := Repository{
|
||||
Name: "/DMO/REPO",
|
||||
Branch: "main",
|
||||
Tag: "myTag",
|
||||
}
|
||||
logString := repo.GetPullLogString()
|
||||
assert.Equal(t, "repository / software component '/DMO/REPO', tag 'myTag'", logString, "Expected different string")
|
||||
})
|
||||
}
|
||||
|
||||
func TestCreateRequestBodies(t *testing.T) {
|
||||
t.Run("Clone Body Tag and Commit", func(t *testing.T) {
|
||||
repo := Repository{
|
||||
Name: "/DMO/REPO",
|
||||
Branch: "main",
|
||||
CommitID: "1234567",
|
||||
Tag: "myTag",
|
||||
}
|
||||
body := repo.GetCloneRequestBody()
|
||||
assert.Equal(t, `{"sc_name":"/DMO/REPO", "branch_name":"main", "commit_id":"1234567"}`, body, "Expected different body")
|
||||
})
|
||||
t.Run("Clone Body Tag", func(t *testing.T) {
|
||||
repo := Repository{
|
||||
Name: "/DMO/REPO",
|
||||
Branch: "main",
|
||||
Tag: "myTag",
|
||||
}
|
||||
body := repo.GetCloneRequestBody()
|
||||
assert.Equal(t, `{"sc_name":"/DMO/REPO", "branch_name":"main", "tag_name":"myTag"}`, body, "Expected different body")
|
||||
})
|
||||
t.Run("Pull Body Tag and Commit", func(t *testing.T) {
|
||||
repo := Repository{
|
||||
Name: "/DMO/REPO",
|
||||
Branch: "main",
|
||||
CommitID: "1234567",
|
||||
Tag: "myTag",
|
||||
}
|
||||
body := repo.GetPullRequestBody()
|
||||
assert.Equal(t, `{"sc_name":"/DMO/REPO", "commit_id":"1234567"}`, body, "Expected different body")
|
||||
})
|
||||
t.Run("Pull Body Tag", func(t *testing.T) {
|
||||
repo := Repository{
|
||||
Name: "/DMO/REPO",
|
||||
Branch: "main",
|
||||
Tag: "myTag",
|
||||
}
|
||||
body := repo.GetPullRequestBody()
|
||||
assert.Equal(t, `{"sc_name":"/DMO/REPO", "tag_name":"myTag"}`, body, "Expected different body")
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user