From 75195489020d30dc12a18d79f6f03467630411c4 Mon Sep 17 00:00:00 2001 From: Danny McCormick Date: Fri, 2 Aug 2019 14:44:56 -0400 Subject: [PATCH 01/31] Get it working --- README.md | 4 +-- __tests__/main.test.ts | 4 --- action.yml | 11 ++++--- jest.config.js | 11 ------- lib/main.js | 56 ++++++++++++++++++++++++++++++++--- src/main.ts | 66 ++++++++++++++++++++++++++++++++++++++---- 6 files changed, 122 insertions(+), 30 deletions(-) delete mode 100644 __tests__/main.test.ts delete mode 100644 jest.config.js diff --git a/README.md b/README.md index cdd991c..e519271 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ -# Container Action Template +# First Interaction -To get started, click the `Use this template` button on this repository [which will create a new repository based on this template](https://github.blog/2019-06-06-generate-new-repositories-with-repository-templates/). \ No newline at end of file +An action for filtering pull requests and issues from first-time contributors \ No newline at end of file diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts deleted file mode 100644 index 7df9bad..0000000 --- a/__tests__/main.test.ts +++ /dev/null @@ -1,4 +0,0 @@ -describe('TODO - Add a test suite', () => { - it('TODO - Add a test', async () => { - }); -}); diff --git a/action.yml b/action.yml index 84c30ab..6247b14 100644 --- a/action.yml +++ b/action.yml @@ -1,10 +1,13 @@ -name: 'Container Action Template' +name: 'First interaction' description: 'Get started with Container actions' author: 'GitHub' inputs: - myInput: - description: 'Input to use' - default: 'world' + issueMessage: + description: 'Comment to post on an individuals first issue' + prMessage: + description: 'Comment to post on an individuals first pull request' + repoToken: + description: 'Token for the repo. Can be passed in using {{ secrets.GITHUB_TOKEN }}' runs: using: 'docker' image: 'Dockerfile' \ No newline at end of file diff --git a/jest.config.js b/jest.config.js deleted file mode 100644 index 563d4cc..0000000 --- a/jest.config.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - clearMocks: true, - moduleFileExtensions: ['js', 'ts'], - testEnvironment: 'node', - testMatch: ['**/*.test.ts'], - testRunner: 'jest-circus/runner', - transform: { - '^.+\\.ts$': 'ts-jest' - }, - verbose: true -} \ No newline at end of file diff --git a/lib/main.js b/lib/main.js index a72e6ac..55dd3aa 100644 --- a/lib/main.js +++ b/lib/main.js @@ -12,15 +12,63 @@ const github = require('@actions/github'); function run() { return __awaiter(this, void 0, void 0, function* () { try { - const myInput = core.getInput('myInput'); - core.debug(`Hello ${myInput} from inside a container`); - // Get github context data + // Get client and context + const client = new github.GitHub(core.getInput('repoToken', { required: true })); const context = github.context; - console.log(`We can even get context data, like the repo: ${context.repo.repo}`); + // Do nothing if its not a pr or issue + const isIssue = !!context.payload.issue; + if (!isIssue && !context.payload.pullRequest) { + core.setNeutral('Not a pull request or issue'); + return; + } + // Do nothing if its not their first contribution + const sender = context.payload.sender.login; + const firstContribution = isIssue ? yield isFirstIssue(client, context, isIssue, sender) : yield isFirstPull(client, context, isIssue, sender); + if (!firstContribution) { + core.setNeutral('Not the users first contribution'); + return; + } + // Do nothing if no message set for this type of contribution + const message = isIssue ? core.getInput('issueMessage') : core.getInput('prMessage'); + if (!message) { + core.setNeutral('No message provided for this type of contribution'); + } + // Add a comment to the appropriate place + const issue = context.issue; + yield client.issues.createComment(issue.owner, issue.repo, issue.number, message); } catch (error) { core.setFailed(error.message); + return; } }); } +function isFirstIssue(client, owner, repo, sender) { + return __awaiter(this, void 0, void 0, function* () { + const { status, data: issues } = yield client.issues.listForRepo({ owner: owner, repo: repo, creator: sender, state: 'all' }); + if (status !== 200) { + throw new Error(`Received API status code ${status}`); + } + return issues.length === 0; + }); +} +// No way to filter pulls by creator +function isFirstPull(client, owner, repo, sender, page = 1) { + return __awaiter(this, void 0, void 0, function* () { + const { status, data: pulls } = yield client.pulls.list({ owner: owner, repo: repo, per_page: 100, page: page, state: 'all' }); + if (status !== 200) { + throw new Error(`Received API status code ${status}`); + } + if (pulls.length === 0) { + return true; + } + for (const pull of pulls) { + const login = pull.user.login; + if (login === sender) { + return false; + } + } + return yield isFirstPull(client, owner, repo, sender, page + 1); + }); +} run(); diff --git a/src/main.ts b/src/main.ts index 757639d..4fd93ae 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,15 +3,71 @@ const github = require('@actions/github'); async function run() { try { - const myInput = core.getInput('myInput'); - core.debug(`Hello ${myInput} from inside a container`); - - // Get github context data + // Get client and context + const client = new github.GitHub(core.getInput('repoToken', { required: true })); const context = github.context; - console.log(`We can even get context data, like the repo: ${context.repo.repo}`) + + // Do nothing if its not a pr or issue + const isIssue = !!context.payload.issue; + if (!isIssue && !context.payload.pullRequest) { + core.setNeutral('Not a pull request or issue'); + return; + } + + // Do nothing if its not their first contribution + const sender = context.payload.sender.login; + const firstContribution = isIssue ? await isFirstIssue(client, context, isIssue, sender) : await isFirstPull(client, context, isIssue, sender); + if (!firstContribution) { + core.setNeutral('Not the users first contribution'); + return; + } + + // Do nothing if no message set for this type of contribution + const message = isIssue ? core.getInput('issueMessage') : core.getInput('prMessage'); + if (!message) { + core.setNeutral('No message provided for this type of contribution'); + } + + // Add a comment to the appropriate place + const issue = context.issue; + await client.issues.createComment(issue.owner, issue.repo, issue.number, message); + } catch (error) { core.setFailed(error.message); + return; } } +async function isFirstIssue(client, owner, repo, sender): Promise { + const {status, data: issues} = await client.issues.listForRepo({owner: owner, repo: repo, creator: sender, state: 'all'}); + + if (status !== 200) { + throw new Error(`Received API status code ${status}`); + } + + return issues.length === 0; +} + +// No way to filter pulls by creator +async function isFirstPull(client, owner, repo, sender, page = 1): Promise { + const {status, data: pulls} = await client.pulls.list({owner: owner, repo: repo, per_page: 100, page: page, state: 'all'}); + + if (status !== 200) { + throw new Error(`Received API status code ${status}`); + } + + if (pulls.length === 0) { + return true; + } + + for (const pull of pulls) { + const login = pull.user.login; + if (login === sender) { + return false; + } + } + + return await isFirstPull(client, owner, repo, sender, page+1); +} + run(); From 7c5fe33faa7ea91eb2f1c662ee42c0de577d8495 Mon Sep 17 00:00:00 2001 From: Danny McCormick Date: Fri, 2 Aug 2019 14:47:26 -0400 Subject: [PATCH 02/31] Required token --- action.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index 6247b14..c41d374 100644 --- a/action.yml +++ b/action.yml @@ -1,13 +1,14 @@ name: 'First interaction' description: 'Get started with Container actions' author: 'GitHub' -inputs: +inputs: + repoToken: + description: 'Token for the repo. Can be passed in using {{ secrets.GITHUB_TOKEN }}' + required: true issueMessage: description: 'Comment to post on an individuals first issue' prMessage: description: 'Comment to post on an individuals first pull request' - repoToken: - description: 'Token for the repo. Can be passed in using {{ secrets.GITHUB_TOKEN }}' runs: using: 'docker' image: 'Dockerfile' \ No newline at end of file From 1e3c1376428a436b0b35a4f3df670e1e024e3bac Mon Sep 17 00:00:00 2001 From: Danny McCormick Date: Fri, 2 Aug 2019 14:58:40 -0400 Subject: [PATCH 03/31] Logging --- lib/main.js | 5 +++++ src/main.ts | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/lib/main.js b/lib/main.js index 55dd3aa..bf1579c 100644 --- a/lib/main.js +++ b/lib/main.js @@ -13,15 +13,18 @@ function run() { return __awaiter(this, void 0, void 0, function* () { try { // Get client and context + console.log('Getting a gitub client and context'); const client = new github.GitHub(core.getInput('repoToken', { required: true })); const context = github.context; // Do nothing if its not a pr or issue + console.log('Checking if its a PR, issue, or something else'); const isIssue = !!context.payload.issue; if (!isIssue && !context.payload.pullRequest) { core.setNeutral('Not a pull request or issue'); return; } // Do nothing if its not their first contribution + console.log('Checking if its the users first contribution'); const sender = context.payload.sender.login; const firstContribution = isIssue ? yield isFirstIssue(client, context, isIssue, sender) : yield isFirstPull(client, context, isIssue, sender); if (!firstContribution) { @@ -29,11 +32,13 @@ function run() { return; } // Do nothing if no message set for this type of contribution + console.log('Getting the right message for this type of contribution'); const message = isIssue ? core.getInput('issueMessage') : core.getInput('prMessage'); if (!message) { core.setNeutral('No message provided for this type of contribution'); } // Add a comment to the appropriate place + console.log('Adding a comment in the issue or PR'); const issue = context.issue; yield client.issues.createComment(issue.owner, issue.repo, issue.number, message); } diff --git a/src/main.ts b/src/main.ts index 4fd93ae..12a8d9b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,10 +4,12 @@ const github = require('@actions/github'); async function run() { try { // Get client and context + console.log('Getting a gitub client and context'); const client = new github.GitHub(core.getInput('repoToken', { required: true })); const context = github.context; // Do nothing if its not a pr or issue + console.log('Checking if its a PR, issue, or something else'); const isIssue = !!context.payload.issue; if (!isIssue && !context.payload.pullRequest) { core.setNeutral('Not a pull request or issue'); @@ -15,6 +17,7 @@ async function run() { } // Do nothing if its not their first contribution + console.log('Checking if its the users first contribution'); const sender = context.payload.sender.login; const firstContribution = isIssue ? await isFirstIssue(client, context, isIssue, sender) : await isFirstPull(client, context, isIssue, sender); if (!firstContribution) { @@ -23,12 +26,14 @@ async function run() { } // Do nothing if no message set for this type of contribution + console.log('Getting the right message for this type of contribution'); const message = isIssue ? core.getInput('issueMessage') : core.getInput('prMessage'); if (!message) { core.setNeutral('No message provided for this type of contribution'); } // Add a comment to the appropriate place + console.log('Adding a comment in the issue or PR'); const issue = context.issue; await client.issues.createComment(issue.owner, issue.repo, issue.number, message); From 5006440e3d4b1b241330ea2c4f719645e38b0831 Mon Sep 17 00:00:00 2001 From: Danny McCormick Date: Fri, 2 Aug 2019 15:00:57 -0400 Subject: [PATCH 04/31] Debug --- lib/main.js | 2 +- src/main.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index bf1579c..778fdcf 100644 --- a/lib/main.js +++ b/lib/main.js @@ -17,7 +17,7 @@ function run() { const client = new github.GitHub(core.getInput('repoToken', { required: true })); const context = github.context; // Do nothing if its not a pr or issue - console.log('Checking if its a PR, issue, or something else'); + console.log('Checking if its a PR, issue, or something else, context payload: ' + context.payload); const isIssue = !!context.payload.issue; if (!isIssue && !context.payload.pullRequest) { core.setNeutral('Not a pull request or issue'); diff --git a/src/main.ts b/src/main.ts index 12a8d9b..7632a9d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -9,7 +9,7 @@ async function run() { const context = github.context; // Do nothing if its not a pr or issue - console.log('Checking if its a PR, issue, or something else'); + console.log('Checking if its a PR, issue, or something else, context payload: ' + context.payload); const isIssue = !!context.payload.issue; if (!isIssue && !context.payload.pullRequest) { core.setNeutral('Not a pull request or issue'); From 2d4a807c8a89a5120ae2b16eba02ef57759620bf Mon Sep 17 00:00:00 2001 From: Danny McCormick Date: Fri, 2 Aug 2019 15:03:21 -0400 Subject: [PATCH 05/31] Debug --- lib/main.js | 2 +- src/main.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 778fdcf..5a19678 100644 --- a/lib/main.js +++ b/lib/main.js @@ -17,7 +17,7 @@ function run() { const client = new github.GitHub(core.getInput('repoToken', { required: true })); const context = github.context; // Do nothing if its not a pr or issue - console.log('Checking if its a PR, issue, or something else, context payload: ' + context.payload); + console.log('Checking if its a PR, issue, or something else, context payload: ' + !!context.payload.issue); const isIssue = !!context.payload.issue; if (!isIssue && !context.payload.pullRequest) { core.setNeutral('Not a pull request or issue'); diff --git a/src/main.ts b/src/main.ts index 7632a9d..dbcde55 100644 --- a/src/main.ts +++ b/src/main.ts @@ -9,7 +9,7 @@ async function run() { const context = github.context; // Do nothing if its not a pr or issue - console.log('Checking if its a PR, issue, or something else, context payload: ' + context.payload); + console.log('Checking if its a PR, issue, or something else, context payload: ' + !!context.payload.issue); const isIssue = !!context.payload.issue; if (!isIssue && !context.payload.pullRequest) { core.setNeutral('Not a pull request or issue'); From b18432d2d0b37bf2abb4a3cdbb078e65b23a3dd3 Mon Sep 17 00:00:00 2001 From: Danny McCormick Date: Fri, 2 Aug 2019 15:06:28 -0400 Subject: [PATCH 06/31] Correct logging --- lib/main.js | 12 ++++++------ src/main.ts | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5a19678..991ddb2 100644 --- a/lib/main.js +++ b/lib/main.js @@ -13,14 +13,13 @@ function run() { return __awaiter(this, void 0, void 0, function* () { try { // Get client and context - console.log('Getting a gitub client and context'); const client = new github.GitHub(core.getInput('repoToken', { required: true })); const context = github.context; // Do nothing if its not a pr or issue - console.log('Checking if its a PR, issue, or something else, context payload: ' + !!context.payload.issue); const isIssue = !!context.payload.issue; if (!isIssue && !context.payload.pullRequest) { - core.setNeutral('Not a pull request or issue'); + console.log('Not a pull request or issue'); + core.setNeutral(); return; } // Do nothing if its not their first contribution @@ -28,14 +27,15 @@ function run() { const sender = context.payload.sender.login; const firstContribution = isIssue ? yield isFirstIssue(client, context, isIssue, sender) : yield isFirstPull(client, context, isIssue, sender); if (!firstContribution) { - core.setNeutral('Not the users first contribution'); + console.log('Not the users first contribution'); + core.setNeutral(); return; } // Do nothing if no message set for this type of contribution - console.log('Getting the right message for this type of contribution'); const message = isIssue ? core.getInput('issueMessage') : core.getInput('prMessage'); if (!message) { - core.setNeutral('No message provided for this type of contribution'); + console.log('No message provided for this type of contribution'); + core.setNeutral(); } // Add a comment to the appropriate place console.log('Adding a comment in the issue or PR'); diff --git a/src/main.ts b/src/main.ts index dbcde55..59c970c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,15 +4,14 @@ const github = require('@actions/github'); async function run() { try { // Get client and context - console.log('Getting a gitub client and context'); const client = new github.GitHub(core.getInput('repoToken', { required: true })); const context = github.context; // Do nothing if its not a pr or issue - console.log('Checking if its a PR, issue, or something else, context payload: ' + !!context.payload.issue); const isIssue = !!context.payload.issue; if (!isIssue && !context.payload.pullRequest) { - core.setNeutral('Not a pull request or issue'); + console.log('Not a pull request or issue'); + core.setNeutral(); return; } @@ -21,15 +20,16 @@ async function run() { const sender = context.payload.sender.login; const firstContribution = isIssue ? await isFirstIssue(client, context, isIssue, sender) : await isFirstPull(client, context, isIssue, sender); if (!firstContribution) { - core.setNeutral('Not the users first contribution'); + console.log('Not the users first contribution'); + core.setNeutral(); return; } // Do nothing if no message set for this type of contribution - console.log('Getting the right message for this type of contribution'); const message = isIssue ? core.getInput('issueMessage') : core.getInput('prMessage'); if (!message) { - core.setNeutral('No message provided for this type of contribution'); + console.log('No message provided for this type of contribution') + core.setNeutral(); } // Add a comment to the appropriate place From 87feb3de3e3916b6053f5e10c5e5924c4cf7b746 Mon Sep 17 00:00:00 2001 From: Danny McCormick Date: Fri, 2 Aug 2019 15:08:29 -0400 Subject: [PATCH 07/31] No setNeutral --- lib/main.js | 3 --- src/main.ts | 3 --- 2 files changed, 6 deletions(-) diff --git a/lib/main.js b/lib/main.js index 991ddb2..b67e7ba 100644 --- a/lib/main.js +++ b/lib/main.js @@ -19,7 +19,6 @@ function run() { const isIssue = !!context.payload.issue; if (!isIssue && !context.payload.pullRequest) { console.log('Not a pull request or issue'); - core.setNeutral(); return; } // Do nothing if its not their first contribution @@ -28,14 +27,12 @@ function run() { const firstContribution = isIssue ? yield isFirstIssue(client, context, isIssue, sender) : yield isFirstPull(client, context, isIssue, sender); if (!firstContribution) { console.log('Not the users first contribution'); - core.setNeutral(); return; } // Do nothing if no message set for this type of contribution const message = isIssue ? core.getInput('issueMessage') : core.getInput('prMessage'); if (!message) { console.log('No message provided for this type of contribution'); - core.setNeutral(); } // Add a comment to the appropriate place console.log('Adding a comment in the issue or PR'); diff --git a/src/main.ts b/src/main.ts index 59c970c..be4659a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -11,7 +11,6 @@ async function run() { const isIssue = !!context.payload.issue; if (!isIssue && !context.payload.pullRequest) { console.log('Not a pull request or issue'); - core.setNeutral(); return; } @@ -21,7 +20,6 @@ async function run() { const firstContribution = isIssue ? await isFirstIssue(client, context, isIssue, sender) : await isFirstPull(client, context, isIssue, sender); if (!firstContribution) { console.log('Not the users first contribution'); - core.setNeutral(); return; } @@ -29,7 +27,6 @@ async function run() { const message = isIssue ? core.getInput('issueMessage') : core.getInput('prMessage'); if (!message) { console.log('No message provided for this type of contribution') - core.setNeutral(); } // Add a comment to the appropriate place From 39f5783c33bbafe63c21c453ebf97d20f44eac07 Mon Sep 17 00:00:00 2001 From: Danny McCormick Date: Fri, 2 Aug 2019 15:14:34 -0400 Subject: [PATCH 08/31] debug --- lib/main.js | 3 +++ src/main.ts | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index b67e7ba..33678da 100644 --- a/lib/main.js +++ b/lib/main.js @@ -9,10 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }; const core = require('@actions/core'); const github = require('@actions/github'); +const fs = require('fs'); function run() { return __awaiter(this, void 0, void 0, function* () { try { // Get client and context + console.log(fs.readFileSync(process.env['GITHUB_EVENT_PATH'], { encoding: 'utf8' })); const client = new github.GitHub(core.getInput('repoToken', { required: true })); const context = github.context; // Do nothing if its not a pr or issue @@ -33,6 +35,7 @@ function run() { const message = isIssue ? core.getInput('issueMessage') : core.getInput('prMessage'); if (!message) { console.log('No message provided for this type of contribution'); + return; } // Add a comment to the appropriate place console.log('Adding a comment in the issue or PR'); diff --git a/src/main.ts b/src/main.ts index be4659a..269e9c0 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,9 +1,11 @@ const core = require('@actions/core'); const github = require('@actions/github'); +const fs = require('fs'); async function run() { try { // Get client and context + console.log(fs.readFileSync(process.env['GITHUB_EVENT_PATH'], { encoding: 'utf8' })); const client = new github.GitHub(core.getInput('repoToken', { required: true })); const context = github.context; @@ -26,7 +28,8 @@ async function run() { // Do nothing if no message set for this type of contribution const message = isIssue ? core.getInput('issueMessage') : core.getInput('prMessage'); if (!message) { - console.log('No message provided for this type of contribution') + console.log('No message provided for this type of contribution'); + return; } // Add a comment to the appropriate place From e342e79e07cb9186a841633fdb3b190ae51e8db2 Mon Sep 17 00:00:00 2001 From: Danny McCormick Date: Fri, 2 Aug 2019 15:21:21 -0400 Subject: [PATCH 09/31] debug --- toolkit/actions-github-0.0.0.tgz | Bin 3106 -> 3118 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/toolkit/actions-github-0.0.0.tgz b/toolkit/actions-github-0.0.0.tgz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^ZT>!tSOma) z+#!}bRol5f92@Wj!^_m;Fn9i0p1KN7Y$q2=#Uw6;vmUl(w5CsL!(i-O_)fAo+H5Ae znR@QHtdH@XGYFm=B7I22_X01!ynC7N^K>6B!`V*gGJGPusPBpQ39C}$;%aVbZvVGgd0t+x w|A$DK=l>Z)_#zA-!ErARAP)Z_oa)2o`n$Fbm^k=630yZ0wr2s|%09C>gkN^Mx From d809f74da4e91608377d24e6968faf3bc5d3c218 Mon Sep 17 00:00:00 2001 From: Danny McCormick Date: Fri, 2 Aug 2019 15:24:01 -0400 Subject: [PATCH 10/31] debug --- lib/main.js | 2 +- src/main.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 33678da..cb0b4fc 100644 --- a/lib/main.js +++ b/lib/main.js @@ -19,7 +19,7 @@ function run() { const context = github.context; // Do nothing if its not a pr or issue const isIssue = !!context.payload.issue; - if (!isIssue && !context.payload.pullRequest) { + if (!isIssue && !context.payload.pull_request) { console.log('Not a pull request or issue'); return; } diff --git a/src/main.ts b/src/main.ts index 269e9c0..40a4100 100644 --- a/src/main.ts +++ b/src/main.ts @@ -11,7 +11,7 @@ async function run() { // Do nothing if its not a pr or issue const isIssue = !!context.payload.issue; - if (!isIssue && !context.payload.pullRequest) { + if (!isIssue && !context.payload.pull_request) { console.log('Not a pull request or issue'); return; } From c0b5c3f51bf605ccc91c50438d4af0ef0cb05ec0 Mon Sep 17 00:00:00 2001 From: Danny McCormick Date: Fri, 2 Aug 2019 15:30:18 -0400 Subject: [PATCH 11/31] debug --- lib/main.js | 3 ++- src/main.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index cb0b4fc..66e997e 100644 --- a/lib/main.js +++ b/lib/main.js @@ -14,9 +14,9 @@ function run() { return __awaiter(this, void 0, void 0, function* () { try { // Get client and context - console.log(fs.readFileSync(process.env['GITHUB_EVENT_PATH'], { encoding: 'utf8' })); const client = new github.GitHub(core.getInput('repoToken', { required: true })); const context = github.context; + console.log(fs.readFileSync(process.env['GITHUB_EVENT_PATH'], { encoding: 'utf8' })); // Do nothing if its not a pr or issue const isIssue = !!context.payload.issue; if (!isIssue && !context.payload.pull_request) { @@ -60,6 +60,7 @@ function isFirstIssue(client, owner, repo, sender) { // No way to filter pulls by creator function isFirstPull(client, owner, repo, sender, page = 1) { return __awaiter(this, void 0, void 0, function* () { + console.log('Checking...'); const { status, data: pulls } = yield client.pulls.list({ owner: owner, repo: repo, per_page: 100, page: page, state: 'all' }); if (status !== 200) { throw new Error(`Received API status code ${status}`); diff --git a/src/main.ts b/src/main.ts index 40a4100..0e0aee7 100644 --- a/src/main.ts +++ b/src/main.ts @@ -5,9 +5,9 @@ const fs = require('fs'); async function run() { try { // Get client and context - console.log(fs.readFileSync(process.env['GITHUB_EVENT_PATH'], { encoding: 'utf8' })); const client = new github.GitHub(core.getInput('repoToken', { required: true })); const context = github.context; + console.log(fs.readFileSync(process.env['GITHUB_EVENT_PATH'], { encoding: 'utf8' })); // Do nothing if its not a pr or issue const isIssue = !!context.payload.issue; @@ -55,6 +55,7 @@ async function isFirstIssue(client, owner, repo, sender): Promise { // No way to filter pulls by creator async function isFirstPull(client, owner, repo, sender, page = 1): Promise { + console.log('Checking...'); const {status, data: pulls} = await client.pulls.list({owner: owner, repo: repo, per_page: 100, page: page, state: 'all'}); if (status !== 200) { From b20989f225dea70f24d09bb36ccd3f733603778d Mon Sep 17 00:00:00 2001 From: Danny McCormick Date: Fri, 2 Aug 2019 15:41:06 -0400 Subject: [PATCH 12/31] debug --- lib/main.js | 2 +- src/main.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 66e997e..373a1bc 100644 --- a/lib/main.js +++ b/lib/main.js @@ -60,7 +60,7 @@ function isFirstIssue(client, owner, repo, sender) { // No way to filter pulls by creator function isFirstPull(client, owner, repo, sender, page = 1) { return __awaiter(this, void 0, void 0, function* () { - console.log('Checking...'); + console.log(`Checking owner: ${owner}, repo: ${repo}, per_page: 100, page: ${page}`); const { status, data: pulls } = yield client.pulls.list({ owner: owner, repo: repo, per_page: 100, page: page, state: 'all' }); if (status !== 200) { throw new Error(`Received API status code ${status}`); diff --git a/src/main.ts b/src/main.ts index 0e0aee7..b231198 100644 --- a/src/main.ts +++ b/src/main.ts @@ -55,7 +55,7 @@ async function isFirstIssue(client, owner, repo, sender): Promise { // No way to filter pulls by creator async function isFirstPull(client, owner, repo, sender, page = 1): Promise { - console.log('Checking...'); + console.log(`Checking owner: ${owner}, repo: ${repo}, per_page: 100, page: ${page}`); const {status, data: pulls} = await client.pulls.list({owner: owner, repo: repo, per_page: 100, page: page, state: 'all'}); if (status !== 200) { From 9e41c1ca20e9c6feb25f616e286ad85cdb411091 Mon Sep 17 00:00:00 2001 From: Danny McCormick Date: Fri, 2 Aug 2019 15:44:17 -0400 Subject: [PATCH 13/31] debug --- lib/main.js | 3 ++- src/main.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 373a1bc..2b1f8b8 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,8 @@ function run() { // Do nothing if its not their first contribution console.log('Checking if its the users first contribution'); const sender = context.payload.sender.login; - const firstContribution = isIssue ? yield isFirstIssue(client, context, isIssue, sender) : yield isFirstPull(client, context, isIssue, sender); + const repo = context.repo; + const firstContribution = isIssue ? yield isFirstIssue(client, repo.owner, repo.repo, sender) : yield isFirstPull(client, repo.owner, repo.repo, sender); if (!firstContribution) { console.log('Not the users first contribution'); return; diff --git a/src/main.ts b/src/main.ts index b231198..5505aeb 100644 --- a/src/main.ts +++ b/src/main.ts @@ -19,7 +19,8 @@ async function run() { // Do nothing if its not their first contribution console.log('Checking if its the users first contribution'); const sender = context.payload.sender.login; - const firstContribution = isIssue ? await isFirstIssue(client, context, isIssue, sender) : await isFirstPull(client, context, isIssue, sender); + const repo = context.repo; + const firstContribution = isIssue ? await isFirstIssue(client, repo.owner, repo.repo, sender) : await isFirstPull(client, repo.owner, repo.repo, sender); if (!firstContribution) { console.log('Not the users first contribution'); return; From de6cf472aea88b1c6a5bded2fa621bef483b4565 Mon Sep 17 00:00:00 2001 From: Danny McCormick Date: Fri, 2 Aug 2019 15:47:29 -0400 Subject: [PATCH 14/31] debug --- lib/main.js | 2 +- src/main.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2b1f8b8..588659b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ function run() { const sender = context.payload.sender.login; const repo = context.repo; const firstContribution = isIssue ? yield isFirstIssue(client, repo.owner, repo.repo, sender) : yield isFirstPull(client, repo.owner, repo.repo, sender); - if (!firstContribution) { + if (firstContribution) { console.log('Not the users first contribution'); return; } diff --git a/src/main.ts b/src/main.ts index 5505aeb..835d8ac 100644 --- a/src/main.ts +++ b/src/main.ts @@ -21,7 +21,7 @@ async function run() { const sender = context.payload.sender.login; const repo = context.repo; const firstContribution = isIssue ? await isFirstIssue(client, repo.owner, repo.repo, sender) : await isFirstPull(client, repo.owner, repo.repo, sender); - if (!firstContribution) { + if (firstContribution) { console.log('Not the users first contribution'); return; } From 35d5b33f4c6f71599f9dbc2dcb3131a671502292 Mon Sep 17 00:00:00 2001 From: Danny McCormick Date: Fri, 2 Aug 2019 15:58:08 -0400 Subject: [PATCH 15/31] debug --- lib/main.js | 15 ++++++++++----- src/main.ts | 16 +++++++++++----- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/lib/main.js b/lib/main.js index 588659b..34e4324 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,9 +26,10 @@ function run() { // Do nothing if its not their first contribution console.log('Checking if its the users first contribution'); const sender = context.payload.sender.login; - const repo = context.repo; - const firstContribution = isIssue ? yield isFirstIssue(client, repo.owner, repo.repo, sender) : yield isFirstPull(client, repo.owner, repo.repo, sender); - if (firstContribution) { + const issue = context.issue; + const firstContribution = isIssue ? yield isFirstIssue(client, issue.owner, issue.repo, sender) : yield isFirstPull(client, issue.owner, issue.repo, sender); + // if (!firstContribution) { + if (!firstContribution) { console.log('Not the users first contribution'); return; } @@ -40,8 +41,12 @@ function run() { } // Add a comment to the appropriate place console.log('Adding a comment in the issue or PR'); - const issue = context.issue; - yield client.issues.createComment(issue.owner, issue.repo, issue.number, message); + if (isIssue) { + yield client.issues.createComment(issue.owner, issue.repo, issue.number, message); + } + else { + yield client.pulls.createReview({ owner: issue.owner, repo: issue.repo, pull_number: issue.number, body: message, event: 'COMMENT' }); + } } catch (error) { core.setFailed(error.message); diff --git a/src/main.ts b/src/main.ts index 835d8ac..0785731 100644 --- a/src/main.ts +++ b/src/main.ts @@ -19,9 +19,10 @@ async function run() { // Do nothing if its not their first contribution console.log('Checking if its the users first contribution'); const sender = context.payload.sender.login; - const repo = context.repo; - const firstContribution = isIssue ? await isFirstIssue(client, repo.owner, repo.repo, sender) : await isFirstPull(client, repo.owner, repo.repo, sender); - if (firstContribution) { + const issue = context.issue; + const firstContribution = isIssue ? await isFirstIssue(client, issue.owner, issue.repo, sender) : await isFirstPull(client, issue.owner, issue.repo, sender); + // if (!firstContribution) { + if (!firstContribution) { console.log('Not the users first contribution'); return; } @@ -35,8 +36,13 @@ async function run() { // Add a comment to the appropriate place console.log('Adding a comment in the issue or PR'); - const issue = context.issue; - await client.issues.createComment(issue.owner, issue.repo, issue.number, message); + if (isIssue) { + await client.issues.createComment(issue.owner, issue.repo, issue.number, message); + } + else { + await client.pulls.createReview({ owner: issue.owner, repo: issue.repo, pull_number: issue.number, body: message, event: 'COMMENT' }); + } + } catch (error) { core.setFailed(error.message); From 1f01da4ac819f18ce616a6d695d0274749578ed5 Mon Sep 17 00:00:00 2001 From: Danny McCormick Date: Fri, 2 Aug 2019 15:59:46 -0400 Subject: [PATCH 16/31] debug --- lib/main.js | 2 +- src/main.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 34e4324..52f7a63 100644 --- a/lib/main.js +++ b/lib/main.js @@ -29,7 +29,7 @@ function run() { const issue = context.issue; const firstContribution = isIssue ? yield isFirstIssue(client, issue.owner, issue.repo, sender) : yield isFirstPull(client, issue.owner, issue.repo, sender); // if (!firstContribution) { - if (!firstContribution) { + if (firstContribution) { console.log('Not the users first contribution'); return; } diff --git a/src/main.ts b/src/main.ts index 0785731..2936a22 100644 --- a/src/main.ts +++ b/src/main.ts @@ -22,7 +22,7 @@ async function run() { const issue = context.issue; const firstContribution = isIssue ? await isFirstIssue(client, issue.owner, issue.repo, sender) : await isFirstPull(client, issue.owner, issue.repo, sender); // if (!firstContribution) { - if (!firstContribution) { + if (firstContribution) { console.log('Not the users first contribution'); return; } From 2c446b73934ca6bcc73cddefb79464e94b277825 Mon Sep 17 00:00:00 2001 From: Danny McCormick Date: Fri, 2 Aug 2019 16:04:26 -0400 Subject: [PATCH 17/31] debug --- lib/main.js | 2 +- src/main.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 52f7a63..a2461f7 100644 --- a/lib/main.js +++ b/lib/main.js @@ -40,7 +40,7 @@ function run() { return; } // Add a comment to the appropriate place - console.log('Adding a comment in the issue or PR'); + console.log(`Adding message: ${message}`); if (isIssue) { yield client.issues.createComment(issue.owner, issue.repo, issue.number, message); } diff --git a/src/main.ts b/src/main.ts index 2936a22..a3a3a96 100644 --- a/src/main.ts +++ b/src/main.ts @@ -35,7 +35,7 @@ async function run() { } // Add a comment to the appropriate place - console.log('Adding a comment in the issue or PR'); + console.log(`Adding message: ${message}`); if (isIssue) { await client.issues.createComment(issue.owner, issue.repo, issue.number, message); } From 8332ac1d5cc8cf65fb6657abe56a07cc8aabf78d Mon Sep 17 00:00:00 2001 From: Danny McCormick Date: Fri, 2 Aug 2019 16:07:03 -0400 Subject: [PATCH 18/31] debug --- lib/main.js | 2 +- src/main.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index a2461f7..1b82f5d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -42,7 +42,7 @@ function run() { // Add a comment to the appropriate place console.log(`Adding message: ${message}`); if (isIssue) { - yield client.issues.createComment(issue.owner, issue.repo, issue.number, message); + yield client.issues.createComment({ owner: issue.owner, repo: issue.repo, issue_number: issue.number, body: message }); } else { yield client.pulls.createReview({ owner: issue.owner, repo: issue.repo, pull_number: issue.number, body: message, event: 'COMMENT' }); diff --git a/src/main.ts b/src/main.ts index a3a3a96..784bc3d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -37,7 +37,7 @@ async function run() { // Add a comment to the appropriate place console.log(`Adding message: ${message}`); if (isIssue) { - await client.issues.createComment(issue.owner, issue.repo, issue.number, message); + await client.issues.createComment({ owner: issue.owner, repo: issue.repo, issue_number: issue.number, body: message }); } else { await client.pulls.createReview({ owner: issue.owner, repo: issue.repo, pull_number: issue.number, body: message, event: 'COMMENT' }); From cbef4a8f49e1ac3248e36abc805fb5a714ba6a53 Mon Sep 17 00:00:00 2001 From: Danny McCormick Date: Fri, 2 Aug 2019 16:10:27 -0400 Subject: [PATCH 19/31] working --- lib/main.js | 3 +-- src/main.ts | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 1b82f5d..92869e8 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,8 +28,7 @@ function run() { const sender = context.payload.sender.login; const issue = context.issue; const firstContribution = isIssue ? yield isFirstIssue(client, issue.owner, issue.repo, sender) : yield isFirstPull(client, issue.owner, issue.repo, sender); - // if (!firstContribution) { - if (firstContribution) { + if (!firstContribution) { console.log('Not the users first contribution'); return; } diff --git a/src/main.ts b/src/main.ts index 784bc3d..d7424aa 100644 --- a/src/main.ts +++ b/src/main.ts @@ -21,8 +21,7 @@ async function run() { const sender = context.payload.sender.login; const issue = context.issue; const firstContribution = isIssue ? await isFirstIssue(client, issue.owner, issue.repo, sender) : await isFirstPull(client, issue.owner, issue.repo, sender); - // if (!firstContribution) { - if (firstContribution) { + if (!firstContribution) { console.log('Not the users first contribution'); return; } From 520b49f50ea9096d36462524f4122fa09b128dfa Mon Sep 17 00:00:00 2001 From: Danny McCormick Date: Fri, 2 Aug 2019 16:13:37 -0400 Subject: [PATCH 20/31] logging --- lib/main.js | 2 +- src/main.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 92869e8..9ba525a 100644 --- a/lib/main.js +++ b/lib/main.js @@ -65,7 +65,7 @@ function isFirstIssue(client, owner, repo, sender) { // No way to filter pulls by creator function isFirstPull(client, owner, repo, sender, page = 1) { return __awaiter(this, void 0, void 0, function* () { - console.log(`Checking owner: ${owner}, repo: ${repo}, per_page: 100, page: ${page}`); + console.log('Checking...'); const { status, data: pulls } = yield client.pulls.list({ owner: owner, repo: repo, per_page: 100, page: page, state: 'all' }); if (status !== 200) { throw new Error(`Received API status code ${status}`); diff --git a/src/main.ts b/src/main.ts index d7424aa..324ca1d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -61,7 +61,7 @@ async function isFirstIssue(client, owner, repo, sender): Promise { // No way to filter pulls by creator async function isFirstPull(client, owner, repo, sender, page = 1): Promise { - console.log(`Checking owner: ${owner}, repo: ${repo}, per_page: 100, page: ${page}`); + console.log('Checking...'); const {status, data: pulls} = await client.pulls.list({owner: owner, repo: repo, per_page: 100, page: page, state: 'all'}); if (status !== 200) { From d88141820a733c9689842f68e41cf6602438f478 Mon Sep 17 00:00:00 2001 From: Danny McCormick Date: Fri, 2 Aug 2019 16:29:46 -0400 Subject: [PATCH 21/31] logging --- lib/main.js | 20 +++++++++++++++----- src/main.ts | 22 +++++++++++++++++----- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/lib/main.js b/lib/main.js index 9ba525a..7650fb3 100644 --- a/lib/main.js +++ b/lib/main.js @@ -27,7 +27,7 @@ function run() { console.log('Checking if its the users first contribution'); const sender = context.payload.sender.login; const issue = context.issue; - const firstContribution = isIssue ? yield isFirstIssue(client, issue.owner, issue.repo, sender) : yield isFirstPull(client, issue.owner, issue.repo, sender); + const firstContribution = isIssue ? yield isFirstIssue(client, issue.owner, issue.repo, issue.number, sender) : yield isFirstPull(client, issue.owner, issue.repo, issue.number, sender); if (!firstContribution) { console.log('Not the users first contribution'); return; @@ -53,17 +53,26 @@ function run() { } }); } -function isFirstIssue(client, owner, repo, sender) { +function isFirstIssue(client, owner, repo, sender, number) { return __awaiter(this, void 0, void 0, function* () { const { status, data: issues } = yield client.issues.listForRepo({ owner: owner, repo: repo, creator: sender, state: 'all' }); if (status !== 200) { throw new Error(`Received API status code ${status}`); } - return issues.length === 0; + if (issues.length === 0) { + return true; + } + for (const issue of issues) { + const issueNumber = issue.number; + if (issueNumber < number) { + return false; + } + } + return true; }); } // No way to filter pulls by creator -function isFirstPull(client, owner, repo, sender, page = 1) { +function isFirstPull(client, owner, repo, sender, number, page = 1) { return __awaiter(this, void 0, void 0, function* () { console.log('Checking...'); const { status, data: pulls } = yield client.pulls.list({ owner: owner, repo: repo, per_page: 100, page: page, state: 'all' }); @@ -75,7 +84,8 @@ function isFirstPull(client, owner, repo, sender, page = 1) { } for (const pull of pulls) { const login = pull.user.login; - if (login === sender) { + const pullNumber = pull.number; + if (login === sender && pullNumber < number) { return false; } } diff --git a/src/main.ts b/src/main.ts index 324ca1d..7a32614 100644 --- a/src/main.ts +++ b/src/main.ts @@ -20,7 +20,7 @@ async function run() { console.log('Checking if its the users first contribution'); const sender = context.payload.sender.login; const issue = context.issue; - const firstContribution = isIssue ? await isFirstIssue(client, issue.owner, issue.repo, sender) : await isFirstPull(client, issue.owner, issue.repo, sender); + const firstContribution = isIssue ? await isFirstIssue(client, issue.owner, issue.repo, issue.number, sender) : await isFirstPull(client, issue.owner, issue.repo, issue.number, sender); if (!firstContribution) { console.log('Not the users first contribution'); return; @@ -49,18 +49,29 @@ async function run() { } } -async function isFirstIssue(client, owner, repo, sender): Promise { +async function isFirstIssue(client, owner, repo, sender, number): Promise { const {status, data: issues} = await client.issues.listForRepo({owner: owner, repo: repo, creator: sender, state: 'all'}); if (status !== 200) { throw new Error(`Received API status code ${status}`); } - return issues.length === 0; + if (issues.length === 0) { + return true; + } + + for (const issue of issues) { + const issueNumber = issue.number; + if (issueNumber < number) { + return false; + } + } + + return true; } // No way to filter pulls by creator -async function isFirstPull(client, owner, repo, sender, page = 1): Promise { +async function isFirstPull(client, owner, repo, sender, number, page = 1): Promise { console.log('Checking...'); const {status, data: pulls} = await client.pulls.list({owner: owner, repo: repo, per_page: 100, page: page, state: 'all'}); @@ -74,7 +85,8 @@ async function isFirstPull(client, owner, repo, sender, page = 1): Promise Date: Fri, 2 Aug 2019 16:33:25 -0400 Subject: [PATCH 22/31] logging --- lib/main.js | 2 +- src/main.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 7650fb3..06744ae 100644 --- a/lib/main.js +++ b/lib/main.js @@ -89,7 +89,7 @@ function isFirstPull(client, owner, repo, sender, number, page = 1) { return false; } } - return yield isFirstPull(client, owner, repo, sender, page + 1); + return yield isFirstPull(client, owner, repo, sender, number, page + 1); }); } run(); diff --git a/src/main.ts b/src/main.ts index 7a32614..7f03c2e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -91,7 +91,7 @@ async function isFirstPull(client, owner, repo, sender, number, page = 1): Promi } } - return await isFirstPull(client, owner, repo, sender, page+1); + return await isFirstPull(client, owner, repo, sender, number, page+1); } run(); From 18fbab1ebc9c7c0eaac1fa69ef3bd5d9b5d11155 Mon Sep 17 00:00:00 2001 From: Danny McCormick Date: Fri, 2 Aug 2019 16:41:44 -0400 Subject: [PATCH 23/31] logging --- lib/main.js | 4 ++++ src/main.ts | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/lib/main.js b/lib/main.js index 06744ae..975f123 100644 --- a/lib/main.js +++ b/lib/main.js @@ -17,6 +17,10 @@ function run() { const client = new github.GitHub(core.getInput('repoToken', { required: true })); const context = github.context; console.log(fs.readFileSync(process.env['GITHUB_EVENT_PATH'], { encoding: 'utf8' })); + if (context.payload.action !== 'opened') { + console.log('Nothing was opened'); + return; + } // Do nothing if its not a pr or issue const isIssue = !!context.payload.issue; if (!isIssue && !context.payload.pull_request) { diff --git a/src/main.ts b/src/main.ts index 7f03c2e..296213c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -9,6 +9,11 @@ async function run() { const context = github.context; console.log(fs.readFileSync(process.env['GITHUB_EVENT_PATH'], { encoding: 'utf8' })); + if (context.payload.action !== 'opened') { + console.log('Nothing was opened'); + return; + } + // Do nothing if its not a pr or issue const isIssue = !!context.payload.issue; if (!isIssue && !context.payload.pull_request) { From bb93c8f71108494bf09f08b9eb69217cff74fe23 Mon Sep 17 00:00:00 2001 From: Danny McCormick Date: Fri, 2 Aug 2019 16:43:05 -0400 Subject: [PATCH 24/31] logging --- lib/main.js | 2 +- src/main.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 975f123..50229ee 100644 --- a/lib/main.js +++ b/lib/main.js @@ -17,7 +17,7 @@ function run() { const client = new github.GitHub(core.getInput('repoToken', { required: true })); const context = github.context; console.log(fs.readFileSync(process.env['GITHUB_EVENT_PATH'], { encoding: 'utf8' })); - if (context.payload.action !== 'opened') { + if (context.action !== 'opened') { console.log('Nothing was opened'); return; } diff --git a/src/main.ts b/src/main.ts index 296213c..cadec3d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -9,7 +9,7 @@ async function run() { const context = github.context; console.log(fs.readFileSync(process.env['GITHUB_EVENT_PATH'], { encoding: 'utf8' })); - if (context.payload.action !== 'opened') { + if (context.action !== 'opened') { console.log('Nothing was opened'); return; } From 9447e13bd22cfdc073f2a92e71d87108c7503184 Mon Sep 17 00:00:00 2001 From: Danny McCormick Date: Fri, 2 Aug 2019 16:43:24 -0400 Subject: [PATCH 25/31] logging --- lib/main.js | 1 - src/main.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 50229ee..f75e794 100644 --- a/lib/main.js +++ b/lib/main.js @@ -16,7 +16,6 @@ function run() { // Get client and context const client = new github.GitHub(core.getInput('repoToken', { required: true })); const context = github.context; - console.log(fs.readFileSync(process.env['GITHUB_EVENT_PATH'], { encoding: 'utf8' })); if (context.action !== 'opened') { console.log('Nothing was opened'); return; diff --git a/src/main.ts b/src/main.ts index cadec3d..265d137 100644 --- a/src/main.ts +++ b/src/main.ts @@ -7,7 +7,6 @@ async function run() { // Get client and context const client = new github.GitHub(core.getInput('repoToken', { required: true })); const context = github.context; - console.log(fs.readFileSync(process.env['GITHUB_EVENT_PATH'], { encoding: 'utf8' })); if (context.action !== 'opened') { console.log('Nothing was opened'); From 5250ff524688cdca947a8406a278003390d6f009 Mon Sep 17 00:00:00 2001 From: Danny McCormick Date: Fri, 2 Aug 2019 16:50:19 -0400 Subject: [PATCH 26/31] logging --- lib/main.js | 2 +- src/main.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index f75e794..cffd0aa 100644 --- a/lib/main.js +++ b/lib/main.js @@ -17,7 +17,7 @@ function run() { const client = new github.GitHub(core.getInput('repoToken', { required: true })); const context = github.context; if (context.action !== 'opened') { - console.log('Nothing was opened'); + console.log('Nothing was opened, event was ' + context.action); return; } // Do nothing if its not a pr or issue diff --git a/src/main.ts b/src/main.ts index 265d137..c708686 100644 --- a/src/main.ts +++ b/src/main.ts @@ -9,7 +9,7 @@ async function run() { const context = github.context; if (context.action !== 'opened') { - console.log('Nothing was opened'); + console.log('Nothing was opened, event was ' + context.action); return; } From 28d385b69c4c9242705ff710bf46c5b908946fe2 Mon Sep 17 00:00:00 2001 From: Danny McCormick Date: Fri, 2 Aug 2019 16:51:59 -0400 Subject: [PATCH 27/31] logging --- lib/main.js | 2 +- src/main.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index cffd0aa..84f8a5f 100644 --- a/lib/main.js +++ b/lib/main.js @@ -17,7 +17,7 @@ function run() { const client = new github.GitHub(core.getInput('repoToken', { required: true })); const context = github.context; if (context.action !== 'opened') { - console.log('Nothing was opened, event was ' + context.action); + console.log('Nothing was opened, event was ' + context.eventName); return; } // Do nothing if its not a pr or issue diff --git a/src/main.ts b/src/main.ts index c708686..3ddddd4 100644 --- a/src/main.ts +++ b/src/main.ts @@ -9,7 +9,7 @@ async function run() { const context = github.context; if (context.action !== 'opened') { - console.log('Nothing was opened, event was ' + context.action); + console.log('Nothing was opened, event was ' + context.eventName); return; } From e327910ff9a59ba95743cdd00cbea37e487cc428 Mon Sep 17 00:00:00 2001 From: Danny McCormick Date: Fri, 2 Aug 2019 16:53:56 -0400 Subject: [PATCH 28/31] logging --- lib/main.js | 4 ++-- src/main.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 84f8a5f..00b49e8 100644 --- a/lib/main.js +++ b/lib/main.js @@ -16,8 +16,8 @@ function run() { // Get client and context const client = new github.GitHub(core.getInput('repoToken', { required: true })); const context = github.context; - if (context.action !== 'opened') { - console.log('Nothing was opened, event was ' + context.eventName); + if (context.payload.action !== 'opened') { + console.log('Nothing was opened, payload action was: ' + context.payload.action); return; } // Do nothing if its not a pr or issue diff --git a/src/main.ts b/src/main.ts index 3ddddd4..2110713 100644 --- a/src/main.ts +++ b/src/main.ts @@ -8,8 +8,8 @@ async function run() { const client = new github.GitHub(core.getInput('repoToken', { required: true })); const context = github.context; - if (context.action !== 'opened') { - console.log('Nothing was opened, event was ' + context.eventName); + if (context.payload.action !== 'opened') { + console.log('Nothing was opened, payload action was: ' + context.payload.action); return; } From d8d767f883402eb7dc6a126c3fb1a8403f35be00 Mon Sep 17 00:00:00 2001 From: Danny McCormick Date: Fri, 2 Aug 2019 16:59:03 -0400 Subject: [PATCH 29/31] logging --- lib/main.js | 3 ++- src/main.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 00b49e8..d0deb02 100644 --- a/lib/main.js +++ b/lib/main.js @@ -17,7 +17,7 @@ function run() { const client = new github.GitHub(core.getInput('repoToken', { required: true })); const context = github.context; if (context.payload.action !== 'opened') { - console.log('Nothing was opened, payload action was: ' + context.payload.action); + console.log('Nothing was opened'); return; } // Do nothing if its not a pr or issue @@ -67,6 +67,7 @@ function isFirstIssue(client, owner, repo, sender, number) { } for (const issue of issues) { const issueNumber = issue.number; + console.log(issueNumber, number); if (issueNumber < number) { return false; } diff --git a/src/main.ts b/src/main.ts index 2110713..f4a46a3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -9,7 +9,7 @@ async function run() { const context = github.context; if (context.payload.action !== 'opened') { - console.log('Nothing was opened, payload action was: ' + context.payload.action); + console.log('Nothing was opened'); return; } @@ -66,6 +66,7 @@ async function isFirstIssue(client, owner, repo, sender, number): Promise Date: Fri, 2 Aug 2019 17:01:26 -0400 Subject: [PATCH 30/31] debug --- lib/main.js | 1 + src/main.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/main.js b/lib/main.js index d0deb02..2dc22b2 100644 --- a/lib/main.js +++ b/lib/main.js @@ -58,6 +58,7 @@ function run() { } function isFirstIssue(client, owner, repo, sender, number) { return __awaiter(this, void 0, void 0, function* () { + console.log(`owner ${owner}, repo ${repo}, creator: ${sender}`); const { status, data: issues } = yield client.issues.listForRepo({ owner: owner, repo: repo, creator: sender, state: 'all' }); if (status !== 200) { throw new Error(`Received API status code ${status}`); diff --git a/src/main.ts b/src/main.ts index f4a46a3..b7b3bad 100644 --- a/src/main.ts +++ b/src/main.ts @@ -54,6 +54,7 @@ async function run() { } async function isFirstIssue(client, owner, repo, sender, number): Promise { + console.log(`owner ${owner}, repo ${repo}, creator: ${sender}`); const {status, data: issues} = await client.issues.listForRepo({owner: owner, repo: repo, creator: sender, state: 'all'}); if (status !== 200) { From 1c55bc5b7684d33442483a997a6cb19c378e6056 Mon Sep 17 00:00:00 2001 From: Danny McCormick Date: Fri, 2 Aug 2019 17:03:24 -0400 Subject: [PATCH 31/31] debug --- lib/main.js | 2 +- src/main.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2dc22b2..5910234 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ function run() { console.log('Checking if its the users first contribution'); const sender = context.payload.sender.login; const issue = context.issue; - const firstContribution = isIssue ? yield isFirstIssue(client, issue.owner, issue.repo, issue.number, sender) : yield isFirstPull(client, issue.owner, issue.repo, issue.number, sender); + const firstContribution = isIssue ? yield isFirstIssue(client, issue.owner, issue.repo, sender, issue.number) : yield isFirstPull(client, issue.owner, issue.repo, sender, issue.number); if (!firstContribution) { console.log('Not the users first contribution'); return; diff --git a/src/main.ts b/src/main.ts index b7b3bad..edd230d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -24,7 +24,7 @@ async function run() { console.log('Checking if its the users first contribution'); const sender = context.payload.sender.login; const issue = context.issue; - const firstContribution = isIssue ? await isFirstIssue(client, issue.owner, issue.repo, issue.number, sender) : await isFirstPull(client, issue.owner, issue.repo, issue.number, sender); + const firstContribution = isIssue ? await isFirstIssue(client, issue.owner, issue.repo, sender, issue.number) : await isFirstPull(client, issue.owner, issue.repo, sender, issue.number); if (!firstContribution) { console.log('Not the users first contribution'); return;