Need to fill more options to commit to github (#42)
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
committed by
GitHub
parent
efc82bde30
commit
9347193fdc
3
go.mod
3
go.mod
@@ -13,7 +13,7 @@ require (
|
||||
github.com/go-telegram/bot v1.2.1
|
||||
github.com/gofiber/fiber/v2 v2.52.4
|
||||
github.com/gofiber/template/html/v2 v2.1.1
|
||||
github.com/google/go-github/v61 v61.0.0
|
||||
github.com/google/go-github/v69 v69.2.0
|
||||
github.com/onsi/ginkgo/v2 v2.15.0
|
||||
github.com/onsi/gomega v1.31.1
|
||||
github.com/philippgille/chromem-go v0.5.0
|
||||
@@ -44,7 +44,6 @@ require (
|
||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
||||
github.com/golang/protobuf v1.5.3 // indirect
|
||||
github.com/google/go-cmp v0.6.0 // indirect
|
||||
github.com/google/go-github/v69 v69.2.0 // indirect
|
||||
github.com/google/go-querystring v1.1.0 // indirect
|
||||
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
|
||||
2
go.sum
2
go.sum
@@ -83,8 +83,6 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
|
||||
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/go-github/v61 v61.0.0 h1:VwQCBwhyE9JclCI+22/7mLB1PuU9eowCXKY5pNlu1go=
|
||||
github.com/google/go-github/v61 v61.0.0/go.mod h1:0WR+KmsWX75G2EbpyGsGmradjo3IiciuI4BmdVCobQY=
|
||||
github.com/google/go-github/v69 v69.2.0 h1:wR+Wi/fN2zdUx9YxSmYE0ktiX9IAR/BeePzeaUUbEHE=
|
||||
github.com/google/go-github/v69 v69.2.0/go.mod h1:xne4jymxLR6Uj9b7J7PyTpkMYstEMMwGZa0Aehh1azM=
|
||||
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
|
||||
|
||||
@@ -68,7 +68,8 @@ func (a *GenImageAction) Run(ctx context.Context, params action.ActionParams) (a
|
||||
}
|
||||
|
||||
return action.ActionResult{
|
||||
Result: fmt.Sprintf("The image was generated and available at: %s", resp.Data[0].URL), Metadata: map[string]interface{}{
|
||||
Result: fmt.Sprintf("The image was generated and available at: %s", resp.Data[0].URL),
|
||||
Metadata: map[string]interface{}{
|
||||
MetadataImages: []string{resp.Data[0].URL},
|
||||
}}, nil
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
type GithubRepositoryCreateOrUpdateContent struct {
|
||||
token, repository, owner, customActionName string
|
||||
token, repository, owner, customActionName, defaultBranch, commitAuthor, commitMail string
|
||||
context context.Context
|
||||
client *github.Client
|
||||
}
|
||||
@@ -24,6 +24,9 @@ func NewGithubRepositoryCreateOrUpdateContent(ctx context.Context, config map[st
|
||||
repository: config["repository"],
|
||||
owner: config["owner"],
|
||||
customActionName: config["customActionName"],
|
||||
commitAuthor: config["commitAuthor"],
|
||||
commitMail: config["commitMail"],
|
||||
defaultBranch: config["defaultBranch"],
|
||||
context: ctx,
|
||||
}
|
||||
}
|
||||
@@ -34,6 +37,8 @@ func (g *GithubRepositoryCreateOrUpdateContent) Run(ctx context.Context, params
|
||||
Repository string `json:"repository"`
|
||||
Owner string `json:"owner"`
|
||||
Content string `json:"content"`
|
||||
Branch string `json:"branch"`
|
||||
CommitMessage string `json:"commit_message"`
|
||||
}{}
|
||||
err := params.Unmarshal(&result)
|
||||
if err != nil {
|
||||
@@ -42,12 +47,30 @@ func (g *GithubRepositoryCreateOrUpdateContent) Run(ctx context.Context, params
|
||||
return action.ActionResult{}, err
|
||||
}
|
||||
|
||||
if result.Branch == "" {
|
||||
result.Branch = "main"
|
||||
}
|
||||
|
||||
if result.CommitMessage == "" {
|
||||
result.CommitMessage = "LocalAgent commit"
|
||||
}
|
||||
|
||||
if g.repository != "" && g.owner != "" {
|
||||
result.Repository = g.repository
|
||||
result.Owner = g.owner
|
||||
}
|
||||
|
||||
if g.defaultBranch != "" {
|
||||
result.Branch = g.defaultBranch
|
||||
}
|
||||
|
||||
fileContent, _, err := g.client.Repositories.CreateFile(g.context, result.Owner, result.Repository, result.Path, &github.RepositoryContentFileOptions{
|
||||
Message: &result.CommitMessage,
|
||||
Committer: &github.CommitAuthor{
|
||||
Name: &g.commitAuthor,
|
||||
Email: &g.commitMail,
|
||||
},
|
||||
Branch: &result.Branch,
|
||||
Content: []byte(result.Content),
|
||||
})
|
||||
if err != nil {
|
||||
@@ -64,44 +87,51 @@ func (g *GithubRepositoryCreateOrUpdateContent) Definition() action.ActionDefini
|
||||
if g.customActionName != "" {
|
||||
actionName = g.customActionName
|
||||
}
|
||||
properties := map[string]jsonschema.Definition{
|
||||
"path": {
|
||||
Type: jsonschema.String,
|
||||
Description: "The path to the file or directory",
|
||||
},
|
||||
"content": {
|
||||
Type: jsonschema.String,
|
||||
Description: "The content to create/update",
|
||||
},
|
||||
"commit_message": {
|
||||
Type: jsonschema.String,
|
||||
Description: "The commit message",
|
||||
},
|
||||
}
|
||||
|
||||
if g.defaultBranch != "" {
|
||||
properties["branch"] = jsonschema.Definition{
|
||||
Type: jsonschema.String,
|
||||
Description: "The branch to create/update the file",
|
||||
}
|
||||
}
|
||||
|
||||
if g.repository != "" && g.owner != "" {
|
||||
return action.ActionDefinition{
|
||||
Name: action.ActionDefinitionName(actionName),
|
||||
Description: actionDescription,
|
||||
Properties: map[string]jsonschema.Definition{
|
||||
"path": {
|
||||
Type: jsonschema.String,
|
||||
Description: "The path to the file or directory",
|
||||
},
|
||||
"content": {
|
||||
Type: jsonschema.String,
|
||||
Description: "The content to create/update",
|
||||
},
|
||||
},
|
||||
Properties: properties,
|
||||
Required: []string{"path", "content"},
|
||||
}
|
||||
}
|
||||
|
||||
properties["owner"] = jsonschema.Definition{
|
||||
Type: jsonschema.String,
|
||||
Description: "The owner of the repository",
|
||||
}
|
||||
|
||||
properties["repository"] = jsonschema.Definition{
|
||||
Type: jsonschema.String,
|
||||
Description: "The repository to search in",
|
||||
}
|
||||
|
||||
return action.ActionDefinition{
|
||||
Name: action.ActionDefinitionName(actionName),
|
||||
Description: actionDescription,
|
||||
Properties: map[string]jsonschema.Definition{
|
||||
"path": {
|
||||
Type: jsonschema.String,
|
||||
Description: "The path to the file or directory",
|
||||
},
|
||||
"repository": {
|
||||
Type: jsonschema.String,
|
||||
Description: "The repository to search in",
|
||||
},
|
||||
"owner": {
|
||||
Type: jsonschema.String,
|
||||
Description: "The owner of the repository",
|
||||
},
|
||||
"content": {
|
||||
Type: jsonschema.String,
|
||||
Description: "The content to create/update",
|
||||
},
|
||||
},
|
||||
Properties: properties,
|
||||
Required: []string{"path", "repository", "owner", "content"},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,10 @@ func (g *GithubRepositoryGetContent) Run(ctx context.Context, params action.Acti
|
||||
return action.ActionResult{Result: resultString}, err
|
||||
}
|
||||
|
||||
content := fileContent.Content
|
||||
var content string
|
||||
if fileContent.Content != nil {
|
||||
content = *fileContent.Content
|
||||
}
|
||||
|
||||
return action.ActionResult{Result: fmt.Sprintf("File %s\nContent:%s\n", result.Path, content)}, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user