feat(forge): add CreateIssue to the forge contract (#1770)
Issue-level writes could comment and close but not open an issue, so no curator or workflow stage can file its own work yet. Adds the rpc to proto/forge/v1, regenerates the contracts, and threads it through the domain interface, forgerpc client/server (comment permission, like CloseIssue), forgeext, and the archipelago SDK + gitea/github plugins.
This commit is contained in:
8 files changed
+503
-263
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -23,6 +23,7 @@ const (
|
||||
ForgeService_AssignedIssues_FullMethodName = "/forge.v1.ForgeService/AssignedIssues"
|
||||
ForgeService_IssuesWithLabel_FullMethodName = "/forge.v1.ForgeService/IssuesWithLabel"
|
||||
ForgeService_Comment_FullMethodName = "/forge.v1.ForgeService/Comment"
|
||||
ForgeService_CreateIssue_FullMethodName = "/forge.v1.ForgeService/CreateIssue"
|
||||
ForgeService_CloseIssue_FullMethodName = "/forge.v1.ForgeService/CloseIssue"
|
||||
ForgeService_React_FullMethodName = "/forge.v1.ForgeService/React"
|
||||
ForgeService_SetStateLabel_FullMethodName = "/forge.v1.ForgeService/SetStateLabel"
|
||||
@@ -60,6 +61,7 @@ type ForgeServiceClient interface {
|
||||
AssignedIssues(ctx context.Context, in *AssignedIssuesRequest, opts ...grpc.CallOption) (*AssignedIssuesResponse, error)
|
||||
IssuesWithLabel(ctx context.Context, in *IssuesWithLabelRequest, opts ...grpc.CallOption) (*IssuesWithLabelResponse, error)
|
||||
Comment(ctx context.Context, in *CommentRequest, opts ...grpc.CallOption) (*CommentResponse, error)
|
||||
CreateIssue(ctx context.Context, in *CreateIssueRequest, opts ...grpc.CallOption) (*CreateIssueResponse, error)
|
||||
CloseIssue(ctx context.Context, in *CloseIssueRequest, opts ...grpc.CallOption) (*CloseIssueResponse, error)
|
||||
React(ctx context.Context, in *ReactRequest, opts ...grpc.CallOption) (*ReactResponse, error)
|
||||
SetStateLabel(ctx context.Context, in *SetStateLabelRequest, opts ...grpc.CallOption) (*SetStateLabelResponse, error)
|
||||
@@ -132,6 +134,16 @@ func (c *forgeServiceClient) Comment(ctx context.Context, in *CommentRequest, op
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *forgeServiceClient) CreateIssue(ctx context.Context, in *CreateIssueRequest, opts ...grpc.CallOption) (*CreateIssueResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(CreateIssueResponse)
|
||||
err := c.cc.Invoke(ctx, ForgeService_CreateIssue_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *forgeServiceClient) CloseIssue(ctx context.Context, in *CloseIssueRequest, opts ...grpc.CallOption) (*CloseIssueResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(CloseIssueResponse)
|
||||
@@ -338,6 +350,7 @@ type ForgeServiceServer interface {
|
||||
AssignedIssues(context.Context, *AssignedIssuesRequest) (*AssignedIssuesResponse, error)
|
||||
IssuesWithLabel(context.Context, *IssuesWithLabelRequest) (*IssuesWithLabelResponse, error)
|
||||
Comment(context.Context, *CommentRequest) (*CommentResponse, error)
|
||||
CreateIssue(context.Context, *CreateIssueRequest) (*CreateIssueResponse, error)
|
||||
CloseIssue(context.Context, *CloseIssueRequest) (*CloseIssueResponse, error)
|
||||
React(context.Context, *ReactRequest) (*ReactResponse, error)
|
||||
SetStateLabel(context.Context, *SetStateLabelRequest) (*SetStateLabelResponse, error)
|
||||
@@ -382,6 +395,9 @@ func (UnimplementedForgeServiceServer) IssuesWithLabel(context.Context, *IssuesW
|
||||
func (UnimplementedForgeServiceServer) Comment(context.Context, *CommentRequest) (*CommentResponse, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method Comment not implemented")
|
||||
}
|
||||
func (UnimplementedForgeServiceServer) CreateIssue(context.Context, *CreateIssueRequest) (*CreateIssueResponse, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method CreateIssue not implemented")
|
||||
}
|
||||
func (UnimplementedForgeServiceServer) CloseIssue(context.Context, *CloseIssueRequest) (*CloseIssueResponse, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method CloseIssue not implemented")
|
||||
}
|
||||
@@ -529,6 +545,24 @@ func _ForgeService_Comment_Handler(srv interface{}, ctx context.Context, dec fun
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _ForgeService_CreateIssue_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(CreateIssueRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(ForgeServiceServer).CreateIssue(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: ForgeService_CreateIssue_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(ForgeServiceServer).CreateIssue(ctx, req.(*CreateIssueRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _ForgeService_CloseIssue_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(CloseIssueRequest)
|
||||
if err := dec(in); err != nil {
|
||||
@@ -869,6 +903,10 @@ var ForgeService_ServiceDesc = grpc.ServiceDesc{
|
||||
MethodName: "Comment",
|
||||
Handler: _ForgeService_Comment_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "CreateIssue",
|
||||
Handler: _ForgeService_CreateIssue_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "CloseIssue",
|
||||
Handler: _ForgeService_CloseIssue_Handler,
|
||||
|
||||
@@ -45,6 +45,11 @@ type recordedForge struct {
|
||||
deliveries Deliveries
|
||||
}
|
||||
|
||||
func (f recordedForge) CreateIssue(ctx context.Context, owner, repo, title, _ string, _ []string) (int, error) {
|
||||
f.deliveries.Record(ctx, fmt.Sprintf("open issue %q in %s/%s", title, owner, repo))
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func (f recordedForge) CloseIssue(ctx context.Context, owner, repo string, number int, _ string) error {
|
||||
f.deliveries.Record(ctx, fmt.Sprintf("close issue %s/%s#%d", owner, repo, number))
|
||||
return nil
|
||||
|
||||
@@ -38,6 +38,10 @@ type IssueForge interface {
|
||||
// Comment posts an issue (or PR) comment and returns its id.
|
||||
Comment(ctx context.Context, owner, repo string, number int, body string) (int64, error)
|
||||
|
||||
// CreateIssue opens an issue with title, body and optional labels,
|
||||
// returning its number.
|
||||
CreateIssue(ctx context.Context, owner, repo, title, body string, labels []string) (int, error)
|
||||
|
||||
// CloseIssue closes an issue with an optional final comment.
|
||||
CloseIssue(ctx context.Context, owner, repo string, number int, comment string) error
|
||||
|
||||
|
||||
@@ -30,6 +30,10 @@ func (n *NoopForge) Comment(ctx context.Context, owner, repo string, number int,
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func (n *NoopForge) CreateIssue(ctx context.Context, owner, repo, title, body string, labels []string) (int, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func (n *NoopForge) CloseIssue(ctx context.Context, owner, repo string, number int, comment string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
|
||||
const (
|
||||
SubjectComment = "archie.forge.comment"
|
||||
SubjectCreateIssue = "archie.forge.create_issue"
|
||||
SubjectCloseIssue = "archie.forge.close_issue"
|
||||
SubjectCreatePR = "archie.forge.create_pr"
|
||||
SubjectLinkBranch = "archie.forge.link_branch"
|
||||
@@ -35,8 +36,9 @@ const (
|
||||
// set a task of that identity may publish to.
|
||||
func Subjects(identity string) []string {
|
||||
bases := []string{
|
||||
SubjectComment, SubjectCloseIssue, SubjectCreatePR, SubjectLinkBranch,
|
||||
SubjectSetStateLabel, SubjectCreateReviewComment, SubjectReplyToReview,
|
||||
SubjectComment, SubjectCreateIssue, SubjectCloseIssue, SubjectCreatePR,
|
||||
SubjectLinkBranch, SubjectSetStateLabel, SubjectCreateReviewComment,
|
||||
SubjectReplyToReview,
|
||||
}
|
||||
out := make([]string, len(bases))
|
||||
for i, base := range bases {
|
||||
@@ -80,6 +82,17 @@ type CommentResponse struct {
|
||||
natsrpc.Envelope
|
||||
}
|
||||
|
||||
type CreateIssueRequest struct {
|
||||
Target
|
||||
Title, Body string
|
||||
Labels []string
|
||||
}
|
||||
|
||||
type CreateIssueResponse struct {
|
||||
Number int `json:"number"`
|
||||
natsrpc.Envelope
|
||||
}
|
||||
|
||||
type CloseIssueRequest struct {
|
||||
Target
|
||||
Number int
|
||||
@@ -168,6 +181,7 @@ func (s *Server) RegisterFor(nc *nats.Conn, identity string) (unsubscribe func()
|
||||
}
|
||||
return natsrpc.RegisterAll(nc, []natsrpc.Registration{
|
||||
{Subject: serverSubject(identity, SubjectComment), Handler: as(s.handleComment)},
|
||||
{Subject: serverSubject(identity, SubjectCreateIssue), Handler: as(s.handleCreateIssue)},
|
||||
{Subject: serverSubject(identity, SubjectCloseIssue), Handler: as(s.handleCloseIssue)},
|
||||
{Subject: serverSubject(identity, SubjectCreatePR), Handler: as(s.handleCreatePR)},
|
||||
{Subject: serverSubject(identity, SubjectLinkBranch), Handler: as(s.handleLinkBranch)},
|
||||
@@ -249,6 +263,21 @@ func (s *Server) handleComment(ctx context.Context, identity string, msg *nats.M
|
||||
s.respond(msg, CommentResponse{ID: id, Envelope: natsrpc.NewEnvelope(err)})
|
||||
}
|
||||
|
||||
func (s *Server) handleCreateIssue(ctx context.Context, identity string, msg *nats.Msg) {
|
||||
var req CreateIssueRequest
|
||||
if err := json.Unmarshal(msg.Data, &req); err != nil {
|
||||
s.respond(msg, CreateIssueResponse{Envelope: natsrpc.NewEnvelope(fmt.Errorf("decode create_issue request: %w", err))})
|
||||
return
|
||||
}
|
||||
client, err := s.authorizedForge(ctx, identity, req.Target, "comment")
|
||||
if err != nil {
|
||||
s.respond(msg, CreateIssueResponse{Envelope: natsrpc.NewEnvelope(err)})
|
||||
return
|
||||
}
|
||||
number, err := client.CreateIssue(ctx, req.Owner, req.Repo, req.Title, req.Body, req.Labels)
|
||||
s.respond(msg, CreateIssueResponse{Number: number, Envelope: natsrpc.NewEnvelope(err)})
|
||||
}
|
||||
|
||||
func (s *Server) handleCloseIssue(ctx context.Context, identity string, msg *nats.Msg) {
|
||||
var req CloseIssueRequest
|
||||
if err := json.Unmarshal(msg.Data, &req); err != nil {
|
||||
@@ -392,6 +421,18 @@ func (c *Client) Comment(ctx context.Context, owner, repo string, number int, bo
|
||||
return resp.ID, nil
|
||||
}
|
||||
|
||||
func (c *Client) CreateIssue(ctx context.Context, owner, repo, title, body string, labels []string) (int, error) {
|
||||
req := CreateIssueRequest{Target: c.target(owner, repo), Title: title, Body: body, Labels: labels}
|
||||
resp, err := natsrpc.Call[CreateIssueResponse](ctx, c.rpc(), c.subject(SubjectCreateIssue), req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if err := resp.Err(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return resp.Number, nil
|
||||
}
|
||||
|
||||
func (c *Client) CloseIssue(ctx context.Context, owner, repo string, number int, comment string) error {
|
||||
req := CloseIssueRequest{Target: c.target(owner, repo), Number: number, Comment: comment}
|
||||
resp, err := natsrpc.Call[Response](ctx, c.rpc(), c.subject(SubjectCloseIssue), req)
|
||||
|
||||
@@ -195,6 +195,16 @@ func (f *Forge) Comment(ctx context.Context, owner, repo string, number int, bod
|
||||
return resp.GetId(), err
|
||||
}
|
||||
|
||||
func (f *Forge) CreateIssue(ctx context.Context, owner, repo, title, body string, labels []string) (int, error) {
|
||||
resp, err := call(ctx, f, "create issue", func(c forgev1.ForgeServiceClient) (*forgev1.CreateIssueResponse, error) {
|
||||
return c.CreateIssue(ctx, &forgev1.CreateIssueRequest{Repo: ref(owner, repo), Title: title, Body: body, Labels: labels})
|
||||
})
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return int(resp.GetNumber()), nil
|
||||
}
|
||||
|
||||
func (f *Forge) CloseIssue(ctx context.Context, owner, repo string, number int, comment string) error {
|
||||
_, err := call(ctx, f, "close issue", func(c forgev1.ForgeServiceClient) (*forgev1.CloseIssueResponse, error) {
|
||||
return c.CloseIssue(ctx, &forgev1.CloseIssueRequest{Repo: ref(owner, repo), Number: int32(number), Comment: comment}) // issue numbers fit int32
|
||||
|
||||
@@ -18,6 +18,7 @@ service ForgeService {
|
||||
rpc AssignedIssues(AssignedIssuesRequest) returns (AssignedIssuesResponse);
|
||||
rpc IssuesWithLabel(IssuesWithLabelRequest) returns (IssuesWithLabelResponse);
|
||||
rpc Comment(CommentRequest) returns (CommentResponse);
|
||||
rpc CreateIssue(CreateIssueRequest) returns (CreateIssueResponse);
|
||||
rpc CloseIssue(CloseIssueRequest) returns (CloseIssueResponse);
|
||||
rpc React(ReactRequest) returns (ReactResponse);
|
||||
rpc SetStateLabel(SetStateLabelRequest) returns (SetStateLabelResponse);
|
||||
@@ -86,6 +87,16 @@ message CommentRequest {
|
||||
}
|
||||
message CommentResponse { int64 id = 1; }
|
||||
|
||||
// CreateIssueRequest opens an issue with title, body and optional labels,
|
||||
// returning its number.
|
||||
message CreateIssueRequest {
|
||||
RepoRef repo = 1;
|
||||
string title = 2;
|
||||
string body = 3;
|
||||
repeated string labels = 4;
|
||||
}
|
||||
message CreateIssueResponse { int32 number = 1; }
|
||||
|
||||
message CloseIssueRequest {
|
||||
RepoRef repo = 1;
|
||||
int32 number = 2;
|
||||
|
||||
Reference in new issue
Block a user