feat(github-actions): allow to bind to a specific repository
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
@@ -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.",
|
||||
|
||||
@@ -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.",
|
||||
|
||||
@@ -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.",
|
||||
|
||||
@@ -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"},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user