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,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.",
|
||||
|
||||
Reference in New Issue
Block a user