From db9a19fd2a2732128701d0524c3c5711d0cbc276 Mon Sep 17 00:00:00 2001 From: Jon Bodner Date: Thu, 19 May 2016 18:18:14 -0400 Subject: [PATCH] Remove unused code --- remote/github/github.go | 69 ----------------------------------------- remote/mock/remote.go | 23 -------------- remote/remote.go | 23 -------------- web/push_hook.go | 29 ----------------- 4 files changed, 144 deletions(-) delete mode 100644 web/push_hook.go diff --git a/remote/github/github.go b/remote/github/github.go index 08b4040..98b38a0 100644 --- a/remote/github/github.go +++ b/remote/github/github.go @@ -440,65 +440,6 @@ func (g *Github) GetPRHook(r *http.Request) (*model.PRHook, error) { return hook, nil } -func (g *Github) GetPushHook(r *http.Request) (*model.PushHook, error) { - - // only process comment hooks - if r.Header.Get("X-Github-Event") != "push" { - return nil, nil - } - - data := pushHook{} - err := json.NewDecoder(r.Body).Decode(&data) - if err != nil { - return nil, err - } - - log.Debug(data) - - if data.HeadCommit == nil { - return nil, nil - } - - hook := new(model.PushHook) - - hook.SHA = data.HeadCommit.ID - hook.Repo = new(model.Repo) - hook.Repo.Owner = data.Repository.Owner.Login - hook.Repo.Name = data.Repository.Name - hook.Repo.Slug = data.Repository.FullName - - log.Debug(*hook) - - return hook, nil -} - -func (g *Github) UpdatePRsForCommit(u *model.User, r *model.Repo, sha *string) (bool, error) { - //if we have a new commit on an existing open PR, then we need to put a new pending LGTM status on it - //if the commit is not associated with an open PR, then we don't do any status update - client := setupClient(g.API, u.Token) - log.Debug("sha == ", *sha) - issues, _, err := client.Search.Issues(fmt.Sprintf("%s&type=pr", *sha), &github.SearchOptions{ - TextMatch: false, - }) - if err != nil { - return false, err - } - if issues.Total != nil && *issues.Total > 0 { - status := "pending" - desc := "this commit is pending approval" - - data := github.RepoStatus{ - Context: github.String(context), - State: github.String(status), - Description: github.String(desc), - } - - _, _, err = client.Repositories.CreateStatus(r.Owner, r.Name, *sha, &data) - return true, err - } - return false, nil -} - func (g *Github) GetPullRequestsForCommit(u *model.User, r *model.Repo, sha *string) ([]model.PullRequest, error) { client := setupClient(g.API, u.Token) log.Debug("sha == ", *sha) @@ -562,16 +503,6 @@ func (g *Github) GetPullRequestsForCommit(u *model.User, r *model.Repo, sha *str return out, nil } -func (g *Github) GetBranchStatus(u *model.User, r *model.Repo, branch string) (*model.BranchStatus, error) { - client := setupClient(g.API, u.Token) - statuses, _, err := client.Repositories.GetCombinedStatus(r.Owner, r.Name, branch, nil) - if err != nil { - return nil, err - } - - return (*model.BranchStatus)(statuses.State), nil -} - func (g *Github) MergePR(u *model.User, r *model.Repo, pullRequest model.PullRequest, approvers []*model.Person) (*string, error) { client := setupClient(g.API, u.Token) diff --git a/remote/mock/remote.go b/remote/mock/remote.go index 33f92f4..9b36534 100644 --- a/remote/mock/remote.go +++ b/remote/mock/remote.go @@ -27,29 +27,6 @@ func (_m *Remote) DelHook(_a0 *model.User, _a1 *model.Repo, _a2 string) error { return r0 } -// GetBranchStatus provides a mock function with given fields: _a0, _a1, _a2 -func (_m *Remote) GetBranchStatus(_a0 *model.User, _a1 *model.Repo, _a2 string) (*model.BranchStatus, error) { - ret := _m.Called(_a0, _a1, _a2) - - var r0 *model.BranchStatus - if rf, ok := ret.Get(0).(func(*model.User, *model.Repo, string) *model.BranchStatus); ok { - r0 = rf(_a0, _a1, _a2) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*model.BranchStatus) - } - } - - var r1 error - if rf, ok := ret.Get(1).(func(*model.User, *model.Repo, string) error); ok { - r1 = rf(_a0, _a1, _a2) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - // GetComments provides a mock function with given fields: _a0, _a1, _a2 func (_m *Remote) GetComments(_a0 *model.User, _a1 *model.Repo, _a2 int) ([]*model.Comment, error) { ret := _m.Called(_a0, _a1, _a2) diff --git a/remote/remote.go b/remote/remote.go index cb5e2c9..19317ec 100644 --- a/remote/remote.go +++ b/remote/remote.go @@ -59,12 +59,6 @@ type Remote interface { // GetPRHook gets the pull request hook from the http Request. GetPRHook(r *http.Request) (*model.PRHook, error) - // GetPushHook gets the push hook from the http Request. - GetPushHook(r *http.Request) (*model.PushHook, error) - - // GetBranchStatus returns overall status for the named branch from the remote system - GetBranchStatus(*model.User, *model.Repo, string) (*model.BranchStatus, error) - // MergePR merges the named pull request from the remote system MergePR(u *model.User, r *model.Repo, pullRequest model.PullRequest, approvers []*model.Person) (*string, error) @@ -77,9 +71,6 @@ type Remote interface { // GetPullRequestsForCommit returns all pull requests associated with a commit SHA GetPullRequestsForCommit(u *model.User, r *model.Repo, sha *string) ([]model.PullRequest, error) - // UpdatePRsForCommit sets the commit's status to pending for LGTM if it is already on an open Pull Request - UpdatePRsForCommit(u *model.User, r *model.Repo, sha *string) (bool, error) - // WriteComment puts a new comment from LGTM into the PR WriteComment(u *model.User, r *model.Repo, num int, message string) error } @@ -165,16 +156,6 @@ func GetPRHook(c context.Context, r *http.Request) (*model.PRHook, error) { return FromContext(c).GetPRHook(r) } -// GetPushHook gets the push hook from the http Request. -func GetPushHook(c context.Context, r *http.Request) (*model.PushHook, error) { - return FromContext(c).GetPushHook(r) -} - -// GetBranchStatus gets the overal status for a branch from the remote repository. -func GetBranchStatus(c context.Context, u *model.User, r *model.Repo, branch string) (*model.BranchStatus, error) { - return FromContext(c).GetBranchStatus(u, r, branch) -} - func MergePR(c context.Context, u *model.User, r *model.Repo, pullRequest model.PullRequest, approvers []*model.Person) (*string, error) { return FromContext(c).MergePR(u, r, pullRequest, approvers) } @@ -192,10 +173,6 @@ func GetPullRequestsForCommit(c context.Context, u *model.User, r *model.Repo, s } -func UpdatePRsForCommit(c context.Context, u *model.User, r *model.Repo, sha *string) (bool, error) { - return FromContext(c).UpdatePRsForCommit(u, r, sha) -} - func WriteComment(c context.Context, u *model.User, r *model.Repo, num int, message string) error { return FromContext(c).WriteComment(u, r, num, message) } diff --git a/web/push_hook.go b/web/push_hook.go deleted file mode 100644 index f2d9d1e..0000000 --- a/web/push_hook.go +++ /dev/null @@ -1,29 +0,0 @@ -package web - -import ( - log "github.com/Sirupsen/logrus" - "github.com/gin-gonic/gin" - "github.com/lgtmco/lgtm/model" - "github.com/lgtmco/lgtm/remote" -) - -func processPushHook(c *gin.Context, pushHook *model.PushHook) { - repo, user, err := getRepoAndUser(c, pushHook.Repo.Slug) - if err != nil { - return - } - updated, err := remote.UpdatePRsForCommit(c, user, repo, &pushHook.SHA) - if err != nil { - log.Errorf("Error setting status. %s", err) - c.String(500, "Error setting status. %s", err) - return - } - if updated { - c.IndentedJSON(200, gin.H{ - "commit": pushHook.SHA, - "status": "pending", - }) - } else { - c.IndentedJSON(200, gin.H{}) - } -}