2013-06-03 04:04:25 +04:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2013-12-28 13:14:07 +04:00
|
|
|
"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"
|
2013-12-21 04:45:48 +04:00
|
|
|
"path/filepath"
|
2013-07-29 21:50:28 +04:00
|
|
|
"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) {
|
2013-07-29 21:50:28 +04:00
|
|
|
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 {
|
2013-12-28 13:14:07 +04:00
|
|
|
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
|
|
|
|
}
|
2013-12-21 04:45:48 +04:00
|
|
|
|
|
|
|
func isEmptyDir(path string) bool {
|
|
|
|
fullPath := filepath.Join(path, "*")
|
|
|
|
match, _ := filepath.Glob(fullPath)
|
|
|
|
return match == nil
|
|
|
|
}
|