-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
—pr
options to backport via pull request number (#145)
* Add `—pr` options to backport via pull request number * Remove obsolete snapshot * Add test for `getFormattedCommitMessage` * Move unit tests to src folder * Bump node types
- Loading branch information
Showing
55 changed files
with
1,467 additions
and
1,414 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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
test/unit/options/cliArgs.test.ts → src/options/cliArgs.test.ts
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
4 changes: 2 additions & 2 deletions
4
test/unit/options/config/config.test.ts → src/options/config/config.test.ts
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
9 changes: 3 additions & 6 deletions
9
.../unit/options/config/globalConfig.test.ts → src/options/config/globalConfig.test.ts
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
6 changes: 3 additions & 3 deletions
6
...unit/options/config/projectConfig.test.ts → src/options/config/projectConfig.test.ts
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
4 changes: 2 additions & 2 deletions
4
test/unit/scripts/postinstall.test.ts → src/scripts/postinstall.test.ts
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
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,51 @@ | ||
import { | ||
getFirstCommitMessageLine, | ||
getFormattedCommitMessage | ||
} from './commitFormatters'; | ||
|
||
describe('getFirstCommitMessageLine', () => { | ||
it('should only return the first line of the message', () => { | ||
expect( | ||
getFirstCommitMessageLine( | ||
'My commit message (#1234)\n\n Additional commit message body' | ||
) | ||
).toEqual('My commit message (#1234)'); | ||
}); | ||
|
||
it('should return the commit message as-is', () => { | ||
expect(getFirstCommitMessageLine('My commit message')).toEqual( | ||
'My commit message' | ||
); | ||
}); | ||
}); | ||
|
||
describe('getFormattedCommitMessage', () => { | ||
it('should return the first message line verbatim', () => { | ||
expect( | ||
getFormattedCommitMessage({ | ||
message: 'This is my commit message (#1234)\n\nthis is a second line', | ||
pullNumber: 1234, | ||
sha: 'sha123456789' | ||
}) | ||
).toBe('This is my commit message (#1234)'); | ||
}); | ||
|
||
it('should add pullNumber as suffix', () => { | ||
expect( | ||
getFormattedCommitMessage({ | ||
message: 'This is my commit message\n\nthis is a second line', | ||
pullNumber: 1234, | ||
sha: 'sha123456789' | ||
}) | ||
).toBe('This is my commit message (#1234)'); | ||
}); | ||
|
||
it('should add commit sha as suffix', () => { | ||
expect( | ||
getFormattedCommitMessage({ | ||
message: 'This is my commit message\n\nthis is a second line', | ||
sha: 'sha123456789' | ||
}) | ||
).toBe('This is my commit message (sha12345)'); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,23 +1,33 @@ | ||
import { CommitChoice, CommitSelected } from './Commit'; | ||
|
||
export function getHumanReadableReference(commit: CommitSelected) { | ||
return commit.pullNumber ? `#${commit.pullNumber}` : getShortSha(commit.sha); | ||
} | ||
|
||
export function getShortSha(sha: string) { | ||
return sha.slice(0, 8); | ||
} | ||
|
||
export function getFirstCommitMessageLine(message: string) { | ||
return message.split('\n')[0].replace(/\s\(#\d+\)/g, ''); | ||
return message.split('\n')[0]; | ||
} | ||
|
||
export function withFormattedCommitMessage< | ||
T extends CommitSelected | CommitChoice | ||
>(commit: T): T { | ||
const firstMessageLine = getFirstCommitMessageLine(commit.message); | ||
return { | ||
...commit, | ||
message: `${firstMessageLine} (${getHumanReadableReference(commit)})` | ||
}; | ||
export function getFormattedCommitMessage({ | ||
message, | ||
pullNumber, | ||
sha | ||
}: { | ||
message: string; | ||
pullNumber?: number; | ||
sha: string; | ||
}) { | ||
const firstMessageLine = getFirstCommitMessageLine(message); | ||
if (pullNumber) { | ||
const messageHasPullNumber = firstMessageLine.includes(`#${pullNumber}`); | ||
|
||
// message already contain pull number | ||
if (messageHasPullNumber) { | ||
return firstMessageLine; | ||
} | ||
|
||
// message doesn't contain pull number. Add it | ||
return `${firstMessageLine} (#${pullNumber})`; | ||
} | ||
|
||
// pull number not available. Add commit | ||
return `${firstMessageLine} (${getShortSha(sha)})`; | ||
} |
Oops, something went wrong.