Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
github
hub
提交
47a42322
H
hub
项目概览
github
/
hub
11 个月 前同步成功
通知
3
Star
22523
Fork
2406
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hub
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
47a42322
编写于
5月 29, 2013
作者:
J
Jingwen Owen Ou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Allow multiple configs
上级
64fa8168
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
68 addition
and
36 deletion
+68
-36
commands/pull_request.go
commands/pull_request.go
+1
-1
config/config.go
config/config.go
+44
-9
config/config_test.go
config/config_test.go
+17
-4
github/github.go
github/github.go
+6
-4
github/github_test.go
github/github_test.go
+0
-18
未找到文件。
commands/pull_request.go
浏览文件 @
47a42322
...
...
@@ -63,7 +63,7 @@ func pullRequest(cmd *Command, args []string) {
}
params
:=
github
.
PullRequestParams
{
title
,
body
,
repo
.
Base
,
repo
.
Head
}
gh
:=
github
.
New
GitHub
()
gh
:=
github
.
New
()
pullRequestResponse
,
err
:=
gh
.
CreatePullRequest
(
repo
.
Project
,
params
)
utils
.
Check
(
err
)
...
...
config/config.go
浏览文件 @
47a42322
...
...
@@ -3,6 +3,7 @@ package config
import
(
"bufio"
"encoding/json"
"errors"
"os"
"path/filepath"
)
...
...
@@ -18,27 +19,43 @@ func init() {
DefaultFile
=
filepath
.
Join
(
os
.
Getenv
(
"HOME"
),
".config"
,
"gh"
)
}
func
Load
()
(
*
Config
,
error
)
{
return
loadFrom
(
DefaultFile
)
func
Load
(
user
string
)
(
*
Config
,
error
)
{
configs
,
err
:=
loadFrom
(
DefaultFile
)
if
err
!=
nil
{
return
nil
,
err
}
for
_
,
c
:=
range
configs
{
if
c
.
User
==
user
{
return
&
c
,
nil
}
}
return
nil
,
errors
.
New
(
"There's no matching config for user: "
+
user
)
}
func
loadFrom
(
filename
string
)
(
*
Config
,
error
)
{
func
loadFrom
(
filename
string
)
(
[]
Config
,
error
)
{
f
,
err
:=
os
.
Open
(
filename
)
if
err
!=
nil
{
return
nil
,
err
}
return
doLoadFrom
(
f
)
}
func
doLoadFrom
(
f
*
os
.
File
)
([]
Config
,
error
)
{
defer
f
.
Close
()
reader
:=
bufio
.
NewReader
(
f
)
dec
:=
json
.
NewDecoder
(
reader
)
var
c
Config
err
=
dec
.
Decode
(
&
c
)
var
c
[]
Config
err
:
=
dec
.
Decode
(
&
c
)
if
err
!=
nil
{
return
nil
,
err
}
return
&
c
,
nil
return
c
,
nil
}
func
Save
(
config
Config
)
error
{
...
...
@@ -46,6 +63,8 @@ func Save(config Config) error {
}
func
saveTo
(
filename
string
,
config
Config
)
error
{
configs
,
_
:=
loadFrom
(
filename
)
err
:=
os
.
MkdirAll
(
filepath
.
Dir
(
filename
),
0771
)
if
err
!=
nil
{
return
err
...
...
@@ -55,10 +74,26 @@ func saveTo(filename string, config Config) error {
if
err
!=
nil
{
return
err
}
var
foundConfig
*
Config
for
_
,
c
:=
range
configs
{
if
c
.
User
==
config
.
User
{
foundConfig
=
&
c
break
}
}
if
foundConfig
==
nil
{
configs
=
append
(
configs
,
config
)
}
else
{
foundConfig
.
Token
=
config
.
Token
}
return
doSaveTo
(
f
,
configs
)
}
func
doSaveTo
(
f
*
os
.
File
,
configs
[]
Config
)
error
{
defer
f
.
Close
()
enc
:=
json
.
NewEncoder
(
f
)
enc
.
Encode
(
config
)
return
nil
return
enc
.
Encode
(
configs
)
}
config/config_test.go
浏览文件 @
47a42322
...
...
@@ -10,13 +10,26 @@ import (
func
TestSave
(
t
*
testing
.
T
)
{
config
:=
Config
{
"jingweno"
,
"123"
}
file
:=
"./test_support/test"
defer
os
.
RemoveAll
(
filepath
.
Dir
(
file
))
err
:=
saveTo
(
file
,
config
)
assert
.
Equal
(
t
,
nil
,
err
)
configs
,
err
:=
loadFrom
(
file
)
assert
.
Equal
(
t
,
nil
,
err
)
assert
.
Equal
(
t
,
1
,
len
(
configs
))
assert
.
Equal
(
t
,
"jingweno"
,
configs
[
0
]
.
User
)
assert
.
Equal
(
t
,
"123"
,
configs
[
0
]
.
Token
)
newConfig
,
_
:=
loadFrom
(
file
)
assert
.
Equal
(
t
,
"jingweno"
,
newConfig
.
User
)
assert
.
Equal
(
t
,
"123"
,
newConfig
.
Token
)
newConfig
:=
Config
{
"foo"
,
"456"
}
err
=
saveTo
(
file
,
newConfig
)
assert
.
Equal
(
t
,
nil
,
err
)
os
.
RemoveAll
(
filepath
.
Dir
(
file
))
configs
,
err
=
loadFrom
(
file
)
assert
.
Equal
(
t
,
nil
,
err
)
assert
.
Equal
(
t
,
2
,
len
(
configs
))
assert
.
Equal
(
t
,
"jingweno"
,
configs
[
0
]
.
User
)
assert
.
Equal
(
t
,
"123"
,
configs
[
0
]
.
Token
)
assert
.
Equal
(
t
,
"foo"
,
configs
[
1
]
.
User
)
assert
.
Equal
(
t
,
"456"
,
configs
[
1
]
.
Token
)
}
github/github.go
浏览文件 @
47a42322
...
...
@@ -47,11 +47,12 @@ type Authorization struct {
NoteUrl
string
`josn:"note_url"`
}
func
NewGitHub
()
*
GitHub
{
config
,
_
:=
config
.
Load
()
func
New
()
*
GitHub
{
project
:=
CurrentProject
()
config
,
err
:=
config
.
Load
(
project
.
Owner
)
var
user
,
auth
string
if
config
!
=
nil
{
if
err
=
=
nil
{
user
=
config
.
User
auth
=
config
.
Token
}
...
...
@@ -60,7 +61,7 @@ func NewGitHub() *GitHub {
auth
=
fmt
.
Sprintf
(
"token %s"
,
auth
)
}
return
&
GitHub
{
&
http
.
Client
{},
user
,
""
,
auth
}
return
&
GitHub
{
&
http
.
Client
{},
user
,
""
,
auth
,
project
}
}
func
hashAuth
(
u
,
p
string
)
string
{
...
...
@@ -73,6 +74,7 @@ type GitHub struct {
User
string
Password
string
Authorization
string
Project
*
Project
}
func
(
gh
*
GitHub
)
performBasicAuth
()
error
{
...
...
github/github_test.go
已删除
100644 → 0
浏览文件 @
64fa8168
package
github
import
(
"github.com/bmizerany/assert"
"github.com/jingweno/gh/config"
"net/http"
"testing"
)
func
_TestCreatePullRequest
(
t
*
testing
.
T
)
{
config
,
_
:=
config
.
Load
()
client
:=
&
http
.
Client
{}
gh
:=
GitHub
{
client
,
"jingweno"
,
"123"
,
config
.
Token
}
params
:=
PullRequestParams
{
"title"
,
"body"
,
"jingweno:master"
,
"jingweno:pull_request"
}
_
,
err
:=
gh
.
CreatePullRequest
(
CurrentProject
(),
params
)
assert
.
Equal
(
t
,
nil
,
err
)
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录