Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
github
hub
提交
04fa2016
H
hub
项目概览
github
/
hub
12 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
04fa2016
编写于
1月 29, 2018
作者:
M
Mislav Marohnić
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Create a repository without octokit
上级
de6a2bd5
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
34 addition
and
21 deletion
+34
-21
features/authentication.feature
features/authentication.feature
+7
-0
features/create.feature
features/create.feature
+13
-1
github/client.go
github/client.go
+14
-20
未找到文件。
features/authentication.feature
浏览文件 @
04fa2016
...
...
@@ -22,6 +22,7 @@ Feature: OAuth authentication
}
post('/user/repos') {
halt 401 unless request.env['HTTP_AUTHORIZATION'] == 'token OTOKEN'
status 201
json :full_name => 'mislav/dotfiles'
}
"""
...
...
@@ -60,6 +61,7 @@ Feature: OAuth authentication
json :login => 'MiSlAv'
}
post('/user/repos') {
status 201
json :full_name => 'mislav/dotfiles'
}
"""
...
...
@@ -102,12 +104,14 @@ Feature: OAuth authentication
"""
post('/authorizations') {
assert_basic_auth 'mislav', 'kitty'
status 201
json :token => 'OTOKEN'
}
get('/user') {
json :login => 'mislav'
}
post('/user/repos') {
status 201
json :full_name => 'mislav/dotfiles'
}
"""
...
...
@@ -126,6 +130,7 @@ Feature: OAuth authentication
}
post('/user/repos') {
halt 401 unless request.env["HTTP_AUTHORIZATION"] == "token OTOKEN"
status 201
json :full_name => 'mislav/dotfiles'
}
"""
...
...
@@ -212,6 +217,7 @@ Feature: OAuth authentication
json :login => 'mislav'
}
post('/user/repos') {
status 201
json :full_name => 'mislav/dotfiles'
}
"""
...
...
@@ -245,6 +251,7 @@ Feature: OAuth authentication
json :login => 'mislav'
}
post('/user/repos') {
status 201
json :full_name => 'mislav/dotfiles'
}
"""
...
...
features/create.feature
浏览文件 @
04fa2016
...
...
@@ -8,6 +8,7 @@ Feature: hub create
"""
post('/user/repos') {
assert :private => false
status 201
json :full_name => 'mislav/dotfiles'
}
"""
...
...
@@ -20,6 +21,7 @@ Feature: hub create
"""
post('/user/repos') {
assert :private => true
status 201
json :full_name => 'mislav/dotfiles'
}
"""
...
...
@@ -30,6 +32,7 @@ Feature: hub create
Given the GitHub API server
:
"""
post('/user/repos') {
status 201
json :full_name => 'mislav/dotfiles'
}
"""
...
...
@@ -41,6 +44,7 @@ Feature: hub create
Given the GitHub API server
:
"""
post('/orgs/acme/repos') {
status 201
json :full_name => 'acme/dotfiles'
}
"""
...
...
@@ -63,6 +67,7 @@ Feature: hub create
"""
post('/user/repos') {
assert :name => 'myconfig'
status 201
json :full_name => 'mislav/myconfig'
}
"""
...
...
@@ -75,6 +80,7 @@ Feature: hub create
post('/user/repos') {
assert :description => 'mydesc',
:homepage => 'http://example.com'
status 201
json :full_name => 'mislav/dotfiles'
}
"""
...
...
@@ -98,6 +104,7 @@ Feature: hub create
Given the GitHub API server
:
"""
post('/user/repos') {
status 201
json :full_name => 'mislav/dotfiles'
}
"""
...
...
@@ -109,6 +116,7 @@ Feature: hub create
Given the GitHub API server
:
"""
post('/user/repos') {
status 201
json :full_name => 'mislav/dotfiles'
}
"""
...
...
@@ -129,6 +137,7 @@ Feature: hub create
Given the GitHub API server
:
"""
post('/user/repos') {
status 201
json :full_name => 'Mooslav/myconfig'
}
"""
...
...
@@ -140,6 +149,7 @@ Feature: hub create
Given the GitHub API server
:
"""
post('/user/repos') {
status 201
json :full_name => 'Mooslav/myconfig'
}
"""
...
...
@@ -153,6 +163,7 @@ Feature: hub create
"""
post('/user/repos') {
assert :name => 'my-dot-files'
status 201
json :full_name => 'mislav/my-dot-files'
}
"""
...
...
@@ -165,6 +176,7 @@ Feature: hub create
get('/repos/mislav/dotfiles') { status 404 }
post('/user/repos') {
response['location'] = 'http://disney.com'
status 201
json :full_name => 'mislav/dotfiles'
}
"""
...
...
@@ -184,7 +196,7 @@ Feature: hub create
"""
And the stderr should contain
:
"""
< HTTP 20
0
< HTTP 20
1
< Location: http://disney.com
{"full_name":"mislav/dotfiles"}\n
"""
github/client.go
浏览文件 @
04fa2016
...
...
@@ -214,38 +214,31 @@ func (client *Client) IsRepositoryExist(project *Project) bool {
return
err
==
nil
&&
repo
!=
nil
}
func
(
client
*
Client
)
CreateRepository
(
project
*
Project
,
description
,
homepage
string
,
isPrivate
bool
)
(
repo
*
octokit
.
Repository
,
err
error
)
{
var
repoURL
octokit
.
Hyperlink
func
(
client
*
Client
)
CreateRepository
(
project
*
Project
,
description
,
homepage
string
,
isPrivate
bool
)
(
repo
*
Repository
,
err
error
)
{
repoURL
:=
"user/repos"
if
project
.
Owner
!=
client
.
Host
.
User
{
repoURL
=
octokit
.
OrgRepositoriesURL
}
else
{
repoURL
=
octokit
.
UserRepositoriesURL
repoURL
=
fmt
.
Sprintf
(
"orgs/%s/repos"
,
project
.
Owner
)
}
url
,
err
:=
repoURL
.
Expand
(
octokit
.
M
{
"org"
:
project
.
Owner
})
if
err
!=
nil
{
return
params
:=
map
[
string
]
interface
{}{
"name"
:
project
.
Name
,
"description"
:
description
,
"homepage"
:
homepage
,
"private"
:
isPrivate
,
}
api
,
err
:=
client
.
a
pi
()
api
,
err
:=
client
.
simpleA
pi
()
if
err
!=
nil
{
err
=
FormatError
(
"creating repository"
,
err
)
return
}
params
:=
octokit
.
Repository
{
Name
:
project
.
Name
,
Description
:
description
,
Homepage
:
homepage
,
Private
:
isPrivate
,
}
hyperlink
:=
octokit
.
Hyperlink
(
client
.
requestURL
(
url
)
.
String
())
repo
,
result
:=
api
.
Repositories
()
.
Create
(
&
hyperlink
,
octokit
.
M
{},
params
)
if
result
.
HasError
()
{
err
=
FormatError
(
"creating repository"
,
result
.
Err
)
res
,
err
:=
api
.
PostJSON
(
repoURL
,
params
)
if
err
=
checkStatus
(
201
,
"creating repository"
,
res
,
err
);
err
!=
nil
{
return
}
repo
=
&
Repository
{}
err
=
res
.
Unmarshal
(
repo
)
return
}
...
...
@@ -443,6 +436,7 @@ func (client *Client) FetchCIStatus(project *Project, sha string) (status *CISta
type
Repository
struct
{
Name
string
`json:"name"`
FullName
string
`json:"full_name"`
Parent
*
Repository
`json:"parent"`
Owner
*
User
`json:"owner"`
Private
bool
`json:"private"`
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录