feat(forge): add CreateIssue to the forge SDK, gitea and github plugins
publish / publish (push) Successful in 1m57s
publish / publish (push) Successful in 1m57s
Mirrors archie-core's proto/forge/v1 change: the SDK Forge interface and server dispatch gain CreateIssue; gitea resolves label names to IDs (creating missing labels) and github passes label names through.
This commit is contained in:
6 files changed
+475
-261
No files matched your search
@@ -396,6 +396,30 @@ func normalizeGiteaReviewState(s gitea.ReviewStateType) string {
|
||||
}
|
||||
}
|
||||
|
||||
// CreateIssue opens an issue with title, body and optional labels, resolving
|
||||
// label names to IDs (creating missing labels) and returning the issue number.
|
||||
func (c *GiteaClient) CreateIssue(ctx context.Context, owner, repo, title, body string, labels []string) (int, error) {
|
||||
issue, _, err := c.api(ctx).CreateIssue(owner, repo, gitea.CreateIssueOption{Title: title, Body: body})
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("create issue in %s/%s: %w", owner, repo, err)
|
||||
}
|
||||
number := int(issue.Index)
|
||||
if len(labels) > 0 {
|
||||
ids := make([]int64, 0, len(labels))
|
||||
for _, name := range labels {
|
||||
id, err := c.labelID(ctx, owner, repo, name)
|
||||
if err != nil {
|
||||
return number, fmt.Errorf("resolve label %q in %s/%s: %w", name, owner, repo, err)
|
||||
}
|
||||
ids = append(ids, id)
|
||||
}
|
||||
if _, _, err := c.api(ctx).ReplaceIssueLabels(owner, repo, issue.Index, gitea.IssueLabelsOption{Labels: ids}); err != nil {
|
||||
return number, fmt.Errorf("label issue %s/%s#%d: %w", owner, repo, number, err)
|
||||
}
|
||||
}
|
||||
return number, nil
|
||||
}
|
||||
|
||||
// CloseIssue closes an issue with an optional final comment.
|
||||
func (c *GiteaClient) CloseIssue(ctx context.Context, owner, repo string, number int, comment string) error {
|
||||
if comment != "" {
|
||||
|
||||
@@ -416,6 +416,19 @@ func (c *GitHubClient) selfLogin(ctx context.Context) (string, error) {
|
||||
return c.login, nil
|
||||
}
|
||||
|
||||
// CreateIssue opens an issue with title, body and optional labels.
|
||||
func (c *GitHubClient) CreateIssue(ctx context.Context, owner, repo, title, body string, labels []string) (int, error) {
|
||||
req := &github.IssueRequest{Title: new(title), Body: new(body)}
|
||||
if len(labels) > 0 {
|
||||
req.Labels = &labels
|
||||
}
|
||||
issue, _, err := c.gh.Issues.Create(ctx, owner, repo, req)
|
||||
if err != nil {
|
||||
return 0, apiError(fmt.Sprintf("create issue in %s/%s", owner, repo), err)
|
||||
}
|
||||
return issue.GetNumber(), nil
|
||||
}
|
||||
|
||||
// CloseIssue closes an issue with a final comment (feasibility "won't do").
|
||||
func (c *GitHubClient) CloseIssue(ctx context.Context, owner, repo string, number int, comment string) error {
|
||||
if comment != "" {
|
||||
|
||||
@@ -35,6 +35,9 @@ type Forge interface {
|
||||
AssignedIssues(ctx context.Context, owner, repo, assignee string) ([]Issue, error)
|
||||
IssuesWithLabel(ctx context.Context, owner, repo, label string) ([]Issue, error)
|
||||
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(ctx context.Context, owner, repo string, number int, comment string) error
|
||||
React(ctx context.Context, owner, repo string, number int, reaction string) error
|
||||
// SetStateLabel makes label the issue's only state label, removing any
|
||||
|
||||
@@ -104,6 +104,15 @@ func (s *server) Comment(ctx context.Context, r *forgev1.CommentRequest) (*forge
|
||||
return &forgev1.CommentResponse{Id: id}, fail(err)
|
||||
}
|
||||
|
||||
func (s *server) CreateIssue(ctx context.Context, r *forgev1.CreateIssueRequest) (*forgev1.CreateIssueResponse, error) {
|
||||
f, err := s.forge()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
number, err := f.CreateIssue(ctx, r.GetRepo().GetOwner(), r.GetRepo().GetRepo(), r.GetTitle(), r.GetBody(), r.GetLabels())
|
||||
return &forgev1.CreateIssueResponse{Number: int32(number)}, fail(err) // issue numbers fit int32
|
||||
}
|
||||
|
||||
func (s *server) CloseIssue(ctx context.Context, r *forgev1.CloseIssueRequest) (*forgev1.CloseIssueResponse, error) {
|
||||
f, err := s.forge()
|
||||
if err != nil {
|
||||
|
||||
+388
-261
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,
|
||||
|
||||
Reference in new issue
Block a user