Skip to content

Commit

Permalink
deleting user field
Browse files Browse the repository at this point in the history
  • Loading branch information
Claire.Nicholas authored and Claire.Nicholas committed Dec 20, 2023
1 parent 6af9667 commit 55d9167
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 54 deletions.
9 changes: 0 additions & 9 deletions database/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ type Deployment struct {
Number sql.NullInt64 `sql:"number"`
RepoID sql.NullInt64 `sql:"repo_id"`
URL sql.NullString `sql:"url"`
User sql.NullString `sql:"user"`
Commit sql.NullString `sql:"commit"`
Ref sql.NullString `sql:"ref"`
Task sql.NullString `sql:"task"`
Expand Down Expand Up @@ -71,11 +70,6 @@ func (d *Deployment) Nullify() *Deployment {
d.URL.Valid = false
}

// check if the User field should be false
if len(d.User.String) == 0 {
d.User.Valid = false
}

// check if the Commit field should be false
if len(d.Commit.String) == 0 {
d.Commit.Valid = false
Expand Down Expand Up @@ -123,7 +117,6 @@ func (d *Deployment) ToLibrary(builds *[]library.Build) *library.Deployment {
deployment.SetNumber(d.Number.Int64)
deployment.SetRepoID(d.RepoID.Int64)
deployment.SetURL(d.URL.String)
deployment.SetUser(d.User.String)
deployment.SetCommit(d.Commit.String)
deployment.SetRef(d.Ref.String)
deployment.SetTask(d.Task.String)
Expand Down Expand Up @@ -153,7 +146,6 @@ func (d *Deployment) Validate() error {
// ensure that all Deployment string fields
// that can be returned as JSON are sanitized
// to avoid unsafe HTML content
d.User = sql.NullString{String: sanitize(d.User.String), Valid: d.User.Valid}
d.Commit = sql.NullString{String: sanitize(d.Commit.String), Valid: d.Commit.Valid}
d.Ref = sql.NullString{String: sanitize(d.Ref.String), Valid: d.Ref.Valid}
d.Task = sql.NullString{String: sanitize(d.Task.String), Valid: d.Task.Valid}
Expand All @@ -176,7 +168,6 @@ func DeploymentFromLibrary(d *library.Deployment) *Deployment {
Number: sql.NullInt64{Int64: d.GetNumber(), Valid: true},
RepoID: sql.NullInt64{Int64: d.GetRepoID(), Valid: true},
URL: sql.NullString{String: d.GetURL(), Valid: true},
User: sql.NullString{String: d.GetUser(), Valid: true},
Commit: sql.NullString{String: d.GetCommit(), Valid: true},
Ref: sql.NullString{String: d.GetRef(), Valid: true},
Task: sql.NullString{String: d.GetTask(), Valid: true},
Expand Down
4 changes: 0 additions & 4 deletions database/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ func TestDatabase_Deployment_Nullify(t *testing.T) {
Number: sql.NullInt64{Int64: 0, Valid: false},
RepoID: sql.NullInt64{Int64: 0, Valid: false},
URL: sql.NullString{String: "", Valid: false},
User: sql.NullString{String: "", Valid: false},
Commit: sql.NullString{String: "", Valid: false},
Ref: sql.NullString{String: "", Valid: false},
Task: sql.NullString{String: "", Valid: false},
Expand Down Expand Up @@ -69,7 +68,6 @@ func TestDatabase_Deployment_ToLibrary(t *testing.T) {
want.SetNumber(1)
want.SetRepoID(1)
want.SetURL("https://github.com/github/octocat/deployments/1")
want.SetUser("octocat")
want.SetCommit("1234")
want.SetRef("refs/heads/main")
want.SetTask("deploy:vela")
Expand Down Expand Up @@ -136,7 +134,6 @@ func TestDatabase_DeploymentFromLibrary(t *testing.T) {
d.SetNumber(1)
d.SetRepoID(1)
d.SetURL("https://github.com/github/octocat/deployments/1")
d.SetUser("octocat")
d.SetCommit("1234")
d.SetRef("refs/heads/main")
d.SetTask("deploy:vela")
Expand Down Expand Up @@ -164,7 +161,6 @@ func testDeployment() *Deployment {
Number: sql.NullInt64{Int64: 1, Valid: true},
RepoID: sql.NullInt64{Int64: 1, Valid: true},
URL: sql.NullString{String: "https://github.com/github/octocat/deployments/1", Valid: true},
User: sql.NullString{String: "octocat", Valid: true},
Commit: sql.NullString{String: "1234", Valid: true},
Ref: sql.NullString{String: "refs/heads/main", Valid: true},
Task: sql.NullString{String: "deploy:vela", Valid: true},
Expand Down
29 changes: 0 additions & 29 deletions library/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ type Deployment struct {
Number *int64 `json:"number,omitempty"`
RepoID *int64 `json:"repo_id,omitempty"`
URL *string `json:"url,omitempty"`
User *string `json:"user,omitempty"`
Commit *string `json:"commit,omitempty"`
Ref *string `json:"ref,omitempty"`
Task *string `json:"task,omitempty"`
Expand Down Expand Up @@ -80,19 +79,6 @@ func (d *Deployment) GetURL() string {
return *d.URL
}

// GetUser returns the User field.
//
// When the provided Deployment type is nil, or the field within
// the type is nil, it returns the zero value for the field.
func (d *Deployment) GetUser() string {
// return zero value if Deployment type or User field is nil
if d == nil || d.User == nil {
return ""
}

return *d.User
}

// GetCommit returns the Commit field.
//
// When the provided Deployment type is nil, or the field within
Expand Down Expand Up @@ -261,19 +247,6 @@ func (d *Deployment) SetURL(v string) {
d.URL = &v
}

// SetUser sets the User field.
//
// When the provided Deployment type is nil, it
// will set nothing and immediately return.
func (d *Deployment) SetUser(v string) {
// return if Deployment type is nil
if d == nil {
return
}

d.User = &v
}

// SetCommit sets the Commit field.
//
// When the provided Deployment type is nil, it
Expand Down Expand Up @@ -405,7 +378,6 @@ func (d *Deployment) String() string {
Target: %s,
Task: %s,
URL: %s,
User: %s,
Payload: %s,
Builds: %d,
}`,
Expand All @@ -420,7 +392,6 @@ func (d *Deployment) String() string {
d.GetTarget(),
d.GetTask(),
d.GetURL(),
d.GetUser(),
d.GetPayload(),
len(d.GetBuilds()),
)
Expand Down
12 changes: 0 additions & 12 deletions library/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ func TestLibrary_Deployment_Getters(t *testing.T) {
t.Errorf("GetURL is %v, want %v", test.deployment.GetURL(), test.want.GetURL())
}

if test.deployment.GetUser() != test.want.GetUser() {
t.Errorf("GetUser is %v, want %v", test.deployment.GetUser(), test.want.GetUser())
}

if test.deployment.GetCommit() != test.want.GetCommit() {
t.Errorf("GetCommit is %v, want %v", test.deployment.GetCommit(), test.want.GetCommit())
}
Expand Down Expand Up @@ -101,7 +97,6 @@ func TestLibrary_Deployment_Setters(t *testing.T) {
test.deployment.SetNumber(test.want.GetNumber())
test.deployment.SetRepoID(test.want.GetRepoID())
test.deployment.SetURL(test.want.GetURL())
test.deployment.SetUser(test.want.GetUser())
test.deployment.SetCommit(test.want.GetCommit())
test.deployment.SetRef(test.want.GetRef())
test.deployment.SetTask(test.want.GetTask())
Expand All @@ -127,10 +122,6 @@ func TestLibrary_Deployment_Setters(t *testing.T) {
t.Errorf("SetURL is %v, want %v", test.deployment.GetURL(), test.want.GetURL())
}

if test.deployment.GetUser() != test.want.GetUser() {
t.Errorf("SetUser is %v, want %v", test.deployment.GetUser(), test.want.GetUser())
}

if test.deployment.GetCommit() != test.want.GetCommit() {
t.Errorf("SetCommit is %v, want %v", test.deployment.GetCommit(), test.want.GetCommit())
}
Expand Down Expand Up @@ -181,7 +172,6 @@ func TestLibrary_Deployment_String(t *testing.T) {
Target: %s,
Task: %s,
URL: %s,
User: %s,
Payload: %s,
Builds: %d,
}`,
Expand All @@ -196,7 +186,6 @@ func TestLibrary_Deployment_String(t *testing.T) {
d.GetTarget(),
d.GetTask(),
d.GetURL(),
d.GetUser(),
d.GetPayload(),
len(d.GetBuilds()),
)
Expand All @@ -218,7 +207,6 @@ func testDeployment() *Deployment {
d.SetNumber(0)
d.SetRepoID(1)
d.SetURL("https://api.github.com/repos/github/octocat/deployments/1")
d.SetUser("octocat")
d.SetCommit("48afb5bdc41ad69bf22588491333f7cf71135163")
d.SetRef("refs/heads/main")
d.SetTask("vela-deploy")
Expand Down

0 comments on commit 55d9167

Please sign in to comment.