Skip to content

Commit

Permalink
Update PR description formatting.
Browse files Browse the repository at this point in the history
Previously, the commit description was dropped after the stack list and was in a pre-formatted block, which removes any markdown formatting and other niceties of description commit bodies.

This instead pulls the commit body to the top, and adds a horizontal divider, after which the SPR stack and other trailer info is added. This keeps the PR description more in line with the commit message, while still including the Stack info.

commit-id:e0bb6ce4
  • Loading branch information
josephschmitt authored and Eitan Joffe committed Jan 19, 2022
1 parent 78d0aea commit 1606b8f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
22 changes: 15 additions & 7 deletions github/githubclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"bytes"
"context"
"fmt"
"gopkg.in/yaml.v3"
"net/url"
"os"
"path"
"regexp"
"strings"

"gopkg.in/yaml.v3"

"github.com/ejoffe/spr/config"
"github.com/ejoffe/spr/git"
"github.com/ejoffe/spr/github"
Expand Down Expand Up @@ -130,7 +131,7 @@ Alternatively, configure a token manually in ~/.config/hub:
protocol: https
This configuration file is shared with GitHub's "hub" CLI (https://hub.github.com/),
so if you already use that, spr will automatically pick up your token.
so if you already use that, spr will automatically pick up your token.
`

func NewGitHubClient(ctx context.Context, config *config.Config) *client {
Expand Down Expand Up @@ -367,17 +368,24 @@ func wrapInMarkdown(s string) string {
}
}

return fmt.Sprintf("<pre>\n%s\n</pre>\n%s", linkifyPlainLinks(s), trailer.String())
return fmt.Sprintf("%s\n\n%s", linkifyPlainLinks(s), trailer.String())
}

func formatBody(commit git.Commit, stack []*github.PullRequest) string {
body := wrapInMarkdown(commit.Body)

if len(stack) <= 1 {
return wrapInMarkdown(commit.Body)
return strings.TrimSpace(body)
}

if body == "" {
return fmt.Sprintf("**Stack**:\n%s",
addManualMergeNotice(formatStackMarkdown(commit, stack)))
}

return fmt.Sprintf("**Stack**:\n%s\n\n%s",
formatStackMarkdown(commit, stack),
addManualMergeNotice(wrapInMarkdown(commit.Body)))
return fmt.Sprintf("%s---\n\n**Stack**:\n%s",
body,
addManualMergeNotice(formatStackMarkdown(commit, stack)))
}

func addManualMergeNotice(body string) string {
Expand Down
20 changes: 8 additions & 12 deletions github/githubclient/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,22 @@ It even includes some **markdown** formatting.`}
stack: []*github.PullRequest{},
},
{
description: `<pre>
This body describes my nice PR.
It even includes some **markdown** formatting.
</pre>
`,
description: `This body describes my nice PR.
It even includes some **markdown** formatting.`,
commit: descriptiveCommit,
stack: []*github.PullRequest{
&github.PullRequest{Number: 2, Commit: descriptiveCommit},
},
},
{
description: `**Stack**:
- #2 ⮜
- #1
description: `This body describes my nice PR.
It even includes some **markdown** formatting.
---
<pre>
This body describes my nice PR.
It even includes some **markdown** formatting.
</pre>
**Stack**:
- #2 ⮜
- #1
⚠️ *Part of a stack created by [spr](https://github.com/ejoffe/spr). Do not merge manually using the UI - doing so may have unexpected results.*`,
Expand Down

0 comments on commit 1606b8f

Please sign in to comment.