Skip to content

Commit

Permalink
changing DeployID back to DeployNumber
Browse files Browse the repository at this point in the history
  • Loading branch information
Claire.Nicholas authored and Claire.Nicholas committed Dec 22, 2023
1 parent 21d86e3 commit 41884d1
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 31 deletions.
10 changes: 5 additions & 5 deletions database/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type Build struct {
Started sql.NullInt64 `sql:"started"`
Finished sql.NullInt64 `sql:"finished"`
Deploy sql.NullString `sql:"deploy"`
DeployID sql.NullInt64 `sql:"deploy_id"`
DeployNumber sql.NullInt64 `sql:"deploy_number"`
DeployPayload raw.StringSliceMap `sql:"deploy_payload" gorm:"type:varchar(2000)"`
Clone sql.NullString `sql:"clone"`
Source sql.NullString `sql:"source"`
Expand Down Expand Up @@ -171,8 +171,8 @@ func (b *Build) Nullify() *Build {
b.Deploy.Valid = false
}

// check if the DeployID field should be false
if b.DeployID.Int64 == 0 {
// check if the DeployNumber field should be false
if b.DeployNumber.Int64 == 0 {
b.Deploy.Valid = false
}

Expand Down Expand Up @@ -288,7 +288,7 @@ func (b *Build) ToLibrary() *library.Build {
build.SetStarted(b.Started.Int64)
build.SetFinished(b.Finished.Int64)
build.SetDeploy(b.Deploy.String)
build.SetDeployID(b.DeployID.Int64)
build.SetDeployNumber(b.DeployNumber.Int64)
build.SetDeployPayload(b.DeployPayload)
build.SetClone(b.Clone.String)
build.SetSource(b.Source.String)
Expand Down Expand Up @@ -372,7 +372,7 @@ func BuildFromLibrary(b *library.Build) *Build {
Started: sql.NullInt64{Int64: b.GetStarted(), Valid: true},
Finished: sql.NullInt64{Int64: b.GetFinished(), Valid: true},
Deploy: sql.NullString{String: b.GetDeploy(), Valid: true},
DeployID: sql.NullInt64{Int64: b.GetDeployID(), Valid: true},
DeployNumber: sql.NullInt64{Int64: b.GetDeployNumber(), Valid: true},
DeployPayload: b.GetDeployPayload(),
Clone: sql.NullString{String: b.GetClone(), Valid: true},
Source: sql.NullString{String: b.GetSource(), Valid: true},
Expand Down
8 changes: 4 additions & 4 deletions database/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestDatabase_Build_Nullify(t *testing.T) {
Started: sql.NullInt64{Int64: 0, Valid: false},
Finished: sql.NullInt64{Int64: 0, Valid: false},
Deploy: sql.NullString{String: "", Valid: false},
DeployID: sql.NullInt64{Int64: 0, Valid: false},
DeployNumber: sql.NullInt64{Int64: 0, Valid: false},
DeployPayload: nil,
Clone: sql.NullString{String: "", Valid: false},
Source: sql.NullString{String: "", Valid: false},
Expand Down Expand Up @@ -122,7 +122,7 @@ func TestDatabase_Build_ToLibrary(t *testing.T) {
want.SetStarted(1563474078)
want.SetFinished(1563474079)
want.SetDeploy("")
want.SetDeployID(0)
want.SetDeployNumber(0)
want.SetDeployPayload(nil)
want.SetClone("https://github.com/github/octocat.git")
want.SetSource("https://github.com/github/octocat/48afb5bdc41ad69bf22588491333f7cf71135163")
Expand Down Expand Up @@ -214,7 +214,7 @@ func TestDatabase_BuildFromLibrary(t *testing.T) {
b.SetStarted(1563474078)
b.SetFinished(1563474079)
b.SetDeploy("")
b.SetDeployID(0)
b.SetDeployNumber(0)
b.SetDeployPayload(nil)
b.SetClone("https://github.com/github/octocat.git")
b.SetSource("https://github.com/github/octocat/48afb5bdc41ad69bf22588491333f7cf71135163")
Expand Down Expand Up @@ -276,7 +276,7 @@ func testBuild() *Build {
Started: sql.NullInt64{Int64: 1563474078, Valid: true},
Finished: sql.NullInt64{Int64: 1563474079, Valid: true},
Deploy: sql.NullString{String: "", Valid: false},
DeployID: sql.NullInt64{Int64: 0, Valid: true},
DeployNumber: sql.NullInt64{Int64: 0, Valid: true},
DeployPayload: raw.StringSliceMap{"foo": "test1", "bar": "test2"},
Clone: sql.NullString{String: "https://github.com/github/octocat.git", Valid: true},
Source: sql.NullString{String: "https://github.com/github/octocat/48afb5bdc41ad69bf22588491333f7cf71135163", Valid: true},
Expand Down
4 changes: 2 additions & 2 deletions database/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestDatabase_Deployment_ToLibrary(t *testing.T) {
buildOne.SetStarted(1563474078)
buildOne.SetFinished(1563474079)
buildOne.SetDeploy("")
buildOne.SetDeployID(0)
buildOne.SetDeployNumber(0)
buildOne.SetDeployPayload(nil)
buildOne.SetClone("https://github.com/github/octocat.git")
buildOne.SetSource("https://github.com/github/octocat/48afb5bdc41ad69bf22588491333f7cf71135163")
Expand Down Expand Up @@ -186,7 +186,7 @@ func TestDatabase_DeploymentFromLibrary(t *testing.T) {
buildOne.SetStarted(1563474078)
buildOne.SetFinished(1563474079)
buildOne.SetDeploy("")
buildOne.SetDeployID(0)
buildOne.SetDeployNumber(0)
buildOne.SetDeployPayload(nil)
buildOne.SetClone("https://github.com/github/octocat.git")
buildOne.SetSource("https://github.com/github/octocat/48afb5bdc41ad69bf22588491333f7cf71135163")
Expand Down
21 changes: 11 additions & 10 deletions library/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type Build struct {
Started *int64 `json:"started,omitempty"`
Finished *int64 `json:"finished,omitempty"`
Deploy *string `json:"deploy,omitempty"`
DeployID *int64 `json:"deploy_id,omitempty"`
DeployNumber *int64 `json:"deploy_number,omitempty"`
DeployPayload *raw.StringSliceMap `json:"deploy_payload,omitempty"`
Clone *string `json:"clone,omitempty"`
Source *string `json:"source,omitempty"`
Expand Down Expand Up @@ -159,6 +159,7 @@ func (b *Build) Environment(workspace, channel string) map[string]string {
envs["VELA_BUILD_TARGET"] = target
envs["VELA_DEPLOYMENT"] = target
envs["BUILD_TARGET"] = target
envs["VELA_DEPLOYMENT_NUMBER"] = ToString(b.GetDeployNumber())

// handle when deployment event is for a tag
if strings.HasPrefix(b.GetRef(), "refs/tags/") {
Expand Down Expand Up @@ -384,17 +385,17 @@ func (b *Build) GetDeploy() string {
return *b.Deploy
}

// GetDeployID returns the DeployID field.
// GetDeployNumber returns the DeployNumber field.
//
// When the provided Build type is nil, or the field within
// the type is nil, it returns the zero value for the field.
func (b *Build) GetDeployID() int64 {
func (b *Build) GetDeployNumber() int64 {
// return zero value if Build type or Deploy field is nil
if b == nil || b.DeployID == nil {
if b == nil || b.DeployNumber == nil {
return 0
}

return *b.DeployID
return *b.DeployNumber
}

// GetDeployPayload returns the DeployPayload field.
Expand Down Expand Up @@ -826,17 +827,17 @@ func (b *Build) SetDeploy(v string) {
b.Deploy = &v
}

// SetDeployID sets the DeployID field.
// SetDeployNumber sets the DeployNumber field.
//
// When the provided Build type is nil, it
// will set nothing and immediately return.
func (b *Build) SetDeployID(v int64) {
func (b *Build) SetDeployNumber(v int64) {
// return if Build type is nil
if b == nil {
return
}

b.DeployID = &v
b.DeployNumber = &v
}

// SetDeployPayload sets the DeployPayload field.
Expand Down Expand Up @@ -1100,7 +1101,7 @@ func (b *Build) String() string {
Commit: %s,
Created: %d,
Deploy: %s,
DeployID: %d,
DeployNumber: %d,
DeployPayload: %s,
Distribution: %s,
Email: %s,
Expand Down Expand Up @@ -1135,7 +1136,7 @@ func (b *Build) String() string {
b.GetCommit(),
b.GetCreated(),
b.GetDeploy(),
b.GetDeployID(),
b.GetDeployNumber(),
b.GetDeployPayload(),
b.GetDistribution(),
b.GetEmail(),
Expand Down
20 changes: 10 additions & 10 deletions library/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestLibrary_Build_Environment(t *testing.T) {
_deploy := testBuild()
_deploy.SetEvent("deployment")
_deploy.SetDeploy("production")
_deploy.SetDeployID(0)
_deploy.SetDeployNumber(0)
_deploy.SetDeployPayload(map[string]string{
"foo": "test1",
"bar": "test2",
Expand All @@ -65,7 +65,7 @@ func TestLibrary_Build_Environment(t *testing.T) {
_deployTag.SetRef("refs/tags/v0.1.0")
_deployTag.SetEvent("deployment")
_deployTag.SetDeploy("production")
_deployTag.SetDeployID(0)
_deployTag.SetDeployNumber(0)
_deployTag.SetDeployPayload(map[string]string{
"foo": "test1",
"bar": "test2",
Expand Down Expand Up @@ -519,8 +519,8 @@ func TestLibrary_Build_Getters(t *testing.T) {
t.Errorf("GetDeploy is %v, want %v", test.build.GetDeploy(), test.want.GetDeploy())
}

if test.build.GetDeployID() != test.want.GetDeployID() {
t.Errorf("GetDeployID is %v, want %v", test.build.GetDeployID(), test.want.GetDeployID())
if test.build.GetDeployNumber() != test.want.GetDeployNumber() {
t.Errorf("GetDeployNumber is %v, want %v", test.build.GetDeployNumber(), test.want.GetDeployNumber())
}

if !reflect.DeepEqual(test.build.GetDeployPayload(), test.want.GetDeployPayload()) {
Expand Down Expand Up @@ -636,7 +636,7 @@ func TestLibrary_Build_Setters(t *testing.T) {
test.build.SetStarted(test.want.GetStarted())
test.build.SetFinished(test.want.GetFinished())
test.build.SetDeploy(test.want.GetDeploy())
test.build.SetDeployID(test.want.GetDeployID())
test.build.SetDeployNumber(test.want.GetDeployNumber())
test.build.SetDeployPayload(test.want.GetDeployPayload())
test.build.SetClone(test.want.GetClone())
test.build.SetSource(test.want.GetSource())
Expand Down Expand Up @@ -713,8 +713,8 @@ func TestLibrary_Build_Setters(t *testing.T) {
t.Errorf("SetDeploy is %v, want %v", test.build.GetDeploy(), test.want.GetDeploy())
}

if test.build.GetDeployID() != test.want.GetDeployID() {
t.Errorf("SetDeployID is %v, want %v", test.build.GetDeployID(), test.want.GetDeployID())
if test.build.GetDeployNumber() != test.want.GetDeployNumber() {
t.Errorf("SetDeployNumber is %v, want %v", test.build.GetDeployNumber(), test.want.GetDeployNumber())
}

if !reflect.DeepEqual(test.build.GetDeployPayload(), test.want.GetDeployPayload()) {
Expand Down Expand Up @@ -809,7 +809,7 @@ func TestLibrary_Build_String(t *testing.T) {
Commit: %s,
Created: %d,
Deploy: %s,
DeployID: %d,
DeployNumber: %d,
DeployPayload: %s,
Distribution: %s,
Email: %s,
Expand Down Expand Up @@ -844,7 +844,7 @@ func TestLibrary_Build_String(t *testing.T) {
b.GetCommit(),
b.GetCreated(),
b.GetDeploy(),
b.GetDeployID(),
b.GetDeployNumber(),
b.GetDeployPayload(),
b.GetDistribution(),
b.GetEmail(),
Expand Down Expand Up @@ -897,7 +897,7 @@ func testBuild() *Build {
b.SetStarted(1563474078)
b.SetFinished(1563474079)
b.SetDeploy("")
b.SetDeployID(0)
b.SetDeployNumber(0)
b.SetDeployPayload(raw.StringSliceMap{"foo": "test1"})
b.SetClone("https://github.com/github/octocat.git")
b.SetSource("https://github.com/github/octocat/48afb5bdc41ad69bf22588491333f7cf71135163")
Expand Down

0 comments on commit 41884d1

Please sign in to comment.