Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let message = context.payload.pull_request.title;
// if there is only one commit, lint the commit rather than
// the pull request title:
if (commits.length === 1) {
message = commits[0].commit.message;
}
// support "foo!: message" syntax, see:
// https://github.com/conventional-changelog/commitlint/pull/767
message = message.replace('!:', ':');
let text = '';
let lintError = false;
const result = await lint(message, rules);
if (result.valid === false) {
lintError = true;
text += `:x: linting errors for "*${result.input}*"\n`;
result.errors.forEach(error => {
text += `* ${error.message}\n`;
});
text += '\n\n';
}
// post the status of commit linting to the PR, using:
// https://developer.github.com/v3/checks/
let checkParams = context.repo({
name: 'conventionalcommits.org',
conclusion: 'success' as Conclusion,
head_sha: commits[commits.length - 1].sha,
});
it('respect max length', async () => {
const valideLength =
'fix: This line contains exactly 72 characters meaning it passes the test'
expect((await lint(valideLength, rules)).valid).toBeTruthy()
const invalidLength =
'refactor: This one contains more than 72 so it really should not pass the test because no one can read the end'
expect((await lint(invalidLength, rules)).valid).toBeFalsy()
})
it('respect max length', async () => {
const valideLength =
'fix: This line contains exactly 72 characters meaning it passes the test'
expect((await lint(valideLength, rules)).valid).toBeTruthy()
const invalidLength =
'refactor: This one contains more than 72 so it really should not pass the test because no one can read the end'
expect((await lint(invalidLength, rules)).valid).toBeFalsy()
})
it('respect scope', async () => {
const validScope = ['LineChart', 'balance history']
for (const scope of validScope) {
expect((await lint(`feat(${scope}): Bar`, rules)).valid).toBeTruthy()
}
})
it('can use emojis in your commit subject', async () => {
const validEmojis = [
'fix: š This is a valid commit',
'fix: This is a valid commit š'
]
for (const emoji of validEmojis) {
expect((await lint(emoji, rules)).valid).toBeTruthy()
}
const invalidEmojis = 'š fix: This is an invalid commit'
expect((await lint(invalidEmojis, rules)).valid).toBeFalsy()
})
})
it('can use emojis in your commit subject', async () => {
const validEmojis = [
'fix: š This is a valid commit',
'fix: This is a valid commit š'
]
for (const emoji of validEmojis) {
expect((await lint(emoji, rules)).valid).toBeTruthy()
}
const invalidEmojis = 'š fix: This is an invalid commit'
expect((await lint(invalidEmojis, rules)).valid).toBeFalsy()
})
})
it('respect max length', async () => {
const validBody = [`fix: Bar\n\nWith a small body`]
for (const body of validBody) {
expect((await lint(body, rules)).valid).toBeTruthy()
}
const invalidBody = [
`fix: Bar\n\n${TOO_LONG}`,
`fix: Bar\n\nWith a small body\n${TOO_LONG}`
]
for (const body of invalidBody) {
expect((await lint(body, rules)).valid).toBeFalsy()
}
})
})
commits.forEach(async (commit) => {
const result = await lint(
commit.message,
rules,
parserPreset
? {
parserOpts: parserPreset.parserOpts,
}
: {}
)
if (!result.valid) {
if (result.errors.length > 0) {
let message = `The commit - ${commit.sha.trim()} doesn't conform the conventional commit guidelines. \n\n**Errors**:\n\n`
message += table([['Message'], ...result.errors.map((error) => [error.message])])
message += `\n\nš” For a guidance on how to fix this problem please refer to [https://www.conventionalcommits.org](https://www.conventionalcommits.org)`