Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
github
hub
提交
0d383181
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 搜索 >>
提交
0d383181
编写于
12月 31, 2013
作者:
J
Jingwen Owen Ou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move GetTitleAndBodyFromFlags to commands/utils
上级
dea049f2
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
54 addition
and
53 deletion
+54
-53
commands/issue.go
commands/issue.go
+3
-3
commands/pull_request.go
commands/pull_request.go
+1
-1
commands/release.go
commands/release.go
+3
-3
commands/utils.go
commands/utils.go
+47
-14
github/editor.go
github/editor.go
+0
-32
未找到文件。
commands/issue.go
浏览文件 @
0d383181
...
...
@@ -41,7 +41,7 @@ func init() {
$ gh issue
*/
func
issue
(
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 issues for %s
\n
"
,
project
)
}
else
{
...
...
@@ -63,11 +63,11 @@ func issue(cmd *Command, args *Args) {
}
func
createIssue
(
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 create an issue for %s
\n
"
,
project
)
}
else
{
title
,
body
,
err
:=
g
ithub
.
G
etTitleAndBodyFromFlags
(
flagIssueMessage
,
flagIssueFile
)
title
,
body
,
err
:=
getTitleAndBodyFromFlags
(
flagIssueMessage
,
flagIssueFile
)
utils
.
Check
(
err
)
if
title
==
""
{
...
...
commands/pull_request.go
浏览文件 @
0d383181
...
...
@@ -132,7 +132,7 @@ func pullRequest(cmd *Command, args *Args) {
}
}
title
,
body
,
err
:=
g
ithub
.
G
etTitleAndBodyFromFlags
(
flagPullRequestMessage
,
flagPullRequestFile
)
title
,
body
,
err
:=
getTitleAndBodyFromFlags
(
flagPullRequestMessage
,
flagPullRequestFile
)
utils
.
Check
(
err
)
fullBase
:=
fmt
.
Sprintf
(
"%s:%s"
,
baseProject
.
Owner
,
base
)
...
...
commands/release.go
浏览文件 @
0d383181
...
...
@@ -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,12 +82,12 @@ 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
()
title
,
body
,
err
:=
g
ithub
.
G
etTitleAndBodyFromFlags
(
flagReleaseMessage
,
flagReleaseFile
)
title
,
body
,
err
:=
getTitleAndBodyFromFlags
(
flagReleaseMessage
,
flagReleaseFile
)
utils
.
Check
(
err
)
if
title
==
""
{
...
...
commands/utils.go
浏览文件 @
0d383181
...
...
@@ -4,11 +4,25 @@ import (
"github.com/jingweno/gh/github"
"github.com/jingweno/gh/utils"
"github.com/jingweno/go-octokit/octokit"
"io/ioutil"
"os"
"path/filepath"
"strings"
)
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
}
func
isDir
(
file
string
)
bool
{
f
,
err
:=
os
.
Open
(
file
)
if
err
!=
nil
{
...
...
@@ -54,26 +68,45 @@ func isEmptyDir(path string) bool {
return
match
==
nil
}
func
RunInLocalRepo
(
fn
func
(
localRepo
*
github
.
GitHubRepo
,
project
*
github
.
Project
,
client
*
github
.
Client
))
{
localRepo
:=
github
.
LocalRepo
()
project
,
err
:=
localRepo
.
CurrentProject
()
func
getTitleAndBodyFromFlags
(
messageFlag
,
fileFlag
string
)
(
title
,
body
string
,
err
error
)
{
if
messageFlag
!=
""
{
title
,
body
=
readMsg
(
messageFlag
)
}
else
if
fileFlag
!=
""
{
var
(
content
[]
byte
err
error
)
if
fileFlag
==
"-"
{
content
,
err
=
ioutil
.
ReadAll
(
os
.
Stdin
)
}
else
{
content
,
err
=
ioutil
.
ReadFile
(
fileFlag
)
}
utils
.
Check
(
err
)
client
:=
github
.
NewClient
(
project
.
Host
)
fn
(
localRepo
,
project
,
client
)
title
,
body
=
readMsg
(
string
(
content
)
)
}
os
.
Exit
(
0
)
return
}
type
listFlag
[]
string
func
readMsg
(
msg
string
)
(
title
,
body
string
)
{
split
:=
strings
.
SplitN
(
msg
,
"
\n\n
"
,
2
)
title
=
strings
.
TrimSpace
(
split
[
0
])
if
len
(
split
)
>
1
{
body
=
strings
.
TrimSpace
(
split
[
1
])
}
func
(
l
*
listFlag
)
String
()
string
{
return
strings
.
Join
([]
string
(
*
l
),
","
)
return
}
func
(
l
*
listFlag
)
Set
(
value
string
)
error
{
for
_
,
flag
:=
range
strings
.
Split
(
value
,
","
)
{
*
l
=
append
(
*
l
,
flag
)
}
return
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
)
}
github/editor.go
浏览文件 @
0d383181
...
...
@@ -6,7 +6,6 @@ import (
"fmt"
"github.com/jingweno/gh/cmd"
"github.com/jingweno/gh/git"
"github.com/jingweno/gh/utils"
"io"
"io/ioutil"
"os"
...
...
@@ -15,27 +14,6 @@ import (
"strings"
)
func
GetTitleAndBodyFromFlags
(
messageFlag
,
fileFlag
string
)
(
title
,
body
string
,
err
error
)
{
if
messageFlag
!=
""
{
title
,
body
=
readMsg
(
messageFlag
)
}
else
if
fileFlag
!=
""
{
var
(
content
[]
byte
err
error
)
if
fileFlag
==
"-"
{
content
,
err
=
ioutil
.
ReadAll
(
os
.
Stdin
)
}
else
{
content
,
err
=
ioutil
.
ReadFile
(
fileFlag
)
}
utils
.
Check
(
err
)
title
,
body
=
readMsg
(
string
(
content
))
}
return
}
func
NewEditor
(
topic
,
message
string
)
(
editor
*
Editor
,
err
error
)
{
messageFile
,
err
:=
getMessageFile
(
topic
)
if
err
!=
nil
{
...
...
@@ -155,16 +133,6 @@ func readLine(r *bufio.Reader) (string, error) {
return
string
(
ln
),
err
}
func
readMsg
(
msg
string
)
(
title
,
body
string
)
{
split
:=
strings
.
SplitN
(
msg
,
"
\n\n
"
,
2
)
title
=
strings
.
TrimSpace
(
split
[
0
])
if
len
(
split
)
>
1
{
body
=
strings
.
TrimSpace
(
split
[
1
])
}
return
}
func
getMessageFile
(
about
string
)
(
string
,
error
)
{
gitDir
,
err
:=
git
.
Dir
()
if
err
!=
nil
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录