From 50b01810eb81decbf43632ed192fe9250e84dead Mon Sep 17 00:00:00 2001 From: Jordan Brockopp Date: Mon, 16 Dec 2019 11:41:12 -0600 Subject: [PATCH] feat(build): add email and link fields (#29) --- database/build.go | 16 ++++++++++++++ database/build_test.go | 12 ++++++++++ library/build.go | 50 ++++++++++++++++++++++++++++++++++++++++++ library/build_test.go | 40 +++++++++++++++++++++++++++++++++ 4 files changed, 118 insertions(+) diff --git a/database/build.go b/database/build.go index 6dca2492..27c7fb9c 100644 --- a/database/build.go +++ b/database/build.go @@ -42,6 +42,8 @@ type Build struct { Commit sql.NullString `sql:"commit"` Sender sql.NullString `sql:"sender"` Author sql.NullString `sql:"author"` + Email sql.NullString `sql:"email"` + Link sql.NullString `sql:"link"` Branch sql.NullString `sql:"branch"` Ref sql.NullString `sql:"ref"` BaseRef sql.NullString `sql:"base_ref"` @@ -172,6 +174,16 @@ func (b *Build) Nullify() *Build { b.Author.Valid = false } + // check if the Email field should be false + if len(b.Email.String) == 0 { + b.Email.Valid = false + } + + // check if the Link field should be false + if len(b.Link.String) == 0 { + b.Link.Valid = false + } + // check if the Branch field should be false if len(b.Branch.String) == 0 { b.Branch.Valid = false @@ -229,6 +241,8 @@ func (b *Build) ToLibrary() *library.Build { build.SetCommit(b.Commit.String) build.SetSender(b.Sender.String) build.SetAuthor(b.Author.String) + build.SetEmail(b.Email.String) + build.SetLink(b.Link.String) build.SetBranch(b.Branch.String) build.SetRef(b.Ref.String) build.SetBaseRef(b.BaseRef.String) @@ -278,6 +292,8 @@ func BuildFromLibrary(b *library.Build) *Build { Commit: sql.NullString{String: b.GetCommit(), Valid: true}, Sender: sql.NullString{String: b.GetSender(), Valid: true}, Author: sql.NullString{String: b.GetAuthor(), Valid: true}, + Email: sql.NullString{String: b.GetEmail(), Valid: true}, + Link: sql.NullString{String: b.GetLink(), Valid: true}, Branch: sql.NullString{String: b.GetBranch(), Valid: true}, Ref: sql.NullString{String: b.GetRef(), Valid: true}, BaseRef: sql.NullString{String: b.GetBaseRef(), Valid: true}, diff --git a/database/build_test.go b/database/build_test.go index 5b81cc5b..55fdb735 100644 --- a/database/build_test.go +++ b/database/build_test.go @@ -58,6 +58,8 @@ func TestDatabase_Build_Nullify(t *testing.T) { Commit: sql.NullString{String: "", Valid: true}, Sender: sql.NullString{String: "", Valid: true}, Author: sql.NullString{String: "", Valid: true}, + Email: sql.NullString{String: "", Valid: true}, + Link: sql.NullString{String: "", Valid: true}, Branch: sql.NullString{String: "", Valid: true}, Ref: sql.NullString{String: "", Valid: true}, BaseRef: sql.NullString{String: "", Valid: true}, @@ -85,6 +87,8 @@ func TestDatabase_Build_Nullify(t *testing.T) { Commit: sql.NullString{String: "", Valid: false}, Sender: sql.NullString{String: "", Valid: false}, Author: sql.NullString{String: "", Valid: false}, + Email: sql.NullString{String: "", Valid: false}, + Link: sql.NullString{String: "", Valid: false}, Branch: sql.NullString{String: "", Valid: false}, Ref: sql.NullString{String: "", Valid: false}, BaseRef: sql.NullString{String: "", Valid: false}, @@ -140,6 +144,8 @@ func TestDatabase_Build_ToLibrary(t *testing.T) { Commit: &str, Sender: &str, Author: &str, + Email: &str, + Link: &str, Branch: &str, Ref: &str, BaseRef: &str, @@ -167,6 +173,8 @@ func TestDatabase_Build_ToLibrary(t *testing.T) { Commit: sql.NullString{String: str, Valid: true}, Sender: sql.NullString{String: str, Valid: true}, Author: sql.NullString{String: str, Valid: true}, + Email: sql.NullString{String: str, Valid: true}, + Link: sql.NullString{String: str, Valid: true}, Branch: sql.NullString{String: str, Valid: true}, Ref: sql.NullString{String: str, Valid: true}, BaseRef: sql.NullString{String: str, Valid: true}, @@ -255,6 +263,8 @@ func TestDatabase_BuildFromLibrary(t *testing.T) { Commit: sql.NullString{String: str, Valid: true}, Sender: sql.NullString{String: str, Valid: true}, Author: sql.NullString{String: str, Valid: true}, + Email: sql.NullString{String: str, Valid: true}, + Link: sql.NullString{String: str, Valid: true}, Branch: sql.NullString{String: str, Valid: true}, Ref: sql.NullString{String: str, Valid: true}, BaseRef: sql.NullString{String: str, Valid: true}, @@ -283,6 +293,8 @@ func TestDatabase_BuildFromLibrary(t *testing.T) { Commit: &str, Sender: &str, Author: &str, + Email: &str, + Link: &str, Branch: &str, Ref: &str, BaseRef: &str, diff --git a/library/build.go b/library/build.go index ce26084e..57fa7b34 100644 --- a/library/build.go +++ b/library/build.go @@ -27,6 +27,8 @@ type Build struct { Commit *string `json:"commit,omitempty"` Sender *string `json:"sender,omitempty"` Author *string `json:"author,omitempty"` + Email *string `json:"email,omitempty"` + Link *string `json:"link,omitempty"` Branch *string `json:"branch,omitempty"` Ref *string `json:"ref,omitempty"` BaseRef *string `json:"base_ref,omitempty"` @@ -263,6 +265,30 @@ func (b *Build) GetAuthor() string { return *b.Author } +// GetEmail returns the Email 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) GetEmail() string { + // return zero value if Build type or Email field is nil + if b == nil || b.Email == nil { + return "" + } + return *b.Email +} + +// GetLink returns the Link 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) GetLink() string { + // return zero value if Build type or Link field is nil + if b == nil || b.Link == nil { + return "" + } + return *b.Link +} + // GetBranch returns the Branch field. // // When the provided Build type is nil, or the field within @@ -563,6 +589,30 @@ func (b *Build) SetAuthor(v string) { b.Author = &v } +// SetEmail sets the Email field. +// +// When the provided Build type is nil, it +// will set nothing and immediately return. +func (b *Build) SetEmail(v string) { + // return if Build type is nil + if b == nil { + return + } + b.Email = &v +} + +// SetLink sets the Link field. +// +// When the provided Build type is nil, it +// will set nothing and immediately return. +func (b *Build) SetLink(v string) { + // return if Build type is nil + if b == nil { + return + } + b.Link = &v +} + // SetBranch sets the Branch field. // // When the provided Build type is nil, it diff --git a/library/build_test.go b/library/build_test.go index df1f4328..9c658eb8 100644 --- a/library/build_test.go +++ b/library/build_test.go @@ -35,6 +35,8 @@ func TestLibrary_Build_Getters(t *testing.T) { Commit: &str, Sender: &str, Author: &str, + Email: &str, + Link: &str, Branch: &str, Ref: &str, BaseRef: &str, @@ -61,6 +63,8 @@ func TestLibrary_Build_Getters(t *testing.T) { wantCommit := str wantSender := str wantAuthor := str + wantEmail := str + wantLink := str wantBranch := str wantRef := str wantBaseRef := str @@ -88,6 +92,8 @@ func TestLibrary_Build_Getters(t *testing.T) { gotCommit := b.GetCommit() gotSender := b.GetSender() gotAuthor := b.GetAuthor() + gotEmail := b.GetEmail() + gotLink := b.GetLink() gotBranch := b.GetBranch() gotRef := b.GetRef() gotBaseRef := b.GetBaseRef() @@ -152,6 +158,12 @@ func TestLibrary_Build_Getters(t *testing.T) { if gotAuthor != wantAuthor { t.Errorf("GetAuthor is %v, want %v", gotAuthor, wantAuthor) } + if gotEmail != wantEmail { + t.Errorf("GetEmail is %v, want %v", gotEmail, wantEmail) + } + if gotLink != wantLink { + t.Errorf("GetLink is %v, want %v", gotLink, wantLink) + } if gotBranch != wantBranch { t.Errorf("GetBranch is %v, want %v", gotBranch, wantBranch) } @@ -196,6 +208,8 @@ func TestLibrary_Build_Getters_Empty(t *testing.T) { gotCommit := b.GetCommit() gotSender := b.GetSender() gotAuthor := b.GetAuthor() + gotEmail := b.GetEmail() + gotLink := b.GetLink() gotBranch := b.GetBranch() gotRef := b.GetRef() gotBaseRef := b.GetBaseRef() @@ -260,6 +274,12 @@ func TestLibrary_Build_Getters_Empty(t *testing.T) { if gotAuthor != "" { t.Errorf("GetAuthor is %v, want \"\"", gotAuthor) } + if gotEmail != "" { + t.Errorf("GetEmail is %v, want \"\"", gotEmail) + } + if gotLink != "" { + t.Errorf("GetLink is %v, want \"\"", gotLink) + } if gotBranch != "" { t.Errorf("GetBranch is %v, want \"\"", gotBranch) } @@ -306,6 +326,8 @@ func TestLibrary_Build_Setters(t *testing.T) { wantCommit := str wantSender := str wantAuthor := str + wantEmail := str + wantLink := str wantBranch := str wantRef := str wantBaseRef := str @@ -333,6 +355,8 @@ func TestLibrary_Build_Setters(t *testing.T) { b.SetCommit(wantCommit) b.SetSender(wantSender) b.SetAuthor(wantAuthor) + b.SetEmail(wantEmail) + b.SetLink(wantLink) b.SetBranch(wantBranch) b.SetRef(wantRef) b.SetBaseRef(wantBaseRef) @@ -397,6 +421,12 @@ func TestLibrary_Build_Setters(t *testing.T) { if b.GetAuthor() != wantAuthor { t.Errorf("SetAuthor is %v, want %v", b.GetAuthor(), wantAuthor) } + if b.GetEmail() != wantEmail { + t.Errorf("SetEmail is %v, want %v", b.GetEmail(), wantEmail) + } + if b.GetLink() != wantLink { + t.Errorf("SetLink is %v, want %v", b.GetLink(), wantLink) + } if b.GetBranch() != wantBranch { t.Errorf("SetBranch is %v, want %v", b.GetBranch(), wantBranch) } @@ -442,6 +472,8 @@ func TestLibrary_Build_Setters_Empty(t *testing.T) { b.SetCommit("") b.SetSender("") b.SetAuthor("") + b.SetEmail("") + b.SetLink("") b.SetBranch("") b.SetRef("") b.SetBaseRef("") @@ -506,6 +538,12 @@ func TestLibrary_Build_Setters_Empty(t *testing.T) { if b.GetAuthor() != "" { t.Errorf("SetAuthor is %v, want \"\"", b.GetAuthor()) } + if b.GetEmail() != "" { + t.Errorf("SetEmail is %v, want \"\"", b.GetEmail()) + } + if b.GetLink() != "" { + t.Errorf("SetLink is %v, want \"\"", b.GetLink()) + } if b.GetBranch() != "" { t.Errorf("SetBranch is %v, want \"\"", b.GetBranch()) } @@ -551,6 +589,8 @@ func TestLibrary_Build_String(t *testing.T) { Commit: &str, Sender: &str, Author: &str, + Email: &str, + Link: &str, Branch: &str, Ref: &str, BaseRef: &str,