From 8a5856e65aa53a5672090590c9cf462e61f438b4 Mon Sep 17 00:00:00 2001 From: Noah Lee Date: Fri, 24 May 2024 14:42:15 +0900 Subject: [PATCH] feat: Handle merge conflicts and commit status check failures in CreateRemoteDeployment This commit modifies the CreateRemoteDeployment function in the `deployment.go` file. It adds logic to handle merge conflicts and commit status check failures when creating a remote deployment. If a merge conflict is detected, the function returns an error message instructing the user to resolve the conflict before retrying. If a commit status check fails, the function returns an error message indicating that a commit status check has failed. Refactor the commit message to adhere to the established conventions. --- internal/pkg/github/deployment.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/internal/pkg/github/deployment.go b/internal/pkg/github/deployment.go index 1ee57637..83723721 100644 --- a/internal/pkg/github/deployment.go +++ b/internal/pkg/github/deployment.go @@ -32,9 +32,21 @@ func (g *Github) CreateRemoteDeployment(ctx context.Context, u *ent.User, r *ent ProductionEnvironment: env.ProductionEnvironment, }) if res.StatusCode == http.StatusConflict { + // Determine if there is a merge conflict or a commit status check failed. + // https://github.com/gitploy-io/gitploy/issues/526 + for _, es := range err.(*github.ErrorResponse).Errors { + if es.Field == "required_contexts" { + return nil, e.NewErrorWithMessage( + e.ErrorCodeEntityUnprocessable, + "A commit status check failed.", + err, + ) + } + } + return nil, e.NewErrorWithMessage( e.ErrorCodeEntityUnprocessable, - "There is merge conflict or a commit status check failed.", + "There is merge conflict. Retry after resolving the conflict.", err, ) } else if res.StatusCode == http.StatusUnprocessableEntity {