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
@@ -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,9 +10,9 @@ import (
|
||||
)
|
||||
|
||||
type GithubRepositoryCreateOrUpdateContent struct {
|
||||
token, repository, owner, customActionName string
|
||||
context context.Context
|
||||
client *github.Client
|
||||
token, repository, owner, customActionName, defaultBranch, commitAuthor, commitMail string
|
||||
context context.Context
|
||||
client *github.Client
|
||||
}
|
||||
|
||||
func NewGithubRepositoryCreateOrUpdateContent(ctx context.Context, config map[string]string) *GithubRepositoryCreateOrUpdateContent {
|
||||
@@ -24,16 +24,21 @@ 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,
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GithubRepositoryCreateOrUpdateContent) Run(ctx context.Context, params action.ActionParams) (action.ActionResult, error) {
|
||||
result := struct {
|
||||
Path string `json:"path"`
|
||||
Repository string `json:"repository"`
|
||||
Owner string `json:"owner"`
|
||||
Content string `json:"content"`
|
||||
Path string `json:"path"`
|
||||
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",
|
||||
},
|
||||
},
|
||||
Required: []string{"path", "content"},
|
||||
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",
|
||||
},
|
||||
},
|
||||
Required: []string{"path", "repository", "owner", "content"},
|
||||
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