Skip to content

Commit 89953af

Browse files
authored
fix: resolve commit message issue (#423)
1 parent 629c5b8 commit 89953af

3 files changed

Lines changed: 58 additions & 13 deletions

File tree

lib/add-contributor.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const getUserDetails = require("./get-user-details");
44
const ContentFiles = require("./modules/content-files");
55
const convertMessage = require("commit-conv");
66

7+
const { generatePrTitle } = require("./modules/helpers");
8+
79
async function addContributor({
810
context,
911
commentReply,
@@ -53,15 +55,10 @@ async function addContributor({
5355
originalSha: config.getOriginalSha(),
5456
};
5557

56-
const contributionsTitlePartLimit = 3
57-
const arr = contributions.slice(0, contributionsTitlePartLimit);
58-
if (arr.length > contributionsTitlePartLimit) arr[arr.length - 1] = `${contributions.length - 2} more`
59-
const contributionsTitlePartText = arr.slice(0, arr.length - 1).join(', ') + ", and " + arr.slice(-1);
60-
6158
const convention = config.get().commitConvention;
6259
const prTitle = convertMessage({
6360
tag: "docs",
64-
msg: `add ${who} as a contributor for ${contributionsTitlePartText}`,
61+
msg: generatePrTitle(`add ${who} as a contributor`, contributions),
6562
convention
6663
});
6764

lib/modules/helpers.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
function generateValidProfileLink(blog, githubProfileURL) {
22
const validRegexWithScheme = /^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/
33
const validRegexWithoutScheme = /^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/
4-
if (validRegexWithScheme.test(blog)) return blog;
54
if (validRegexWithoutScheme.test(blog)) return `http://${blog}`;
5+
if (validRegexWithScheme.test(blog)) return blog;
66
return githubProfileURL || ''
77
}
88

9+
function generatePrTitle(message, contributions) {
10+
const contributionsTitlePartLimit = 3
11+
12+
let contributionsTitlePartText = contributions.join(', ')
13+
14+
const arr = contributions.slice(0, contributionsTitlePartLimit);
15+
if (contributions.length > contributionsTitlePartLimit) arr[arr.length - 1] = `${contributions.length - 2} more`
16+
if (arr.length > 1) contributionsTitlePartText = arr.slice(0, arr.length - 1).join(', ') + ", and " + arr.slice(-1);
17+
18+
return [message, `for ${contributionsTitlePartText}`].join(' ')
19+
}
20+
921
module.exports = {
22+
generatePrTitle,
1023
generateValidProfileLink
1124
}

test/unit/helpers.test.js

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,39 @@
1-
const { generateValidProfileLink } = require('../../lib/modules/helpers');
1+
const {
2+
generatePrTitle,
3+
generateValidProfileLink,
4+
} = require('../../lib/modules/helpers');
5+
6+
describe('generatePrTitle', () => {
7+
const message = 'add tenshiAMD as a contributor';
8+
9+
test('returns valid message - with 1 contribution type/s', async () => {
10+
let contributions = ['code'];
11+
let validText = generatePrTitle(message, contributions);
12+
13+
expect(validText).toEqual('add tenshiAMD as a contributor for code');
14+
});
15+
16+
test('returns valid message - with 2 contribution type/s', async () => {
17+
let contributions = ['code', 'bug'];
18+
let validText = generatePrTitle(message, contributions);
19+
20+
expect(validText).toEqual('add tenshiAMD as a contributor for code, and bug');
21+
});
22+
23+
test('returns valid message - with 3 contribution type/s', async () => {
24+
let contributions = ['code', 'bug', 'design'];
25+
let validText = generatePrTitle(message, contributions);
26+
27+
expect(validText).toEqual('add tenshiAMD as a contributor for code, bug, and design');
28+
});
29+
30+
test('returns valid message - with nth contribution type/s', async () => {
31+
let contributions = ['code', 'bug', 'a11y', 'design', 'review'];
32+
let validText = generatePrTitle(message, contributions);
33+
34+
expect(validText).toEqual(`add tenshiAMD as a contributor for code, bug, and ${contributions.length - 2} more`);
35+
});
36+
});
237

338
describe('generateValidProfileLink', () => {
439
const githubProfileUrl = 'https://github.com/tenshiAMD'
@@ -28,35 +63,35 @@ describe('generateValidProfileLink', () => {
2863
let url = 'tenshhttpiamd.com';
2964
let validUrl = generateValidProfileLink(url, githubProfileUrl);
3065

31-
expect(validUrl).toEqual(url);
66+
expect(validUrl).toEqual(`http://${url}`);
3267
});
3368

3469
test('returns valid link - valid URL format with `https` in between', async () => {
3570
let url = 'tenshhttpsiamd.com';
3671
let validUrl = generateValidProfileLink(url, githubProfileUrl);
3772

38-
expect(validUrl).toEqual(url);
73+
expect(validUrl).toEqual(`http://${url}`);
3974
});
4075

4176
test('returns valid link - no protocol', async () => {
4277
let url = 'tenshiamd.com';
4378
let validUrl = generateValidProfileLink(url, githubProfileUrl);
4479

45-
expect(validUrl).toEqual(url);
80+
expect(validUrl).toEqual(`http://${url}`);
4681
});
4782

4883
test('returns valid link - no protocol and starting with `http`', async () => {
4984
let url = 'httptenshiamd.com';
5085
let validUrl = generateValidProfileLink(url, githubProfileUrl);
5186

52-
expect(validUrl).toEqual(url);
87+
expect(validUrl).toEqual(`http://${url}`);
5388
});
5489

5590
test('returns valid link - no protocol and starting with `https`', async () => {
5691
let url = 'httpstenshiamd.com';
5792
let validUrl = generateValidProfileLink(url, githubProfileUrl);
5893

59-
expect(validUrl).toEqual(url);
94+
expect(validUrl).toEqual(`http://${url}`);
6095
});
6196

6297
test('returns valid link - incomplete URL format', async () => {

0 commit comments

Comments
 (0)