-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): add option semverTag to history command (#626)
- Loading branch information
Showing
27 changed files
with
1,013 additions
and
349 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,36 @@ | ||
import { HistoryOptions } from '@code-pushup/core'; | ||
import { getHashFromTag, isSemver } from '@code-pushup/utils'; | ||
import { HistoryCliOptions } from './history.model'; | ||
|
||
export async function normalizeHashOptions( | ||
processArgs: HistoryCliOptions & HistoryOptions, | ||
): Promise<HistoryCliOptions & HistoryOptions> { | ||
const { | ||
onlySemverTags, | ||
// overwritten | ||
maxCount, | ||
...opt | ||
} = processArgs; | ||
|
||
// eslint-disable-next-line functional/no-let, prefer-const | ||
let { from, to, ...processOptions } = opt; | ||
// if no semver filter is used resolve hash of tags, as hashes are used to collect history | ||
if (!onlySemverTags) { | ||
if (from && isSemver(from)) { | ||
const { hash } = await getHashFromTag(from); | ||
from = hash; | ||
} | ||
if (to && isSemver(to)) { | ||
const { hash } = await getHashFromTag(to); | ||
to = hash; | ||
} | ||
} | ||
|
||
return { | ||
...processOptions, | ||
onlySemverTags, | ||
maxCount: maxCount && maxCount > 0 ? maxCount : undefined, | ||
from, | ||
to, | ||
}; | ||
} |
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,120 @@ | ||
import { describe, expect, vi } from 'vitest'; | ||
import { type HistoryOptions } from '@code-pushup/core'; | ||
import { HistoryCliOptions } from './history.model'; | ||
import { normalizeHashOptions } from './utils'; | ||
|
||
vi.mock('simple-git', async () => { | ||
const actual = await vi.importActual('simple-git'); | ||
const orderedTagsHistory = ['2.0.0', '1.0.0']; | ||
return { | ||
...actual, | ||
simpleGit: () => ({ | ||
branch: () => Promise.resolve('dummy'), | ||
raw: () => Promise.resolve('main'), | ||
tag: () => Promise.resolve(orderedTagsHistory.join('\n')), | ||
show: ([_, __, tag]: string) => | ||
orderedTagsHistory.includes(tag || '') | ||
? Promise.resolve(`${tag}\ncommit--release-v${tag}`) | ||
: Promise.reject('NOT FOUND TAG'), | ||
checkout: () => Promise.resolve(), | ||
log: ({ maxCount }: { maxCount: number } = { maxCount: 1 }) => | ||
Promise.resolve({ | ||
all: [ | ||
{ hash: 'commit-6' }, | ||
{ hash: 'commit-5' }, | ||
{ hash: `commit--release-v${orderedTagsHistory.at(0)}` }, | ||
{ hash: 'commit-3' }, | ||
{ hash: `commit--release-v${orderedTagsHistory.at(1)}` }, | ||
{ hash: 'commit-1' }, | ||
].slice(-maxCount), | ||
}), | ||
}), | ||
}; | ||
}); | ||
|
||
describe('normalizeHashOptions', () => { | ||
it('should forwards other options', async () => { | ||
await expect( | ||
normalizeHashOptions({ | ||
test: 42, | ||
} as unknown as HistoryCliOptions & HistoryOptions), | ||
).resolves.toEqual( | ||
expect.objectContaining({ | ||
test: 42, | ||
}), | ||
); | ||
}); | ||
|
||
it('should set "maxCount" to undefined if "0" is passed', async () => { | ||
await expect( | ||
normalizeHashOptions({ maxCount: 0 } as HistoryCliOptions & | ||
HistoryOptions), | ||
).resolves.toEqual( | ||
expect.objectContaining({ | ||
maxCount: undefined, | ||
}), | ||
); | ||
}); | ||
|
||
it('should forward hashes "from" and "to" as is if "onlySemverTags" is false', async () => { | ||
await expect( | ||
normalizeHashOptions({ | ||
from: 'commit-3', | ||
to: 'commit-1', | ||
} as HistoryCliOptions & HistoryOptions), | ||
).resolves.toEqual( | ||
expect.objectContaining({ | ||
from: 'commit-3', | ||
to: 'commit-1', | ||
}), | ||
); | ||
}); | ||
|
||
it('should transform tags "from" and "to" to commit hashes if "onlySemverTags" is false', async () => { | ||
await expect( | ||
normalizeHashOptions({ | ||
onlySemverTags: false, | ||
from: '2.0.0', | ||
to: '1.0.0', | ||
} as HistoryCliOptions & HistoryOptions), | ||
).resolves.toEqual( | ||
expect.objectContaining({ | ||
onlySemverTags: false, | ||
from: 'commit--release-v2.0.0', | ||
to: 'commit--release-v1.0.0', | ||
}), | ||
); | ||
}); | ||
|
||
it('should forward tags "from" and "to" if "onlySemverTags" is true', async () => { | ||
await expect( | ||
normalizeHashOptions({ | ||
onlySemverTags: true, | ||
from: '2.0.0', | ||
to: '1.0.0', | ||
} as HistoryCliOptions & HistoryOptions), | ||
).resolves.toEqual( | ||
expect.objectContaining({ | ||
onlySemverTags: true, | ||
from: '2.0.0', | ||
to: '1.0.0', | ||
}), | ||
); | ||
}); | ||
|
||
it('should forward hashes "from" and "to" if "onlySemverTags" is true', async () => { | ||
await expect( | ||
normalizeHashOptions({ | ||
onlySemverTags: true, | ||
from: 'commit-3', | ||
to: 'commit-1', | ||
} as HistoryCliOptions & HistoryOptions), | ||
).resolves.toEqual( | ||
expect.objectContaining({ | ||
onlySemverTags: true, | ||
from: 'commit-3', | ||
to: 'commit-1', | ||
}), | ||
); | ||
}); | ||
}); |
Oops, something went wrong.