Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
github
hub
提交
0df403f1
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,发现更多精彩内容 >>
提交
0df403f1
编写于
5月 23, 2013
作者:
J
Jingwen Owen Ou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Start basic auth implementation
上级
ba1fe663
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
22 addition
and
15 deletion
+22
-15
config.go
config.go
+3
-3
config_test.go
config_test.go
+1
-3
git.go
git.go
+1
-1
git_hub.go
git_hub.go
+15
-4
git_hub_test.go
git_hub_test.go
+1
-3
main.go
main.go
+0
-1
pull_request.go
pull_request.go
+1
-0
未找到文件。
config.go
浏览文件 @
0df403f1
...
...
@@ -12,10 +12,10 @@ type Config struct {
Token
string
}
func
loadConfig
(
filename
string
)
Config
{
func
LoadConfig
(
filename
string
)
(
*
Config
,
error
)
{
f
,
err
:=
os
.
Open
(
filename
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
return
&
Config
{},
err
}
defer
f
.
Close
()
...
...
@@ -28,5 +28,5 @@ func loadConfig(filename string) Config {
log
.
Fatal
(
err
)
}
return
c
return
&
c
,
nil
}
config_test.go
浏览文件 @
0df403f1
...
...
@@ -2,13 +2,11 @@ package main
import
(
"github.com/bmizerany/assert"
"os"
"testing"
)
func
TestLoadConfig
(
t
*
testing
.
T
)
{
home
:=
os
.
Getenv
(
"HOME"
)
config
:=
loadConfig
(
home
+
"/.config/gh"
)
config
,
_
:=
LoadConfig
(
"./test_support/gh"
)
assert
.
Equal
(
t
,
"jingweno"
,
config
.
User
)
assert
.
Equal
(
t
,
"02a66f3bdde949182bc0d629f1abef0d501e6a53"
,
config
.
Token
)
...
...
git.go
浏览文件 @
0df403f1
...
...
@@ -38,7 +38,7 @@ func FetchGitHead() string {
// FIXME: only care about origin push remote now
func
FetchGitRemote
()
string
{
r
:=
regexp
.
MustCompile
(
"origin
\t
(.+)
\\
(push
\\
)"
)
r
:=
regexp
.
MustCompile
(
"origin
\t
(.+
github.com.+
)
\\
(push
\\
)"
)
for
_
,
output
:=
range
execGitCmd
([]
string
{
"remote"
,
"-v"
})
{
if
r
.
MatchString
(
output
)
{
return
r
.
FindStringSubmatch
(
output
)[
1
]
...
...
git_hub.go
浏览文件 @
0df403f1
...
...
@@ -7,6 +7,9 @@ import (
"fmt"
"io/ioutil"
"net/http"
"net/url"
"os"
"path/filepath"
)
const
(
...
...
@@ -26,11 +29,11 @@ type unprocessableEntity struct {
Errors
[]
unprocessableEntityError
`json:"errors"`
}
func
NewGitHub
(
configFile
string
)
GitHub
{
config
:=
loadConfig
(
configFile
)
c
lient
:=
&
http
.
Client
{}
func
NewGitHub
(
)
*
GitHub
{
config
File
:=
filepath
.
Join
(
os
.
Getenv
(
"HOME"
),
".config"
,
"gh"
)
c
onfig
,
_
:=
LoadConfig
(
configFile
)
return
GitHub
{
client
,
config
.
Token
}
return
&
GitHub
{
&
http
.
Client
{}
,
config
.
Token
}
}
type
GitHub
struct
{
...
...
@@ -38,7 +41,15 @@ type GitHub struct {
Authorization
string
}
func
(
gh
*
GitHub
)
performBasicAuth
(
url
*
url
.
URL
)
{
url
.
String
()
}
func
(
gh
*
GitHub
)
call
(
request
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
if
len
(
gh
.
Authorization
)
==
0
{
gh
.
performBasicAuth
(
request
.
URL
)
}
request
.
Header
.
Set
(
"Authorization"
,
"token "
+
gh
.
Authorization
)
response
,
err
:=
gh
.
httpClient
.
Do
(
request
)
...
...
git_hub_test.go
浏览文件 @
0df403f1
...
...
@@ -3,13 +3,11 @@ package main
import
(
"github.com/bmizerany/assert"
"net/http"
"os"
"testing"
)
func
_TestCreatePullRequest
(
t
*
testing
.
T
)
{
home
:=
os
.
Getenv
(
"HOME"
)
config
:=
loadConfig
(
home
+
"/.config/gh"
)
config
,
_
:=
LoadConfig
(
"./test_support/gh"
)
client
:=
&
http
.
Client
{}
gh
:=
GitHub
{
client
,
config
.
Token
}
...
...
main.go
浏览文件 @
0df403f1
...
...
@@ -45,7 +45,6 @@ var (
cmdPullRequest
,
cmdHelp
,
}
gh
=
NewGitHub
(
os
.
Getenv
(
"HOME"
)
+
"/.config/gh"
)
repo
=
NewRepo
()
)
...
...
pull_request.go
浏览文件 @
0df403f1
...
...
@@ -65,6 +65,7 @@ func pullRequest(cmd *Command, args []string) {
}
params
:=
PullRequestParams
{
title
,
body
,
flagPullRequestBase
,
flagPullRequestHead
}
gh
:=
NewGitHub
()
pullRequestResponse
,
err
:=
gh
.
CreatePullRequest
(
repo
.
Owner
,
repo
.
Project
,
params
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录