Skip to content

Commit

Permalink
Remove code left over from pre-formatting message
Browse files Browse the repository at this point in the history
  • Loading branch information
CyanoKobalamyne authored and Eitan Joffe committed May 29, 2022
1 parent 96cce78 commit 4894734
Showing 1 changed file with 2 additions and 30 deletions.
32 changes: 2 additions & 30 deletions github/githubclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,37 +389,9 @@ func formatStackMarkdown(commit git.Commit, stack []*github.PullRequest) string
return buf.String()
}

var issueReferenceRegex = regexp.MustCompile(`(?mi)((close|closes|closed|fix|fixes|fixed|ref|resolve|resolves|resolved)\s)?([a-zA-Z-]+\/[a-zA-Z-]+#\d+|#\d+|https?://.+?/[a-zA-Z-]+\/[a-zA-Z-]+/(issues|pull)/\d+)`)

// linkifyPlainLinks replaces plain links in the body by <a> tags, which makes them clickable
// inside a GitHub code area.
func linkifyPlainLinks(body string) string {
return string(xurls.Relaxed.ReplaceAll([]byte(body), []byte("<a href=\"$1\">$1</a>")))
}

func wrapInMarkdown(s string) string {
if strings.TrimSpace(s) == "" {
return ""
}

// Extract issue references for GitHub to find them outside the code block
refs := issueReferenceRegex.FindAllString(s, -1)
var trailer bytes.Buffer
if len(refs) > 0 {
trailer.WriteString("**Issue references**: \n")
for _, ref := range refs {
trailer.WriteString(fmt.Sprintf("\n - %s", ref))
}
}

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 strings.TrimSpace(body)
return strings.TrimSpace(commit.Body)
}

if body == "" {
Expand All @@ -428,7 +400,7 @@ func formatBody(commit git.Commit, stack []*github.PullRequest) string {
}

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

Expand Down

0 comments on commit 4894734

Please sign in to comment.