diff --git a/presentation/controller/webhooks.go b/presentation/controller/webhooks.go index b96d1c2a..7b0a11a6 100644 --- a/presentation/controller/webhooks.go +++ b/presentation/controller/webhooks.go @@ -54,7 +54,7 @@ func (c *JobController) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } - ctx, repo, ref, command, err := c.parseIssueComment(event, requestId, runtimeUrl) + ctx, repo, ref, sha, command, err := c.parseIssueComment(event, requestId, runtimeUrl) if err == SkipBuild { logger.Info(requestId, "skip build") w.WriteHeader(http.StatusOK) @@ -65,14 +65,7 @@ func (c *JobController) ServeHTTP(w http.ResponseWriter, r *http.Request) { http.Error(w, err.Error(), http.StatusInternalServerError) return } - pr, err := c.GitHub.GetPullRequest(ctx, repo, event.GetIssue().GetNumber()) - if err != nil { - logger.Errorf(requestId, "%+v", err) - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - sha := pr.GetHead().GetSHA() c.GitHub.CreateCommitStatus(ctx, repo, plumbing.NewHash(sha), github.PENDING, "waiting...") go c.Runner.Run(ctx, repo, ref, command...) case "push": @@ -104,13 +97,13 @@ func (c *JobController) parseIssueComment( event *go_github.IssueCommentEvent, requestId uuid.UUID, url *url.URL, -) (ctx context.Context, repo *go_github.Repository, ref string, command []string, err error) { +) (ctx context.Context, repo *go_github.Repository, ref string, sha string, command []string, err error) { if !isValidAction(event.Action) { - return nil, nil, "", nil, SkipBuild + return nil, nil, "", "", nil, SkipBuild } if !regexp.MustCompile("^ci\\s+[^\\s]+").Match([]byte(event.Comment.GetBody())) { - return nil, nil, "", nil, SkipBuild + return nil, nil, "", "", nil, SkipBuild } phrase := regexp.MustCompile("^ci\\s+").ReplaceAllString(event.Comment.GetBody(), "") command = strings.Split(phrase, " ") @@ -118,12 +111,13 @@ func (c *JobController) parseIssueComment( 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, errors.WithStack(err) } repo = event.GetRepo() ref = fmt.Sprintf("refs/heads/%s", pr.GetHead().GetRef()) - return ctx, repo, ref, command, err + sha = pr.GetHead().GetSHA() + return ctx, repo, ref, sha, command, err } func isValidAction(action *string) bool {