-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(version): option to add commit login username on each changelog …
…entry, closes #248 (#272) * feat(version): option to add commit login username on each changelog entry, closes #248
- Loading branch information
1 parent
5c59e95
commit 2ca0dca
Showing
18 changed files
with
734 additions
and
98 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
2 changes: 2 additions & 0 deletions
2
packages/core/src/__mocks__/get-commits-since-last-release.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const getCommitsSinceLastRelease = jest.fn(() => Promise.resolve()); | ||
export const getLastTagDetails = jest.fn(() => ({ tagHash: undefined, tagDate: undefined, tagRefCount: 0 })); |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
const releases = new Map(); | ||
|
||
// keep test data isolated | ||
afterEach(() => { | ||
releases.clear(); | ||
}); | ||
|
||
export const graphqlCommitNodes = [ | ||
{ | ||
oid: 'deadbeef123456789', | ||
author: { | ||
name: 'Tester McPerson', | ||
user: { | ||
login: 'tester-mcperson', | ||
}, | ||
}, | ||
message: 'fix(stuff): changed something', | ||
}, | ||
{ | ||
oid: 'bee1234beef7890abc', | ||
author: { | ||
name: 'Tester McPerson', | ||
user: { | ||
login: 'tester-mcperson', | ||
}, | ||
}, | ||
message: 'chore(thing): updated some small stuff', | ||
}, | ||
]; | ||
|
||
const client = { | ||
repos: { | ||
createRelease: jest.fn((opts) => { | ||
releases.set(opts.name, opts); | ||
return Promise.resolve(); | ||
}), | ||
}, | ||
graphql: jest.fn(() => { | ||
return { | ||
repository: { | ||
ref: { | ||
target: { | ||
history: { | ||
nodes: graphqlCommitNodes, | ||
pageInfo: { | ||
hasNextPage: false, | ||
endCursor: '123abc456efg789', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
}), | ||
}; | ||
|
||
export const createGitHubClient: any = jest.fn(() => client); | ||
createGitHubClient.releases = releases; | ||
|
||
export const parseGitRepo = () => ({ | ||
owner: 'lerna', | ||
name: 'lerna', | ||
}); |
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
88 changes: 88 additions & 0 deletions
88
packages/core/src/conventional-commits/__tests__/get-commits-since-last-release.spec.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
jest.mock('../../utils/describe-ref'); | ||
jest.mock('../../child-process'); | ||
jest.mock('../get-github-commits'); | ||
|
||
import { getGithubCommits } from '../get-github-commits'; | ||
import { describeRefSync } from '../../utils/describe-ref'; | ||
import { getCommitsSinceLastRelease, getLastTagDetails } from '../get-commits-since-last-release'; | ||
import { execSync } from '../../child-process'; | ||
|
||
(execSync as jest.Mock).mockReturnValue('"deadbeef 2022-07-01T00:01:02-04:00"'); | ||
|
||
const tagStub = { | ||
lastTagName: 'v1.0.0', | ||
lastVersion: '1.0.0', | ||
refCount: '1', | ||
sha: 'deadbeef', | ||
isDirty: false, | ||
}; | ||
const commitsStub = [ | ||
{ | ||
authorName: 'Tester McPerson', | ||
login: 'tester-mcperson', | ||
shortHash: 'SHA', | ||
message: 'fix(stuff): changed something', | ||
}, | ||
]; | ||
|
||
describe('getCommitsSinceLastRelease', () => { | ||
const execOpts = { cwd: '/test' }; | ||
beforeEach(() => { | ||
(describeRefSync as jest.Mock).mockReturnValue(tagStub); | ||
}); | ||
|
||
it('throws an error if used with a remote client other than "github"', async () => { | ||
await expect(getCommitsSinceLastRelease('gitlab', 'durable', 'main', execOpts)).rejects.toThrow( | ||
'Invalid remote client type, "github" is currently the only supported client with the option --changelog-include-commits-client-login.' | ||
); | ||
}); | ||
|
||
it('should expect commits returned when using "github" when a valid tag is returned', async () => { | ||
(getGithubCommits as jest.Mock).mockResolvedValue(commitsStub); | ||
const result = await getCommitsSinceLastRelease('github', 'durable', 'main', execOpts); | ||
|
||
expect(result).toEqual(commitsStub); | ||
}); | ||
}); | ||
|
||
describe('getLastTagDetails', () => { | ||
const execOpts = { cwd: '/test' }; | ||
|
||
describe('with existing tag', () => { | ||
beforeEach(() => { | ||
(describeRefSync as jest.Mock).mockReturnValue(tagStub); | ||
}); | ||
|
||
it('should expect a result with a tag date, hash and ref count', async () => { | ||
const result = await getLastTagDetails(execOpts); | ||
const execSpy = (execSync as jest.Mock).mockReturnValue('"deadbeef 2022-07-01T00:01:02-04:00"'); | ||
|
||
expect(execSpy).toHaveBeenCalledWith('git', ['log', '-1', '--format="%h %cI"', 'v1.0.0'], execOpts); | ||
expect(result).toEqual({ tagDate: '2022-07-01T00:01:02-04:00', tagHash: 'deadbeef', tagRefCount: '1' }); | ||
}); | ||
}); | ||
|
||
describe('without tag', () => { | ||
beforeEach(() => { | ||
(describeRefSync as jest.Mock).mockReturnValue({ | ||
lastTagName: undefined, | ||
lastVersion: undefined, | ||
refCount: '1', | ||
sha: 'deadbeef', | ||
isDirty: false, | ||
}); | ||
}); | ||
|
||
it('should return first commit date when describeRefSync() did not return a tag date', async () => { | ||
const execSpy = (execSync as jest.Mock).mockReturnValue('"abcbeef 2022-07-01T00:01:02-04:00"'); | ||
const result = await getLastTagDetails(execOpts); | ||
|
||
expect(execSpy).toHaveBeenCalledWith( | ||
'git', | ||
['log', '--oneline', '--format="%h %cI"', '--reverse', '--max-parents=0', 'HEAD'], | ||
execOpts | ||
); | ||
expect(result).toEqual({ tagDate: '2022-07-01T00:01:02-04:00', tagHash: 'abcbeef', tagRefCount: '1' }); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.