-
Notifications
You must be signed in to change notification settings - Fork 933
Support linting from the last tag #4110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import {execa} from 'execa'; | |
interface GetCommitMessageOptions { | ||
cwd?: string; | ||
from?: string; | ||
fromLastTag?: boolean; | ||
to?: string; | ||
last?: boolean; | ||
edit?: boolean | string; | ||
|
@@ -19,25 +20,54 @@ interface GetCommitMessageOptions { | |
export default async function getCommitMessages( | ||
settings: GetCommitMessageOptions | ||
): Promise<string[]> { | ||
const {cwd, from, to, last, edit, gitLogArgs} = settings; | ||
const {cwd, fromLastTag, to, last, edit, gitLogArgs} = settings; | ||
let from = settings.from; | ||
|
||
if (edit) { | ||
return getEditCommit(cwd, edit); | ||
} | ||
|
||
if (last) { | ||
const gitCommandResult = await execa('git', [ | ||
'log', | ||
'-1', | ||
'--pretty=format:%B', | ||
]); | ||
const gitCommandResult = await execa( | ||
'git', | ||
['log', '-1', '--pretty=format:%B'], | ||
{cwd} | ||
); | ||
Comment on lines
+31
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Find a bug, fix a bug. Previously using the |
||
let output = gitCommandResult.stdout; | ||
// strip output of extra quotation marks ("") | ||
if (output[0] == '"' && output[output.length - 1] == '"') | ||
output = output.slice(1, -1); | ||
return [output]; | ||
} | ||
|
||
if (!from && fromLastTag) { | ||
const {stdout} = await execa( | ||
'git', | ||
[ | ||
'describe', | ||
'--abbrev=40', | ||
'--always', | ||
'--first-parent', | ||
'--long', | ||
'--tags', | ||
], | ||
Comment on lines
+45
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These git arguments have been battle tested against dozens of repos over several years. Most git output is designed for humans, not for machines (i.e. deserialization), so it takes some work to get stable, deterministic output. |
||
{cwd} | ||
); | ||
|
||
if (stdout.length === 40) { | ||
// Hash only means no last tag. Use that as the from ref which | ||
// results in a no-op. | ||
from = stdout; | ||
} else { | ||
// Description will be in the format: <tag>-<count>-g<hash> | ||
// Example: v3.2.0-11-g9057371a52adaae5180d93fe4d0bb808d874b9fb | ||
// Minus zero based (1), dash (1), "g" prefix (1), hash (40) = -43 | ||
const tagSlice = stdout.lastIndexOf('-', stdout.length - 43); | ||
Comment on lines
+62
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably a few ways to skin this cat. The complexity comes from the fact that tags can themselves contain the dash |
||
|
||
from = stdout.slice(0, tagSlice); | ||
} | ||
} | ||
|
||
let gitOptions: GitOptions = {from, to}; | ||
if (gitLogArgs) { | ||
gitOptions = { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Locked in the
--last
fix with a test. Previously it was not covered.