-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #439 from hongaar/feature/configurable-commit-message
feat: configurable commit message
- Loading branch information
Showing
12 changed files
with
428 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { PullRequestInfo } from './models' | ||
import { Config } from './config' | ||
|
||
export function getCommitMessage ( | ||
pullRequestInfo: PullRequestInfo, | ||
config: Config | ||
) { | ||
return config.mergeCommitMessage | ||
? getCustomCommitMessage(pullRequestInfo, config.mergeCommitMessage) | ||
: null | ||
} | ||
|
||
export function splitCommitMessage (message: string) { | ||
const [title, ...body] = message.trim().split('\n') | ||
|
||
return { | ||
title: title.trim(), | ||
body: body.join('\n').trim() | ||
} | ||
} | ||
|
||
type Tag = 'title' | 'body' | 'number' | 'branch' | 'commits' | ||
|
||
type Tags = { | ||
[key in Tag]: (pullRequestInfo: PullRequestInfo) => string | ||
} | ||
|
||
function getCustomCommitMessage ( | ||
pullRequestInfo: PullRequestInfo, | ||
template: string | ||
) { | ||
const tagResolvers: Tags = { | ||
title: pullRequestInfo => pullRequestInfo.title, | ||
body: pullRequestInfo => pullRequestInfo.body, | ||
number: pullRequestInfo => pullRequestInfo.number.toString(), | ||
branch: pullRequestInfo => pullRequestInfo.headRefName, | ||
commits: pullRequestInfo => pullRequestInfo.allCommits.nodes | ||
.map(node => `* ${node.commit.messageHeadline} (${node.commit.abbreviatedOid})`) | ||
.join('\n') | ||
} | ||
|
||
return template.replace(/\{(\w+)\}/g, (match, tagName: Tag) => { | ||
const tagResolver = tagResolvers[tagName] | ||
if (tagResolver) { | ||
return tagResolver(pullRequestInfo) | ||
} else { | ||
return match | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.