hub/commands/utils.go

56 строки
968 B
Go
Исходник Обычный вид История

2013-06-03 04:04:25 +04:00
package commands
import (
"github.com/jingweno/gh/github"
2013-07-20 09:53:38 +04:00
"github.com/jingweno/gh/utils"
2013-12-03 23:35:52 +04:00
"github.com/jingweno/go-octokit/octokit"
2013-07-01 21:11:02 +04:00
"os"
"path/filepath"
"strings"
2013-06-03 04:04:25 +04:00
)
2013-07-01 21:11:02 +04:00
func isDir(file string) bool {
f, err := os.Open(file)
if err != nil {
return false
}
defer f.Close()
fi, err := f.Stat()
if err != nil {
return false
}
return fi.IsDir()
}
2013-07-02 23:08:48 +04:00
2013-11-07 02:04:04 +04:00
func parseUserBranchFromPR(pullRequest *octokit.PullRequest) (user string, branch string) {
userBranch := strings.SplitN(pullRequest.Head.Label, ":", 2)
user = userBranch[0]
if len(userBranch) > 1 {
branch = userBranch[1]
} else {
branch = pullRequest.Head.Ref
}
return
}
2013-07-20 09:53:38 +04:00
func hasGitRemote(name string) bool {
remotes, err := github.Remotes()
2013-07-20 09:53:38 +04:00
utils.Check(err)
for _, remote := range remotes {
if remote.Name == name {
return true
}
}
return false
}
func isEmptyDir(path string) bool {
fullPath := filepath.Join(path, "*")
match, _ := filepath.Glob(fullPath)
return match == nil
}