Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
github
hub
提交
bb4e5f2d
H
hub
项目概览
github
/
hub
10 个月 前同步成功
通知
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 搜索 >>
提交
bb4e5f2d
编写于
12月 30, 2013
作者:
D
David Calavera
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add command to create issues.
上级
755d067f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
122 addition
and
42 deletion
+122
-42
commands/issue.go
commands/issue.go
+75
-29
commands/release.go
commands/release.go
+2
-13
commands/utils.go
commands/utils.go
+24
-0
github/client.go
github/client.go
+21
-0
未找到文件。
commands/issue.go
浏览文件 @
bb4e5f2d
...
...
@@ -4,17 +4,36 @@ import (
"fmt"
"github.com/jingweno/gh/github"
"github.com/jingweno/gh/utils"
"os"
)
var
cmdIssue
=
&
Command
{
Run
:
issue
,
Usage
:
"issue"
,
Short
:
"Manipulate issues on GitHub"
,
Long
:
`Lists summary of the open issues for the project that the "origin" remove points to.`
,
}
var
(
cmdIssue
=
&
Command
{
Run
:
issue
,
Usage
:
"issue"
,
Short
:
"List issues on GitHub"
,
Long
:
`List summary of the open issues for the project that the "origin" remove points to.`
,
}
cmdCreateIssue
=
&
Command
{
Key
:
"create"
,
Run
:
createIssue
,
Usage
:
"issue create [-m <MESSAGE>|-f <FILE>] -l LABEL1,LABEL2"
,
Short
:
"Create an issue on GitHub"
,
Long
:
`Create an issue for the project that the "origin" remove points to.`
,
}
flagIssueMessage
,
flagIssueFile
string
flagIssueLabels
listFlag
)
func
init
()
{
cmdCreateIssue
.
Flag
.
StringVarP
(
&
flagIssueMessage
,
"message"
,
"m"
,
""
,
"MESSAGE"
)
cmdCreateIssue
.
Flag
.
StringVarP
(
&
flagIssueFile
,
"file"
,
"f"
,
""
,
"FILE"
)
cmdCreateIssue
.
Flag
.
VarP
(
&
flagIssueLabels
,
"label"
,
"l"
,
"LABEL"
)
cmdIssue
.
Use
(
cmdCreateIssue
)
CmdRunner
.
Use
(
cmdIssue
)
}
...
...
@@ -22,29 +41,56 @@ func init() {
$ gh issue
*/
func
issue
(
cmd
*
Command
,
args
*
Args
)
{
localRepo
:=
github
.
LocalRepo
()
project
,
err
:=
localRepo
.
CurrentProject
()
utils
.
Check
(
err
)
gh
:=
github
.
NewClient
(
project
.
Host
)
if
args
.
Noop
{
fmt
.
Printf
(
"Would request list of issues for %s
\n
"
,
project
)
}
else
{
issues
,
err
:=
gh
.
Issues
(
project
)
utils
.
Check
(
err
)
for
_
,
issue
:=
range
issues
{
var
url
string
// use the pull request URL if we have one
if
issue
.
PullRequest
.
HTMLURL
!=
""
{
url
=
issue
.
PullRequest
.
HTMLURL
}
else
{
url
=
issue
.
HTMLURL
RunInLocalRepo
(
func
(
localRepo
*
github
.
GitHubRepo
,
project
*
github
.
Project
,
gh
*
github
.
Client
)
{
if
args
.
Noop
{
fmt
.
Printf
(
"Would request list of issues for %s
\n
"
,
project
)
}
else
{
issues
,
err
:=
gh
.
Issues
(
project
)
utils
.
Check
(
err
)
for
_
,
issue
:=
range
issues
{
var
url
string
// use the pull request URL if we have one
if
issue
.
PullRequest
.
HTMLURL
!=
""
{
url
=
issue
.
PullRequest
.
HTMLURL
}
else
{
url
=
issue
.
HTMLURL
}
// "nobody" should have more than 1 million github issues
fmt
.
Printf
(
"% 7d] %s ( %s )
\n
"
,
issue
.
Number
,
issue
.
Title
,
url
)
}
// "nobody" should have more than 1 million github issues
fmt
.
Printf
(
"% 7d] %s ( %s )
\n
"
,
issue
.
Number
,
issue
.
Title
,
url
)
}
}
})
}
func
createIssue
(
cmd
*
Command
,
args
*
Args
)
{
RunInLocalRepo
(
func
(
localRepo
*
github
.
GitHubRepo
,
project
*
github
.
Project
,
gh
*
github
.
Client
)
{
if
args
.
Noop
{
fmt
.
Printf
(
"Would create an issue for %s
\n
"
,
project
)
}
else
{
title
,
body
,
err
:=
github
.
GetTitleAndBodyFromFlags
(
flagIssueMessage
,
flagIssueFile
)
utils
.
Check
(
err
)
if
title
==
""
{
title
,
body
,
err
=
writeIssueTitleAndBody
(
project
)
utils
.
Check
(
err
)
}
issue
,
err
:=
gh
.
CreateIssue
(
project
,
title
,
body
,
flagIssueLabels
)
utils
.
Check
(
err
)
fmt
.
Println
(
issue
.
HTMLURL
)
}
})
}
func
writeIssueTitleAndBody
(
project
*
github
.
Project
)
(
string
,
string
,
error
)
{
message
:=
`
# Creating issue for %s.
#
# Write a message for this issue. The first block
# of the text is the title and the rest is description.
`
message
=
fmt
.
Sprintf
(
message
,
project
.
Name
)
os
.
Exit
(
0
)
return
github
.
GetTitleAndBodyFromEditor
(
"ISSUE"
,
message
)
}
commands/release.go
浏览文件 @
bb4e5f2d
...
...
@@ -54,7 +54,7 @@ func init() {
}
func
release
(
cmd
*
Command
,
args
*
Args
)
{
r
unInLocalRepo
(
func
(
localRepo
*
github
.
GitHubRepo
,
project
*
github
.
Project
,
gh
*
github
.
Client
)
{
R
unInLocalRepo
(
func
(
localRepo
*
github
.
GitHubRepo
,
project
*
github
.
Project
,
gh
*
github
.
Client
)
{
if
args
.
Noop
{
fmt
.
Printf
(
"Would request list of releases for %s
\n
"
,
project
)
}
else
{
...
...
@@ -82,7 +82,7 @@ func createRelease(cmd *Command, args *Args) {
assetsDir
,
err
:=
getAssetsDirectory
(
flagReleaseAssetsDir
,
tag
)
utils
.
Check
(
err
)
r
unInLocalRepo
(
func
(
localRepo
*
github
.
GitHubRepo
,
project
*
github
.
Project
,
gh
*
github
.
Client
)
{
R
unInLocalRepo
(
func
(
localRepo
*
github
.
GitHubRepo
,
project
*
github
.
Project
,
gh
*
github
.
Client
)
{
currentBranch
,
err
:=
localRepo
.
CurrentBranch
()
utils
.
Check
(
err
)
branchName
:=
currentBranch
.
ShortName
()
...
...
@@ -124,17 +124,6 @@ func writeReleaseTitleAndBody(project *github.Project, tag, currentBranch string
return
github
.
GetTitleAndBodyFromEditor
(
"RELEASE"
,
message
)
}
func
runInLocalRepo
(
fn
func
(
localRepo
*
github
.
GitHubRepo
,
project
*
github
.
Project
,
client
*
github
.
Client
))
{
localRepo
:=
github
.
LocalRepo
()
project
,
err
:=
localRepo
.
CurrentProject
()
utils
.
Check
(
err
)
client
:=
github
.
NewClient
(
project
.
Host
)
fn
(
localRepo
,
project
,
client
)
os
.
Exit
(
0
)
}
func
getAssetsDirectory
(
assetsDir
,
tag
string
)
(
string
,
error
)
{
if
assetsDir
==
""
{
pwd
,
err
:=
os
.
Getwd
()
...
...
commands/utils.go
浏览文件 @
bb4e5f2d
...
...
@@ -53,3 +53,27 @@ func isEmptyDir(path string) bool {
match
,
_
:=
filepath
.
Glob
(
fullPath
)
return
match
==
nil
}
func
RunInLocalRepo
(
fn
func
(
localRepo
*
github
.
GitHubRepo
,
project
*
github
.
Project
,
client
*
github
.
Client
))
{
localRepo
:=
github
.
LocalRepo
()
project
,
err
:=
localRepo
.
CurrentProject
()
utils
.
Check
(
err
)
client
:=
github
.
NewClient
(
project
.
Host
)
fn
(
localRepo
,
project
,
client
)
os
.
Exit
(
0
)
}
type
listFlag
[]
string
func
(
l
*
listFlag
)
String
()
string
{
return
strings
.
Join
([]
string
(
*
l
),
","
)
}
func
(
l
*
listFlag
)
Set
(
value
string
)
error
{
for
_
,
flag
:=
range
strings
.
Split
(
value
,
","
)
{
*
l
=
append
(
*
l
,
flag
)
}
return
nil
}
github/client.go
浏览文件 @
bb4e5f2d
...
...
@@ -206,6 +206,27 @@ func (client *Client) Issues(project *Project) (issues []octokit.Issue, err erro
return
}
func
(
client
*
Client
)
CreateIssue
(
project
*
Project
,
title
,
body
string
,
labels
[]
string
)
(
issue
*
octokit
.
Issue
,
err
error
)
{
url
,
err
:=
octokit
.
RepoIssuesURL
.
Expand
(
octokit
.
M
{
"owner"
:
project
.
Owner
,
"repo"
:
project
.
Name
})
if
err
!=
nil
{
return
}
params
:=
octokit
.
IssueParams
{
Title
:
title
,
Body
:
body
,
Labels
:
labels
,
}
issue
,
result
:=
client
.
octokit
()
.
Issues
(
client
.
requestURL
(
url
))
.
Create
(
params
)
if
result
.
HasError
()
{
err
=
result
.
Err
return
}
return
}
func
(
client
*
Client
)
FindOrCreateToken
(
user
,
password
,
twoFactorCode
string
)
(
token
string
,
err
error
)
{
url
,
e
:=
octokit
.
AuthorizationsURL
.
Expand
(
nil
)
if
e
!=
nil
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录