Skip to content

Commit

Permalink
handle no projects impacted case
Browse files Browse the repository at this point in the history
  • Loading branch information
motatoes committed Jan 25, 2024
1 parent c2eea85 commit 8ecc62e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
11 changes: 9 additions & 2 deletions backend/controllers/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,10 @@ func handlePullRequestEvent(gh utils.GithubClientProvider, payload *github.PullR
utils.InitCommentReporter(ghService, prNumber, fmt.Sprintf(":x: Failed to comment initial status for jobs: %v", err))
return fmt.Errorf("failed to comment initial status for jobs")
}

if len(jobsForImpactedProjects) == 0 {
return nil
}

err = utils.SetPRStatusForJobs(ghService, prNumber, jobsForImpactedProjects)
if err != nil {
Expand Down Expand Up @@ -573,7 +577,7 @@ func handleIssueCommentEvent(gh utils.GithubClientProvider, payload *github.Issu
issueNumber := *payload.Issue.Number

if *payload.Action != "created" {
log.Printf("comment is not created, ignoring")
log.Printf("comment is not of type 'created', ignoring")
return nil
}

Expand Down Expand Up @@ -610,7 +614,6 @@ func handleIssueCommentEvent(gh utils.GithubClientProvider, payload *github.Issu
}

jobs, _, err := dg_github.ConvertGithubIssueCommentEventToJobs(payload, impactedProjects, requestedProject, config.Workflows, prBranchName)

if err != nil {
log.Printf("Error converting event to jobs: %v", err)
utils.InitCommentReporter(ghService, issueNumber, fmt.Sprintf(":x: Error converting event to jobs: %v", err))
Expand All @@ -625,6 +628,10 @@ func handleIssueCommentEvent(gh utils.GithubClientProvider, payload *github.Issu
return fmt.Errorf("failed to comment initial status for jobs")
}

if len(jobs) == 0 {
return nil
}

err = utils.SetPRStatusForJobs(ghService, issueNumber, jobs)
if err != nil {
log.Printf("error setting status for PR: %v", err)
Expand Down
21 changes: 21 additions & 0 deletions backend/utils/pr_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,27 @@ func InitCommentReporter(prService *github2.GithubService, prNumber int, comment
}

func ReportInitialJobsStatus(cr *CommentReporter, jobs []orchestrator.Job) error {
prNumber := cr.PrNumber
prService := cr.PrService
commentId := cr.CommentId
message := ""
if len(jobs) == 0 {
message = message + ":construction_worker: The following projects are impacted\n\n"
for _, job := range jobs {
message = message + fmt.Sprintf(""+
"<!-- PROJECTHOLDER %v -->\n"+
":clock11: **%v**: pending...\n"+
"<!-- PROJECTHOLDEREND %v -->\n"+
"", job.ProjectName, job.ProjectName, job.ProjectName)
}
} else {
message = message + ":construction_worker: No projects impacted"
}
err := prService.EditComment(prNumber, commentId, message)
return err
}

func ReportNoProjectsImpacted(cr *CommentReporter, jobs []orchestrator.Job) error {
prNumber := cr.PrNumber
prService := cr.PrService
commentId := cr.CommentId
Expand Down

0 comments on commit 8ecc62e

Please sign in to comment.