Skip to content

Commit

Permalink
Merge pull request #4 from tadashi-aikawa/0.5.0
Browse files Browse the repository at this point in the history
0.5.0
  • Loading branch information
tadashi-aikawa committed Nov 25, 2018
2 parents 8b44c4a + cd0ac9b commit 1243d24
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 24 deletions.
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ version := $(shell git rev-parse --abbrev-ref HEAD)

#------

package-windows:
package-windows: ## Create gowl.exe for Windows.
@mkdir -p dist
GOOS=windows GOARCH=amd64 go build -o dist/gowl.exe

package-linux:
package-linux: ## Create gowl for Linux.
@mkdir -p dist
GOOS=linux GOARCH=amd64 go build -a -tags netgo -installsuffix netgo --ldflags '-extldflags "-static"' -o dist/gowl

clean-package:
clean-package: ## Remove packages with dist.
rm -rf dist

release: clean-package
release: clean-package ## Build and upload packages, regarding branch name as version
@echo '1. Update versions'
@sed -i -r 's/const version = ".+"/const version = "$(version)"/g' args.go

Expand Down Expand Up @@ -56,4 +56,4 @@ release: clean-package
@echo 'Success All!!'
@echo 'Create a pull request and merge to master!!'
@echo 'https://github.com/tadashi-aikawa/gowl/compare/$(version)?expand=1'
@echo '..And deploy package!!'
@echo '..And deploy package!!'
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ vim = "vim"

[github]
token = "your github token"
# If `overrideUser = true`, Add userName and mailAddress to `.git/config` (`user.name` and `user.email`)
overrideUser = true
userName = "your github account name"
mailAddress = "your github email address"

[bitbucketserver]
baseurl = "http://your.bitbucket.server.url"
Expand Down Expand Up @@ -101,6 +105,15 @@ For example..
2. `gowl edit`


Configuration
-------------

Gowl uses toml format as a configuration file.
Please check `config.go`.

TODO: Definition table


Root directory
--------------

Expand All @@ -111,6 +124,24 @@ The root directory is determined by the following priority.
3. `<HOME>/.gowlroot`


Other
-----

If you use fzf(or peco), the following setting may make you happy!

bash
```
alias cdg="cd $(gowl list | fzf)"
```

fish
```
alias cdg "cd (gowl list | fzf)"
```

![DEMO2](https://raw.githubusercontent.com/tadashi-aikawa/gowl/master/demo2.gif)


For developer
-------------

Expand All @@ -124,3 +155,20 @@ For developer
```
$ dep ensure
```

### Release

#### Requirements

* make
* bash
* dep
* ghr

#### Packaging and deploy

Confirm that your branch name equals release version, then...

```
$ make release
```
2 changes: 1 addition & 1 deletion args.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/pkg/errors"
)

