Skip to content

Commit

Permalink
DEVPROD-11199 Add git triggered info to version rest api (#8365)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZackarySantana authored Oct 3, 2024
1 parent dba9fbb commit a9c26a0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 16 deletions.
16 changes: 13 additions & 3 deletions rest/model/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ type APIVersion struct {
Requester *string `json:"requester"`
Errors []*string `json:"errors"`
// Will be null for versions created before this field was added.
Activated *bool `json:"activated"`
Aborted *bool `json:"aborted"`
GitTags []APIGitTag `json:"git_tags"`
Activated *bool `json:"activated"`
Aborted *bool `json:"aborted"`
// The git tag that triggered this version, if any.
TriggeredGitTag *APIGitTag `json:"triggered_by_git_tag"`
// Git tags that were pushed to this version.
GitTags []APIGitTag `json:"git_tags"`
// Indicates if the version was ignored due to only making changes to ignored files.
Ignored *bool `json:"ignored"`
}
Expand Down Expand Up @@ -111,6 +114,13 @@ func (apiVersion *APIVersion) BuildFromService(v model.Version) {
})
}

if v.TriggeredByGitTag.Tag != "" {
apiVersion.TriggeredGitTag = &APIGitTag{
Tag: utility.ToStringPtr(v.TriggeredByGitTag.Tag),
Pusher: utility.ToStringPtr(v.TriggeredByGitTag.Pusher),
}
}

if v.Identifier != "" {
identifier, err := model.GetIdentifierForProject(v.Identifier)
if err == nil {
Expand Down
47 changes: 34 additions & 13 deletions rest/model/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/evergreen-ci/evergreen/model"
"github.com/evergreen-ci/utility"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

// TestVersionBuildFromService tests that BuildFromService function completes
Expand Down Expand Up @@ -40,20 +41,32 @@ func TestVersionBuildFromService(t *testing.T) {
BuildId: bi2,
},
}
gitTags := []model.GitTag{
{
Tag: "tag",
Pusher: "pusher",
},
}
triggeredGitTag := model.GitTag{
Tag: "my-triggered-tag",
Pusher: "pusher",
}
v := model.Version{
Id: versionId,
CreateTime: time,
StartTime: time,
FinishTime: time,
Revision: revision,
Author: author,
AuthorEmail: authorEmail,
Message: msg,
Status: status,
Repo: repo,
Branch: branch,
BuildVariants: buildVariants,
Errors: errors,
Id: versionId,
CreateTime: time,
StartTime: time,
FinishTime: time,
Revision: revision,
Author: author,
AuthorEmail: authorEmail,
Message: msg,
Status: status,
Repo: repo,
Branch: branch,
BuildVariants: buildVariants,
Errors: errors,
GitTags: gitTags,
TriggeredByGitTag: triggeredGitTag,
}

apiVersion := &APIVersion{}
Expand All @@ -78,4 +91,12 @@ func TestVersionBuildFromService(t *testing.T) {
assert.Equal(bvs[0].BuildId, utility.ToStringPtr(bi1))
assert.Equal(bvs[1].BuildVariant, utility.ToStringPtr(bv2))
assert.Equal(bvs[1].BuildId, utility.ToStringPtr(bi2))

gts := apiVersion.GitTags
require.Len(t, gts, 1)
assert.Equal(gts[0].Pusher, utility.ToStringPtr("pusher"))
assert.Equal(gts[0].Tag, utility.ToStringPtr("tag"))

require.NotNil(t, apiVersion.TriggeredGitTag)
assert.Equal(apiVersion.TriggeredGitTag.Tag, utility.ToStringPtr("my-triggered-tag"))
}

0 comments on commit a9c26a0

Please sign in to comment.