Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion github/template/template_custom/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (t *CustomTemplatizer) Body(info *github.GitHubInfo, commit git.Commit) str
if err != nil {
log.Fatal().Err(err).Msg("failed to insert body into PR template")
}
return commit.Body
return body
}

func (t *CustomTemplatizer) formatBody(commit git.Commit, stack []*github.PullRequest) string {
Expand Down
32 changes: 18 additions & 14 deletions github/template/template_custom/template_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package template_custom

import (
"context"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -33,6 +34,10 @@ func (m *mockGit) RootDir() string {
return m.rootDir
}

func (m *mockGit) DeleteRemoteBranch(ctx context.Context, branch string) error {
return nil
}

func TestTitle(t *testing.T) {
repoConfig := &config.RepoConfig{}
gitcmd := &mockGit{rootDir: "/tmp"}
Expand Down Expand Up @@ -204,7 +209,7 @@ func TestReadPRTemplate(t *testing.T) {
tmpDir := t.TempDir()
templatePath := filepath.Join(tmpDir, "pr_template.md")
templateContent := "# PR Template\n\n<!-- INSERT_BODY -->\n\n## Additional Notes\n"

err := os.WriteFile(templatePath, []byte(templateContent), 0644)
require.NoError(t, err)

Expand All @@ -221,7 +226,7 @@ func TestReadPRTemplate(t *testing.T) {

func TestReadPRTemplateNotFound(t *testing.T) {
tmpDir := t.TempDir()

repoConfig := &config.RepoConfig{
PRTemplatePath: "nonexistent_template.md",
}
Expand All @@ -238,10 +243,10 @@ func TestReadPRTemplateWithSubdirectory(t *testing.T) {
subDir := filepath.Join(tmpDir, "templates")
err := os.MkdirAll(subDir, 0755)
require.NoError(t, err)

templatePath := filepath.Join(subDir, "pr_template.md")
templateContent := "Template in subdirectory"

err = os.WriteFile(templatePath, []byte(templateContent), 0644)
require.NoError(t, err)

Expand Down Expand Up @@ -323,7 +328,7 @@ func TestGetSectionOfPRTemplate(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result, err := getSectionOfPRTemplate(tt.text, tt.searchString, tt.matchType)

if tt.expectError {
assert.Error(t, err)
} else {
Expand All @@ -338,7 +343,7 @@ func TestInsertBodyIntoPRTemplate(t *testing.T) {
tmpDir := t.TempDir()
templatePath := filepath.Join(tmpDir, "pr_template.md")
prTemplate := "# PR Template\n\n<!-- START -->\n\n<!-- END -->\n\n## Additional Notes\n"

err := os.WriteFile(templatePath, []byte(prTemplate), 0644)
require.NoError(t, err)

Expand All @@ -362,21 +367,21 @@ func TestInsertBodyIntoPRTemplateWithExistingPR(t *testing.T) {
tmpDir := t.TempDir()
templatePath := filepath.Join(tmpDir, "pr_template.md")
prTemplate := "# PR Template\n\n<!-- START -->\n\n<!-- END -->\n"

err := os.WriteFile(templatePath, []byte(prTemplate), 0644)
require.NoError(t, err)

repoConfig := &config.RepoConfig{
PRTemplatePath: "pr_template.md",
PRTemplateInsertStart: "<!-- START -->",
PRTemplateInsertEnd: "<!-- END -->",
PRTemplateInsertStart: "<!-- START -->",
PRTemplateInsertEnd: "<!-- END -->",
}
gitcmd := &mockGit{rootDir: tmpDir}
templatizer := NewCustomTemplatizer(repoConfig, gitcmd)

body := "Updated commit body"
existingPRBody := "# PR Template\n\n<!-- START -->\nOld body\n\n<!-- END -->\n"

result, err := templatizer.insertBodyIntoPRTemplate(body, prTemplate, &github.PullRequest{
Body: existingPRBody,
})
Expand All @@ -392,7 +397,7 @@ func TestInsertBodyIntoPRTemplateMissingStartMarker(t *testing.T) {
prTemplate := "# PR Template\n\n<!-- END -->\n"

repoConfig := &config.RepoConfig{
PRTemplatePath: "pr_template.md",
PRTemplatePath: "pr_template.md",
PRTemplateInsertStart: "<!-- START -->",
PRTemplateInsertEnd: "<!-- END -->",
}
Expand All @@ -410,7 +415,7 @@ func TestInsertBodyIntoPRTemplateMissingEndMarker(t *testing.T) {
prTemplate := "# PR Template\n\n<!-- START -->\n"

repoConfig := &config.RepoConfig{
PRTemplatePath: "pr_template.md",
PRTemplatePath: "pr_template.md",
PRTemplateInsertStart: "<!-- START -->",
PRTemplateInsertEnd: "<!-- END -->",
}
Expand All @@ -428,7 +433,7 @@ func TestInsertBodyIntoPRTemplateMultipleStartMarkers(t *testing.T) {
prTemplate := "# PR Template\n\n<!-- START -->\n<!-- START -->\n<!-- END -->\n"

repoConfig := &config.RepoConfig{
PRTemplatePath: "pr_template.md",
PRTemplatePath: "pr_template.md",
PRTemplateInsertStart: "<!-- START -->",
PRTemplateInsertEnd: "<!-- END -->",
}
Expand Down Expand Up @@ -509,4 +514,3 @@ func TestFormatBodyCurrentCommitIndicator(t *testing.T) {
assert.Contains(t, result, "#2 ⬅")
assert.NotContains(t, result, "#1 ⬅")
}

Loading