Skip to content

Commit

Permalink
Add detail to errors and log successful actions (#1970)
Browse files Browse the repository at this point in the history
  • Loading branch information
bstoll authored Aug 2, 2023
1 parent dc63f44 commit 5e0af39
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
4 changes: 2 additions & 2 deletions tools/ci-trigger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ func ghWebhook(_ http.ResponseWriter, r *http.Request) {
case *github.PullRequestEvent:
if event.GetAction() == "opened" || event.GetAction() == "synchronize" {
if err := t.processPullRequest(r.Context(), event); err != nil {
glog.Errorf("ProcessPullRequest error: %s", err)
glog.Errorf("ProcessPullRequest PR%d user %q error: %s", event.GetPullRequest().GetNumber(), event.GetPullRequest().GetUser().GetLogin(), err)
return
}
}
case *github.IssueCommentEvent:
if event.GetAction() == "created" {
if err := t.processIssueComment(r.Context(), event); err != nil {
glog.Errorf("ProcessIssueComment error: %s", err)
glog.Errorf("ProcessIssueComment PR%d comment %d user %q error: %s", event.GetIssue().GetNumber(), event.GetComment().GetID(), event.GetComment().GetUser().GetLogin(), err)
return
}
}
Expand Down
3 changes: 2 additions & 1 deletion tools/ci-trigger/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ func (p *pullRequest) createBuild(ctx context.Context, buildClient *cloudbuild.S
}
jobID, logURL, err := cb.submitBuild(ctx)
if err != nil {
return fmt.Errorf("error creating CloudBuild job for PR%d: %w", p.ID, err)
return fmt.Errorf("submitBuild device %q: %w", virtualDevice.Type.String(), err)
}
glog.Infof("Created CloudBuild Job %s for PR%d at commit %q for device %q", jobID, p.ID, p.HeadSHA, virtualDevice.Type.String())
p.Virtual[i].CloudBuildID = jobID
p.Virtual[i].CloudBuildLogURL = logURL
vendor := strings.ToLower(virtualDevice.Type.Vendor.String())
Expand Down
29 changes: 17 additions & 12 deletions tools/ci-trigger/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"strings"

"cloud.google.com/go/storage"
"github.com/golang/glog"
"github.com/google/go-github/v50/github"
"golang.org/x/oauth2"
"google.golang.org/api/cloudbuild/v1"
Expand Down Expand Up @@ -53,9 +54,10 @@ func (t *trigger) processIssueComment(ctx context.Context, e *github.IssueCommen
return nil
}

auth, err := t.authorizedUser(ctx, e.GetComment().GetUser().GetLogin())
requestingUser := e.GetComment().GetUser().GetLogin()
auth, err := t.authorizedUser(ctx, requestingUser)
if err != nil {
return fmt.Errorf("validating user auth: %w", err)
return fmt.Errorf("validate user %q auth: %w", requestingUser, err)
}
if !auth {
return nil
Expand Down Expand Up @@ -91,23 +93,24 @@ func (t *trigger) processIssueComment(ctx context.Context, e *github.IssueCommen
localPath: tmpDir,
}
if err := pr.identifyModifiedTests(); err != nil {
return fmt.Errorf("identify modified tests: %w", err)
return fmt.Errorf("identify modified tests for commit %q: %w", pr.HeadSHA, err)
}

pr.populateObjectMetadata(ctx, t.storClient)

for keyword, deviceTypes := range triggerKeywords {
if strings.Contains(strings.ToLower(e.GetComment().GetBody()), keyword) {
glog.Infof("User %q launching CloudBuild jobs for PR%d at commit %q", requestingUser, pr.ID, pr.HeadSHA)
if err := pr.createBuild(ctx, t.buildClient, t.storClient, deviceTypes); err != nil {
return fmt.Errorf("create build: %w", err)
return fmt.Errorf("create build for commit %q: %w", pr.HeadSHA, err)
}

if err := pr.updateBadges(ctx, t.storClient); err != nil {
return fmt.Errorf("update GCS badges: %w", err)
return fmt.Errorf("update GCS badges for commit %q: %w", pr.HeadSHA, err)
}

if err := pr.updateGitHub(ctx, t.githubClient); err != nil {
return fmt.Errorf("update GitHub PR: %w", err)
return fmt.Errorf("update GitHub PR for commit %q: %w", pr.HeadSHA, err)
}

break
Expand All @@ -133,25 +136,27 @@ func (t *trigger) processPullRequest(ctx context.Context, e *github.PullRequestE
localPath: tmpDir,
}
if err := pr.identifyModifiedTests(); err != nil {
return fmt.Errorf("identify modified tests: %w", err)
return fmt.Errorf("identify modified tests for commit %q: %w", pr.HeadSHA, err)
}

auth, err := t.authorizedUser(ctx, e.GetPullRequest().GetUser().GetLogin())
requestingUser := e.GetPullRequest().GetUser().GetLogin()
auth, err := t.authorizedUser(ctx, requestingUser)
if err != nil {
return fmt.Errorf("validating user auth: %w", err)
return fmt.Errorf("validate user %q auth: %w", requestingUser, err)
}
if auth {
glog.Infof("User %q launching jobs for PR%d at commit %q", requestingUser, pr.ID, pr.HeadSHA)
if err := pr.createBuild(ctx, t.buildClient, t.storClient, virtualDeviceTypes); err != nil {
return fmt.Errorf("create build: %w", err)
return fmt.Errorf("create build for commit %q: %w", pr.HeadSHA, err)
}
}

if err := pr.updateBadges(ctx, t.storClient); err != nil {
return fmt.Errorf("update GCS badges: %w", err)
return fmt.Errorf("update GCS badges for commit %q: %w", pr.HeadSHA, err)
}

if err := pr.updateGitHub(ctx, t.githubClient); err != nil {
return fmt.Errorf("update GitHub: %w", err)
return fmt.Errorf("update GitHub PR for commit %q: %w", pr.HeadSHA, err)
}

return nil
Expand Down

0 comments on commit 5e0af39

Please sign in to comment.