-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from dyweb/app/github/init
[app][github] Init GitHub app to manage issue labels #77 - read from `~/.ayi.yml` for user config (only github token) - save label from repository - a html page for default label colors #80
- Loading branch information
Showing
31 changed files
with
967 additions
and
126 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package git | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
|
||
"github.com/dyweb/gommon/errors" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func (a *App) cloneCommand() *cobra.Command { | ||
var useSSH bool | ||
root := &cobra.Command{ | ||
Use: "clone", | ||
Short: "auto deduct clone url", | ||
Long: "Detect repository from url and convert to a cloneable url", | ||
Example: ` | ||
ayi git clone dyweb/gommon | ||
`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if len(args) < 1 { | ||
a.log.Fatal("must provide at least one url") | ||
return | ||
} | ||
err := a.clone(args, useSSH) | ||
if err != nil { | ||
a.log.Fatal(err) | ||
} | ||
}, | ||
} | ||
root.Flags().BoolVar(&useSSH, "ssh", true, "use ssh instead of http") | ||
return root | ||
} | ||
|
||
// TODO: considering clone one repo and move the loop to caller? | ||
func (a *App) clone(urls []string, ssh bool) error { | ||
merr := errors.NewMultiErr() | ||
for _, u := range urls { | ||
repo, err := UrlToRepo(u) | ||
if err != nil { | ||
a.log.Warnf("invalid repo url %s", err) | ||
merr.Append(errors.Wrap(err, "invalid repo url")) | ||
continue | ||
} | ||
var ( | ||
src string | ||
dst string | ||
) | ||
if ssh { | ||
src = repo.SshUrl() | ||
} else { | ||
src = repo.HttpUrl() | ||
} | ||
if DefaultWorkspace() != "" { | ||
dst = filepath.Join(DefaultWorkspace(), repo.Host, repo.Owner, repo.Repository) | ||
} else { | ||
dst = "" | ||
} | ||
// TODO: clone result and keep track of cloned repo | ||
cmd := fmt.Sprintf("clone %s %s", src, dst) | ||
a.log.Infof("execute git %s", cmd) | ||
if err := RunCommand(cmd); err != nil { | ||
merr.Append(err) | ||
a.log.Error(err) | ||
} else { | ||
a.log.Infof("success git %s", cmd) | ||
} | ||
} | ||
return merr.ErrorOrNil() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.