feat(github): add issue editor (#106)
* feat(github): add issue editor Signed-off-by: mudler <mudler@localai.io> * Small changes --------- Signed-off-by: mudler <mudler@localai.io>
This commit is contained in:
committed by
GitHub
parent
9c555bd99f
commit
62ce629bf1
@@ -22,6 +22,7 @@ const (
|
|||||||
ActionDeepResearchRunner = "deep-research-runner"
|
ActionDeepResearchRunner = "deep-research-runner"
|
||||||
ActionGithubIssueLabeler = "github-issue-labeler"
|
ActionGithubIssueLabeler = "github-issue-labeler"
|
||||||
ActionGithubIssueOpener = "github-issue-opener"
|
ActionGithubIssueOpener = "github-issue-opener"
|
||||||
|
ActionGithubIssueEditor = "github-issue-editor"
|
||||||
ActionGithubIssueCloser = "github-issue-closer"
|
ActionGithubIssueCloser = "github-issue-closer"
|
||||||
ActionGithubIssueSearcher = "github-issue-searcher"
|
ActionGithubIssueSearcher = "github-issue-searcher"
|
||||||
ActionGithubRepositoryGet = "github-repository-get-content"
|
ActionGithubRepositoryGet = "github-repository-get-content"
|
||||||
@@ -50,6 +51,7 @@ var AvailableActions = []string{
|
|||||||
ActionCustom,
|
ActionCustom,
|
||||||
ActionGithubIssueLabeler,
|
ActionGithubIssueLabeler,
|
||||||
ActionGithubIssueOpener,
|
ActionGithubIssueOpener,
|
||||||
|
ActionGithubIssueEditor,
|
||||||
ActionGithubIssueCloser,
|
ActionGithubIssueCloser,
|
||||||
ActionGithubIssueSearcher,
|
ActionGithubIssueSearcher,
|
||||||
ActionGithubRepositoryGet,
|
ActionGithubRepositoryGet,
|
||||||
@@ -117,6 +119,8 @@ func Action(name, agentName string, config map[string]string, pool *state.AgentP
|
|||||||
a = actions.NewGithubIssueLabeler(config)
|
a = actions.NewGithubIssueLabeler(config)
|
||||||
case ActionGithubIssueOpener:
|
case ActionGithubIssueOpener:
|
||||||
a = actions.NewGithubIssueOpener(config)
|
a = actions.NewGithubIssueOpener(config)
|
||||||
|
case ActionGithubIssueEditor:
|
||||||
|
a = actions.NewGithubIssueEditor(config)
|
||||||
case ActionGithubIssueCloser:
|
case ActionGithubIssueCloser:
|
||||||
a = actions.NewGithubIssueCloser(config)
|
a = actions.NewGithubIssueCloser(config)
|
||||||
case ActionGithubIssueSearcher:
|
case ActionGithubIssueSearcher:
|
||||||
@@ -205,6 +209,11 @@ func ActionsConfigMeta() []config.FieldGroup {
|
|||||||
Label: "GitHub Issue Opener",
|
Label: "GitHub Issue Opener",
|
||||||
Fields: actions.GithubIssueOpenerConfigMeta(),
|
Fields: actions.GithubIssueOpenerConfigMeta(),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "github-issue-editor",
|
||||||
|
Label: "GitHub Issue Editor",
|
||||||
|
Fields: actions.GithubIssueEditorConfigMeta(),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Name: "github-issue-closer",
|
Name: "github-issue-closer",
|
||||||
Label: "GitHub Issue Closer",
|
Label: "GitHub Issue Closer",
|
||||||
|
|||||||
141
services/actions/githubissueedit.go
Normal file
141
services/actions/githubissueedit.go
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
package actions
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/google/go-github/v69/github"
|
||||||
|
"github.com/mudler/LocalAGI/core/types"
|
||||||
|
"github.com/mudler/LocalAGI/pkg/config"
|
||||||
|
"github.com/sashabaranov/go-openai/jsonschema"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GithubIssueEditor struct {
|
||||||
|
token, repository, owner, customActionName string
|
||||||
|
client *github.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewGithubIssueEditor(config map[string]string) *GithubIssueEditor {
|
||||||
|
client := github.NewClient(nil).WithAuthToken(config["token"])
|
||||||
|
|
||||||
|
return &GithubIssueEditor{
|
||||||
|
client: client,
|
||||||
|
token: config["token"],
|
||||||
|
customActionName: config["customActionName"],
|
||||||
|
repository: config["repository"],
|
||||||
|
owner: config["owner"],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *GithubIssueEditor) Run(ctx context.Context, params types.ActionParams) (types.ActionResult, error) {
|
||||||
|
result := struct {
|
||||||
|
Repository string `json:"repository"`
|
||||||
|
Owner string `json:"owner"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
IssueNumber int `json:"issue_number"`
|
||||||
|
}{}
|
||||||
|
err := params.Unmarshal(&result)
|
||||||
|
if err != nil {
|
||||||
|
return types.ActionResult{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if g.repository != "" && g.owner != "" {
|
||||||
|
result.Repository = g.repository
|
||||||
|
result.Owner = g.owner
|
||||||
|
}
|
||||||
|
|
||||||
|
_, _, err = g.client.Issues.Edit(ctx, result.Owner, result.Repository, result.IssueNumber,
|
||||||
|
&github.IssueRequest{
|
||||||
|
Body: &result.Description,
|
||||||
|
})
|
||||||
|
resultString := fmt.Sprintf("Updated description for issue %d in repository %s/%s", result.IssueNumber, result.Owner, result.Repository)
|
||||||
|
if err != nil {
|
||||||
|
resultString = fmt.Sprintf("Error updating description for issue %d in repository %s/%s: %v", result.IssueNumber, result.Owner, result.Repository, err)
|
||||||
|
}
|
||||||
|
return types.ActionResult{Result: resultString}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *GithubIssueEditor) Definition() types.ActionDefinition {
|
||||||
|
actionName := "edit_github_issue"
|
||||||
|
if g.customActionName != "" {
|
||||||
|
actionName = g.customActionName
|
||||||
|
}
|
||||||
|
description := "Edit the description of a Github issue in a repository."
|
||||||
|
if g.repository != "" && g.owner != "" {
|
||||||
|
return types.ActionDefinition{
|
||||||
|
Name: types.ActionDefinitionName(actionName),
|
||||||
|
Description: description,
|
||||||
|
Properties: map[string]jsonschema.Definition{
|
||||||
|
"issue_number": {
|
||||||
|
Type: jsonschema.Number,
|
||||||
|
Description: "The number of the issue to edit.",
|
||||||
|
},
|
||||||
|
"description": {
|
||||||
|
Type: jsonschema.String,
|
||||||
|
Description: "The new description for the issue.",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Required: []string{"issue_number", "description"},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return types.ActionDefinition{
|
||||||
|
Name: types.ActionDefinitionName(actionName),
|
||||||
|
Description: description,
|
||||||
|
Properties: map[string]jsonschema.Definition{
|
||||||
|
"issue_number": {
|
||||||
|
Type: jsonschema.Number,
|
||||||
|
Description: "The number of the issue to edit.",
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
Type: jsonschema.String,
|
||||||
|
Description: "The repository containing the issue.",
|
||||||
|
},
|
||||||
|
"owner": {
|
||||||
|
Type: jsonschema.String,
|
||||||
|
Description: "The owner of the repository.",
|
||||||
|
},
|
||||||
|
"description": {
|
||||||
|
Type: jsonschema.String,
|
||||||
|
Description: "The new description for the issue.",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Required: []string{"issue_number", "repository", "owner", "description"},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *GithubIssueEditor) Plannable() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// GithubIssueEditorConfigMeta returns the metadata for GitHub Issue Editor action configuration fields
|
||||||
|
func GithubIssueEditorConfigMeta() []config.Field {
|
||||||
|
return []config.Field{
|
||||||
|
{
|
||||||
|
Name: "token",
|
||||||
|
Label: "GitHub Token",
|
||||||
|
Type: config.FieldTypeText,
|
||||||
|
Required: true,
|
||||||
|
HelpText: "GitHub API token with repository access",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "repository",
|
||||||
|
Label: "Repository",
|
||||||
|
Type: config.FieldTypeText,
|
||||||
|
Required: false,
|
||||||
|
HelpText: "GitHub repository name",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "owner",
|
||||||
|
Label: "Owner",
|
||||||
|
Type: config.FieldTypeText,
|
||||||
|
Required: false,
|
||||||
|
HelpText: "GitHub repository owner",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "customActionName",
|
||||||
|
Label: "Custom Action Name",
|
||||||
|
Type: config.FieldTypeText,
|
||||||
|
HelpText: "Custom name for this action",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user