Skip to content

Commit

Permalink
feat: add comment support for ruleset (#47)
Browse files Browse the repository at this point in the history
* feat: add comment support for ruleset

* feat: add ability for repos to enable comments
  • Loading branch information
Neal committed Apr 8, 2020
1 parent cda7598 commit 5750ec2
Show file tree
Hide file tree
Showing 12 changed files with 404 additions and 294 deletions.
3 changes: 3 additions & 0 deletions constants/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ const (

// EventDeploy defines the event type for build and repo deployment events.
EventDeploy = "deployment"

// EventComment defines the event type for comments added to a pull request.
EventComment = "comment"
)
75 changes: 39 additions & 36 deletions database/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,25 @@ var (

// Repo is the database representation of a repo.
type Repo struct {
ID sql.NullInt64 `sql:"id"`
UserID sql.NullInt64 `sql:"user_id"`
Hash sql.NullString `sql:"hash"`
Org sql.NullString `sql:"org"`
Name sql.NullString `sql:"name"`
FullName sql.NullString `sql:"full_name"`
Link sql.NullString `sql:"link"`
Clone sql.NullString `sql:"clone"`
Branch sql.NullString `sql:"branch"`
Timeout sql.NullInt64 `sql:"timeout"`
Visibility sql.NullString `sql:"visibility"`
Private sql.NullBool `sql:"private"`
Trusted sql.NullBool `sql:"trusted"`
Active sql.NullBool `sql:"active"`
AllowPull sql.NullBool `sql:"allow_pull"`
AllowPush sql.NullBool `sql:"allow_push"`
AllowDeploy sql.NullBool `sql:"allow_deploy"`
AllowTag sql.NullBool `sql:"allow_tag"`
ID sql.NullInt64 `sql:"id"`
UserID sql.NullInt64 `sql:"user_id"`
Hash sql.NullString `sql:"hash"`
Org sql.NullString `sql:"org"`
Name sql.NullString `sql:"name"`
FullName sql.NullString `sql:"full_name"`
Link sql.NullString `sql:"link"`
Clone sql.NullString `sql:"clone"`
Branch sql.NullString `sql:"branch"`
Timeout sql.NullInt64 `sql:"timeout"`
Visibility sql.NullString `sql:"visibility"`
Private sql.NullBool `sql:"private"`
Trusted sql.NullBool `sql:"trusted"`
Active sql.NullBool `sql:"active"`
AllowPull sql.NullBool `sql:"allow_pull"`
AllowPush sql.NullBool `sql:"allow_push"`
AllowDeploy sql.NullBool `sql:"allow_deploy"`
AllowTag sql.NullBool `sql:"allow_tag"`
AllowComment sql.NullBool `sql:"allow_comment"`
}

// Nullify ensures the valid flag for
Expand Down Expand Up @@ -151,6 +152,7 @@ func (r *Repo) ToLibrary() *library.Repo {
repo.SetAllowPush(r.AllowPush.Bool)
repo.SetAllowDeploy(r.AllowDeploy.Bool)
repo.SetAllowTag(r.AllowTag.Bool)
repo.SetAllowComment(r.AllowComment.Bool)

return repo
}
Expand Down Expand Up @@ -195,24 +197,25 @@ func (r *Repo) Validate() error {
// to a database repo type.
func RepoFromLibrary(r *library.Repo) *Repo {
repo := &Repo{
ID: sql.NullInt64{Int64: r.GetID(), Valid: true},
UserID: sql.NullInt64{Int64: r.GetUserID(), Valid: true},
Hash: sql.NullString{String: r.GetHash(), Valid: true},
Org: sql.NullString{String: r.GetOrg(), Valid: true},
Name: sql.NullString{String: r.GetName(), Valid: true},
FullName: sql.NullString{String: r.GetFullName(), Valid: true},
Link: sql.NullString{String: r.GetLink(), Valid: true},
Clone: sql.NullString{String: r.GetClone(), Valid: true},
Branch: sql.NullString{String: r.GetBranch(), Valid: true},
Timeout: sql.NullInt64{Int64: r.GetTimeout(), Valid: true},
Visibility: sql.NullString{String: r.GetVisibility(), Valid: true},
Private: sql.NullBool{Bool: r.GetPrivate(), Valid: true},
Trusted: sql.NullBool{Bool: r.GetTrusted(), Valid: true},
Active: sql.NullBool{Bool: r.GetActive(), Valid: true},
AllowPull: sql.NullBool{Bool: r.GetAllowPull(), Valid: true},
AllowPush: sql.NullBool{Bool: r.GetAllowPush(), Valid: true},
AllowDeploy: sql.NullBool{Bool: r.GetAllowDeploy(), Valid: true},
AllowTag: sql.NullBool{Bool: r.GetAllowTag(), Valid: true},
ID: sql.NullInt64{Int64: r.GetID(), Valid: true},
UserID: sql.NullInt64{Int64: r.GetUserID(), Valid: true},
Hash: sql.NullString{String: r.GetHash(), Valid: true},
Org: sql.NullString{String: r.GetOrg(), Valid: true},
Name: sql.NullString{String: r.GetName(), Valid: true},
FullName: sql.NullString{String: r.GetFullName(), Valid: true},
Link: sql.NullString{String: r.GetLink(), Valid: true},
Clone: sql.NullString{String: r.GetClone(), Valid: true},
Branch: sql.NullString{String: r.GetBranch(), Valid: true},
Timeout: sql.NullInt64{Int64: r.GetTimeout(), Valid: true},
Visibility: sql.NullString{String: r.GetVisibility(), Valid: true},
Private: sql.NullBool{Bool: r.GetPrivate(), Valid: true},
Trusted: sql.NullBool{Bool: r.GetTrusted(), Valid: true},
Active: sql.NullBool{Bool: r.GetActive(), Valid: true},
AllowPull: sql.NullBool{Bool: r.GetAllowPull(), Valid: true},
AllowPush: sql.NullBool{Bool: r.GetAllowPush(), Valid: true},
AllowDeploy: sql.NullBool{Bool: r.GetAllowDeploy(), Valid: true},
AllowTag: sql.NullBool{Bool: r.GetAllowTag(), Valid: true},
AllowComment: sql.NullBool{Bool: r.GetAllowComment(), Valid: true},
}

return repo.Nullify()
Expand Down
222 changes: 114 additions & 108 deletions database/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,46 @@ import (
func TestDatabase_Repo_Nullify(t *testing.T) {
// setup types
r := &Repo{
ID: sql.NullInt64{Int64: 0, Valid: true},
UserID: sql.NullInt64{Int64: 0, Valid: true},
Hash: sql.NullString{String: "", Valid: true},
Org: sql.NullString{String: "", Valid: true},
Name: sql.NullString{String: "", Valid: true},
FullName: sql.NullString{String: "", Valid: true},
Link: sql.NullString{String: "", Valid: true},
Clone: sql.NullString{String: "", Valid: true},
Branch: sql.NullString{String: "", Valid: true},
Timeout: sql.NullInt64{Int64: 0, Valid: true},
Visibility: sql.NullString{String: "", Valid: true},
Private: sql.NullBool{Bool: false, Valid: true},
Trusted: sql.NullBool{Bool: false, Valid: true},
Active: sql.NullBool{Bool: false, Valid: true},
AllowPull: sql.NullBool{Bool: false, Valid: true},
AllowPush: sql.NullBool{Bool: false, Valid: true},
AllowDeploy: sql.NullBool{Bool: false, Valid: true},
AllowTag: sql.NullBool{Bool: false, Valid: true},
ID: sql.NullInt64{Int64: 0, Valid: true},
UserID: sql.NullInt64{Int64: 0, Valid: true},
Hash: sql.NullString{String: "", Valid: true},
Org: sql.NullString{String: "", Valid: true},
Name: sql.NullString{String: "", Valid: true},
FullName: sql.NullString{String: "", Valid: true},
Link: sql.NullString{String: "", Valid: true},
Clone: sql.NullString{String: "", Valid: true},
Branch: sql.NullString{String: "", Valid: true},
Timeout: sql.NullInt64{Int64: 0, Valid: true},
Visibility: sql.NullString{String: "", Valid: true},
Private: sql.NullBool{Bool: false, Valid: true},
Trusted: sql.NullBool{Bool: false, Valid: true},
Active: sql.NullBool{Bool: false, Valid: true},
AllowPull: sql.NullBool{Bool: false, Valid: true},
AllowPush: sql.NullBool{Bool: false, Valid: true},
AllowDeploy: sql.NullBool{Bool: false, Valid: true},
AllowTag: sql.NullBool{Bool: false, Valid: true},
AllowComment: sql.NullBool{Bool: false, Valid: true},
}
want := &Repo{
ID: sql.NullInt64{Int64: 0, Valid: false},
UserID: sql.NullInt64{Int64: 0, Valid: false},
Hash: sql.NullString{String: "", Valid: false},
Org: sql.NullString{String: "", Valid: false},
Name: sql.NullString{String: "", Valid: false},
FullName: sql.NullString{String: "", Valid: false},
Link: sql.NullString{String: "", Valid: false},
Clone: sql.NullString{String: "", Valid: false},
Branch: sql.NullString{String: "", Valid: false},
Timeout: sql.NullInt64{Int64: 0, Valid: false},
Visibility: sql.NullString{String: "", Valid: false},
Private: sql.NullBool{Bool: false, Valid: true},
Trusted: sql.NullBool{Bool: false, Valid: true},
Active: sql.NullBool{Bool: false, Valid: true},
AllowPull: sql.NullBool{Bool: false, Valid: true},
AllowPush: sql.NullBool{Bool: false, Valid: true},
AllowDeploy: sql.NullBool{Bool: false, Valid: true},
AllowTag: sql.NullBool{Bool: false, Valid: true},
ID: sql.NullInt64{Int64: 0, Valid: false},
UserID: sql.NullInt64{Int64: 0, Valid: false},
Hash: sql.NullString{String: "", Valid: false},
Org: sql.NullString{String: "", Valid: false},
Name: sql.NullString{String: "", Valid: false},
FullName: sql.NullString{String: "", Valid: false},
Link: sql.NullString{String: "", Valid: false},
Clone: sql.NullString{String: "", Valid: false},
Branch: sql.NullString{String: "", Valid: false},
Timeout: sql.NullInt64{Int64: 0, Valid: false},
Visibility: sql.NullString{String: "", Valid: false},
Private: sql.NullBool{Bool: false, Valid: true},
Trusted: sql.NullBool{Bool: false, Valid: true},
Active: sql.NullBool{Bool: false, Valid: true},
AllowPull: sql.NullBool{Bool: false, Valid: true},
AllowPush: sql.NullBool{Bool: false, Valid: true},
AllowDeploy: sql.NullBool{Bool: false, Valid: true},
AllowTag: sql.NullBool{Bool: false, Valid: true},
AllowComment: sql.NullBool{Bool: false, Valid: true},
}

// run test
Expand Down Expand Up @@ -82,44 +84,46 @@ func TestDatabase_Repo_ToLibrary(t *testing.T) {
num64 := int64(num)
str := "foo"
want := &library.Repo{
ID: &num64,
UserID: &num64,
Hash: &str,
Org: &str,
Name: &str,
FullName: &str,
Link: &str,
Clone: &str,
Branch: &str,
Timeout: &num64,
Visibility: &str,
Private: &booL,
Trusted: &booL,
Active: &booL,
AllowPull: &booL,
AllowPush: &booL,
AllowDeploy: &booL,
AllowTag: &booL,
ID: &num64,
UserID: &num64,
Hash: &str,
Org: &str,
Name: &str,
FullName: &str,
Link: &str,
Clone: &str,
Branch: &str,
Timeout: &num64,
Visibility: &str,
Private: &booL,
Trusted: &booL,
Active: &booL,
AllowPull: &booL,
AllowPush: &booL,
AllowDeploy: &booL,
AllowTag: &booL,
AllowComment: &booL,
}
r := &Repo{
ID: sql.NullInt64{Int64: num64, Valid: true},
UserID: sql.NullInt64{Int64: num64, Valid: true},
Hash: sql.NullString{String: str, Valid: true},
Org: sql.NullString{String: str, Valid: true},
Name: sql.NullString{String: str, Valid: true},
FullName: sql.NullString{String: str, Valid: true},
Link: sql.NullString{String: str, Valid: true},
Clone: sql.NullString{String: str, Valid: true},
Branch: sql.NullString{String: str, Valid: true},
Timeout: sql.NullInt64{Int64: num64, Valid: true},
Visibility: sql.NullString{String: str, Valid: true},
Private: sql.NullBool{Bool: booL, Valid: true},
Trusted: sql.NullBool{Bool: booL, Valid: true},
Active: sql.NullBool{Bool: booL, Valid: true},
AllowPull: sql.NullBool{Bool: booL, Valid: true},
AllowPush: sql.NullBool{Bool: booL, Valid: true},
AllowDeploy: sql.NullBool{Bool: booL, Valid: true},
AllowTag: sql.NullBool{Bool: booL, Valid: true},
ID: sql.NullInt64{Int64: num64, Valid: true},
UserID: sql.NullInt64{Int64: num64, Valid: true},
Hash: sql.NullString{String: str, Valid: true},
Org: sql.NullString{String: str, Valid: true},
Name: sql.NullString{String: str, Valid: true},
FullName: sql.NullString{String: str, Valid: true},
Link: sql.NullString{String: str, Valid: true},
Clone: sql.NullString{String: str, Valid: true},
Branch: sql.NullString{String: str, Valid: true},
Timeout: sql.NullInt64{Int64: num64, Valid: true},
Visibility: sql.NullString{String: str, Valid: true},
Private: sql.NullBool{Bool: booL, Valid: true},
Trusted: sql.NullBool{Bool: booL, Valid: true},
Active: sql.NullBool{Bool: booL, Valid: true},
AllowPull: sql.NullBool{Bool: booL, Valid: true},
AllowPush: sql.NullBool{Bool: booL, Valid: true},
AllowDeploy: sql.NullBool{Bool: booL, Valid: true},
AllowTag: sql.NullBool{Bool: booL, Valid: true},
AllowComment: sql.NullBool{Bool: booL, Valid: true},
}

// run test
Expand Down Expand Up @@ -268,44 +272,46 @@ func TestDatabase_RepoFromLibrary(t *testing.T) {
num64 := int64(num)
str := "foo"
want := &Repo{
ID: sql.NullInt64{Int64: num64, Valid: true},
UserID: sql.NullInt64{Int64: num64, Valid: true},
Hash: sql.NullString{String: str, Valid: true},
Org: sql.NullString{String: str, Valid: true},
Name: sql.NullString{String: str, Valid: true},
FullName: sql.NullString{String: str, Valid: true},
Link: sql.NullString{String: str, Valid: true},
Clone: sql.NullString{String: str, Valid: true},
Branch: sql.NullString{String: str, Valid: true},
Timeout: sql.NullInt64{Int64: num64, Valid: true},
Visibility: sql.NullString{String: str, Valid: true},
Private: sql.NullBool{Bool: booL, Valid: true},
Trusted: sql.NullBool{Bool: booL, Valid: true},
Active: sql.NullBool{Bool: booL, Valid: true},
AllowPull: sql.NullBool{Bool: booL, Valid: true},
AllowPush: sql.NullBool{Bool: booL, Valid: true},
AllowDeploy: sql.NullBool{Bool: booL, Valid: true},
AllowTag: sql.NullBool{Bool: booL, Valid: true},
ID: sql.NullInt64{Int64: num64, Valid: true},
UserID: sql.NullInt64{Int64: num64, Valid: true},
Hash: sql.NullString{String: str, Valid: true},
Org: sql.NullString{String: str, Valid: true},
Name: sql.NullString{String: str, Valid: true},
FullName: sql.NullString{String: str, Valid: true},
Link: sql.NullString{String: str, Valid: true},
Clone: sql.NullString{String: str, Valid: true},
Branch: sql.NullString{String: str, Valid: true},
Timeout: sql.NullInt64{Int64: num64, Valid: true},
Visibility: sql.NullString{String: str, Valid: true},
Private: sql.NullBool{Bool: booL, Valid: true},
Trusted: sql.NullBool{Bool: booL, Valid: true},
Active: sql.NullBool{Bool: booL, Valid: true},
AllowPull: sql.NullBool{Bool: booL, Valid: true},
AllowPush: sql.NullBool{Bool: booL, Valid: true},
AllowDeploy: sql.NullBool{Bool: booL, Valid: true},
AllowTag: sql.NullBool{Bool: booL, Valid: true},
AllowComment: sql.NullBool{Bool: booL, Valid: true},
}
r := &library.Repo{
ID: &num64,
UserID: &num64,
Hash: &str,
Org: &str,
Name: &str,
FullName: &str,
Link: &str,
Clone: &str,
Branch: &str,
Timeout: &num64,
Visibility: &str,
Private: &booL,
Trusted: &booL,
Active: &booL,
AllowPull: &booL,
AllowPush: &booL,
AllowDeploy: &booL,
AllowTag: &booL,
ID: &num64,
UserID: &num64,
Hash: &str,
Org: &str,
Name: &str,
FullName: &str,
Link: &str,
Clone: &str,
Branch: &str,
Timeout: &num64,
Visibility: &str,
Private: &booL,
Trusted: &booL,
Active: &booL,
AllowPull: &booL,
AllowPush: &booL,
AllowDeploy: &booL,
AllowTag: &booL,
AllowComment: &booL,
}

// run test
Expand Down
Loading

0 comments on commit 5750ec2

Please sign in to comment.