Set title/body from commit-message if given
If `title`, `body`, and `body-path` are all not given, and `commit-message` is, parse the `title` and `body` from the 'commit-message'. A properly formatted message (title, blank line, then body) will be used as title and body. Otherwise, the first line is used as title and the remaining lines as body. Another valid approach could be to take all the lines as title, or all the lines until the first blank as title, but the former is unlikely to be the user's intention and the latter would introduce complexity. The parsing function was added in `utils` to facilitate testing.
This commit is contained in:
parent
fa9200e5b4
commit
939b9b261c
@ -37,6 +37,40 @@ describe('utils tests', () => {
|
|||||||
expect(array[2]).toEqual('team3')
|
expect(array[2]).toEqual('team3')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('getTitleBodyFromCommitMessage works for single-line', async () => {
|
||||||
|
const {title, body} = utils.getTitleBodyFromCommitMessage(
|
||||||
|
'This is a commit message'
|
||||||
|
)
|
||||||
|
expect(title).toEqual('This is a commit message')
|
||||||
|
expect(body).toEqual('')
|
||||||
|
})
|
||||||
|
|
||||||
|
test('getTitleBodyFromCommitMessage works for multi-line', async () => {
|
||||||
|
const {title, body} = utils.getTitleBodyFromCommitMessage(
|
||||||
|
'This is a commit message\n' +
|
||||||
|
'That is not properly formatted with blank line\n' +
|
||||||
|
'between title and body'
|
||||||
|
)
|
||||||
|
expect(title).toEqual('This is a commit message')
|
||||||
|
expect(body).toEqual(
|
||||||
|
'That is not properly formatted with blank line\n' +
|
||||||
|
'between title and body'
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('getTitleBodyFromCommitMessage works for title with body', async () => {
|
||||||
|
const {title, body} = utils.getTitleBodyFromCommitMessage(
|
||||||
|
'This is a commit message\n' +
|
||||||
|
'\n' +
|
||||||
|
'That IS properly formatted with blank line\n' +
|
||||||
|
'between title and body'
|
||||||
|
)
|
||||||
|
expect(title).toEqual('This is a commit message')
|
||||||
|
expect(body).toEqual(
|
||||||
|
'That IS properly formatted with blank line\n' + 'between title and body'
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
test('getRepoPath successfully returns the path to the repository', async () => {
|
test('getRepoPath successfully returns the path to the repository', async () => {
|
||||||
expect(utils.getRepoPath()).toEqual(process.env['GITHUB_WORKSPACE'])
|
expect(utils.getRepoPath()).toEqual(process.env['GITHUB_WORKSPACE'])
|
||||||
expect(utils.getRepoPath('foo')).toEqual(
|
expect(utils.getRepoPath('foo')).toEqual(
|
||||||
|
|||||||
12
src/main.ts
12
src/main.ts
@ -44,6 +44,18 @@ async function run(): Promise<void> {
|
|||||||
if (!inputs.token) {
|
if (!inputs.token) {
|
||||||
throw new Error(`Input 'token' not supplied. Unable to continue.`)
|
throw new Error(`Input 'token' not supplied. Unable to continue.`)
|
||||||
}
|
}
|
||||||
|
if (
|
||||||
|
inputs.commitMessage &&
|
||||||
|
inputs.commitMessage !== '' &&
|
||||||
|
inputs.body === '' &&
|
||||||
|
inputs.bodyPath === ''
|
||||||
|
) {
|
||||||
|
const {title, body} = utils.getTitleBodyFromCommitMessage(
|
||||||
|
inputs.commitMessage
|
||||||
|
)
|
||||||
|
inputs.title = title
|
||||||
|
inputs.body = body
|
||||||
|
}
|
||||||
if (!inputs.branchToken) {
|
if (!inputs.branchToken) {
|
||||||
inputs.branchToken = inputs.token
|
inputs.branchToken = inputs.token
|
||||||
}
|
}
|
||||||
|
|||||||
12
src/utils.ts
12
src/utils.ts
@ -26,6 +26,18 @@ export function stripOrgPrefixFromTeams(teams: string[]): string[] {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getTitleBodyFromCommitMessage(commitMessage: string): {
|
||||||
|
title: string
|
||||||
|
body: string
|
||||||
|
} {
|
||||||
|
const lines = commitMessage.split('\n')
|
||||||
|
|
||||||
|
return {
|
||||||
|
title: lines[0] ?? '',
|
||||||
|
body: lines.slice(1).join('\n').trim()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function getRepoPath(relativePath?: string): string {
|
export function getRepoPath(relativePath?: string): string {
|
||||||
let githubWorkspacePath = process.env['GITHUB_WORKSPACE']
|
let githubWorkspacePath = process.env['GITHUB_WORKSPACE']
|
||||||
if (!githubWorkspacePath) {
|
if (!githubWorkspacePath) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user