Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
Reduce return values
Browse files Browse the repository at this point in the history
  • Loading branch information
duck8823 committed Aug 26, 2018
1 parent aeea678 commit 1939553
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions presentation/controller/webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (c *JobController) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}

ctx, repo, ref, sha, command, err := c.parseIssueComment(event, requestId, runtimeUrl)
ctx, repo, head, command, err := c.parseIssueComment(event, requestId, runtimeUrl)
if err == SkipBuild {
logger.Info(requestId, "skip build")
w.WriteHeader(http.StatusOK)
Expand All @@ -66,8 +66,8 @@ func (c *JobController) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}

c.GitHub.CreateCommitStatus(ctx, repo, plumbing.NewHash(sha), github.PENDING, "waiting...")
go c.Runner.Run(ctx, repo, ref, command...)
c.GitHub.CreateCommitStatus(ctx, repo, plumbing.NewHash(head.GetSHA()), github.PENDING, "waiting...")
go c.Runner.Run(ctx, repo, head.GetRef(), command...)
case "push":
event := &go_github.PushEvent{}
if err := json.NewDecoder(r.Body).Decode(event); err != nil {
Expand Down Expand Up @@ -97,27 +97,27 @@ func (c *JobController) parseIssueComment(
event *go_github.IssueCommentEvent,
requestId uuid.UUID,
url *url.URL,
) (ctx context.Context, repo *go_github.Repository, ref string, sha string, command []string, err error) {
) (ctx context.Context, repo *go_github.Repository, head *go_github.PullRequestBranch, command []string, err error) {

if !isValidAction(event.Action) {
return nil, nil, "", "", nil, SkipBuild
return nil, nil, nil, nil, SkipBuild
}

if !regexp.MustCompile("^ci\\s+[^\\s]+").Match([]byte(event.Comment.GetBody())) {
return nil, nil, "", "", nil, SkipBuild
return nil, nil, nil, nil, SkipBuild
}
phrase := regexp.MustCompile("^ci\\s+").ReplaceAllString(event.Comment.GetBody(), "")
command = strings.Split(phrase, " ")
ctx = context.New(fmt.Sprintf("%s/pr/%s", application.Name, command[0]), requestId, url)

pr, err := c.GitHub.GetPullRequest(ctx, event.GetRepo(), event.GetIssue().GetNumber())
if err != nil {
return nil, nil, "", "", nil, errors.WithStack(err)
return nil, nil, nil, nil, errors.WithStack(err)
}

repo = event.GetRepo()
ref = fmt.Sprintf("refs/heads/%s", pr.GetHead().GetRef())
sha = pr.GetHead().GetSHA()
return ctx, repo, ref, sha, command, err
head = pr.GetHead()
return ctx, repo, head, command, err
}

func isValidAction(action *string) bool {
Expand Down

0 comments on commit 1939553

Please sign in to comment.