-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(prlint): stricter validation around breaking changes (#14278)
Increase the scrutiny on how breaking changes are formatted. Motivation A previous PR - #14227 - incorrectly specified breaking changes that standard-release failed to record in the changelog. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Niranjan Jayakar
authored
Apr 21, 2021
1 parent
e0d1047
commit 016611d
Showing
3 changed files
with
82 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
const GitHub = require('github-api'); | ||
jest.mock('github-api'); | ||
const linter = require('../index'); | ||
|
||
beforeEach(() => { | ||
GitHub.mockClear(); | ||
}); | ||
|
||
describe('breaking changes format', () => { | ||
test('disallow variations to "BREAKING CHANGE:"', async () => { | ||
const issue = { | ||
body: 'BREAKING CHANGES:', | ||
labels: [{ name: 'pr-linter/exempt-test' }, { name: 'pr-linter/exempt-readme' }] | ||
}; | ||
configureMock(issue, undefined); | ||
await expect(linter.validatePr(1000)).rejects.toThrow(/'BREAKING CHANGE: ', variations are not allowed/); | ||
}); | ||
|
||
test('the first breaking change should immediately follow "BREAKING CHANGE:"', async () => { | ||
const issue = { | ||
body: `BREAKING CHANGE: | ||
* **module:** another change`, | ||
labels: [{ name: 'pr-linter/exempt-test' }, { name: 'pr-linter/exempt-readme' }] | ||
}; | ||
configureMock(issue, undefined); | ||
await expect(linter.validatePr(1000)).rejects.toThrow(/description of the first breaking change should immediately follow/); | ||
}); | ||
|
||
test('invalid title', async () => { | ||
const issue = { | ||
title: 'chore(foo/bar): some title', | ||
body: 'BREAKING CHANGE: this breaking change', | ||
labels: [{ name: 'pr-linter/exempt-test' }, { name: 'pr-linter/exempt-readme' }] | ||
}; | ||
configureMock(issue, undefined); | ||
await expect(linter.validatePr(1000)).rejects.toThrow(/must specify the module name that the first breaking change/); | ||
}); | ||
|
||
test('valid title', async () => { | ||
const issue = { | ||
title: 'chore(foo): some title', | ||
body: 'BREAKING CHANGE: this breaking change', | ||
labels: [{ name: 'pr-linter/exempt-test' }, { name: 'pr-linter/exempt-readme' }] | ||
}; | ||
configureMock(issue, undefined); | ||
await linter.validatePr(1000); // not throw | ||
}); | ||
}); | ||
|
||
function configureMock(issue, prFiles) { | ||
GitHub.mockImplementation(() => { | ||
return { | ||
getIssues: () => { | ||
return { | ||
getIssue: () => { | ||
return { data: issue }; | ||
}, | ||
}; | ||
}, | ||
getRepo: () => { | ||
return { | ||
listPullRequestFiles: () => { | ||
return { data: prFiles }; | ||
} | ||
} | ||
} | ||
}; | ||
}); | ||
} |