Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
github
hub
提交
9144e1df
H
hub
项目概览
github
/
hub
大约 1 年 前同步成功
通知
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,发现更多精彩内容 >>
提交
9144e1df
编写于
4月 12, 2016
作者:
G
ganmacs
提交者:
Jake Zimmerman
5月 30, 2016
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add template tests
上级
ad6ac945
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
108 addition
and
25 deletion
+108
-25
commands/pull_request.go
commands/pull_request.go
+1
-1
fixtures/test_repo.go
fixtures/test_repo.go
+4
-19
github/template.go
github/template.go
+2
-2
github/template_test.go
github/template_test.go
+101
-3
未找到文件。
commands/pull_request.go
浏览文件 @
9144e1df
...
@@ -278,7 +278,7 @@ func createPullRequestMessage(base, head, fullBase, fullHead string) (string, er
...
@@ -278,7 +278,7 @@ func createPullRequestMessage(base, head, fullBase, fullHead string) (string, er
}
}
}
}
if
t
mplate
:=
github
.
GetPullRequestTemplate
();
t
mplate
!=
""
{
if
t
emplate
:=
github
.
GetPullRequestTemplate
();
te
mplate
!=
""
{
defaultMsg
=
github
.
GeneratePRTemplate
(
defaultMsg
)
defaultMsg
=
github
.
GeneratePRTemplate
(
defaultMsg
)
}
}
...
...
fixtures/test_repo.go
浏览文件 @
9144e1df
...
@@ -59,29 +59,14 @@ func (r *TestRepo) AddRemote(name, url, pushURL string) {
...
@@ -59,29 +59,14 @@ func (r *TestRepo) AddRemote(name, url, pushURL string) {
}
}
}
}
func
(
r
*
TestRepo
)
AddGithubTemplatesDir
()
{
func
(
r
*
TestRepo
)
AddFile
(
filePath
string
,
content
string
)
{
github_dir
:=
filepath
.
Join
(
r
.
dir
,
"test.git"
,
".github"
)
path
:=
filepath
.
Join
(
r
.
dir
,
filePath
)
pr_template_path
:=
filepath
.
Join
(
github_dir
,
"PULL_REQUEST_TEMPLATE.md"
)
err
:=
os
.
MkdirAll
(
filepath
.
Dir
(
path
),
0771
)
issue_template_path
:=
filepath
.
Join
(
github_dir
,
"ISSUE_TEMPLATE"
)
// Make `.github` dir in root of test repo
err
:=
os
.
MkdirAll
(
filepath
.
Dir
(
issue_template_path
),
0771
)
if
err
!=
nil
{
panic
(
err
)
}
// Switch to the root of the project dir
err
=
os
.
Chdir
(
filepath
.
Join
(
r
.
dir
,
"test.git"
))
if
err
!=
nil
{
if
err
!=
nil
{
panic
(
err
)
panic
(
err
)
}
}
content
:=
`Description
ioutil
.
WriteFile
(
path
,
[]
byte
(
content
),
os
.
ModePerm
)
-----------
[Enter your pull request description here]
`
ioutil
.
WriteFile
(
pr_template_path
,
[]
byte
(
content
),
os
.
ModePerm
)
ioutil
.
WriteFile
(
issue_template_path
,
[]
byte
(
content
),
os
.
ModePerm
)
}
}
func
(
r
*
TestRepo
)
clone
(
repo
,
dir
string
)
error
{
func
(
r
*
TestRepo
)
clone
(
repo
,
dir
string
)
error
{
...
...
github/template.go
浏览文件 @
9144e1df
...
@@ -10,13 +10,13 @@ import (
...
@@ -10,13 +10,13 @@ import (
)
)
const
(
const
(
pullRequestTemp
al
te
=
"PULL_REQUEST_TEMPLATE"
pullRequestTemp
la
te
=
"PULL_REQUEST_TEMPLATE"
issueTemplate
=
"ISSUE_TEMPLATE"
issueTemplate
=
"ISSUE_TEMPLATE"
githubTemplateDir
=
".github"
githubTemplateDir
=
".github"
)
)
func
GetPullRequestTemplate
()
string
{
func
GetPullRequestTemplate
()
string
{
return
getGithubTemplate
(
pullRequestTemp
al
te
)
return
getGithubTemplate
(
pullRequestTemp
la
te
)
}
}
func
GetIssueTemplate
()
string
{
func
GetIssueTemplate
()
string
{
...
...
github/template_test.go
浏览文件 @
9144e1df
package
github
package
github
import
(
import
(
"path/filepath"
"testing"
"testing"
"github.com/bmizerany/assert"
"github.com/bmizerany/assert"
"github.com/github/hub/fixtures"
"github.com/github/hub/fixtures"
)
)
var
prContent
=
`Description
-----------
[Enter your pull request description here]
`
var
issueContent
=
`Description
-----------
[Enter your issue description here]
`
func
TestGithubTemplate_withoutTemplate
(
t
*
testing
.
T
)
{
repo
:=
fixtures
.
SetupTestRepo
()
defer
repo
.
TearDown
()
assert
.
Equal
(
t
,
""
,
GetPullRequestTemplate
())
assert
.
Equal
(
t
,
""
,
GetIssueTemplate
())
}
func
TestGithubTemplate_withInvalidTemplate
(
t
*
testing
.
T
)
{
repo
:=
fixtures
.
SetupTestRepo
()
defer
repo
.
TearDown
()
addGithubTemplates
(
repo
,
map
[
string
]
string
{
"dir"
:
"invalidPath"
})
assert
.
Equal
(
t
,
""
,
GetPullRequestTemplate
())
assert
.
Equal
(
t
,
""
,
GetIssueTemplate
())
}
func
TestGithubTemplate_WithMarkdown
(
t
*
testing
.
T
)
{
repo
:=
fixtures
.
SetupTestRepo
()
defer
repo
.
TearDown
()
addGithubTemplates
(
repo
,
map
[
string
]
string
{
"prTempalte"
:
pullRequestTemplate
+
".md"
,
"issueTempalte"
:
issueTemplate
+
".md"
,
})
assert
.
Equal
(
t
,
prContent
,
GetPullRequestTemplate
())
assert
.
Equal
(
t
,
issueContent
,
GetIssueTemplate
())
}
func
TestGithubTemplate_WithTemplateInHome
(
t
*
testing
.
T
)
{
repo
:=
fixtures
.
SetupTestRepo
()
defer
repo
.
TearDown
()
addGithubTemplates
(
repo
,
map
[
string
]
string
{})
assert
.
Equal
(
t
,
prContent
,
GetPullRequestTemplate
())
assert
.
Equal
(
t
,
issueContent
,
GetIssueTemplate
())
}
func
TestGithubTemplate_WithTemplateInGithubDir
(
t
*
testing
.
T
)
{
repo
:=
fixtures
.
SetupTestRepo
()
defer
repo
.
TearDown
()
addGithubTemplates
(
repo
,
map
[
string
]
string
{
"dir"
:
githubTemplateDir
})
assert
.
Equal
(
t
,
prContent
,
GetPullRequestTemplate
())
assert
.
Equal
(
t
,
issueContent
,
GetIssueTemplate
())
}
func
TestGithubTemplate_WithTemplateInGithubDirAndMarkdown
(
t
*
testing
.
T
)
{
repo
:=
fixtures
.
SetupTestRepo
()
defer
repo
.
TearDown
()
addGithubTemplates
(
repo
,
map
[
string
]
string
{
"prTempalte"
:
pullRequestTemplate
+
".md"
,
"issueTempalte"
:
issueTemplate
+
".md"
,
"dir"
:
githubTemplateDir
,
})
assert
.
Equal
(
t
,
prContent
,
GetPullRequestTemplate
())
assert
.
Equal
(
t
,
issueContent
,
GetIssueTemplate
())
}
// When no default message is provided, two blank lines should be added
// When no default message is provided, two blank lines should be added
// (representing the pull request title), and the left should be template.
// (representing the pull request title), and the left should be template.
func
TestGeneratePRTemplate_NoDefaultMessage
(
t
*
testing
.
T
)
{
func
TestGeneratePRTemplate_NoDefaultMessage
(
t
*
testing
.
T
)
{
repo
:=
fixtures
.
SetupTestRepo
()
repo
:=
fixtures
.
SetupTestRepo
()
defer
repo
.
TearDown
()
defer
repo
.
TearDown
()
repo
.
AddGithubTemplatesDir
(
)
addGithubTemplates
(
repo
,
map
[
string
]
string
{}
)
defaultMessage
:=
""
defaultMessage
:=
""
expectedOutput
:=
`
expectedOutput
:=
`
...
@@ -32,7 +110,7 @@ func TestGeneratePRTemplate_SingleLineDefaultMessage(t *testing.T) {
...
@@ -32,7 +110,7 @@ func TestGeneratePRTemplate_SingleLineDefaultMessage(t *testing.T) {
repo
:=
fixtures
.
SetupTestRepo
()
repo
:=
fixtures
.
SetupTestRepo
()
defer
repo
.
TearDown
()
defer
repo
.
TearDown
()
repo
.
AddGithubTemplatesDir
(
)
addGithubTemplates
(
repo
,
map
[
string
]
string
{}
)
defaultMessage
:=
"Add Pull Request Templates to Hub"
defaultMessage
:=
"Add Pull Request Templates to Hub"
expectedOutput
:=
`Add Pull Request Templates to Hub
expectedOutput
:=
`Add Pull Request Templates to Hub
...
@@ -54,7 +132,7 @@ func TestGeneratePRTemplate_MultiLineDefaultMessage(t *testing.T) {
...
@@ -54,7 +132,7 @@ func TestGeneratePRTemplate_MultiLineDefaultMessage(t *testing.T) {
repo
:=
fixtures
.
SetupTestRepo
()
repo
:=
fixtures
.
SetupTestRepo
()
defer
repo
.
TearDown
()
defer
repo
.
TearDown
()
repo
.
AddGithubTemplatesDir
(
)
addGithubTemplates
(
repo
,
map
[
string
]
string
{}
)
defaultMessage
:=
`Add Pull Request Templates to Hub
defaultMessage
:=
`Add Pull Request Templates to Hub
...
@@ -70,3 +148,23 @@ Description
...
@@ -70,3 +148,23 @@ Description
assert
.
Equal
(
t
,
expectedOutput
,
GeneratePRTemplate
(
defaultMessage
))
assert
.
Equal
(
t
,
expectedOutput
,
GeneratePRTemplate
(
defaultMessage
))
}
}
func
addGithubTemplates
(
r
*
fixtures
.
TestRepo
,
config
map
[
string
]
string
)
{
repoDir
:=
"test.git"
if
dir
:=
config
[
"dir"
];
dir
!=
""
{
repoDir
=
filepath
.
Join
(
repoDir
,
dir
)
}
prTemplatePath
:=
filepath
.
Join
(
repoDir
,
pullRequestTemplate
)
if
prTmplPath
:=
config
[
"prTemplate"
];
prTmplPath
!=
""
{
prTemplatePath
=
prTmplPath
}
issueTemplatePath
:=
filepath
.
Join
(
repoDir
,
issueTemplate
)
if
issueTmplPath
:=
config
[
"issueTemplate"
];
issueTmplPath
!=
""
{
issueTemplatePath
=
issueTmplPath
}
r
.
AddFile
(
prTemplatePath
,
prContent
)
r
.
AddFile
(
issueTemplatePath
,
issueContent
)
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录