Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
github
hub
提交
b2b3184b
H
hub
项目概览
github
/
hub
9 个月 前同步成功
通知
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,体验更适合开发者的 AI 搜索 >>
提交
b2b3184b
编写于
3月 18, 2018
作者:
A
Andreas Baumann
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added a preliminary delete repository command (because I need it)
上级
944f3c74
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
145 addition
and
0 deletion
+145
-0
Makefile
Makefile
+1
-0
commands/delete.go
commands/delete.go
+119
-0
commands/help.go
commands/help.go
+1
-0
github/client.go
github/client.go
+21
-0
share/man/man1/hub.1.ronn
share/man/man1/hub.1.ronn
+3
-0
未找到文件。
Makefile
浏览文件 @
b2b3184b
...
...
@@ -7,6 +7,7 @@ HELP_CMD = \
share/man/man1/hub-ci-status.1
\
share/man/man1/hub-compare.1
\
share/man/man1/hub-create.1
\
share/man/man1/hub-delete.1
\
share/man/man1/hub-fork.1
\
share/man/man1/hub-pr.1
\
share/man/man1/hub-pull-request.1
\
...
...
commands/delete.go
0 → 100644
浏览文件 @
b2b3184b
package
commands
import
(
"os"
"fmt"
"regexp"
"strings"
"github.com/github/hub/git"
"github.com/github/hub/github"
"github.com/github/hub/utils"
)
var
cmdDelete
=
&
Command
{
Run
:
delete
,
Usage
:
"delete [[<ORGANIZATION>/]<NAME>]"
,
Long
:
`Delete an existing repository on GitHub.
## Options:
[<ORGANIZATION>/]<NAME>
The name for the repository on GitHub.
## Examples:
$ hub delete recipes
[ personal repo deleted on GitHub ]
$ hub delete sinatra/recipes
[ repo deleted in GitHub organization ]
## See also:
hub-init(1), hub(1)
`
,
}
var
(
)
func
init
()
{
CmdRunner
.
Use
(
cmdDelete
)
}
func
delete
(
command
*
Command
,
args
*
Args
)
{
var
repoName
string
if
args
.
IsParamsEmpty
()
{
dirName
,
err
:=
git
.
WorkdirName
()
utils
.
Check
(
err
)
repoName
=
github
.
SanitizeProjectName
(
dirName
)
}
else
{
reg
:=
regexp
.
MustCompile
(
"^[^-]"
)
if
!
reg
.
MatchString
(
args
.
FirstParam
())
{
err
:=
fmt
.
Errorf
(
"invalid argument: %s"
,
args
.
FirstParam
())
utils
.
Check
(
err
)
}
repoName
=
args
.
FirstParam
()
}
config
:=
github
.
CurrentConfig
()
host
,
err
:=
config
.
DefaultHost
()
if
err
!=
nil
{
utils
.
Check
(
github
.
FormatError
(
"deleting repository"
,
err
))
}
owner
:=
host
.
User
if
strings
.
Contains
(
repoName
,
"/"
)
{
split
:=
strings
.
SplitN
(
repoName
,
"/"
,
2
)
owner
=
split
[
0
]
repoName
=
split
[
1
]
}
project
:=
github
.
NewProject
(
owner
,
repoName
,
host
.
Host
)
gh
:=
github
.
NewClient
(
project
.
Host
)
if
!
gh
.
IsRepositoryExist
(
project
)
{
fmt
.
Println
(
"No such repository"
)
args
.
NoForward
()
return
}
if
os
.
Getenv
(
"HUB_UNSAFE_DELETE"
)
==
""
{
fmt
.
Printf
(
"Repository '%s' exists. Really delete it (y/N)?"
,
repoName
)
var
s
string
_
,
err
=
fmt
.
Scan
(
&
s
)
if
err
!=
nil
{
fmt
.
Println
(
err
);
args
.
NoForward
()
return
}
s
=
strings
.
TrimSpace
(
s
)
s
=
strings
.
ToLower
(
s
)
if
s
!=
"y"
{
fmt
.
Println
(
"Abort: not deleting anything."
)
args
.
NoForward
()
return
}
fmt
.
Println
(
"Please write the name of the repository again (this operation can not be undone!): "
)
_
,
err
=
fmt
.
Scan
(
&
s
)
if
err
!=
nil
{
fmt
.
Println
(
err
);
args
.
NoForward
()
return
}
s
=
strings
.
TrimSpace
(
s
)
if
s
!=
repoName
{
fmt
.
Println
(
"Names don't match.. bailing out.. no deletion"
)
args
.
NoForward
()
return
}
}
err
=
gh
.
DeleteRepository
(
project
)
utils
.
Check
(
err
)
fmt
.
Printf
(
"Deleted repository %v
\n
"
,
repoName
)
args
.
NoForward
()
}
commands/help.go
浏览文件 @
b2b3184b
...
...
@@ -169,6 +169,7 @@ These GitHub commands are provided by hub:
ci-status Show the CI status of a commit
compare Open a compare page on GitHub
create Create this repository on GitHub and add GitHub as origin
delete Delete a repository on GitHub
fork Make a fork of a remote repository on GitHub and add as remote
issue List or create issues
pr Work with pull requests
...
...
github/client.go
浏览文件 @
b2b3184b
...
...
@@ -247,6 +247,27 @@ func (client *Client) CreateRepository(project *Project, description, homepage s
return
}
func
(
client
*
Client
)
DeleteRepository
(
project
*
Project
)
(
err
error
)
{
var
repoURL
string
if
project
.
Owner
!=
client
.
Host
.
User
{
repoURL
=
fmt
.
Sprintf
(
"/repos/%s/%s"
,
project
.
Owner
,
project
.
Name
)
}
else
{
repoURL
=
fmt
.
Sprintf
(
"/repos/%s/%s"
,
client
.
Host
.
User
,
project
.
Name
)
}
api
,
err
:=
client
.
simpleApi
()
if
err
!=
nil
{
return
}
res
,
err
:=
api
.
Delete
(
repoURL
);
if
err
=
checkStatus
(
204
,
"deleting repository"
,
res
,
err
);
err
!=
nil
{
return
err
}
return
err
}
type
Release
struct
{
Name
string
`json:"name"`
TagName
string
`json:"tag_name"`
...
...
share/man/man1/hub.1.ronn
浏览文件 @
b2b3184b
...
...
@@ -66,6 +66,9 @@ git but that are extended through hub, and custom ones that hub provides.
* hub-create(1):
Create a new repository on GitHub and add a git remote for it.
* hub-delete(1):
Delete a repository on Github.
* hub-fork(1):
Fork the current project on GitHub and add a git remote for it.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录