Skip to content

Commit e40aac8

Browse files
authored
automerge failure patch (#1917)
* automerge failure patch * grammar * add extra logging
1 parent 3378761 commit e40aac8

File tree

3 files changed

+87
-38
lines changed

3 files changed

+87
-38
lines changed

backend/controllers/projects.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,10 @@ func (d DiggerController) SetJobStatusForProject(c *gin.Context) {
493493
err = AutomergePRforBatchIfEnabled(d.GithubClientProvider, batch)
494494
if err != nil {
495495
log.Printf("Error merging PR with automerge option: %v", err)
496-
c.JSON(http.StatusInternalServerError, gin.H{"error": "Error merging PR with automerge option"})
496+
err = utils.PostCommentForBatch(job.Batch, fmt.Sprintf(":yellow_circle: Warning could not automerge PR, please remember to merge it manually. Error: (%v)", err), d.GithubClientProvider)
497+
if err != nil {
498+
log.Printf("Error while posting comment about automerge: %v", err)
499+
}
497500
}
498501

499502
// return batch summary to client

backend/utils/batch_utils.go

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package utils
2+
3+
import (
4+
"fmt"
5+
"github.com/diggerhq/digger/backend/models"
6+
"log"
7+
)
8+
9+
func PostCommentForBatch(batch *models.DiggerBatch, comment string, githubClientProvider GithubClientProvider) error {
10+
// todo: perform for rest of vcs as well
11+
if batch.VCS == models.DiggerVCSGithub {
12+
ghService, _, err := GetGithubService(githubClientProvider, batch.GithubInstallationId, batch.RepoFullName, batch.RepoOwner, batch.RepoName)
13+
if err != nil {
14+
log.Printf("error getting ghService: %v", err)
15+
return fmt.Errorf("error getting ghService: %v", err)
16+
}
17+
_, err = ghService.PublishComment(batch.PrNumber, comment)
18+
if err != nil {
19+
log.Printf("error publishing comment (%v): %v", comment, err)
20+
return fmt.Errorf("error publishing comment (%v): %v", comment, err)
21+
}
22+
return nil
23+
}
24+
log.Printf("Warning: Unknown vcs type: %v", batch.VCS)
25+
return nil
26+
}

0 commit comments

Comments
 (0)