Check repository permission for clone URL

This commit is contained in:
Jingwen Owen Ou 2014-04-07 21:44:08 -07:00
Родитель 30f047300c
Коммит 47a9aa9ec6
6 изменённых файлов: 42 добавлений и 10 удалений

4
Godeps/Godeps.json сгенерированный
Просмотреть файл

@ -60,8 +60,8 @@
}, },
{ {
"ImportPath": "github.com/octokit/go-octokit/octokit", "ImportPath": "github.com/octokit/go-octokit/octokit",
"Comment": "v0.4.0-71-g4fee5e3", "Comment": "v0.4.0-72-ga381371",
"Rev": "4fee5e3019ca20d12c93c1b7f18f20c4a6afff24" "Rev": "a38137165e45c66d9b89e2b2b49ad01da497185f"
}, },
{ {
"ImportPath": "github.com/ogier/pflag", "ImportPath": "github.com/ogier/pflag",

10
Godeps/_workspace/src/github.com/octokit/go-octokit/octokit/repositories.go сгенерированный поставляемый
Просмотреть файл

@ -1,9 +1,10 @@
package octokit package octokit
import ( import (
"github.com/lostisland/go-sawyer/hypermedia"
"net/url" "net/url"
"time" "time"
"github.com/lostisland/go-sawyer/hypermedia"
) )
var ( var (
@ -68,6 +69,7 @@ type Repository struct {
PushedAt time.Time `json:"pushed_at,omitempty"` PushedAt time.Time `json:"pushed_at,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty"` CreatedAt time.Time `json:"created_at,omitempty"`
UpdatedAt time.Time `json:"updated_at,omitempty"` UpdatedAt time.Time `json:"updated_at,omitempty"`
Permissions Permissions `json:"permissions,omitempty"`
Organization *Organization `json:"organization,omitempty"` Organization *Organization `json:"organization,omitempty"`
Parent *Repository `json:"parent,omitempty"` Parent *Repository `json:"parent,omitempty"`
Source *Repository `json:"source,omitempty"` Source *Repository `json:"source,omitempty"`
@ -75,3 +77,9 @@ type Repository struct {
HasWiki bool `json:"has_wiki,omitempty"` HasWiki bool `json:"has_wiki,omitempty"`
HasDownloads bool `json:"has_downloads,omitempty"` HasDownloads bool `json:"has_downloads,omitempty"`
} }
type Permissions struct {
Admin bool
Push bool
Pull bool
}

6
Godeps/_workspace/src/github.com/octokit/go-octokit/octokit/repositories_test.go сгенерированный поставляемый
Просмотреть файл

@ -3,9 +3,10 @@ package octokit
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/bmizerany/assert"
"net/http" "net/http"
"testing" "testing"
"github.com/bmizerany/assert"
) )
func TestRepositoresService_One(t *testing.T) { func TestRepositoresService_One(t *testing.T) {
@ -34,6 +35,9 @@ func TestRepositoresService_One(t *testing.T) {
assert.Equal(t, "git://github.com/jingweno/octokat.git", repo.GitURL) assert.Equal(t, "git://github.com/jingweno/octokat.git", repo.GitURL)
assert.Equal(t, "git@github.com:jingweno/octokat.git", repo.SSHURL) assert.Equal(t, "git@github.com:jingweno/octokat.git", repo.SSHURL)
assert.Equal(t, "master", repo.MasterBranch) assert.Equal(t, "master", repo.MasterBranch)
assert.T(t, !repo.Permissions.Admin)
assert.T(t, !repo.Permissions.Push)
assert.T(t, repo.Permissions.Pull)
} }
func TestRepositoresService_All(t *testing.T) { func TestRepositoresService_All(t *testing.T) {

Просмотреть файл

@ -75,10 +75,14 @@ func transformCloneArgs(args *Args) {
} }
project := github.NewProject(owner, name, hostStr) project := github.NewProject(owner, name, hostStr)
isSSH = isSSH || if !isSSH &&
args.Command != "submodule" && args.Command != "submodule" &&
host != nil && !args.Noop &&
project.Owner == host.User !github.IsHttpsProtocol() {
client := github.NewClient(project.Host)
repo, err := client.Repository(project)
isSSH = (err == nil) && (repo.Private || repo.Permissions.Push)
}
url := project.GitURL(name, owner, isSSH) url := project.GitURL(name, owner, isSSH)
args.ReplaceParam(i, url) args.ReplaceParam(i, url)

Просмотреть файл

@ -1,10 +1,11 @@
package commands package commands
import ( import (
"github.com/bmizerany/assert"
"github.com/github/hub/github"
"os" "os"
"testing" "testing"
"github.com/bmizerany/assert"
"github.com/github/hub/github"
) )
func TestTransformCloneArgs(t *testing.T) { func TestTransformCloneArgs(t *testing.T) {
@ -39,7 +40,7 @@ func TestTransformCloneArgs(t *testing.T) {
transformCloneArgs(args) transformCloneArgs(args)
assert.Equal(t, 1, args.ParamsSize()) assert.Equal(t, 1, args.ParamsSize())
assert.Equal(t, "git@github.com:jingweno/jekyll_and_hyde.git", args.FirstParam()) assert.Equal(t, "git://github.com/jingweno/jekyll_and_hyde.git", args.FirstParam())
args = NewArgs([]string{"clone", "-p", "jekyll_and_hyde"}) args = NewArgs([]string{"clone", "-p", "jekyll_and_hyde"})
transformCloneArgs(args) transformCloneArgs(args)

Просмотреть файл

@ -4,8 +4,23 @@ package github
import ( import (
"code.google.com/p/go.crypto/ssh/terminal" "code.google.com/p/go.crypto/ssh/terminal"
"github.com/github/hub/git"
) )
func IsHttpsProtocol() bool {
httpProcotol, _ := git.Config("hub.protocol")
if httpProcotol == "https" {
return true
}
httpClone, _ := git.Config("--bool hub.http-clone")
if httpClone == "true" {
return true
}
return false
}
func isTerminal(fd uintptr) bool { func isTerminal(fd uintptr) bool {
return terminal.IsTerminal(int(fd)) return terminal.IsTerminal(int(fd))
} }