Skip to content

Commit

Permalink
Merge pull request #405 from merico-dev/feat-gh
Browse files Browse the repository at this point in the history
feat: `util/github` org supporting
  • Loading branch information
IronCore864 authored Apr 11, 2022
2 parents b1a9f9c + 41451a5 commit 4c927b1
Show file tree
Hide file tree
Showing 59 changed files with 214 additions and 58 deletions.
2 changes: 2 additions & 0 deletions docs/plugins/github-repo-scaffolding-golang.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ tools:
options:
# the repo's owner. It should be case-sensitive here; strictly use your GitHub user name; please change the value below.
owner: YOUR_GITHUB_USERNAME
# the repo's org. If you set this property, then the new repo will be created under the org you're given, and the "owner" setting above will be ignored.
org: YOUR_ORGANIZATION_NAME
# the repo which you'd like to create; please change the value below.
repo: YOUR_REPO_NAME
# the branch of the repo you'd like to hold the code
Expand Down
2 changes: 2 additions & 0 deletions docs/plugins/githubactions-golang.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ tools:
options:
# the repo's owner. It should be case-sensitive here; strictly use your GitHub user name; please change the value below.
owner: YOUR_GITHUB_USERNAME
# the repo's org. If you set this property, then the new repo will be created under the org you're given, and the "owner" setting above will be ignored.
org: YOUR_ORGANIZATION_NAME
# the repo where you'd like to setup GitHub Actions; please change the value below to an existing repo.
repo: YOURE_REPO_NAME
# programming language specific settings
Expand Down
2 changes: 2 additions & 0 deletions docs/plugins/githubactions-nodejs.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ tools:
options:
# the repo's owner. It should be case-sensitive here; strictly use your GitHub user name; please change the value below.
owner: YOUR_GITHUB_USERNAME
# the repo's org. If you set this property, then the new repo will be created under the org you're given, and the "owner" setting above will be ignored.
org: YOUR_ORGANIZATION_NAME
# the repo where you'd like to setup GitHub Actions; please change the value below to an existing repo.
repo: YOURE_REPO_NAME
# programming language specific settings
Expand Down
2 changes: 2 additions & 0 deletions docs/plugins/githubactions-python.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ tools:
options:
# the repo's owner. It should be case-sensitive here; strictly use your GitHub user name; please change the value below.
owner: YOUR_GITHUB_USERNAME
# the repo's org. If you set this property, then the new repo will be created under the org you're given, and the "owner" setting above will be ignored.
org: YOUR_ORGANIZATION_NAME
# the repo where you'd like to setup GitHub Actions; please change the value below to an existing repo.
repo: YOURE_REPO_NAME
# programming language specific settings
Expand Down
2 changes: 2 additions & 0 deletions docs/plugins/jira-github-integ.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ tools:
options:
# the repo's owner
owner: YOUR_GITHUB_USERNAME
# the repo's org. If you set this property, then the new repo will be created under the org you're given, and the "owner" setting above will be ignored.
org: YOUR_ORGANIZATION_NAME
# the repo where you'd like to setup GitHub Actions
repo: YOUR_REPO_NAME
# "base url: https://id.atlassian.net"
Expand Down
2 changes: 2 additions & 0 deletions docs/plugins/trello-github-integ.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ tools:
options:
# the repo's owner. It should be case-sensitive here; strictly use your GitHub user name; please change the value below.
owner: YOUR_GITHUB_USERNAME
# the repo's org. If you set this property, then the new repo will be created under the org you're given, and the "owner" setting above will be ignored.
org: YOUR_ORGANIZATION_NAME
# the repo where you'd like to setup GitHub Actions; please change the value below.
repo: YOUR_REPO_NAME
# reference parameters come from dependency, their usage will be explained later
Expand Down
2 changes: 2 additions & 0 deletions docs/plugins/trello.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ tools:
options:
# the repo's owner
owner: YOUR_GITHUB_USERNAME
# the repo's org. If you set this property, then the new repo will be created under the org you're given, and the "owner" setting above will be ignored.
org: YOUR_ORGANIZATION_NAME
# for which repo this board will be used
repo: YOUR_REPO_NAME
# the Tello board name. If empty, use owner/repo as the board's name.
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/plugin/githubactions/golang/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func Create(options map[string]interface{}) (map[string]interface{}, error) {

ghOptions := &github.Option{
Owner: opts.Owner,
Org: opts.Org,
Repo: opts.Repo,
NeedAuth: true,
}
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/plugin/githubactions/golang/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func Delete(options map[string]interface{}) (bool, error) {

ghOptions := &github.Option{
Owner: opts.Owner,
Org: opts.Org,
Repo: opts.Repo,
NeedAuth: true,
}
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/plugin/githubactions/golang/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
ga "github.com/devstream-io/devstream/internal/pkg/plugin/githubactions"
)

// TODO(daniel-hutao): Options should keep as same as other plugins named Param
// Options is the struct for configurations of the githubactions plugin.
type Options struct {
Owner string
Org string
Repo string
Branch string
Language *ga.Language
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/plugin/githubactions/golang/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func Read(options map[string]interface{}) (map[string]interface{}, error) {

ghOptions := &github.Option{
Owner: opts.Owner,
Org: opts.Org,
Repo: opts.Repo,
NeedAuth: true,
}
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/plugin/githubactions/golang/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func Update(options map[string]interface{}) (map[string]interface{}, error) {

ghOptions := &github.Option{
Owner: opts.Owner,
Org: opts.Org,
Repo: opts.Repo,
NeedAuth: true,
}
Expand Down
6 changes: 3 additions & 3 deletions internal/pkg/plugin/githubactions/golang/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
func validate(opts *Options) []error {
retErrors := make([]error, 0)

// owner/repo/branch
if opts.Owner == "" {
retErrors = append(retErrors, fmt.Errorf("owner is empty"))
// owner/org/repo/branch
if opts.Owner == "" && opts.Org == "" {
retErrors = append(retErrors, fmt.Errorf("owner and org are empty"))
}
if opts.Repo == "" {
retErrors = append(retErrors, fmt.Errorf("repo is empty"))
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/plugin/githubactions/nodejs/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func Create(options map[string]interface{}) (map[string]interface{}, error) {

ghOptions := &github.Option{
Owner: opts.Owner,
Org: opts.Org,
Repo: opts.Repo,
NeedAuth: true,
}
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/plugin/githubactions/nodejs/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func Delete(options map[string]interface{}) (bool, error) {

ghOptions := &github.Option{
Owner: opts.Owner,
Org: opts.Org,
Repo: opts.Repo,
NeedAuth: true,
}
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/plugin/githubactions/nodejs/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
ga "github.com/devstream-io/devstream/internal/pkg/plugin/githubactions"
)

// TODO(daniel-hutao): Options should keep as same as other plugins named Param
// Options is the struct for configurations of the githubactions plugin.
type Options struct {
Owner string
Org string
Repo string
Branch string
Language *ga.Language
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/plugin/githubactions/nodejs/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func Read(options map[string]interface{}) (map[string]interface{}, error) {

ghOptions := &github.Option{
Owner: opts.Owner,
Org: opts.Org,
Repo: opts.Repo,
NeedAuth: true,
}
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/plugin/githubactions/nodejs/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func Update(options map[string]interface{}) (map[string]interface{}, error) {

ghOptions := &github.Option{
Owner: opts.Owner,
Org: opts.Org,
Repo: opts.Repo,
NeedAuth: true,
}
Expand Down
6 changes: 3 additions & 3 deletions internal/pkg/plugin/githubactions/nodejs/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import "fmt"
func validate(opts *Options) []error {
retErrors := make([]error, 0)

// owner/repo/branch
if opts.Owner == "" {
retErrors = append(retErrors, fmt.Errorf("owner is empty"))
// owner/org/repo/branch
if opts.Owner == "" && opts.Org == "" {
retErrors = append(retErrors, fmt.Errorf("owner and org are empty"))
}
if opts.Repo == "" {
retErrors = append(retErrors, fmt.Errorf("repo is empty"))
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/plugin/githubactions/python/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func Create(options map[string]interface{}) (map[string]interface{}, error) {

ghOptions := &github.Option{
Owner: opts.Owner,
Org: opts.Org,
Repo: opts.Repo,
NeedAuth: true,
}
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/plugin/githubactions/python/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func Delete(options map[string]interface{}) (bool, error) {

ghOptions := &github.Option{
Owner: opts.Owner,
Org: opts.Org,
Repo: opts.Repo,
NeedAuth: true,
}
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/plugin/githubactions/python/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
ga "github.com/devstream-io/devstream/internal/pkg/plugin/githubactions"
)

// TODO(daniel-hutao): Options should keep as same as other plugins named Param
// Options is the struct for configurations of the githubactions plugin.
type Options struct {
Owner string
Org string
Repo string
Branch string
Language *ga.Language
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/plugin/githubactions/python/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func Read(options map[string]interface{}) (map[string]interface{}, error) {

ghOptions := &github.Option{
Owner: opts.Owner,
Org: opts.Org,
Repo: opts.Repo,
NeedAuth: true,
}
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/plugin/githubactions/python/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func Update(options map[string]interface{}) (map[string]interface{}, error) {

ghOptions := &github.Option{
Owner: opts.Owner,
Org: opts.Org,
Repo: opts.Repo,
NeedAuth: true,
}
Expand Down
6 changes: 3 additions & 3 deletions internal/pkg/plugin/githubactions/python/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
func validate(opts *Options) []error {
retErrors := make([]error, 0)

// owner/repo/branch
if opts.Owner == "" {
retErrors = append(retErrors, fmt.Errorf("owner is empty"))
// owner/org/repo/branch
if opts.Owner == "" && opts.Org == "" {
retErrors = append(retErrors, fmt.Errorf("owner and org are empty"))
}
if opts.Repo == "" {
retErrors = append(retErrors, fmt.Errorf("repo is empty"))
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/plugin/jiragithub/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func Create(options map[string]interface{}) (map[string]interface{}, error) {

ghOptions := &github.Option{
Owner: opts.Owner,
Org: opts.Org,
Repo: opts.Repo,
NeedAuth: true,
}
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/plugin/jiragithub/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func Delete(options map[string]interface{}) (bool, error) {

ghOptions := &github.Option{
Owner: opts.Owner,
Org: opts.Org,
Repo: opts.Repo,
NeedAuth: true,
}
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/plugin/jiragithub/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package jiragithub
// Options is the struct for configurations of the jiragithub plugin.
type Options struct {
Owner string
Org string
Repo string
JiraBaseUrl string
JiraUserEmail string
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/plugin/jiragithub/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func Read(options map[string]interface{}) (map[string]interface{}, error) {

ghOptions := &github.Option{
Owner: opts.Owner,
Org: opts.Org,
Repo: opts.Repo,
NeedAuth: true,
}
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/plugin/jiragithub/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func Update(options map[string]interface{}) (map[string]interface{}, error) {

ghOptions := &github.Option{
Owner: opts.Owner,
Org: opts.Org,
Repo: opts.Repo,
NeedAuth: true,
}
Expand Down
6 changes: 3 additions & 3 deletions internal/pkg/plugin/jiragithub/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import "fmt"
func validate(opts *Options) []error {
retErrors := make([]error, 0)

// owner/repo/branch
if opts.Owner == "" {
retErrors = append(retErrors, fmt.Errorf("owner is empty"))
// owner/org/repo/branch
if opts.Owner == "" && opts.Org == "" {
retErrors = append(retErrors, fmt.Errorf("owner and org are empty"))
}
if opts.Repo == "" {
retErrors = append(retErrors, fmt.Errorf("repo is empty"))
Expand Down
5 changes: 3 additions & 2 deletions internal/pkg/plugin/reposcaffolding/github/golang/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,13 @@ func download() error {
}

func push(opts *Options) error {
ghOption := &github.Option{
ghOptions := &github.Option{
Owner: opts.Owner,
Org: opts.Org,
Repo: opts.Repo,
NeedAuth: true,
}
ghClient, err := github.NewClient(ghOption)
ghClient, err := github.NewClient(ghOptions)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func Delete(options map[string]interface{}) (bool, error) {
func uninstall(opts *Options) (bool, error) {
ghOptions := &github.Option{
Owner: opts.Owner,
Org: opts.Org,
Repo: opts.Repo,
NeedAuth: true,
}
Expand Down
14 changes: 10 additions & 4 deletions internal/pkg/plugin/reposcaffolding/github/golang/golang.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ type Repo struct {

func InitRepoLocalAndPushToRemote(repoPath string, opts *Options, ghClient *github.Client) error {
var retErr error
if err := ghClient.CreateRepo(); err != nil {
// It's ok to give the opts.Org to CreateRepo() when create a repository for a authenticated user.
if err := ghClient.CreateRepo(opts.Org); err != nil {
log.Infof("Failed to create repo: %s.", err)
return err
}
Expand Down Expand Up @@ -117,7 +118,7 @@ func WalkLocalRepoPath(repoPath string, opts *Options, ghClient *github.Client)
if strings.Contains(newPathForGithub, "gitignore") {
err := ghClient.CreateFile(content, strings.TrimSuffix(newPathForGithub, ".tpl"), mainBranch)
if err != nil {
log.Debugf("Failed to add the .gitignore file.")
log.Debugf("Failed to add the .gitignore file: %s.", err)
return err
}
log.Debugf("Added the .gitignore file.")
Expand All @@ -142,12 +143,17 @@ func MergeCommits(ghClient *github.Client, mainBranch string) error {
}

func Render(filePath string, opts *Options) ([]byte, error) {
var owner = opts.Owner
if opts.Org != "" {
owner = opts.Org
}

config := Config{
AppName: opts.Repo,
ImageRepo: opts.ImageRepo,
Repo: Repo{
Name: opts.Repo,
Owner: opts.Owner,
Owner: owner,
},
}
log.Debugf("FilePath: %s.", filePath)
Expand Down Expand Up @@ -195,7 +201,7 @@ func replaceAppNameInPathStr(filePath, appName string) (string, error) {
}
newFilePath := reg.ReplaceAllString(filePath, appName)

log.Debugf("New filePath: %s.", newFilePath)
log.Debugf("New filePath: \"%s\".", newFilePath)

return newFilePath, nil
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package golang

// TODO(daniel-hutao): Param should keep as same as other plugins named Param or keep as same as plugin github-actions?
type Options struct {
Owner string
Org string
Repo string
Branch string
ImageRepo string `mapstructure:"image_repo"`
Expand Down
10 changes: 8 additions & 2 deletions internal/pkg/plugin/reposcaffolding/github/golang/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@ func Read(options map[string]interface{}) (map[string]interface{}, error) {
}

func buildReadState(opts *Options) (map[string]interface{}, error) {
var owner = opts.Owner
if opts.Org != "" {
owner = opts.Org
}

ghOptions := &github.Option{
Owner: opts.Owner,
Org: opts.Org,
Repo: opts.Repo,
NeedAuth: true,
}
Expand All @@ -47,11 +53,11 @@ func buildReadState(opts *Options) (map[string]interface{}, error) {
}

res := make(map[string]interface{})
res["owner"] = *repo.Owner.Login
res["owner"] = owner
res["repoName"] = *repo.Name

outputs := make(map[string]interface{})
outputs["owner"] = opts.Owner
outputs["owner"] = owner
outputs["repo"] = opts.Repo
outputs["repoURL"] = fmt.Sprintf("https://github.com/%s/%s.git", opts.Owner, opts.Repo)

Expand Down
Loading

0 comments on commit 4c927b1

Please sign in to comment.