diff --git a/lib/parse-comment.js b/lib/parse-comment.js index b883c14a..3ea42990 100644 --- a/lib/parse-comment.js +++ b/lib/parse-comment.js @@ -245,6 +245,11 @@ function parseAddComment(message, action) { const sentenceRaw = sentence.data()[0].text; const { who, contributions } = parseAddSentence(sentenceRaw, action); + // TODO: Exclude action same as contributor name + if (who && who.match(/you|videos/)) { + return; + } + if (who) { contributors[who] = contributions; } @@ -261,6 +266,7 @@ function parseComment(message) { const action = doc.toLowerCase().match("#Action").normalize().out("string"); + // TODO: check format if complete if (action.match("add")) { return parseAddComment(message, action); } diff --git a/test/unit/parse-comment.test.js b/test/unit/parse-comment.test.js index 9c6902c2..908e21ab 100644 --- a/test/unit/parse-comment.test.js +++ b/test/unit/parse-comment.test.js @@ -1,186 +1,204 @@ const parseComment = require("../../lib/parse-comment"); -describe('parseComment', () => { - const testBotName = 'all-contributors' +describe("parseComment", () => { + const testBotName = "all-contributors"; - test('Basic intent to add', () => { - expect( - parseComment( - `@${testBotName} please add jakebolam for doc, infra and code`, - ), - ).toEqual({ - action: 'add', - contributors: { - jakebolam: ['doc', 'infra', 'code'], - }, - }) - }) + test("Basic intent to add", () => { + expect( + parseComment( + `@${testBotName} please add jakebolam for doc, infra and code` + ) + ).toEqual({ + action: "add", + contributors: { + jakebolam: ["doc", "infra", "code"], + }, + }); + }); - test('Basic intent to add - ignore case (for action and contributions, NOT for user)', () => { - expect( - parseComment( - `@${testBotName} please Add jakeBolam for DOC, inFra and coDe`, - ), - ).toEqual({ - action: 'add', - contributors: { - jakeBolam: ['doc', 'infra', 'code'], - }, - }) - }) + test("Basic intent to add - ignore case (for action and contributions, NOT for user)", () => { + expect( + parseComment( + `@${testBotName} please Add jakeBolam for DOC, inFra and coDe` + ) + ).toEqual({ + action: "add", + contributors: { + jakeBolam: ["doc", "infra", "code"], + }, + }); + }); - test('Basic intent to add - non name username', () => { - expect( - parseComment(`@${testBotName} please add tbenning for design`), - ).toEqual({ - action: 'add', - contributors: { - tbenning: ['design'], - }, - }) - }) + test("Basic intent to add - non name username", () => { + expect( + parseComment(`@${testBotName} please add tbenning for design`) + ).toEqual({ + action: "add", + contributors: { + tbenning: ["design"], + }, + }); + }); - test('Basic intent to add - captialized username', () => { - expect( - parseComment(`@${testBotName} please add Rbot25_RULES for tool`), - ).toEqual({ - action: 'add', - contributors: { - Rbot25_RULES: ['tool'], - }, - }) - }) + test("Basic intent to add - captialized username", () => { + expect( + parseComment(`@${testBotName} please add Rbot25_RULES for tool`) + ).toEqual({ + action: "add", + contributors: { + Rbot25_RULES: ["tool"], + }, + }); + }); - test('Basic intent to add - username with dash', () => { - expect( - parseComment(`@${testBotName} please add tenshi-AMD for tool`), - ).toEqual({ - action: 'add', - contributors: { - "tenshi-AMD": ['tool'], - }, - }) - }) + test("Basic intent to add - username with dash", () => { + expect( + parseComment(`@${testBotName} please add tenshi-AMD for tool`) + ).toEqual({ + action: "add", + contributors: { + "tenshi-AMD": ["tool"], + }, + }); + }); - test('Basic intent to add - with plurals', () => { - expect( - parseComment(`@${testBotName} please add dat2 for docs`), - ).toEqual({ - action: 'add', - contributors: { - dat2: ['doc'], - }, - }) - }) + test("Basic intent to add - username with dash", () => { + expect( + parseComment(`@${testBotName} Please add @Otto-J for doc, `) + ).toEqual({ + action: "add", + contributors: { + "Otto-J": ["doc"], + }, + }); + }); - test('Add multiple when not spaced (just split via commas)', () => { - expect( - parseComment( - `@${testBotName} please add @stevoo24 for code,content`, - ), - ).toEqual({ - action: 'add', - contributors: { - stevoo24: ['code', 'content'], - }, - }) - }) + test("Basic intent to add - username with dash", () => { + expect( + parseComment( + `@${testBotName} please add @Dev-Soumyaranjan for infrastructure, tests and code ,` + ) + ).toEqual({ + action: "add", + contributors: { + "Dev-Soumyaranjan": ["infra", "test", "code"], + }, + }); + }); + + test("Basic intent to add - with plurals", () => { + expect(parseComment(`@${testBotName} please add dat2 for docs`)).toEqual({ + action: "add", + contributors: { + dat2: ["doc"], + }, + }); + }); + + test("Add multiple when not spaced (just split via commas)", () => { + expect( + parseComment(`@${testBotName} please add @stevoo24 for code,content`) + ).toEqual({ + action: "add", + contributors: { + stevoo24: ["code", "content"], + }, + }); + }); test(`Interpret users who's names are contributions`, () => { - expect( - parseComment(`@${testBotName} please add @ideas for ideas`), - ).toEqual({ - action: 'add', - contributors: { - ideas: ['ideas'], - }, - }) - }) + expect(parseComment(`@${testBotName} please add @ideas for ideas`)).toEqual( + { + action: "add", + contributors: { + ideas: ["ideas"], + }, + } + ); + }); - test('Support full words (like infrastructure)', () => { - expect( - parseComment( - `@${testBotName} please add jakebolam for infrastructure, documentation`, - ), - ).toEqual({ - action: 'add', - contributors: { - jakebolam: ['infra', 'doc'], - }, - }) - }) + test("Support full words (like infrastructure)", () => { + expect( + parseComment( + `@${testBotName} please add jakebolam for infrastructure, documentation` + ) + ).toEqual({ + action: "add", + contributors: { + jakebolam: ["infra", "doc"], + }, + }); + }); - test('Support adding people with mentions', () => { - expect( - parseComment( - `@${testBotName} please add @sinchang for infrastructure`, - ), - ).toEqual({ - action: 'add', - contributors: { - sinchang: ['infra'], - }, - }) - }) + test("Support adding people with mentions", () => { + expect( + parseComment(`@${testBotName} please add @sinchang for infrastructure`) + ).toEqual({ + action: "add", + contributors: { + sinchang: ["infra"], + }, + }); + }); - test('Support alternative sentences', () => { - expect( - parseComment(`@${testBotName} add @sinchang for infrastructure`), - ).toEqual({ - action: 'add', - contributors: { - sinchang: ['infra'], - }, - }) + test("Support alternative sentences", () => { + expect( + parseComment(`@${testBotName} add @sinchang for infrastructure`) + ).toEqual({ + action: "add", + contributors: { + sinchang: ["infra"], + }, + }); - expect( - parseComment( - `Jane you are crushing it in documentation and your infrastructure work has been great too, let's add jane.doe23 for her contributions. cc @${testBotName}`, - ), - ).toEqual({ - action: 'add', - contributors: { - 'jane.doe23': ['doc', 'infra'], - }, - }) - }) + expect( + parseComment( + `Jane you are crushing it in documentation and your infrastructure work has been great too, let's add jane.doe23 for her contributions. cc @${testBotName}` + ) + ).toEqual({ + action: "add", + contributors: { + "jane.doe23": ["doc", "infra"], + }, + }); + }); - test('Support split words (like user testing)', () => { - expect( - parseComment( - `@${testBotName} please add jakebolam for infrastructure, fund finding`, - ), - ).toEqual({ - action: 'add', - contributors: { - jakebolam: ['infra', 'fundingFinding'], - }, - }) + test("Support split words (like user testing)", () => { + expect( + parseComment( + `@${testBotName} please add jakebolam for infrastructure, fund finding` + ) + ).toEqual({ + action: "add", + contributors: { + jakebolam: ["infra", "fundingFinding"], + }, + }); - expect( - parseComment( - `@${testBotName} please add jakebolam for infrastructure, user testing and testing`, - ), - ).toEqual({ - action: 'add', - contributors: { - jakebolam: ['infra', 'userTesting', 'test'], - }, - }) - }) + expect( + parseComment( + `@${testBotName} please add jakebolam for infrastructure, user testing and testing` + ) + ).toEqual({ + action: "add", + contributors: { + jakebolam: ["infra", "userTesting", "test"], + }, + }); + }); - test('Support split words types that are referenced via other terms (e.g. a plural split word)', () => { - expect( - parseComment( - `@${testBotName} please add @jakebolam for infrastructure, funds`, - ), - ).toEqual({ - action: 'add', - contributors: { - jakebolam: ['infra', 'fundingFinding'], - }, - }) - }) + test("Support split words types that are referenced via other terms (e.g. a plural split word)", () => { + expect( + parseComment( + `@${testBotName} please add @jakebolam for infrastructure, funds` + ) + ).toEqual({ + action: "add", + contributors: { + jakebolam: ["infra", "fundingFinding"], + }, + }); + }); // TODO: Looks like this is impossible to parse correctly, maybe we can change the format instead // test('Add multiple users in 1 hit - for some contributions', () => { @@ -197,62 +215,83 @@ describe('parseComment', () => { // }) // }) - test('Add multiple users in 1 hit - seperate sentences', () => { - expect( - parseComment( - `@${testBotName} add @kazydek for doc, review, maintenance. Please add akucharska for code, design. Please add derberg for infra and ideas`, - ), - ).toEqual({ - action: 'add', - contributors: { - kazydek: ['doc', 'review', 'maintenance'], - akucharska: ['code', 'design'], - derberg: ['infra', 'ideas'], - }, - }) - }) + test("Add multiple users in 1 hit - seperate sentences", () => { + expect( + parseComment( + `@${testBotName} add @kazydek for doc, review, maintenance. Please add akucharska for code, design. Please add derberg for infra and ideas` + ) + ).toEqual({ + action: "add", + contributors: { + kazydek: ["doc", "review", "maintenance"], + akucharska: ["code", "design"], + derberg: ["infra", "ideas"], + }, + }); + }); - // TODO: Looks like this is gramatically incorrect - // test('Add multiple users in 1 hit - sentences seperated by commas :think:', () => { - // expect( - // parseComment( - // `@${testBotName} please add kazydek for doc, review, maintenance, please add akucharska for code, maintenance and please add derberg for doc, ideas`, - // ), - // ).toEqual({ - // action: 'add', - // contributors: { - // kazydek: ['doc', 'review', 'maintenance'], - // akucharska: ['code', 'maintenance'], - // derberg: ['doc', 'ideas'] - // }, - // }) - // }) + // TODO: Looks like this one is gramatically incorrect + // test("Add multiple users in 1 hit - sentences seperated by commas :think:", () => { + // expect( + // parseComment( + // `@${testBotName} please add kazydek for doc, review, maintenance, please add akucharska for code, maintenance and please add derberg for doc, ideas` + // ) + // ).toEqual({ + // action: "add", + // contributors: { + // kazydek: ["doc", "review", "maintenance"], + // akucharska: ["code", "maintenance"], + // derberg: ["doc", "ideas"], + // }, + // }); + // }); + + test("Add multiple users in 1 hit - from seperate lines", () => { + expect( + parseComment( + ` + @all-contributors + please add @mikeattara for ideas, infra and design + please add @The24thDS for infra and review + please add @tbenning for code + ` + ) + ).toEqual({ + action: "add", + contributors: { + mikeattara: ["ideas", "infra", "design"], + The24thDS: ["infra", "review"], + tbenning: ["code"], + }, + }); + }); + + test("Add multiple users in 1 hit - from seperate lines with complex text at the beginning", () => { + expect( + parseComment( + ` + Thank you for pointing this out! I've linked to available videos for now, although any PR or issue proposing alternatives will of course be welcome. + + @all-contributors please add @lksmrqrdt for bug + ` + ) + ).toEqual({ + action: "add", + contributors: { + lksmrqrdt: ["bug"], + }, + }); + }); - test('Add multiple users in 1 hit - from seperate lines', () => { - expect( - parseComment( - ` - @all-contributors - please add @mikeattara for ideas, infra and design - please add @The24thDS for infra and review - please add @tbenning for code - ` - ), - ).toEqual({ - action: 'add', - contributors: { - mikeattara: ['ideas', 'infra', 'design'], - The24thDS: ['infra', 'review'], - tbenning: ['code'] - }, - }) - }) + test("Intent unknown", () => { + expect(parseComment(`@${testBotName} please lollmate for tool`)).toEqual({ + action: false, + }); + }); - test('Intent unknown', () => { - expect( - parseComment(`@${testBotName} please lollmate for tool`), - ).toEqual({ - action: false, - }) - }) -}) + test("Intent unknown - incomplete `add` action", () => { + expect(parseComment(`@${testBotName} add`)).toEqual({ + action: false, + }); + }); +});