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,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type GithubIssuesCloser struct {
|
type GithubIssuesCloser struct {
|
||||||
token string
|
token, repository, owner string
|
||||||
context context.Context
|
context context.Context
|
||||||
client *github.Client
|
client *github.Client
|
||||||
}
|
}
|
||||||
@@ -20,6 +20,8 @@ func NewGithubIssueCloser(ctx context.Context, config map[string]string) *Github
|
|||||||
return &GithubIssuesCloser{
|
return &GithubIssuesCloser{
|
||||||
client: client,
|
client: client,
|
||||||
token: config["token"],
|
token: config["token"],
|
||||||
|
repository: config["repository"],
|
||||||
|
owner: config["owner"],
|
||||||
context: ctx,
|
context: ctx,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -37,6 +39,13 @@ func (g *GithubIssuesCloser) Run(ctx context.Context, params action.ActionParams
|
|||||||
return action.ActionResult{}, err
|
return action.ActionResult{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if g.repository != "" {
|
||||||
|
result.Repository = g.repository
|
||||||
|
}
|
||||||
|
|
||||||
|
if g.owner != "" {
|
||||||
|
result.Owner = g.owner
|
||||||
|
}
|
||||||
// _, _, err = g.client.Issues.CreateComment(
|
// _, _, err = g.client.Issues.CreateComment(
|
||||||
// g.context,
|
// g.context,
|
||||||
// result.Owner, result.Repository,
|
// result.Owner, result.Repository,
|
||||||
@@ -68,6 +77,20 @@ func (g *GithubIssuesCloser) Run(ctx context.Context, params action.ActionParams
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *GithubIssuesCloser) Definition() action.ActionDefinition {
|
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{
|
return action.ActionDefinition{
|
||||||
Name: "close_github_issue",
|
Name: "close_github_issue",
|
||||||
Description: "Closes a Github issue.",
|
Description: "Closes a Github issue.",
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type GithubIssuesLabeler struct {
|
type GithubIssuesLabeler struct {
|
||||||
token string
|
token, repository, owner string
|
||||||
availableLabels []string
|
availableLabels []string
|
||||||
context context.Context
|
context context.Context
|
||||||
client *github.Client
|
client *github.Client
|
||||||
@@ -31,6 +31,8 @@ func NewGithubIssueLabeler(ctx context.Context, config map[string]string) *Githu
|
|||||||
return &GithubIssuesLabeler{
|
return &GithubIssuesLabeler{
|
||||||
client: client,
|
client: client,
|
||||||
token: config["token"],
|
token: config["token"],
|
||||||
|
repository: config["repository"],
|
||||||
|
owner: config["owner"],
|
||||||
context: ctx,
|
context: ctx,
|
||||||
availableLabels: availableLabels,
|
availableLabels: availableLabels,
|
||||||
}
|
}
|
||||||
@@ -48,6 +50,11 @@ func (g *GithubIssuesLabeler) Run(ctx context.Context, params action.ActionParam
|
|||||||
return action.ActionResult{}, err
|
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})
|
labels, _, err := g.client.Issues.AddLabelsToIssue(g.context, result.Owner, result.Repository, result.IssueNumber, []string{result.Label})
|
||||||
//labelsNames := []string{}
|
//labelsNames := []string{}
|
||||||
for _, l := range labels {
|
for _, l := range labels {
|
||||||
@@ -63,6 +70,24 @@ func (g *GithubIssuesLabeler) Run(ctx context.Context, params action.ActionParam
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *GithubIssuesLabeler) Definition() action.ActionDefinition {
|
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{
|
return action.ActionDefinition{
|
||||||
Name: "add_label_to_github_issue",
|
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.",
|
Description: "Add a label to a Github issue. You might want to assign labels to issues to categorize them.",
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type GithubIssuesOpener struct {
|
type GithubIssuesOpener struct {
|
||||||
token string
|
token, repository, owner string
|
||||||
context context.Context
|
context context.Context
|
||||||
client *github.Client
|
client *github.Client
|
||||||
}
|
}
|
||||||
@@ -21,6 +21,8 @@ func NewGithubIssueOpener(ctx context.Context, config map[string]string) *Github
|
|||||||
return &GithubIssuesOpener{
|
return &GithubIssuesOpener{
|
||||||
client: client,
|
client: client,
|
||||||
token: config["token"],
|
token: config["token"],
|
||||||
|
repository: config["repository"],
|
||||||
|
owner: config["owner"],
|
||||||
context: ctx,
|
context: ctx,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -39,6 +41,11 @@ func (g *GithubIssuesOpener) Run(ctx context.Context, params action.ActionParams
|
|||||||
return action.ActionResult{}, err
|
return action.ActionResult{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if g.repository != "" && g.owner != "" {
|
||||||
|
result.Repository = g.repository
|
||||||
|
result.Owner = g.owner
|
||||||
|
}
|
||||||
|
|
||||||
issue := &github.IssueRequest{
|
issue := &github.IssueRequest{
|
||||||
Title: &result.Title,
|
Title: &result.Title,
|
||||||
Body: &result.Body,
|
Body: &result.Body,
|
||||||
@@ -56,6 +63,23 @@ func (g *GithubIssuesOpener) Run(ctx context.Context, params action.ActionParams
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *GithubIssuesOpener) Definition() action.ActionDefinition {
|
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{
|
return action.ActionDefinition{
|
||||||
Name: "create_github_issue",
|
Name: "create_github_issue",
|
||||||
Description: "Create a new issue on a GitHub repository.",
|
Description: "Create a new issue on a GitHub repository.",
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type GithubIssueSearch struct {
|
type GithubIssueSearch struct {
|
||||||
token string
|
token, repository, owner string
|
||||||
context context.Context
|
context context.Context
|
||||||
client *github.Client
|
client *github.Client
|
||||||
}
|
}
|
||||||
@@ -22,6 +22,8 @@ func NewGithubIssueSearch(ctx context.Context, config map[string]string) *Github
|
|||||||
return &GithubIssueSearch{
|
return &GithubIssueSearch{
|
||||||
client: client,
|
client: client,
|
||||||
token: config["token"],
|
token: config["token"],
|
||||||
|
repository: config["repository"],
|
||||||
|
owner: config["owner"],
|
||||||
context: ctx,
|
context: ctx,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -39,6 +41,11 @@ func (g *GithubIssueSearch) Run(ctx context.Context, params action.ActionParams)
|
|||||||
return action.ActionResult{}, err
|
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)
|
query := fmt.Sprintf("%s in:%s user:%s", result.Query, result.Repository, result.Owner)
|
||||||
resultString := ""
|
resultString := ""
|
||||||
issues, _, err := g.client.Search.Issues(g.context, query, &github.SearchOptions{
|
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 {
|
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{
|
return action.ActionDefinition{
|
||||||
Name: "search_github_issue",
|
Name: "search_github_issue",
|
||||||
Description: "Search between github issues",
|
Description: "Search between github issues",
|
||||||
@@ -78,6 +98,6 @@ func (g *GithubIssueSearch) Definition() action.ActionDefinition {
|
|||||||
Description: "The owner of the repository",
|
Description: "The owner of the repository",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Required: []string{"text", "repository", "owner"},
|
Required: []string{"query", "repository", "owner"},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user