Add search action
This commit is contained in:
@@ -133,13 +133,20 @@ const (
|
|||||||
ConnectorGithubIssues = "github-issues"
|
ConnectorGithubIssues = "github-issues"
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
ActionSearch = "search"
|
ActionSearch = "search"
|
||||||
ActionGithubIssueLabeler = "github-issue-labeler"
|
ActionGithubIssueLabeler = "github-issue-labeler"
|
||||||
ActionGithubIssueOpener = "github-issue-opener"
|
ActionGithubIssueOpener = "github-issue-opener"
|
||||||
ActionGithubIssueCloser = "github-issue-closer"
|
ActionGithubIssueCloser = "github-issue-closer"
|
||||||
|
ActionGithubIssueSearcher = "github-issue-searcher"
|
||||||
)
|
)
|
||||||
|
|
||||||
var AvailableActions = []string{ActionSearch, ActionGithubIssueLabeler, ActionGithubIssueOpener, ActionGithubIssueCloser}
|
var AvailableActions = []string{
|
||||||
|
ActionSearch,
|
||||||
|
ActionGithubIssueLabeler,
|
||||||
|
ActionGithubIssueOpener,
|
||||||
|
ActionGithubIssueCloser,
|
||||||
|
ActionGithubIssueSearcher,
|
||||||
|
}
|
||||||
|
|
||||||
func (a *AgentConfig) availableActions(ctx context.Context) []Action {
|
func (a *AgentConfig) availableActions(ctx context.Context) []Action {
|
||||||
actions := []Action{}
|
actions := []Action{}
|
||||||
@@ -163,6 +170,8 @@ func (a *AgentConfig) availableActions(ctx context.Context) []Action {
|
|||||||
actions = append(actions, external.NewGithubIssueOpener(ctx, config))
|
actions = append(actions, external.NewGithubIssueOpener(ctx, config))
|
||||||
case ActionGithubIssueCloser:
|
case ActionGithubIssueCloser:
|
||||||
actions = append(actions, external.NewGithubIssueCloser(ctx, config))
|
actions = append(actions, external.NewGithubIssueCloser(ctx, config))
|
||||||
|
case ActionGithubIssueSearcher:
|
||||||
|
actions = append(actions, external.NewGithubIssueSearch(ctx, config))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
4
external/githubissuecloser.go
vendored
4
external/githubissuecloser.go
vendored
@@ -41,7 +41,7 @@ func (g *GithubIssuesCloser) Run(params action.ActionParams) (string, error) {
|
|||||||
// g.context,
|
// g.context,
|
||||||
// result.Owner, result.Repository,
|
// result.Owner, result.Repository,
|
||||||
// result.IssueNumber, &github.IssueComment{
|
// result.IssueNumber, &github.IssueComment{
|
||||||
// Body: &result.Text,
|
// //Body: &result.Text,
|
||||||
// },
|
// },
|
||||||
// )
|
// )
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
@@ -74,7 +74,7 @@ func (g *GithubIssuesCloser) Definition() action.ActionDefinition {
|
|||||||
Properties: map[string]jsonschema.Definition{
|
Properties: map[string]jsonschema.Definition{
|
||||||
"repository": {
|
"repository": {
|
||||||
Type: jsonschema.String,
|
Type: jsonschema.String,
|
||||||
Description: "The repository to add the label to.",
|
Description: "The repository to close the issue in.",
|
||||||
},
|
},
|
||||||
"owner": {
|
"owner": {
|
||||||
Type: jsonschema.String,
|
Type: jsonschema.String,
|
||||||
|
|||||||
81
external/githubissuesearch.go
vendored
Normal file
81
external/githubissuesearch.go
vendored
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
package external
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/google/go-github/v61/github"
|
||||||
|
"github.com/mudler/local-agent-framework/action"
|
||||||
|
"github.com/sashabaranov/go-openai/jsonschema"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GithubIssueSearch struct {
|
||||||
|
token string
|
||||||
|
context context.Context
|
||||||
|
client *github.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewGithubIssueSearch(ctx context.Context, config map[string]string) *GithubIssueSearch {
|
||||||
|
client := github.NewClient(nil).WithAuthToken(config["token"])
|
||||||
|
|
||||||
|
return &GithubIssueSearch{
|
||||||
|
client: client,
|
||||||
|
token: config["token"],
|
||||||
|
context: ctx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *GithubIssueSearch) Run(params action.ActionParams) (string, error) {
|
||||||
|
result := struct {
|
||||||
|
Query string `json:"query"`
|
||||||
|
Repository string `json:"repository"`
|
||||||
|
Owner string `json:"owner"`
|
||||||
|
}{}
|
||||||
|
err := params.Unmarshal(&result)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("error: %v", err)
|
||||||
|
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
query := fmt.Sprintf("%s in:%s user:%s", result.Query, result.Repository, result.Owner)
|
||||||
|
resultString := ""
|
||||||
|
issues, _, err := g.client.Search.Issues(g.context, query, &github.SearchOptions{
|
||||||
|
ListOptions: github.ListOptions{PerPage: 5},
|
||||||
|
Order: "desc",
|
||||||
|
//Sort: "created",
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
resultString = fmt.Sprintf("Error listing issues: %v", err)
|
||||||
|
}
|
||||||
|
for _, i := range issues.Issues {
|
||||||
|
fmt.Println("Issue found:", i.GetTitle())
|
||||||
|
resultString += fmt.Sprintf("Issue found: %s\n", i.GetTitle())
|
||||||
|
resultString += fmt.Sprintf("URL: %s\n", i.GetHTMLURL())
|
||||||
|
// resultString += fmt.Sprintf("Body: %s\n", i.GetBody())
|
||||||
|
}
|
||||||
|
|
||||||
|
return resultString, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *GithubIssueSearch) Definition() action.ActionDefinition {
|
||||||
|
return action.ActionDefinition{
|
||||||
|
Name: "search_github_issue",
|
||||||
|
Description: "Search between github issues",
|
||||||
|
Properties: map[string]jsonschema.Definition{
|
||||||
|
"query": {
|
||||||
|
Type: jsonschema.String,
|
||||||
|
Description: "The text to search for",
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
Type: jsonschema.String,
|
||||||
|
Description: "The repository to search in",
|
||||||
|
},
|
||||||
|
"owner": {
|
||||||
|
Type: jsonschema.String,
|
||||||
|
Description: "The owner of the repository",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Required: []string{"text", "repository", "owner"},
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user