From d3f1d210ab4a1b989ec40416086b2ae58b50182b Mon Sep 17 00:00:00 2001 From: Jon Bodner Date: Fri, 22 Apr 2016 15:29:52 -0400 Subject: [PATCH 1/2] Factor approval code so that it works with both comment validation and version detection. Implement the org-based approval. --- approval/approval.go | 25 +++++++------- approval/org/org.go | 78 ++++++++++++++++++++++++++++++++++++++++++++ web/comment_hook.go | 12 ++++++- web/status_hook.go | 64 ++++++++++++++---------------------- 4 files changed, 125 insertions(+), 54 deletions(-) create mode 100644 approval/org/org.go diff --git a/approval/approval.go b/approval/approval.go index edbe867..566e656 100644 --- a/approval/approval.go +++ b/approval/approval.go @@ -9,13 +9,13 @@ import ( // Func takes in the information needed to figure out which approvers were in the PR comments // and returns a slice of the approvers that were found -type Func func (*model.Config, *model.Maintainer, *model.Issue, []*model.Comment) []*model.Person +type Func func(*model.Config, *model.Maintainer, *model.Issue, []*model.Comment, Processor) var approvalMap = map[string]Func{} func Register(name string, f Func) error { if _, ok := approvalMap[strings.ToLower(name)]; ok { - return fmt.Errorf("Approval Algorithm %s is already registered.",name) + return fmt.Errorf("Approval Algorithm %s is already registered.", name) } approvalMap[strings.ToLower(name)] = f return nil @@ -24,7 +24,7 @@ func Register(name string, f Func) error { func Lookup(name string) (Func, error) { f, ok := approvalMap[strings.ToLower(name)] if !ok { - return nil, fmt.Errorf("Unknown Approval Algorithm %s",name) + return nil, fmt.Errorf("Unknown Approval Algorithm %s", name) } return f, nil } @@ -33,16 +33,17 @@ func init() { Register("simple", Simple) } +type Processor func(*model.Maintainer, *model.Comment) + // Simple is a helper function that analyzes the list of comments -// and returns the list of approvers. -func Simple(config *model.Config, maintainer *model.Maintainer, issue *model.Issue, comments []*model.Comment) []*model.Person { +// and finds the ones that have approvers on the maintainers list. +func Simple(config *model.Config, maintainer *model.Maintainer, issue *model.Issue, comments []*model.Comment, p Processor) { approverm := map[string]bool{} - approvers := []*model.Person{} matcher, err := regexp.Compile(config.Pattern) if err != nil { // this should never happen - return approvers + return } for _, comment := range comments { @@ -51,7 +52,7 @@ func Simple(config *model.Config, maintainer *model.Maintainer, issue *model.Iss continue } // the user must be a valid maintainer of the project - person, ok := maintainer.People[comment.Author] + _, ok := maintainer.People[comment.Author] if !ok { continue } @@ -62,11 +63,7 @@ func Simple(config *model.Config, maintainer *model.Maintainer, issue *model.Iss // verify the comment matches the approval pattern if matcher.MatchString(comment.Body) { approverm[comment.Author] = true - approvers = append(approvers, person) + p(maintainer, comment) } } - - return approvers -} - - +} \ No newline at end of file diff --git a/approval/org/org.go b/approval/org/org.go new file mode 100644 index 0000000..b693044 --- /dev/null +++ b/approval/org/org.go @@ -0,0 +1,78 @@ +package org + +import ( + "regexp" + "github.com/lgtmco/lgtm/model" + "github.com/lgtmco/lgtm/approval" +) + +func init() { + approval.Register("org", Org) +} + +// Org is a helper function that analyzes the list of comments +// and returns the list of approvers. +// The rules for Org are: +// - At most one approver from each team +// - If SelfApprovalOff is true, no member of the team of the creator of the Pull Request is allowed to approve the PR +// - If a person appears on more than one team, they only count once, for the first team in which they appear +// (not solving the optimal grouping problem yet) +func Org(config *model.Config, maintainer *model.Maintainer, issue *model.Issue, comments []*model.Comment, p approval.Processor) { + //groups that have already approved + approvergm := map[string]bool{} + + //org that the author belongs to + authorOrg := "" + + //key is person, value is map of the orgs for that person + orgMap := map[string]map[string]bool{} + + //key is org name, value is org + for k, v := range maintainer.Org { + //value is name of person in the org + for _, name := range v.People { + if name == issue.Author { + authorOrg = name + } + m, ok := orgMap[name] + if !ok { + m := map[string]bool{} + orgMap[name] = m + } + m[k] = true + } + } + + matcher, err := regexp.Compile(config.Pattern) + if err != nil { + // this should never happen + return + } + + for _, comment := range comments { + // verify the comment matches the approval pattern + if !matcher.MatchString(comment.Body) { + continue + } + //get the orgs for the current comment's author + curOrgs, ok := orgMap[comment.Author] + if !ok { + // the user must be a valid maintainer of the project + continue + } + for curOrg := range curOrgs { + // your group cannot lgtm your own pull request + if config.SelfApprovalOff && curOrg == authorOrg { + continue + } + // your group cannot approve twice + if approvergm[curOrg] { + continue + } + //found one! + approvergm[curOrg] = true + p(maintainer, comment) + } + } + return +} diff --git a/web/comment_hook.go b/web/comment_hook.go index 4a0db80..075c68a 100644 --- a/web/comment_hook.go +++ b/web/comment_hook.go @@ -30,7 +30,8 @@ func processCommentHook(c *gin.Context, hook *model.Hook) { c.String(500, "Error getting approval algorithm %s. %s", config.ApprovalAlg, err) return } - approvers := alg(config, maintainer, hook.Issue, comments) + approvers := getApprovers(config, maintainer, hook.Issue, comments, alg) + approved := len(approvers) >= config.Approvals err = remote.SetStatus(c, user, repo, hook.Issue.Number, approved) if err != nil { @@ -48,3 +49,12 @@ func processCommentHook(c *gin.Context, hook *model.Hook) { "approved_by": approvers, }) } + +func getApprovers(config *model.Config, maintainer *model.Maintainer, + issue *model.Issue, comments []*model.Comment, matcher approval.Func) []*model.Person { + approvers := []*model.Person{} + matcher(config, maintainer, issue, comments, func(maintainer *model.Maintainer, comment *model.Comment) { + approvers = append(approvers, maintainer.People[comment.Author]) + }) + return approvers +} diff --git a/web/status_hook.go b/web/status_hook.go index fb0e074..232782d 100644 --- a/web/status_hook.go +++ b/web/status_hook.go @@ -8,6 +8,7 @@ import ( log "github.com/Sirupsen/logrus" "github.com/hashicorp/go-version" "regexp" + "github.com/lgtmco/lgtm/approval" ) type StatusResponse struct { @@ -76,7 +77,14 @@ func processStatusHook(c *gin.Context, hook *model.StatusHook) { continue } - foundVersion := getMaxVersionComment(config, maintainer, v.Issue,comments) + alg, err := approval.Lookup(config.ApprovalAlg) + if err != nil { + log.Errorf("Error getting approval algorithm %s. %s", config.ApprovalAlg, err) + c.String(500, "Error getting approval algorithm %s. %s", config.ApprovalAlg, err) + return + } + + foundVersion := getMaxVersionComment(config, maintainer, v.Issue, comments, alg) if foundVersion != nil && foundVersion.GreaterThan(maxVer) { maxVer = foundVersion @@ -104,50 +112,28 @@ func processStatusHook(c *gin.Context, hook *model.StatusHook) { // getMaxVersionComment is a helper function that analyzes the list of comments // and returns the maximum version found in a comment. -func getMaxVersionComment(config *model.Config, maintainer *model.Maintainer, issue model.Issue, comments []*model.Comment) *version.Version { - approverm := map[string]bool{} - approvers := []*model.Person{} - - matcher, err := regexp.Compile(config.Pattern) +func getMaxVersionComment(config *model.Config, maintainer *model.Maintainer, + issue model.Issue, comments []*model.Comment, matcher approval.Func) *version.Version { + var maxVersion *version.Version + ma, err := regexp.Compile(config.Pattern) if err != nil { - // this should never happen + //this should never happen return nil } - - var maxVersion *version.Version - - for _, comment := range comments { - // cannot lgtm your own pull request - if config.SelfApprovalOff && comment.Author == issue.Author { - continue - } - // the user must be a valid maintainer of the project - person, ok := maintainer.People[comment.Author] - if !ok { - continue - } - // the same author can't approve something twice - if _, ok := approverm[comment.Author]; ok { - continue - } + matcher(config, maintainer, &issue, comments, func(maintainer *model.Maintainer, comment *model.Comment) { // verify the comment matches the approval pattern - m := matcher.FindStringSubmatch(comment.Body) - if len(m) > 0 { - approverm[comment.Author] = true - approvers = append(approvers, person) - - if len(m) > 1 { - //has a version - curVersion, err := version.NewVersion(m[1]) - if err != nil { - continue - } - if maxVersion == nil || curVersion.GreaterThan(maxVersion) { - maxVersion = curVersion - } + m := ma.FindStringSubmatch(comment.Body) + if len(m) > 1 { + //has a version + curVersion, err := version.NewVersion(m[1]) + if err != nil { + return + } + if maxVersion == nil || curVersion.GreaterThan(maxVersion) { + maxVersion = curVersion } } - } + }) return maxVersion } From d00feaeac999b5748027c15cc41ec93fe75fbf1a Mon Sep 17 00:00:00 2001 From: Jon Bodner Date: Thu, 5 May 2016 15:52:35 -0400 Subject: [PATCH 2/2] Merge timestamp changes from master into branch. --- web/status_hook.go | 33 +++---- web/status_hook_test.go | 186 ++++++++++++++++++++-------------------- 2 files changed, 111 insertions(+), 108 deletions(-) diff --git a/web/status_hook.go b/web/status_hook.go index 8862735..bfbb5a0 100644 --- a/web/status_hook.go +++ b/web/status_hook.go @@ -2,14 +2,14 @@ package web import ( "fmt" + log "github.com/Sirupsen/logrus" "github.com/gin-gonic/gin" + "github.com/hashicorp/go-version" + "github.com/lgtmco/lgtm/approval" "github.com/lgtmco/lgtm/model" "github.com/lgtmco/lgtm/remote" - log "github.com/Sirupsen/logrus" - "github.com/hashicorp/go-version" "regexp" "time" - "github.com/lgtmco/lgtm/approval" ) type StatusResponse struct { @@ -29,8 +29,7 @@ func processStatusHook(c *gin.Context, hook *model.StatusHook) { } if !config.DoMerge { - c.IndentedJSON(200, gin.H{ - }) + c.IndentedJSON(200, gin.H{}) return } @@ -91,18 +90,18 @@ func processStatusHook(c *gin.Context, hook *model.StatusHook) { log.Debugf("processed status for %s. received %v ", repo.Slug, hook) c.IndentedJSON(200, gin.H{ - "merged": merged, + "merged": merged, }) } func handleTimestamp(config *model.Config) (*string, error) { /* - All times are in UTC - Valid format strings: - - A standard Go format string - - blank or rfc3339: RFC 3339 format - - millis: milliseconds since the epoch - */ + All times are in UTC + Valid format strings: + - A standard Go format string + - blank or rfc3339: RFC 3339 format + - millis: milliseconds since the epoch + */ curTime := time.Now().UTC() var format string switch config.VersionFormat { @@ -145,7 +144,7 @@ func handleSemver(c *gin.Context, user *model.User, hook *model.StatusHook, pr m maxVer = foundVersion } else { maxParts := maxVer.Segments() - maxVer, _ = version.NewVersion(fmt.Sprintf("%d.%d.%d", maxParts[0], maxParts[1], maxParts[2] + 1)) + maxVer, _ = version.NewVersion(fmt.Sprintf("%d.%d.%d", maxParts[0], maxParts[1], maxParts[2]+1)) } verStr := maxVer.String() @@ -175,13 +174,15 @@ func getMaxExistingTag(tags []model.Tag) *version.Version { // getMaxVersionComment is a helper function that analyzes the list of comments // and returns the maximum version found in a comment. if no matching comment is found, -// the function returns version 0.0.0 +// the function returns version 0.0.0. If there's a bug in the version pattern, +// nil will be returned. func getMaxVersionComment(config *model.Config, maintainer *model.Maintainer, -issue model.Issue, comments []*model.Comment, matcher approval.Func) *version.Version { + issue model.Issue, comments []*model.Comment, matcher approval.Func) *version.Version { maxVersion, _ := version.NewVersion("0.0.0") ma, err := regexp.Compile(config.Pattern) if err != nil { - //this should never happen + //this should never happen, unless a bad pattern was provided by the user + log.Errorf("Invalid version pattern provided so no comment version tagging will be done: %s", config.Pattern) return nil } matcher(config, maintainer, &issue, comments, func(maintainer *model.Maintainer, comment *model.Comment) { diff --git a/web/status_hook_test.go b/web/status_hook_test.go index ffbbc06..f45f569 100644 --- a/web/status_hook_test.go +++ b/web/status_hook_test.go @@ -1,44 +1,45 @@ package web import ( - "testing" - "github.com/lgtmco/lgtm/model" - "time" - "strconv" - "math" + "errors" "fmt" - "github.com/lgtmco/lgtm/remote" "github.com/gin-gonic/gin" "github.com/hashicorp/go-version" - "errors" + "github.com/lgtmco/lgtm/model" + "github.com/lgtmco/lgtm/remote" + "math" "net/http" + "strconv" + "testing" + "time" + "github.com/lgtmco/lgtm/approval" ) func TestHandleTimestampMillis(t *testing.T) { - c := &model.Config { + c := &model.Config{ VersionFormat: "millis", } stamp, err := handleTimestamp(c) if err != nil { - t.Errorf("didn't expect error: %v",err) + t.Errorf("didn't expect error: %v", err) } m := time.Now().UTC().Unix() m1, err := strconv.ParseInt(*stamp, 10, 64) if err != nil { t.Error(err) } - if math.Abs(float64(m-m1)) > 100 { + if math.Abs(float64(m - m1)) > 100 { t.Errorf("shouldn't be that different: %d, %d", m, m1) } } func TestHandleTimestampBlank(t *testing.T) { - c := &model.Config { + c := &model.Config{ VersionFormat: "", } stamp, err := handleTimestamp(c) if err != nil { - t.Errorf("didn't expect error: %v",err) + t.Errorf("didn't expect error: %v", err) } //should be able to parse with rfc3339 t2, err := time.Parse(time.RFC3339, *stamp) @@ -53,12 +54,12 @@ func TestHandleTimestampBlank(t *testing.T) { } func TestHandleTimestamp3339(t *testing.T) { - c := &model.Config { + c := &model.Config{ VersionFormat: "rfc3339", } stamp, err := handleTimestamp(c) if err != nil { - t.Errorf("didn't expect error: %v",err) + t.Errorf("didn't expect error: %v", err) } //should be able to parse with rfc3339 t2, err := time.Parse(time.RFC3339, *stamp) @@ -74,12 +75,12 @@ func TestHandleTimestamp3339(t *testing.T) { func TestHandleTimestampCustom(t *testing.T) { //01/02 03:04:05PM '06 -0700 - c := &model.Config { + c := &model.Config{ VersionFormat: "Jan 2 2006, 3:04:05 PM", } stamp, err := handleTimestamp(c) if err != nil { - t.Errorf("didn't expect error: %v",err) + t.Errorf("didn't expect error: %v", err) } //should be able to parse with custom t2, err := time.Parse(c.VersionFormat, *stamp) @@ -98,7 +99,7 @@ type myR struct { } func (m *myR) ListTags(u *model.User, r *model.Repo) ([]model.Tag, error) { - return []model.Tag { + return []model.Tag{ "a", "0.1.0", "0.0.1", @@ -109,27 +110,27 @@ func (m *myR) GetComments(u *model.User, r *model.Repo, num int) ([]*model.Comme return []*model.Comment{ { Author: "test_guy", - Body: "LGTM 0.1.0", + Body: "LGTM 0.1.0", }, { Author: "not_test_guy", - Body: "this is not an LGTM comment", + Body: "this is not an LGTM comment", }, { Author: "not_test_guy", - Body: "LGTM", + Body: "LGTM", }, { Author: "test_guy", - Body: "LGTM 0.1.0", + Body: "LGTM 0.1.0", }, { Author: "test_guy2", - Body: "LGTM", + Body: "LGTM", }, { Author: "test_guy3", - Body: "LGTM 0.0.1", + Body: "LGTM 0.0.1", }, }, nil } @@ -138,9 +139,9 @@ func TestGetMaxVersionComment(t *testing.T) { c := &gin.Context{} remote.ToContext(c, &myR{}) - config := &model.Config { + config := &model.Config{ DoVersion: true, - Pattern: `(?i)LGTM\s*(\S*)`, + Pattern: `(?i)LGTM\s*(\S*)`, } m := &model.Maintainer{ People: map[string]*model.Person{ @@ -161,30 +162,31 @@ func TestGetMaxVersionComment(t *testing.T) { comments := []*model.Comment{ { Author: "test_guy", - Body: "LGTM 0.1.0", + Body: "LGTM 0.1.0", }, { Author: "not_test_guy", - Body: "this is not an LGTM comment", + Body: "this is not an LGTM comment", }, { Author: "not_test_guy", - Body: "LGTM", + Body: "LGTM", }, { Author: "test_guy", - Body: "LGTM 0.1.0", + Body: "LGTM 0.1.0", }, { Author: "test_guy2", - Body: "LGTM", + Body: "LGTM", }, { Author: "test_guy3", - Body: "LGTM 0.0.1", + Body: "LGTM 0.0.1", }, } - ver := getMaxVersionComment(config, m, i, comments) + alg, _ := approval.Lookup("simple") + ver := getMaxVersionComment(config, m, i, comments, alg) if ver == nil { t.Fatalf("Got nil for version") } @@ -198,9 +200,9 @@ func TestGetMaxVersionCommentBadPattern(t *testing.T) { c := &gin.Context{} remote.ToContext(c, &myR{}) - config := &model.Config { + config := &model.Config{ DoVersion: true, - Pattern: `?i)LGTM\s*(\S*)`, + Pattern: `?i)LGTM\s*(\S*)`, } m := &model.Maintainer{ People: map[string]*model.Person{ @@ -221,40 +223,37 @@ func TestGetMaxVersionCommentBadPattern(t *testing.T) { comments := []*model.Comment{ { Author: "test_guy", - Body: "LGTM 0.1.0", + Body: "LGTM 0.1.0", }, { Author: "not_test_guy", - Body: "this is not an LGTM comment", + Body: "this is not an LGTM comment", }, { Author: "not_test_guy", - Body: "LGTM", + Body: "LGTM", }, { Author: "test_guy", - Body: "not an approval comment", + Body: "not an approval comment", }, { Author: "test_guy", - Body: "LGTM 0.1.0", + Body: "LGTM 0.1.0", }, { Author: "test_guy2", - Body: "LGTM", + Body: "LGTM", }, { Author: "test_guy3", - Body: "LGTM 0.0.1", + Body: "LGTM 0.0.1", }, } - ver := getMaxVersionComment(config, m, i, comments) - if ver == nil { - t.Fatalf("Got nil for version") - } - expected, _ := version.NewVersion("0.0.0") - if !expected.Equal(ver) { - t.Errorf("Expected %s, got %s", expected.String(), ver.String()) + alg, _ := approval.Lookup("simple") + ver := getMaxVersionComment(config, m, i, comments, alg) + if ver != nil { + t.Fatalf("Should get nil for version") } } @@ -262,9 +261,9 @@ func TestGetMaxVersionCommentNoSelfApproval(t *testing.T) { c := &gin.Context{} remote.ToContext(c, &myR{}) - config := &model.Config { - DoVersion: true, - Pattern: `(?i)LGTM\s*(\S*)`, + config := &model.Config{ + DoVersion: true, + Pattern: `(?i)LGTM\s*(\S*)`, SelfApprovalOff: true, } m := &model.Maintainer{ @@ -286,30 +285,31 @@ func TestGetMaxVersionCommentNoSelfApproval(t *testing.T) { comments := []*model.Comment{ { Author: "test_guy", - Body: "LGTM 0.1.0", + Body: "LGTM 0.1.0", }, { Author: "not_test_guy", - Body: "this is not an LGTM comment", + Body: "this is not an LGTM comment", }, { Author: "not_test_guy", - Body: "LGTM", + Body: "LGTM", }, { Author: "test_guy", - Body: "LGTM 0.1.0", + Body: "LGTM 0.1.0", }, { Author: "test_guy2", - Body: "LGTM", + Body: "LGTM", }, { Author: "test_guy3", - Body: "LGTM 0.0.1", + Body: "LGTM 0.0.1", }, } - ver := getMaxVersionComment(config, m, i, comments) + alg, _ := approval.Lookup("simple") + ver := getMaxVersionComment(config, m, i, comments, alg) if ver == nil { t.Fatalf("Got nil for version") } @@ -319,9 +319,8 @@ func TestGetMaxVersionCommentNoSelfApproval(t *testing.T) { } } - func TestGetMaxExistingTagFound(t *testing.T) { - ver := getMaxExistingTag([]model.Tag { + ver := getMaxExistingTag([]model.Tag{ "a", "0.1.0", "0.0.1", @@ -334,7 +333,7 @@ func TestGetMaxExistingTagFound(t *testing.T) { } func TestGetMaxExistingTagNotFound(t *testing.T) { - ver := getMaxExistingTag([]model.Tag { + ver := getMaxExistingTag([]model.Tag{ "a", "b", "c", @@ -350,9 +349,10 @@ func TestHandleSemver(t *testing.T) { c := &gin.Context{} remote.ToContext(c, &myR{}) - config := &model.Config { + config := &model.Config{ DoVersion: true, - Pattern: `(?i)LGTM\s*(\S*)`, + Pattern: `(?i)LGTM\s*(\S*)`, + ApprovalAlg: "simple", } m := &model.Maintainer{ People: map[string]*model.Person{ @@ -367,12 +367,12 @@ func TestHandleSemver(t *testing.T) { }, }, } - user := &model.User {} + user := &model.User{} repo := &model.Repo{} hook := &model.StatusHook{ Repo: &model.Repo{ Owner: "test_guy", - Name: "test_repo", + Name: "test_repo", }, } pr := model.PullRequest{ @@ -395,7 +395,7 @@ type myR2 struct { } func (m *myR2) ListTags(u *model.User, r *model.Repo) ([]model.Tag, error) { - return []model.Tag { + return []model.Tag{ "a", "0.0.1", "0.0.2", @@ -406,27 +406,27 @@ func (m *myR2) GetComments(u *model.User, r *model.Repo, num int) ([]*model.Comm return []*model.Comment{ { Author: "test_guy", - Body: "LGTM 0.1.0", + Body: "LGTM 0.1.0", }, { Author: "not_test_guy", - Body: "this is not an LGTM comment", + Body: "this is not an LGTM comment", }, { Author: "not_test_guy", - Body: "LGTM", + Body: "LGTM", }, { Author: "test_guy", - Body: "LGTM 0.1.0", + Body: "LGTM 0.1.0", }, { Author: "test_guy2", - Body: "LGTM", + Body: "LGTM", }, { Author: "test_guy3", - Body: "LGTM 0.0.1", + Body: "LGTM 0.0.1", }, }, nil } @@ -435,9 +435,10 @@ func TestHandleSemver2(t *testing.T) { c := &gin.Context{} remote.ToContext(c, &myR2{}) - config := &model.Config { + config := &model.Config{ DoVersion: true, - Pattern: `(?i)LGTM\s*(\S*)`, + Pattern: `(?i)LGTM\s*(\S*)`, + ApprovalAlg: "simple", } m := &model.Maintainer{ People: map[string]*model.Person{ @@ -452,12 +453,12 @@ func TestHandleSemver2(t *testing.T) { }, }, } - user := &model.User {} + user := &model.User{} repo := &model.Repo{} hook := &model.StatusHook{ Repo: &model.Repo{ Owner: "test_guy", - Name: "test_repo", + Name: "test_repo", }, } pr := model.PullRequest{ @@ -487,27 +488,27 @@ func (m *myR3) GetComments(u *model.User, r *model.Repo, num int) ([]*model.Comm return []*model.Comment{ { Author: "test_guy", - Body: "LGTM 0.1.0", + Body: "LGTM 0.1.0", }, { Author: "not_test_guy", - Body: "this is not an LGTM comment", + Body: "this is not an LGTM comment", }, { Author: "not_test_guy", - Body: "LGTM", + Body: "LGTM", }, { Author: "test_guy", - Body: "LGTM 0.1.0", + Body: "LGTM 0.1.0", }, { Author: "test_guy2", - Body: "LGTM", + Body: "LGTM", }, { Author: "test_guy3", - Body: "LGTM 0.0.1", + Body: "LGTM 0.0.1", }, }, nil } @@ -516,9 +517,10 @@ func TestHandleSemver3(t *testing.T) { c := &gin.Context{} remote.ToContext(c, &myR3{}) - config := &model.Config { + config := &model.Config{ DoVersion: true, - Pattern: `(?i)LGTM\s*(\S*)`, + Pattern: `(?i)LGTM\s*(\S*)`, + ApprovalAlg: "simple", } m := &model.Maintainer{ People: map[string]*model.Person{ @@ -533,12 +535,12 @@ func TestHandleSemver3(t *testing.T) { }, }, } - user := &model.User {} + user := &model.User{} repo := &model.Repo{} hook := &model.StatusHook{ Repo: &model.Repo{ Owner: "test_guy", - Name: "test_repo", + Name: "test_repo", }, } pr := model.PullRequest{ @@ -561,7 +563,7 @@ type myR4 struct { } func (m *myR4) ListTags(u *model.User, r *model.Repo) ([]model.Tag, error) { - return []model.Tag { + return []model.Tag{ "a", "0.0.1", "0.0.2", @@ -572,7 +574,6 @@ func (m *myR4) GetComments(u *model.User, r *model.Repo, num int) ([]*model.Comm return nil, errors.New("This is an error") } - type myRR struct { gin.ResponseWriter } @@ -591,9 +592,10 @@ func TestHandleSemver4(t *testing.T) { } remote.ToContext(c, &myR4{}) - config := &model.Config { + config := &model.Config{ DoVersion: true, - Pattern: `(?i)LGTM\s*(\S*)`, + Pattern: `(?i)LGTM\s*(\S*)`, + ApprovalAlg: "simple", } m := &model.Maintainer{ People: map[string]*model.Person{ @@ -608,12 +610,12 @@ func TestHandleSemver4(t *testing.T) { }, }, } - user := &model.User {} + user := &model.User{} repo := &model.Repo{} hook := &model.StatusHook{ Repo: &model.Repo{ Owner: "test_guy", - Name: "test_repo", + Name: "test_repo", }, } pr := model.PullRequest{