feat(github-actions): allow to bind to a specific repository

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
Ettore Di Giacinto
2025-03-12 21:59:31 +01:00
parent 0ad2de72e0
commit c69ee9e5f7
4 changed files with 115 additions and 23 deletions

View File

@@ -10,7 +10,7 @@ import (
)
type GithubIssuesCloser struct {
token string
token, repository, owner string
context context.Context
client *github.Client
}
@@ -20,6 +20,8 @@ func NewGithubIssueCloser(ctx context.Context, config map[string]string) *Github
return &GithubIssuesCloser{
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.",

View File

@@ -12,7 +12,7 @@ import (
)
type GithubIssuesLabeler struct {
token string
token, repository, owner string
availableLabels []string
context context.Context
client *github.Client
@@ -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.",

View File

@@ -10,7 +10,7 @@ import (
)
type GithubIssuesOpener struct {
token string
token, repository, owner string
context context.Context
client *github.Client
}
@@ -21,6 +21,8 @@ func NewGithubIssueOpener(ctx context.Context, config map[string]string) *Github
return &GithubIssuesOpener{
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.",

View File

@@ -11,7 +11,7 @@ import (
)
type GithubIssueSearch struct {
token string
token, repository, owner string
context context.Context
client *github.Client
}
@@ -22,6 +22,8 @@ func NewGithubIssueSearch(ctx context.Context, config map[string]string) *Github
return &GithubIssueSearch{
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"},
}
}