Skip to content

Commit

Permalink
Merge pull request #79 from dyweb/app/github/init
Browse files Browse the repository at this point in the history
[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
at15 authored May 6, 2018
2 parents 490b6ad + bc3e458 commit 2cb2a14
Show file tree
Hide file tree
Showing 31 changed files with 967 additions and 126 deletions.
64 changes: 55 additions & 9 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
# go-tests = true
# unused-packages = true

# the latest release v15.0.0 was released on Jan 2018
[[constraint]]
name = "github.com/google/go-github"
branch = "master"

[prune]
go-tests = true
unused-packages = true
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ FLAGS = -X main.version=$(VERSION) -X main.commit=$(BUILD_COMMIT) -X main.buildT

.PHONY: fmt
fmt:
gofmt -d -l -w ./cmd ./app ./util
gofmt -d -l -w ./cmd ./app ./config ./util

.PHONY: test
test:
go test -v -cover ./app/... ./util/...
go test -v -cover ./app/... ./config ./util/...

.PHONY: install
install:
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![GoDoc](https://godoc.org/github.com/dyweb/Ayi?status.svg)](https://godoc.org/github.com/dyweb/Ayi)
[![Build Status](https://travis-ci.org/dyweb/Ayi.svg)](https://travis-ci.org/dyweb/Ayi)

Ayi helps you organize workspace
Ayi organizes your workspace

## Installation

Expand All @@ -12,10 +12,9 @@ Pre-built binary
- Download from [releases](https://github.com/dyweb/Ayi/releases)
- NOTE: Mac and Windows are no longer tested

Build from source
Build from source (recommended)

- go 1.9+
- dep
- go 1.9+ & [dep](https://github.com/golang/dep)
- `dep ensure`
- `make install`

Expand Down
61 changes: 3 additions & 58 deletions app/git/app.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package git

import (
"fmt"
"os"
"path/filepath"

"github.com/dyweb/gommon/errors"
"github.com/dyweb/Ayi"
dlog "github.com/dyweb/gommon/log"
"github.com/spf13/cobra"
)
Expand All @@ -16,7 +14,7 @@ type App struct {
log *dlog.Logger
}

func NewApp() (*App, error) {
func NewApp(r Ayi.Registry) (*App, error) {
a := &App{}
dlog.NewStructLogger(log, a)
root := &cobra.Command{
Expand All @@ -28,64 +26,11 @@ func NewApp() (*App, error) {
os.Exit(1)
},
}
var useSsh bool
clone := &cobra.Command{
Use: "clone",
Short: "auto deduct clone url",
Long: "Detect repository from url and convert to a cloneable url",
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)
}
},
}
clone.Flags().BoolVar(&useSsh, "ssh", true, "use ssh instead of http")
root.AddCommand(clone)
root.AddCommand(a.cloneCommand())
a.root = root
return a, nil
}

func (a *App) CobraCommand() *cobra.Command {
return a.root
}

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()
}
70 changes: 70 additions & 0 deletions app/git/clone.go
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()
}
4 changes: 2 additions & 2 deletions app/git/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const appName = "git"
var log = logutil.NewPackageLogger()

func init() {
Ayi.RegisterAppFactory(appName, func() (Ayi.App, error) {
return NewApp()
Ayi.RegisterAppFactory(appName, func(r Ayi.Registry) (Ayi.App, error) {
return NewApp(r)
})
}
Loading

0 comments on commit 2cb2a14

Please sign in to comment.