fix(github): harden auto-merge and surface task automation (#3128)
This commit is contained in:
@@ -86,6 +86,7 @@ func (c *Controller) RegisterHTTPRoutes(router *gin.Engine) {
|
||||
api.DELETE("/tasks/:taskId/issue", c.httpUnlinkTaskIssue)
|
||||
api.GET("/tasks/:taskId/ci-options", c.httpGetTaskCIOptions)
|
||||
api.PATCH("/tasks/:taskId/ci-options", c.httpPatchTaskCIOptions)
|
||||
api.POST("/tasks/:taskId/ci-automation/retry-merge", c.httpRetryTaskCIAutoMerge)
|
||||
|
||||
api.GET("/prs/:owner/:repo/:number", c.httpGetPRFeedback)
|
||||
api.GET("/prs/:owner/:repo/:number/info", c.httpGetPRInfo)
|
||||
@@ -407,6 +408,48 @@ func (c *Controller) httpPatchTaskCIOptions(ctx *gin.Context) {
|
||||
ctx.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
type retryTaskCIAutoMergeRequest struct {
|
||||
RepositoryID string `json:"repository_id"`
|
||||
PRNumber int `json:"pr_number"`
|
||||
}
|
||||
|
||||
func (c *Controller) httpRetryTaskCIAutoMerge(ctx *gin.Context) {
|
||||
var request retryTaskCIAutoMergeRequest
|
||||
if err := ctx.ShouldBindJSON(&request); err != nil || strings.TrimSpace(request.RepositoryID) == "" || request.PRNumber <= 0 {
|
||||
ctx.JSON(http.StatusBadRequest, gin.H{"error": "repository_id and pr_number are required"})
|
||||
return
|
||||
}
|
||||
pr, err := c.service.RetryTaskCIAutoMerge(
|
||||
ctx.Request.Context(), ctx.Param("taskId"), strings.TrimSpace(request.RepositoryID), request.PRNumber,
|
||||
)
|
||||
if err != nil {
|
||||
if errors.Is(err, ErrTaskCIMergeRetryNotAllowed) {
|
||||
ctx.JSON(http.StatusConflict, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.writeTaskCIOptionsError(ctx, err, "retry merge", "failed to retry automatic merge")
|
||||
return
|
||||
}
|
||||
var publishErr error
|
||||
if c.service == nil || c.service.eventBus == nil {
|
||||
publishErr = errors.New("event bus unavailable")
|
||||
} else {
|
||||
event := bus.NewEvent(events.GitHubTaskPRUpdated, "github", pr)
|
||||
publishErr = c.service.eventBus.Publish(ctx.Request.Context(), events.GitHubTaskPRUpdated, event)
|
||||
}
|
||||
if publishErr != nil {
|
||||
if clearErr := c.service.ClearTaskCIMergeRetryAuthorization(
|
||||
ctx.Request.Context(), pr.TaskID, pr.RepositoryID, pr.PRNumber,
|
||||
); clearErr != nil {
|
||||
c.logger.Debug("clear automatic merge retry authorization failed",
|
||||
zap.String("task_id", pr.TaskID), zap.Error(clearErr))
|
||||
}
|
||||
c.writeTaskCIOptionsError(ctx, publishErr, "publish automatic merge retry", "failed to queue automatic merge retry")
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusAccepted, gin.H{"accepted": true})
|
||||
}
|
||||
|
||||
func (c *Controller) writeTaskCIOptionsError(ctx *gin.Context, err error, operation, message string) {
|
||||
if errors.Is(err, ErrTaskNotFound) ||
|
||||
errors.Is(err, repoerrors.ErrWorkspaceNotFound) ||
|
||||
|
||||
Reference in New Issue
Block a user