const version = "0.4.0"
const version = "0.5.0"
const usage = `Gowl.
Usage:
Expand Down
28 changes: 28 additions & 0 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,24 @@ func clone(url string, dst string, shallow bool, recursive bool) error {
return nil
}

func configureUser(dir string, name, mailAddress *string) error {
if name != nil {
fmt.Printf("Exec: git config user.name %v\n", *name)
if err := execCommand(&dir, "git", "config", "user.name", *name); err != nil {
return errors.Wrap(err, "Fail to config user.name "+*name)
}
}

if mailAddress != nil {
fmt.Printf("Exec: git config user.email %v\n", *mailAddress)
if err := execCommand(&dir, "git", "config", "user.email", *mailAddress); err != nil {
return errors.Wrap(err, "Fail to config user.email "+*mailAddress)
}
}

return nil
}

// CmdGet executes `get`
func CmdGet(handler IHandler, root string, force bool, shallow bool, recursive bool) error {
repo, err := doRepositorySelection(handler)
Expand All @@ -145,13 +163,23 @@ func CmdGet(handler IHandler, root string, force bool, shallow bool, recursive b
dst := filepath.Join(root, handler.GetPrefix(), repo.FullName)
if _, err := os.Stat(dst); os.IsNotExist(err) {
clone(cloneURL, dst, shallow, recursive)
if handler.GetOverrideUser() {
if err := configureUser(dst, handler.GetUserName(), handler.GetMailAddress()); err != nil {
return errors.Wrap(err, "Fail to configure "+dst)
}
}
} else {
if force {
fmt.Printf("Remove %v\n", dst)
if err := os.RemoveAll(dst); err != nil {
return errors.Wrap(err, "Fail to remove "+dst)
}
clone(cloneURL, dst, shallow, recursive)
if handler.GetOverrideUser() {
if err := configureUser(dst, handler.GetUserName(), handler.GetMailAddress()); err != nil {
return errors.Wrap(err, "Fail to configure "+dst)
}
}
} else {
fmt.Printf("Checkout master %v\n", dst)
if err := execCommand(&dst, "git", "checkout", "master"); err != nil {
Expand Down
14 changes: 8 additions & 6 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import (

// Service is information of Github, Bitbucket, and so on.
type Service struct {
Token *string
UserName *string
Password *string
BaseURL *string
Prefix *string
UseSSH bool
Token *string
UserName *string
Password *string
MailAddress *string
BaseURL *string
Prefix *string
UseSSH bool
OverrideUser bool
}

// Config configuration
Expand Down
Binary file added demo2.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
69 changes: 57 additions & 12 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,30 @@ func (r *Repository) fromBitbucketServer(bsr *BitbucketRepository) *Repository {
type IHandler interface {
SearchRepositories(word string) ([]Repository, error)
GetPrefix() string
GetUserName() *string
GetMailAddress() *string
GetUseSSH() bool
GetOverrideUser() bool
}

// GitHubHandler handles a github command.
type GitHubHandler struct {
client *github.Client
prefix string
useSSH bool
client *github.Client
prefix string
userName *string
mailAddress *string
useSSH bool
overrideUser bool
}

// BitbucketServerHandler handles a bitbucket command.
type BitbucketServerHandler struct {
client *BitbucketClient
prefix string
useSSH bool
client *BitbucketClient
prefix string
userName *string
mailAddress *string
useSSH bool
overrideUser bool
}

func createBitbucketClient(userName string, password string, baseURL string) *BitbucketClient {
Expand Down Expand Up @@ -112,18 +121,24 @@ func listRepositories(dir string) ([]string, error) {
// NewGithubHandler creates Githubhandler
func NewGithubHandler(config Config) IHandler {
return &GitHubHandler{
client: createGithubClient(*config.GitHub.Token),
prefix: "github.com",
useSSH: config.GitHub.UseSSH,
client: createGithubClient(*config.GitHub.Token),
prefix: "github.com",
userName: config.GitHub.UserName,
mailAddress: config.GitHub.MailAddress,
useSSH: config.GitHub.UseSSH,
overrideUser: config.GitHub.OverrideUser,
}
}

// NewBitbucketServerHandler creates BitbucketServerHandler
func NewBitbucketServerHandler(config Config) IHandler {
return &BitbucketServerHandler{
client: createBitbucketClient(*config.BitbucketServer.UserName, *config.BitbucketServer.Password, *config.BitbucketServer.BaseURL),
prefix: *config.BitbucketServer.Prefix,
useSSH: config.BitbucketServer.UseSSH,
client: createBitbucketClient(*config.BitbucketServer.UserName, *config.BitbucketServer.Password, *config.BitbucketServer.BaseURL),
prefix: *config.BitbucketServer.Prefix,
userName: config.BitbucketServer.UserName,
mailAddress: config.BitbucketServer.MailAddress,
useSSH: config.BitbucketServer.UseSSH,
overrideUser: config.BitbucketServer.OverrideUser,
}
}

Expand All @@ -137,6 +152,26 @@ func (h *BitbucketServerHandler) GetPrefix() string {
return h.prefix
}

// GetUserName gets user name
func (h *GitHubHandler) GetUserName() *string {
return h.userName
}

// GetUserName gets user name
func (h *BitbucketServerHandler) GetUserName() *string {
return h.userName
}

// GetMailAddress gets user mail address
func (h *GitHubHandler) GetMailAddress() *string {
return h.mailAddress
}

// GetMailAddress gets user mail address
func (h *BitbucketServerHandler) GetMailAddress() *string {
return h.mailAddress
}

// GetUseSSH gets whether use useSSH or not
func (h *GitHubHandler) GetUseSSH() bool {
return h.useSSH
Expand All @@ -147,6 +182,16 @@ func (h *BitbucketServerHandler) GetUseSSH() bool {
return h.useSSH
}

// GetOverrideUser returns OverrideUser
func (h *GitHubHandler) GetOverrideUser() bool {
return h.overrideUser
}

// GetOverrideUser returns OverrideUser
func (h *BitbucketServerHandler) GetOverrideUser() bool {
return h.overrideUser
}

// SearchRepositories search repositories.
func (h *GitHubHandler) SearchRepositories(word string) ([]Repository, error) {
res, _, err := h.client.Search.Repositories(context.Background(), word, &github.SearchOptions{
Expand Down

0 comments on commit 1243d24

Please sign in to comment.