From feb97bb17a9561910a3a55311ee23f04f0597c34 Mon Sep 17 00:00:00 2001 From: Bill Ryan Date: Thu, 23 Sep 2021 14:29:56 -0400 Subject: [PATCH 01/13] Feat: Specify a Target GitHub Repository --- index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 1e6a95b..68bf9d6 100644 --- a/index.js +++ b/index.js @@ -7,6 +7,11 @@ function getRequiredInputValue(key) { return core.getInput(key, { required: true }); } +function getOptionalInputValue(key) { + return core.getInput(key, { required: false }); +} + + async function run() { try { const issueId = getRequiredInputValue('issue_id') @@ -14,13 +19,14 @@ async function run() { , parserSeparator = getRequiredInputValue('separator') , parserMarkerStart = getRequiredInputValue('label_marker_start') , parserMarkerEnd = getRequiredInputValue('label_marker_end') + , repository = getOptionalInputValue('repository') ; const issueUtil = new IssueUtil(githubToken) , parser = new Parser(parserSeparator, parserMarkerStart, parserMarkerEnd) ; - const issueBody = await issueUtil.getIssueBody(issueId); + const issueBody = await issueUtil.getIssueBody(issueId, repository); const parsed = parser.parse(issueBody); if (parsed !== undefined) { From 64ceb2455bad82b5efa2014fdf6207b1f53ac49b Mon Sep 17 00:00:00 2001 From: Bill Ryan Date: Thu, 23 Sep 2021 14:35:31 -0400 Subject: [PATCH 02/13] update readme.md with optional repository param --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 1ee53d7..38b0975 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ octodemo/template-demo-github-user-search | --------------------------| -------- | ------------------------------- | | `github_token` | `true` | PAT(Personal Access Token) for accessing the issues on the repository, defaults to `${{ github.token }}`. | | `issue_id` | `true` | The id of the issue to load the content from.| +| `repository` | `false` | The repository where the issue lives. Defaults to the current repository.| | `separator` | `false` | The separator between the fields defaults to `###` which is markdown h3 which GitHub is currently defaulting to | | `label_marker_start` | `true` | The characters to match for the beginning of a label | | `label_marker_end` | `true` | The characters to match for the ending of a label | @@ -48,6 +49,7 @@ steps: uses: peter-murray/issue-forms-body-parser@v1.1.0 with: issue_id: ${{ github.event.issue.number }} + repository: octokit/rest.js separator: '###' label_marker_start: '>>' label_marker_end: '<<' From a2aae2b4ec4f9e39ababf9c5114dbf5e245b7fdb Mon Sep 17 00:00:00 2001 From: Bill Ryan Date: Thu, 23 Sep 2021 14:54:40 -0400 Subject: [PATCH 03/13] optionally include owner & repo --- src/IssueUtil.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/IssueUtil.js b/src/IssueUtil.js index c2dff90..c2a0872 100644 --- a/src/IssueUtil.js +++ b/src/IssueUtil.js @@ -9,9 +9,13 @@ module.exports = class IssueUtil { this.octokit = github.getOctokit(token); } - getIssueBody(id) { + getIssueBody(id, repository = null) { + var target_repo = repository ? + {owner: repository.split('/')[0], repo: repository.split('/')[1]} : + {...github.context.repo}; + return this.octokit.issues.get({ - ...github.context.repo, + ...target_repo, issue_number: id }).then(result => { if (result.status !== 200) { @@ -22,4 +26,4 @@ module.exports = class IssueUtil { throw err; }); } -} \ No newline at end of file +} From 659eb2c1b44efdbae04268844802f59924590396 Mon Sep 17 00:00:00 2001 From: Bill Ryan Date: Thu, 23 Sep 2021 15:48:56 -0400 Subject: [PATCH 04/13] clean up param parsing for readability --- src/IssueUtil.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/IssueUtil.js b/src/IssueUtil.js index c2a0872..ab8e3ab 100644 --- a/src/IssueUtil.js +++ b/src/IssueUtil.js @@ -9,10 +9,9 @@ module.exports = class IssueUtil { this.octokit = github.getOctokit(token); } - getIssueBody(id, repository = null) { - var target_repo = repository ? - {owner: repository.split('/')[0], repo: repository.split('/')[1]} : - {...github.context.repo}; + getIssueBody(id, repository) { + const [owner, repo] = repository.split('/'); + const target_repo = repository ? {owner, repo} : github.context.repo; return this.octokit.issues.get({ ...target_repo, From 6d2aab2f4c358a2db298403f07218efc091f53dc Mon Sep 17 00:00:00 2001 From: omgitsbillryan Date: Fri, 24 Sep 2021 14:51:20 -0400 Subject: [PATCH 05/13] debug logging --- src/IssueUtil.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/IssueUtil.js b/src/IssueUtil.js index ab8e3ab..7867c41 100644 --- a/src/IssueUtil.js +++ b/src/IssueUtil.js @@ -10,16 +10,20 @@ module.exports = class IssueUtil { } getIssueBody(id, repository) { + console.log(repository) const [owner, repo] = repository.split('/'); const target_repo = repository ? {owner, repo} : github.context.repo; - + console.log('about to start') + console.log(target_repo) return this.octokit.issues.get({ ...target_repo, issue_number: id }).then(result => { + console.log(result.status) if (result.status !== 200) { throw new Error(`Unexpected status code from retrieving issue: ${result.status}`); } + console.log(result.data.body) return result.data.body; }).catch(err => { throw err; From 260a6f5d952f35b9365d68d3a398e706e5d8d39e Mon Sep 17 00:00:00 2001 From: omgitsbillryan Date: Fri, 24 Sep 2021 15:05:34 -0400 Subject: [PATCH 06/13] 2nd attempt at debug logging --- index.js | 12 ++++++------ src/IssueUtil.js | 6 ++---- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 68bf9d6..568a322 100644 --- a/index.js +++ b/index.js @@ -14,12 +14,12 @@ function getOptionalInputValue(key) { async function run() { try { - const issueId = getRequiredInputValue('issue_id') - , githubToken = getRequiredInputValue('github_token') - , parserSeparator = getRequiredInputValue('separator') - , parserMarkerStart = getRequiredInputValue('label_marker_start') - , parserMarkerEnd = getRequiredInputValue('label_marker_end') - , repository = getOptionalInputValue('repository') + const issueId = '42'// getRequiredInputValue('issue_id') + , githubToken = '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' // getRequiredInputValue('github_token') + , parserSeparator = '###'// getRequiredInputValue('separator') + , parserMarkerStart = '>>'// getRequiredInputValue('label_marker_start') + , parserMarkerEnd = '>>'// getRequiredInputValue('label_marker_end') + , repository = "bill-test-org/t-lint"// getOptionalInputValue('repository') ; const issueUtil = new IssueUtil(githubToken) diff --git a/src/IssueUtil.js b/src/IssueUtil.js index 7867c41..433da2c 100644 --- a/src/IssueUtil.js +++ b/src/IssueUtil.js @@ -10,11 +10,9 @@ module.exports = class IssueUtil { } getIssueBody(id, repository) { - console.log(repository) const [owner, repo] = repository.split('/'); const target_repo = repository ? {owner, repo} : github.context.repo; - console.log('about to start') - console.log(target_repo) + return this.octokit.issues.get({ ...target_repo, issue_number: id @@ -26,7 +24,7 @@ module.exports = class IssueUtil { console.log(result.data.body) return result.data.body; }).catch(err => { - throw err; + throw new Error(`Repository... owner=${owner}, repo=${repo}`); }); } } From 1ebaad3463b541a8ce72858d702c4eaa889e738d Mon Sep 17 00:00:00 2001 From: omgitsbillryan Date: Fri, 24 Sep 2021 15:07:58 -0400 Subject: [PATCH 07/13] woops, deleted that PAT --- index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 568a322..68bf9d6 100644 --- a/index.js +++ b/index.js @@ -14,12 +14,12 @@ function getOptionalInputValue(key) { async function run() { try { - const issueId = '42'// getRequiredInputValue('issue_id') - , githubToken = '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' // getRequiredInputValue('github_token') - , parserSeparator = '###'// getRequiredInputValue('separator') - , parserMarkerStart = '>>'// getRequiredInputValue('label_marker_start') - , parserMarkerEnd = '>>'// getRequiredInputValue('label_marker_end') - , repository = "bill-test-org/t-lint"// getOptionalInputValue('repository') + const issueId = getRequiredInputValue('issue_id') + , githubToken = getRequiredInputValue('github_token') + , parserSeparator = getRequiredInputValue('separator') + , parserMarkerStart = getRequiredInputValue('label_marker_start') + , parserMarkerEnd = getRequiredInputValue('label_marker_end') + , repository = getOptionalInputValue('repository') ; const issueUtil = new IssueUtil(githubToken) From 27045fc153b0945dbcab41b8a2dd924e4d18c69f Mon Sep 17 00:00:00 2001 From: omgitsbillryan Date: Fri, 24 Sep 2021 15:18:04 -0400 Subject: [PATCH 08/13] hmm, is this messing with my inputs --- index.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/index.js b/index.js index 68bf9d6..e490a16 100644 --- a/index.js +++ b/index.js @@ -7,11 +7,6 @@ function getRequiredInputValue(key) { return core.getInput(key, { required: true }); } -function getOptionalInputValue(key) { - return core.getInput(key, { required: false }); -} - - async function run() { try { const issueId = getRequiredInputValue('issue_id') @@ -19,7 +14,7 @@ async function run() { , parserSeparator = getRequiredInputValue('separator') , parserMarkerStart = getRequiredInputValue('label_marker_start') , parserMarkerEnd = getRequiredInputValue('label_marker_end') - , repository = getOptionalInputValue('repository') + , repository = getRequiredInputValue('repository') ; const issueUtil = new IssueUtil(githubToken) From 9d6b22b4d21f0fed48fc815e539152859b3a5fea Mon Sep 17 00:00:00 2001 From: omgitsbillryan Date: Fri, 24 Sep 2021 15:20:47 -0400 Subject: [PATCH 09/13] going nuclear --- src/IssueUtil.js | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/IssueUtil.js b/src/IssueUtil.js index 433da2c..0182756 100644 --- a/src/IssueUtil.js +++ b/src/IssueUtil.js @@ -13,18 +13,19 @@ module.exports = class IssueUtil { const [owner, repo] = repository.split('/'); const target_repo = repository ? {owner, repo} : github.context.repo; - return this.octokit.issues.get({ - ...target_repo, - issue_number: id - }).then(result => { - console.log(result.status) - if (result.status !== 200) { - throw new Error(`Unexpected status code from retrieving issue: ${result.status}`); - } - console.log(result.data.body) - return result.data.body; - }).catch(err => { - throw new Error(`Repository... owner=${owner}, repo=${repo}`); - }); + throw new Error(`Repository... owner=${owner}, repo=${repo}`); + + // return this.octokit.issues.get({ + // ...target_repo, + // issue_number: id + // }).then(result => { + // if (result.status !== 200) { + // throw new Error(`Unexpected status code from retrieving issue: ${result.status}`); + // } + + // return result.data.body; + // }).catch(err => { + + // }); } } From 88434394c5d8a8b4a31a073f90be0824868b29c5 Mon Sep 17 00:00:00 2001 From: omgitsbillryan Date: Fri, 24 Sep 2021 15:40:26 -0400 Subject: [PATCH 10/13] put code back in place --- src/IssueUtil.js | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/IssueUtil.js b/src/IssueUtil.js index 0182756..a55513e 100644 --- a/src/IssueUtil.js +++ b/src/IssueUtil.js @@ -13,19 +13,16 @@ module.exports = class IssueUtil { const [owner, repo] = repository.split('/'); const target_repo = repository ? {owner, repo} : github.context.repo; - throw new Error(`Repository... owner=${owner}, repo=${repo}`); - - // return this.octokit.issues.get({ - // ...target_repo, - // issue_number: id - // }).then(result => { - // if (result.status !== 200) { - // throw new Error(`Unexpected status code from retrieving issue: ${result.status}`); - // } - - // return result.data.body; - // }).catch(err => { - - // }); + return this.octokit.issues.get({ + ...target_repo, + issue_number: id + }).then(result => { + if (result.status !== 200) { + throw new Error(`Unexpected status code from retrieving issue: ${result.status}`); + } + return result.data.body; + }).catch(err => { + throw err; + }); } } From 2a6e8c7db71668c3a3bb9578f37fa132d645df4d Mon Sep 17 00:00:00 2001 From: omgitsbillryan Date: Fri, 24 Sep 2021 16:07:22 -0400 Subject: [PATCH 11/13] update action.yml --- action.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/action.yml b/action.yml index 974f492..cc8cdac 100644 --- a/action.yml +++ b/action.yml @@ -13,6 +13,11 @@ inputs: default: ${{ github.token }} required: true + repository: + description: The GitHub repository where the issue lives + default: ${{ github.repository }} + required: true + issue_id: description: The id of the issue to use to extract a payload from the body required: true From 01bedb009cbb9fc8e64fffee8edb4a61dbbe8508 Mon Sep 17 00:00:00 2001 From: omgitsbillryan Date: Fri, 24 Sep 2021 16:26:17 -0400 Subject: [PATCH 12/13] repository is required, no need to pretend it isnt --- src/IssueUtil.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/IssueUtil.js b/src/IssueUtil.js index a55513e..c4338c6 100644 --- a/src/IssueUtil.js +++ b/src/IssueUtil.js @@ -11,10 +11,9 @@ module.exports = class IssueUtil { getIssueBody(id, repository) { const [owner, repo] = repository.split('/'); - const target_repo = repository ? {owner, repo} : github.context.repo; return this.octokit.issues.get({ - ...target_repo, + ...{owner, repo}, issue_number: id }).then(result => { if (result.status !== 200) { From 31eae324321849a64ea56210236f08a4e72ae2f2 Mon Sep 17 00:00:00 2001 From: omgitsbillryan Date: Tue, 28 Sep 2021 12:04:58 -0400 Subject: [PATCH 13/13] build the dang thing --- dist/index.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/dist/index.js b/dist/index.js index b29b831..0c99adb 100644 --- a/dist/index.js +++ b/dist/index.js @@ -21,13 +21,14 @@ async function run() { , parserSeparator = getRequiredInputValue('separator') , parserMarkerStart = getRequiredInputValue('label_marker_start') , parserMarkerEnd = getRequiredInputValue('label_marker_end') + , repository = getRequiredInputValue('repository') ; const issueUtil = new IssueUtil(githubToken) , parser = new Parser(parserSeparator, parserMarkerStart, parserMarkerEnd) ; - const issueBody = await issueUtil.getIssueBody(issueId); + const issueBody = await issueUtil.getIssueBody(issueId, repository); const parsed = parser.parse(issueBody); if (parsed !== undefined) { @@ -5885,9 +5886,11 @@ module.exports = class IssueUtil { this.octokit = github.getOctokit(token); } - getIssueBody(id) { + getIssueBody(id, repository) { + const [owner, repo] = repository.split('/'); + return this.octokit.issues.get({ - ...github.context.repo, + ...{owner, repo}, issue_number: id }).then(result => { if (result.status !== 200) { @@ -5900,6 +5903,7 @@ module.exports = class IssueUtil { } } + /***/ }), /***/ 657: