coverbadge
Advanced tools
Comparing version 0.4.1 to 0.5.0
{ | ||
"name": "coverbadge", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"description": "Create a coverage badge without any service provider.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -26,3 +26,3 @@ const fetch = require('isomorphic-fetch'); | ||
const { emoji, text } = formatMessage(lastCoverage, coverage); | ||
const { vcs, username, project, branch, ignoreSame } = others; | ||
const { vcs, username, project, branch, ignoreSame, prs } = others; | ||
let body = text; | ||
@@ -42,2 +42,18 @@ | ||
if (prs) { | ||
const PR_REGEX = /(?:\/|#)(\d+)\/?$/g; | ||
const prsLinks = prs.split(',').map((pr) => { | ||
const link = pr.trim(); | ||
if (link) { | ||
const group = PR_REGEX.exec(link); | ||
const prNum = group ? group[1] : null; | ||
PR_REGEX.lastIndex = 0; | ||
return prNum !== null ? `<${link}|#${prNum}>` : ''; | ||
} | ||
}).filter(Boolean); | ||
body += ` (${prsLinks.join(',')})`; | ||
} | ||
return fetch(webhook, { | ||
@@ -44,0 +60,0 @@ method: 'POST', |
@@ -72,1 +72,39 @@ import fetch from 'isomorphic-fetch'; | ||
}); | ||
describe('PR', () => { | ||
afterEach(() => { | ||
fetch.mockClear(); | ||
}); | ||
it('should process one pr', async () => { | ||
await sendSlackWebhook('slack', 50, 100, { | ||
prs: 'https://github.com/kevin940726/coverbadge/pull/2', | ||
}); | ||
expect(fetch.mock.calls).toMatchSnapshot(); | ||
}); | ||
it('should process multiple prs', async () => { | ||
await sendSlackWebhook('slack', 50, 100, { | ||
prs: 'https://github.com/kevin940726/coverbadge/pull/1, https://github.com/kevin940726/coverbadge/pull/2', | ||
}); | ||
expect(fetch.mock.calls).toMatchSnapshot(); | ||
}); | ||
it('should handle link error', async () => { | ||
await sendSlackWebhook('slack', 50, 100, { | ||
prs: 'https://github.com/kevin940726/coverbadge/pull/1,', | ||
}); | ||
expect(fetch.mock.calls).toMatchSnapshot(); | ||
}); | ||
it('should handle regex error', async () => { | ||
await sendSlackWebhook('slack', 50, 100, { | ||
prs: 'https://github.com/kevin940726/coverbadge/pull/1x,https://github.com/kevin940726/coverbadge/pull/2', | ||
}); | ||
expect(fetch.mock.calls).toMatchSnapshot(); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
132283
901
33