From 3088103c3506b71b5f7649ca2d02d67e9b70b196 Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Fri, 10 Feb 2023 17:08:00 -0800 Subject: [PATCH 1/7] chore: add unit test for getChildren --- tests/unit/parser.test.ts | 87 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 tests/unit/parser.test.ts diff --git a/tests/unit/parser.test.ts b/tests/unit/parser.test.ts new file mode 100644 index 00000000..1f6cb11d --- /dev/null +++ b/tests/unit/parser.test.ts @@ -0,0 +1,87 @@ +import { getChildren } from '../../lib/parser'; + +/** + * Test data obtained from calling getIssue() on github.com/protocol/engres/issues/5 on 2023-02-10 @ 5pm PST + */ +const example_body_html = '
children:
\neta: 2023Q2
\nView in https://www.starmaps.app/roadmap/github.com/protocol/engres/issues/5#simple
' +const example_body_text = 'children:\n\nprotocol/bedrock#5\nprotocol/bedrock#11\nfilecoin-project/ref-fvm#1144\nfilecoin-project/ref-fvm#1143\nprotocol/netops#34\nprotocol/netops#47\ndrand/roadmap#8\ndrand/roadmap#12\nprotocol/ConsensusLab#180\nprotocol/ConsensusLab#185\nprotocol/ConsensusLab#186\nfilecoin-station/roadmap#3\nfilecoin-station/roadmap#10\nfilecoin-saturn/roadmap#1\nfilecoin-station/roadmap#4\nfilecoin-saturn/roadmap#2\ncryptonetlab/roadmap#19\n\neta: 2023Q2\nView in https://www.starmaps.app/roadmap/github.com/protocol/engres/issues/5#simple' + +describe('parser', function() { + describe('getChildren', function() { + it('Can parse children from body_html', function() { + const children = getChildren(example_body_html); + expect(Array.isArray(children)).toBe(true); + expect(children).toHaveLength(17); + expect(children).toStrictEqual([ + { + group: 'children:', + html_url: 'https://github.com/protocol/bedrock/issues/5' + }, + { + "group": "children:", + "html_url": "https://github.com/protocol/bedrock/issues/11", + }, + { + "group": "children:", + "html_url": "https://github.com/filecoin-project/ref-fvm/issues/1144", + }, + { + "group": "children:", + "html_url": "https://github.com/filecoin-project/ref-fvm/issues/1143", + }, + { + "group": "children:", + "html_url": "https://github.com/protocol/netops/issues/34", + }, + { + "group": "children:", + "html_url": "https://github.com/protocol/netops/issues/47", + }, + { + "group": "children:", + "html_url": "https://github.com/drand/roadmap/issues/8", + }, + { + "group": "children:", + "html_url": "https://github.com/drand/roadmap/issues/12", + }, + { + "group": "children:", + "html_url": "https://github.com/protocol/ConsensusLab/issues/180", + }, + { + "group": "children:", + "html_url": "https://github.com/protocol/ConsensusLab/issues/185", + }, + { + "group": "children:", + "html_url": "https://github.com/protocol/ConsensusLab/issues/186", + }, + { + "group": "children:", + "html_url": "https://github.com/filecoin-station/roadmap/issues/3", + }, + { + "group": "children:", + "html_url": "https://github.com/filecoin-station/roadmap/issues/10", + }, + { + "group": "children:", + "html_url": "https://github.com/filecoin-saturn/roadmap/issues/1", + }, + { + "group": "children:", + "html_url": "https://github.com/filecoin-station/roadmap/issues/4", + }, + { + "group": "children:", + "html_url": "https://github.com/filecoin-saturn/roadmap/issues/2", + }, + { + "group": "children:", + "html_url": "https://github.com/cryptonetlab/roadmap/issues/19", + }, + ]) + }) + }) +}) From b075a90e524aa600571d8446907d316de40ebbd6 Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Fri, 10 Feb 2023 17:48:31 -0800 Subject: [PATCH 2/7] chore: support parsing issue body_text --- lib/parser.ts | 57 ++++++++++++++- tests/unit/parser.test.ts | 150 ++++++++++++++++++++------------------ 2 files changed, 134 insertions(+), 73 deletions(-) diff --git a/lib/parser.ts b/lib/parser.ts index 8bda8390..e9a829b1 100644 --- a/lib/parser.ts +++ b/lib/parser.ts @@ -1,5 +1,6 @@ import { parseHTML } from 'linkedom'; import { ErrorManager } from './backend/errorManager'; +import { getValidUrlFromInput } from './getValidUrlFromInput'; import { getEtaDate, isValidChildren } from './helpers'; import { GithubIssueDataWithChildren, ParserGetChildrenResponse } from './types'; @@ -27,8 +28,60 @@ export const getDueDate = (issue: Pickchildren:
\neta: 2023Q2
\nView in https://www.starmaps.app/roadmap/github.com/protocol/engres/issues/5#simple
' const example_body_text = 'children:\n\nprotocol/bedrock#5\nprotocol/bedrock#11\nfilecoin-project/ref-fvm#1144\nfilecoin-project/ref-fvm#1143\nprotocol/netops#34\nprotocol/netops#47\ndrand/roadmap#8\ndrand/roadmap#12\nprotocol/ConsensusLab#180\nprotocol/ConsensusLab#185\nprotocol/ConsensusLab#186\nfilecoin-station/roadmap#3\nfilecoin-station/roadmap#10\nfilecoin-saturn/roadmap#1\nfilecoin-station/roadmap#4\nfilecoin-saturn/roadmap#2\ncryptonetlab/roadmap#19\n\neta: 2023Q2\nView in https://www.starmaps.app/roadmap/github.com/protocol/engres/issues/5#simple' +const expectedResult = [ + { + group: 'children:', + html_url: 'https://github.com/protocol/bedrock/issues/5' + }, + { + "group": "children:", + "html_url": "https://github.com/protocol/bedrock/issues/11", + }, + { + "group": "children:", + "html_url": "https://github.com/filecoin-project/ref-fvm/issues/1144", + }, + { + "group": "children:", + "html_url": "https://github.com/filecoin-project/ref-fvm/issues/1143", + }, + { + "group": "children:", + "html_url": "https://github.com/protocol/netops/issues/34", + }, + { + "group": "children:", + "html_url": "https://github.com/protocol/netops/issues/47", + }, + { + "group": "children:", + "html_url": "https://github.com/drand/roadmap/issues/8", + }, + { + "group": "children:", + "html_url": "https://github.com/drand/roadmap/issues/12", + }, + { + "group": "children:", + "html_url": "https://github.com/protocol/ConsensusLab/issues/180", + }, + { + "group": "children:", + "html_url": "https://github.com/protocol/ConsensusLab/issues/185", + }, + { + "group": "children:", + "html_url": "https://github.com/protocol/ConsensusLab/issues/186", + }, + { + "group": "children:", + "html_url": "https://github.com/filecoin-station/roadmap/issues/3", + }, + { + "group": "children:", + "html_url": "https://github.com/filecoin-station/roadmap/issues/10", + }, + { + "group": "children:", + "html_url": "https://github.com/filecoin-saturn/roadmap/issues/1", + }, + { + "group": "children:", + "html_url": "https://github.com/filecoin-station/roadmap/issues/4", + }, + { + "group": "children:", + "html_url": "https://github.com/filecoin-saturn/roadmap/issues/2", + }, + { + "group": "children:", + "html_url": "https://github.com/cryptonetlab/roadmap/issues/19", + }, +] + describe('parser', function() { describe('getChildren', function() { it('Can parse children from body_html', function() { const children = getChildren(example_body_html); expect(Array.isArray(children)).toBe(true); expect(children).toHaveLength(17); - expect(children).toStrictEqual([ - { - group: 'children:', - html_url: 'https://github.com/protocol/bedrock/issues/5' - }, - { - "group": "children:", - "html_url": "https://github.com/protocol/bedrock/issues/11", - }, - { - "group": "children:", - "html_url": "https://github.com/filecoin-project/ref-fvm/issues/1144", - }, - { - "group": "children:", - "html_url": "https://github.com/filecoin-project/ref-fvm/issues/1143", - }, - { - "group": "children:", - "html_url": "https://github.com/protocol/netops/issues/34", - }, - { - "group": "children:", - "html_url": "https://github.com/protocol/netops/issues/47", - }, - { - "group": "children:", - "html_url": "https://github.com/drand/roadmap/issues/8", - }, - { - "group": "children:", - "html_url": "https://github.com/drand/roadmap/issues/12", - }, - { - "group": "children:", - "html_url": "https://github.com/protocol/ConsensusLab/issues/180", - }, - { - "group": "children:", - "html_url": "https://github.com/protocol/ConsensusLab/issues/185", - }, - { - "group": "children:", - "html_url": "https://github.com/protocol/ConsensusLab/issues/186", - }, - { - "group": "children:", - "html_url": "https://github.com/filecoin-station/roadmap/issues/3", - }, - { - "group": "children:", - "html_url": "https://github.com/filecoin-station/roadmap/issues/10", - }, - { - "group": "children:", - "html_url": "https://github.com/filecoin-saturn/roadmap/issues/1", - }, - { - "group": "children:", - "html_url": "https://github.com/filecoin-station/roadmap/issues/4", - }, - { - "group": "children:", - "html_url": "https://github.com/filecoin-saturn/roadmap/issues/2", - }, - { - "group": "children:", - "html_url": "https://github.com/cryptonetlab/roadmap/issues/19", - }, - ]) + expect(children).toStrictEqual(expectedResult) + }) + it('Can parse children from body_text', function() { + const children = getChildren(example_body_text); + expect(Array.isArray(children)).toBe(true); + expect(children).toHaveLength(17); + expect(children).toStrictEqual(expectedResult) }) }) }) From 18736b630fe5229cd9dca162e7afa80aecf8330e Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Fri, 10 Feb 2023 18:47:07 -0800 Subject: [PATCH 3/7] feat: support reading children from tasklists --- .../getGithubIssueDataWithGroupAndChildren.ts | 2 +- lib/backend/issue.ts | 1 + lib/parser.ts | 60 +++++++-- lib/types.d.ts | 1 + pages/api/roadmap.ts | 2 +- tests/unit/parser.test.ts | 115 ++++++++++++------ 6 files changed, 132 insertions(+), 49 deletions(-) diff --git a/lib/backend/getGithubIssueDataWithGroupAndChildren.ts b/lib/backend/getGithubIssueDataWithGroupAndChildren.ts index d9dfe4e0..b0a76788 100644 --- a/lib/backend/getGithubIssueDataWithGroupAndChildren.ts +++ b/lib/backend/getGithubIssueDataWithGroupAndChildren.ts @@ -5,7 +5,7 @@ import { resolveChildren } from './resolveChildren'; import { resolveChildrenWithDepth } from './resolveChildrenWithDepth'; export async function getGithubIssueDataWithGroupAndChildren (issueData: GithubIssueDataWithGroup, errorManager: ErrorManager, usePendingChildren = false): Promisechildren:
\neta: 2023Q2
\nView in https://www.starmaps.app/roadmap/github.com/protocol/engres/issues/5#simple
' const example_body_text = 'children:\n\nprotocol/bedrock#5\nprotocol/bedrock#11\nfilecoin-project/ref-fvm#1144\nfilecoin-project/ref-fvm#1143\nprotocol/netops#34\nprotocol/netops#47\ndrand/roadmap#8\ndrand/roadmap#12\nprotocol/ConsensusLab#180\nprotocol/ConsensusLab#185\nprotocol/ConsensusLab#186\nfilecoin-station/roadmap#3\nfilecoin-station/roadmap#10\nfilecoin-saturn/roadmap#1\nfilecoin-station/roadmap#4\nfilecoin-saturn/roadmap#2\ncryptonetlab/roadmap#19\n\neta: 2023Q2\nView in https://www.starmaps.app/roadmap/github.com/protocol/engres/issues/5#simple' +const example_body = 'children: \r\n- https://github.com/protocol/bedrock/issues/5\r\n- https://github.com/protocol/bedrock/issues/11\r\n- https://github.com/filecoin-project/ref-fvm/issues/1144\r\n- https://github.com/filecoin-project/ref-fvm/issues/1143\r\n- https://github.com/protocol/netops/issues/34\r\n- https://github.com/protocol/netops/issues/47\r\n- https://github.com/drand/roadmap/issues/8\r\n- https://github.com/drand/roadmap/issues/12\r\n- https://github.com/protocol/ConsensusLab/issues/180\r\n- https://github.com/protocol/ConsensusLab/issues/185\r\n- https://github.com/protocol/ConsensusLab/issues/186\r\n- https://github.com/filecoin-station/roadmap/issues/3\r\n- https://github.com/filecoin-station/roadmap/issues/10\r\n- https://github.com/filecoin-saturn/roadmap/issues/1\r\n- https://github.com/filecoin-station/roadmap/issues/4\r\n- https://github.com/filecoin-saturn/roadmap/issues/2\r\n- https://github.com/cryptonetlab/roadmap/issues/19\r\n\r\neta: 2023Q2\r\n\r\nView in https://www.starmaps.app/roadmap/github.com/protocol/engres/issues/5#simple\r\n' + +/** + * Test data obtained from calling getIssue() on github.com/ipfs/ipfs-gui/issues/106 on 2023-02-10 @ 5:52pm PST + */ +const example_tasklist_body = 'eta: 2023Q4\r\n\r\nchildren:\r\n- [ ] #121\r\n- [ ] #122\r\n- [ ] #123\r\n- [ ] #124\r\n\r\n```[tasklist]\r\n### Tasks\r\n- [ ] #121\r\n- [ ] #122\r\n- [ ] #123\r\n- [ ] #124\r\n```\r\n' + +/** + * Test data manually removing "children:" from the above example_tasklist_body + */ +const example_tasklist_body_only = 'eta: 2023Q4\r\n\r\n```[tasklist]\r\n### Tasks\r\n- [ ] #121\r\n- [ ] #122\r\n- [ ] #123\r\n- [ ] #124\r\n```\r\n' const expectedResult = [ { @@ -12,84 +23,114 @@ const expectedResult = [ html_url: 'https://github.com/protocol/bedrock/issues/5' }, { - "group": "children:", - "html_url": "https://github.com/protocol/bedrock/issues/11", + group: 'children:', + html_url: 'https://github.com/protocol/bedrock/issues/11', }, { - "group": "children:", - "html_url": "https://github.com/filecoin-project/ref-fvm/issues/1144", + group: 'children:', + html_url: 'https://github.com/filecoin-project/ref-fvm/issues/1144', }, { - "group": "children:", - "html_url": "https://github.com/filecoin-project/ref-fvm/issues/1143", + group: 'children:', + html_url: 'https://github.com/filecoin-project/ref-fvm/issues/1143', }, { - "group": "children:", - "html_url": "https://github.com/protocol/netops/issues/34", + group: 'children:', + html_url: 'https://github.com/protocol/netops/issues/34', }, { - "group": "children:", - "html_url": "https://github.com/protocol/netops/issues/47", + group: 'children:', + html_url: 'https://github.com/protocol/netops/issues/47', }, { - "group": "children:", - "html_url": "https://github.com/drand/roadmap/issues/8", + group: 'children:', + html_url: 'https://github.com/drand/roadmap/issues/8', }, { - "group": "children:", - "html_url": "https://github.com/drand/roadmap/issues/12", + group: 'children:', + html_url: 'https://github.com/drand/roadmap/issues/12', }, { - "group": "children:", - "html_url": "https://github.com/protocol/ConsensusLab/issues/180", + group: 'children:', + html_url: 'https://github.com/protocol/ConsensusLab/issues/180', }, { - "group": "children:", - "html_url": "https://github.com/protocol/ConsensusLab/issues/185", + group: 'children:', + html_url: 'https://github.com/protocol/ConsensusLab/issues/185', }, { - "group": "children:", - "html_url": "https://github.com/protocol/ConsensusLab/issues/186", + group: 'children:', + html_url: 'https://github.com/protocol/ConsensusLab/issues/186', }, { - "group": "children:", - "html_url": "https://github.com/filecoin-station/roadmap/issues/3", + group: 'children:', + html_url: 'https://github.com/filecoin-station/roadmap/issues/3', }, { - "group": "children:", - "html_url": "https://github.com/filecoin-station/roadmap/issues/10", + group: 'children:', + html_url: 'https://github.com/filecoin-station/roadmap/issues/10', }, { - "group": "children:", - "html_url": "https://github.com/filecoin-saturn/roadmap/issues/1", + group: 'children:', + html_url: 'https://github.com/filecoin-saturn/roadmap/issues/1', }, { - "group": "children:", - "html_url": "https://github.com/filecoin-station/roadmap/issues/4", + group: 'children:', + html_url: 'https://github.com/filecoin-station/roadmap/issues/4', }, { - "group": "children:", - "html_url": "https://github.com/filecoin-saturn/roadmap/issues/2", + group: 'children:', + html_url: 'https://github.com/filecoin-saturn/roadmap/issues/2', }, { - "group": "children:", - "html_url": "https://github.com/cryptonetlab/roadmap/issues/19", + group: 'children:', + html_url: 'https://github.com/cryptonetlab/roadmap/issues/19', }, ] describe('parser', function() { describe('getChildren', function() { - it('Can parse children from body_html', function() { - const children = getChildren(example_body_html); + it('Can parse children from issue.body_html', function() { + const children = getChildren({ body_html: example_body_html, body: '', html_url: '' }); + expect(Array.isArray(children)).toBe(true); + expect(children).toHaveLength(17); + expect(children).toStrictEqual(expectedResult) + }) + it('Can parse children from issue.body_text', function() { + const children = getChildren({ body_html: '', body: example_body_text, html_url: '' }); expect(Array.isArray(children)).toBe(true); expect(children).toHaveLength(17); expect(children).toStrictEqual(expectedResult) }) - it('Can parse children from body_text', function() { - const children = getChildren(example_body_text); + it('Can parse children from issue.body', function() { + const children = getChildren({ body_html: '', body: example_body, html_url: '' }); expect(Array.isArray(children)).toBe(true); expect(children).toHaveLength(17); expect(children).toStrictEqual(expectedResult) }) + + it('Can parse tasklist children from body that also has children:', function() { + const children = getChildren({ body_html: '', body: example_tasklist_body, html_url: 'https://github.com/ipfs/ipfs-gui/issues/106' }); + expect(Array.isArray(children)).toBe(true); + expect(children).toHaveLength(4); + expect(children).toStrictEqual([ + { group: 'tasklist', html_url: 'https://github.com/ipfs/ipfs-gui/issues/121' }, + { group: 'tasklist', html_url: 'https://github.com/ipfs/ipfs-gui/issues/122' }, + { group: 'tasklist', html_url: 'https://github.com/ipfs/ipfs-gui/issues/123' }, + { group: 'tasklist', html_url: 'https://github.com/ipfs/ipfs-gui/issues/124' } + ]) + }) + + it('Can parse tasklist children from body', function() { + const children = getChildren({ body_html: '', body: example_tasklist_body_only, html_url: 'https://github.com/ipfs/ipfs-gui/issues/106' }); + expect(Array.isArray(children)).toBe(true); + expect(children).toHaveLength(4); + expect(children).toStrictEqual([ + { group: 'tasklist', html_url: 'https://github.com/ipfs/ipfs-gui/issues/121' }, + { group: 'tasklist', html_url: 'https://github.com/ipfs/ipfs-gui/issues/122' }, + { group: 'tasklist', html_url: 'https://github.com/ipfs/ipfs-gui/issues/123' }, + { group: 'tasklist', html_url: 'https://github.com/ipfs/ipfs-gui/issues/124' } + ]) + }) }) }) From b9e04dc19a9f4bb66195934f0cfb33a67848c88b Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Fri, 10 Feb 2023 18:55:58 -0800 Subject: [PATCH 4/7] fix: parsing children: with only #123 identifier --- lib/parser.ts | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/parser.ts b/lib/parser.ts index 199498f8..af3f133b 100644 --- a/lib/parser.ts +++ b/lib/parser.ts @@ -38,6 +38,13 @@ function getSectionLines(text: string, sectionHeader: string) { return lines; } +function getUrlStringForChildrenLine(line: string, issue: Pick