提交 04fa2016 编写于 作者: M Mislav Marohnić

Create a repository without octokit

上级 de6a2bd5
......@@ -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'
}
"""
......
......@@ -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 200
< HTTP 201
< Location: http://disney.com
{"full_name":"mislav/dotfiles"}\n
"""
......@@ -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.api()
api, err := client.simpleApi()
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.
先完成此消息的编辑!
想要评论请 注册