diff --git a/services/actions/githubissuecloser.go b/services/actions/githubissuecloser.go index 206c107..bbbd0ce 100644 --- a/services/actions/githubissuecloser.go +++ b/services/actions/githubissuecloser.go @@ -10,17 +10,19 @@ import ( ) type GithubIssuesCloser struct { - token string - context context.Context - client *github.Client + token, repository, owner string + context context.Context + client *github.Client } func NewGithubIssueCloser(ctx context.Context, config map[string]string) *GithubIssuesCloser { client := github.NewClient(nil).WithAuthToken(config["token"]) return &GithubIssuesCloser{ - client: client, - token: config["token"], - context: ctx, + client: client, + token: config["token"], + repository: config["repository"], + owner: config["owner"], + context: ctx, } } @@ -37,6 +39,13 @@ func (g *GithubIssuesCloser) Run(ctx context.Context, params action.ActionParams return action.ActionResult{}, err } + if g.repository != "" { + result.Repository = g.repository + } + + if g.owner != "" { + result.Owner = g.owner + } // _, _, err = g.client.Issues.CreateComment( // g.context, // result.Owner, result.Repository, @@ -68,6 +77,20 @@ func (g *GithubIssuesCloser) Run(ctx context.Context, params action.ActionParams } func (g *GithubIssuesCloser) Definition() action.ActionDefinition { + if g.repository != "" && g.owner != "" { + return action.ActionDefinition{ + Name: "close_github_issue", + Description: "Closes a Github issue.", + Properties: map[string]jsonschema.Definition{ + "issue_number": { + Type: jsonschema.Number, + Description: "The issue number to close", + }, + }, + Required: []string{"issue_number"}, + } + } + return action.ActionDefinition{ Name: "close_github_issue", Description: "Closes a Github issue.", diff --git a/services/actions/githubissuelabeler.go b/services/actions/githubissuelabeler.go index db93ebd..aa42c58 100644 --- a/services/actions/githubissuelabeler.go +++ b/services/actions/githubissuelabeler.go @@ -12,10 +12,10 @@ import ( ) type GithubIssuesLabeler struct { - token string - availableLabels []string - context context.Context - client *github.Client + token, repository, owner string + availableLabels []string + context context.Context + client *github.Client } func NewGithubIssueLabeler(ctx context.Context, config map[string]string) *GithubIssuesLabeler { @@ -31,6 +31,8 @@ func NewGithubIssueLabeler(ctx context.Context, config map[string]string) *Githu return &GithubIssuesLabeler{ client: client, token: config["token"], + repository: config["repository"], + owner: config["owner"], context: ctx, availableLabels: availableLabels, } @@ -48,6 +50,11 @@ func (g *GithubIssuesLabeler) Run(ctx context.Context, params action.ActionParam return action.ActionResult{}, err } + if g.repository != "" && g.owner != "" { + result.Repository = g.repository + result.Owner = g.owner + } + labels, _, err := g.client.Issues.AddLabelsToIssue(g.context, result.Owner, result.Repository, result.IssueNumber, []string{result.Label}) //labelsNames := []string{} for _, l := range labels { @@ -63,6 +70,24 @@ func (g *GithubIssuesLabeler) Run(ctx context.Context, params action.ActionParam } func (g *GithubIssuesLabeler) Definition() action.ActionDefinition { + if g.repository != "" && g.owner != "" { + return action.ActionDefinition{ + Name: "add_label_to_github_issue", + Description: "Add a label to a Github issue. You might want to assign labels to issues to categorize them.", + Properties: map[string]jsonschema.Definition{ + "issue_number": { + Type: jsonschema.Number, + Description: "The number of the issue to add the label to.", + }, + "label": { + Type: jsonschema.String, + Description: "The label to add to the issue.", + Enum: g.availableLabels, + }, + }, + Required: []string{"issue_number", "label"}, + } + } return action.ActionDefinition{ Name: "add_label_to_github_issue", Description: "Add a label to a Github issue. You might want to assign labels to issues to categorize them.", diff --git a/services/actions/githubissueopener.go b/services/actions/githubissueopener.go index 7a70273..090d0d5 100644 --- a/services/actions/githubissueopener.go +++ b/services/actions/githubissueopener.go @@ -10,18 +10,20 @@ import ( ) type GithubIssuesOpener struct { - token string - context context.Context - client *github.Client + token, repository, owner string + context context.Context + client *github.Client } func NewGithubIssueOpener(ctx context.Context, config map[string]string) *GithubIssuesOpener { client := github.NewClient(nil).WithAuthToken(config["token"]) return &GithubIssuesOpener{ - client: client, - token: config["token"], - context: ctx, + client: client, + token: config["token"], + repository: config["repository"], + owner: config["owner"], + context: ctx, } } @@ -39,6 +41,11 @@ func (g *GithubIssuesOpener) Run(ctx context.Context, params action.ActionParams return action.ActionResult{}, err } + if g.repository != "" && g.owner != "" { + result.Repository = g.repository + result.Owner = g.owner + } + issue := &github.IssueRequest{ Title: &result.Title, Body: &result.Body, @@ -56,6 +63,23 @@ func (g *GithubIssuesOpener) Run(ctx context.Context, params action.ActionParams } func (g *GithubIssuesOpener) Definition() action.ActionDefinition { + if g.repository != "" && g.owner != "" { + return action.ActionDefinition{ + Name: "create_github_issue", + Description: "Create a new issue on a GitHub repository.", + Properties: map[string]jsonschema.Definition{ + "text": { + Type: jsonschema.String, + Description: "The text of the new issue", + }, + "title": { + Type: jsonschema.String, + Description: "The title of the issue.", + }, + }, + Required: []string{"title", "text"}, + } + } return action.ActionDefinition{ Name: "create_github_issue", Description: "Create a new issue on a GitHub repository.", diff --git a/services/actions/githubissuesearch.go b/services/actions/githubissuesearch.go index dbef041..1c72158 100644 --- a/services/actions/githubissuesearch.go +++ b/services/actions/githubissuesearch.go @@ -11,18 +11,20 @@ import ( ) type GithubIssueSearch struct { - token string - context context.Context - client *github.Client + token, repository, owner 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, + client: client, + token: config["token"], + repository: config["repository"], + owner: config["owner"], + context: ctx, } } @@ -39,6 +41,11 @@ func (g *GithubIssueSearch) Run(ctx context.Context, params action.ActionParams) return action.ActionResult{}, err } + if g.repository != "" && g.owner != "" { + result.Repository = g.repository + result.Owner = g.owner + } + 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{ @@ -61,6 +68,19 @@ func (g *GithubIssueSearch) Run(ctx context.Context, params action.ActionParams) } func (g *GithubIssueSearch) Definition() action.ActionDefinition { + if g.repository != "" && g.owner != "" { + 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", + }, + }, + Required: []string{"query"}, + } + } return action.ActionDefinition{ Name: "search_github_issue", Description: "Search between github issues", @@ -78,6 +98,6 @@ func (g *GithubIssueSearch) Definition() action.ActionDefinition { Description: "The owner of the repository", }, }, - Required: []string{"text", "repository", "owner"}, + Required: []string{"query", "repository", "owner"}, } }