зеркало из https://github.com/mislav/hub.git
Add GeneratePRTemplate method to github/template
The function of this method is to defer the logic of generating a commit message to template.go, and eventually remove that logic from commands/pull_request.go Also adds tests for this new method, which also modifies the fixtures/test_repo.go file to accomidate a test repo with a `.github` PR dir.
This commit is contained in:
Родитель
085821f05e
Коммит
a1e49b89a9
|
@ -59,6 +59,31 @@ func (r *TestRepo) AddRemote(name, url, pushURL string) {
|
|||
}
|
||||
}
|
||||
|
||||
func (r *TestRepo) AddGithubTemplatesDir() {
|
||||
github_dir := filepath.Join(r.dir, "test.git", ".github")
|
||||
pr_template_path := filepath.Join(github_dir, "PULL_REQUEST_TEMPLATE.md")
|
||||
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 {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
content := `Description
|
||||
-----------
|
||||
[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 {
|
||||
cmd := cmd.New("git").WithArgs("clone", repo, dir)
|
||||
output, err := cmd.CombinedOutput()
|
||||
|
|
|
@ -20,7 +20,11 @@ func GetPullRequestTemplate() string {
|
|||
}
|
||||
|
||||
func GetIssueTemplate() string {
|
||||
return getGithubTemplate(issueTempalte)
|
||||
return getGithubTemplate(issueTemplate)
|
||||
}
|
||||
|
||||
func GeneratePRTemplate(defaultMsg string) string {
|
||||
return "\n\n" + GetPullRequestTemplate()
|
||||
}
|
||||
|
||||
func getGithubTemplate(pat string) (body string) {
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package github
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/bmizerany/assert"
|
||||
"github.com/github/hub/fixtures"
|
||||
)
|
||||
|
||||
// When no default message is provided, two blank lines should be added
|
||||
// (representing the pull request title), and the left should be template.
|
||||
func TestGeneratePRTemplate_NoDefaultMessage(t *testing.T) {
|
||||
repo := fixtures.SetupTestRepo()
|
||||
defer repo.TearDown()
|
||||
|
||||
repo.AddGithubTemplatesDir()
|
||||
|
||||
defaultMessage := ""
|
||||
expectedOutput := `
|
||||
|
||||
Description
|
||||
-----------
|
||||
[Enter your pull request description here]
|
||||
`
|
||||
|
||||
assert.Equal(t, expectedOutput, GeneratePRTemplate(defaultMessage))
|
||||
}
|
Загрузка…
Ссылка в новой задаче