Skip to content

Commit

Permalink
feat(build): add email and link fields (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockopp authored and wass3r committed Dec 16, 2019
1 parent 6f79a63 commit 50b0181
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 0 deletions.
16 changes: 16 additions & 0 deletions database/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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},
Expand Down
12 changes: 12 additions & 0 deletions database/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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,
Expand Down
50 changes: 50 additions & 0 deletions library/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions library/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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("")
Expand Down Expand Up @@ -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())
}
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 50b0181

Please sign in to comment.