feat(forge): report a close refused for open dependencies as a typed status (archie #1922)
publish / publish (push) Successful in 1m42s
publish / publish (push) Successful in 1m42s
This commit is contained in:
4 files changed
+30
-4
No files matched your search
@@ -433,11 +433,16 @@ func (c *GiteaClient) CloseIssue(ctx context.Context, owner, repo string, number
|
||||
}
|
||||
}
|
||||
state := gitea.StateClosed
|
||||
if _, _, err := c.api(ctx).EditIssue(owner, repo, int64(number), gitea.EditIssueOption{State: &state}); err != nil {
|
||||
return fmt.Errorf("close issue %s/%s#%d: %w", owner, repo, number, err)
|
||||
}
|
||||
_, resp, err := c.api(ctx).EditIssue(owner, repo, int64(number), gitea.EditIssueOption{State: &state})
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
// Gitea answers 412 when an issue still has open dependencies.
|
||||
if resp != nil && resp.StatusCode == http.StatusPreconditionFailed {
|
||||
return fmt.Errorf("close issue %s/%s#%d: %w: %w", owner, repo, number, forge.ErrBlockedByDependencies, err)
|
||||
}
|
||||
return fmt.Errorf("close issue %s/%s#%d: %w", owner, repo, number, err)
|
||||
}
|
||||
|
||||
// ClosePR closes a pull request without merging, with an optional final
|
||||
// comment.
|
||||
|
||||
@@ -17,6 +17,7 @@ require (
|
||||
github.com/hashicorp/go-plugin v1.8.0
|
||||
github.com/hashicorp/vault/api v1.23.0
|
||||
golang.org/x/crypto v0.55.0
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20260706201446-f0a921348800
|
||||
google.golang.org/grpc v1.84.0
|
||||
google.golang.org/protobuf v1.36.12
|
||||
)
|
||||
@@ -57,5 +58,4 @@ require (
|
||||
golang.org/x/term v0.45.0 // indirect
|
||||
golang.org/x/text v0.41.0 // indirect
|
||||
golang.org/x/time v0.12.0 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20260706201446-f0a921348800 // indirect
|
||||
)
|
||||
@@ -2,12 +2,17 @@ package forge
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// ErrBlockedByDependencies is wrapped by a forge's CloseIssue when the forge
|
||||
// refuses to close an issue that still has open dependencies.
|
||||
var ErrBlockedByDependencies = errors.New("forge refused: open dependencies")
|
||||
|
||||
// Config is what the host hands a forge extension once, after launch.
|
||||
type Config struct {
|
||||
Host string
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
||||
"google.golang.org/genproto/googleapis/rpc/errdetails"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
@@ -69,9 +70,24 @@ func fail(err error) error {
|
||||
if errors.Is(err, errors.ErrUnsupported) {
|
||||
return status.Error(codes.Unimplemented, err.Error())
|
||||
}
|
||||
if errors.Is(err, ErrBlockedByDependencies) {
|
||||
return blockedByDependencies(err)
|
||||
}
|
||||
return status.Error(codes.Unknown, err.Error())
|
||||
}
|
||||
|
||||
// blockedByDependencies carries the refusal as a FailedPrecondition with an
|
||||
// ErrorInfo detail, which the host reads to tell a dependency block from a
|
||||
// generic failure.
|
||||
func blockedByDependencies(err error) error {
|
||||
st := status.New(codes.FailedPrecondition, err.Error())
|
||||
withDetails, derr := st.WithDetails(&errdetails.ErrorInfo{Reason: "BLOCKED_BY_DEPENDENCIES", Domain: "archie.forge"})
|
||||
if derr != nil {
|
||||
return st.Err()
|
||||
}
|
||||
return withDetails.Err()
|
||||
}
|
||||
|
||||
func issues(in []Issue) []*forgev1.Issue {
|
||||
out := make([]*forgev1.Issue, 0, len(in))
|
||||
for _, i := range in {
|
||||
|
||||
Reference in new issue
Block a user