From ad8b9da21964913d8ed2964d6f2ebaa8825acc13 Mon Sep 17 00:00:00 2001 From: Michael Shick Date: Mon, 25 Nov 2019 13:51:39 -0500 Subject: [PATCH] trigger --- .github/workflows/test.yml | 1 + action.yml | 4 ++++ index.js | 29 ++++++++++++++++++++++++++--- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4bc6090..64d2166 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,3 +14,4 @@ jobs: with: msg: Hello! repo-token: ${{ secrets.GITHUB_TOKEN }} + allow-repeats: false diff --git a/action.yml b/action.yml index b48001a..0893050 100644 --- a/action.yml +++ b/action.yml @@ -7,6 +7,10 @@ inputs: repo-token: description: "a github token for API access" required: true + allow-repeats: + description: "allow messages to be repeated" + required: false + default: false runs: using: "node12" main: "index.js" diff --git a/index.js b/index.js index 53f6200..9ea1bef 100644 --- a/index.js +++ b/index.js @@ -5,23 +5,29 @@ async function run() { try { const msg = core.getInput("msg"); const repoToken = core.getInput("repo-token"); + const allowRepeats = core.getInput("allow-repeats"); + + console.log( + `allow repeats: ${allowRepeats}, typeof ${typeof allowRepeats}` + ); core.debug(`Input message: ${msg}`); const octokit = new github.GitHub(repoToken); const { payload: { + after: commitSha, pull_request: pullRequestPayload, repository: repositoryPayload } } = github.context; const { number: pullNumber } = pullRequestPayload; - const { owner: repoOwner, full_name: repoFullName } = repositoryPayload; + const { full_name: repoFullName } = repositoryPayload; const [owner, repo] = repoFullName.split("/"); - core.debug(`OWNER-------------------------------`); - console.log(repoOwner); + // core.debug(`OWNER-------------------------------`); + // console.log(repoOwner); const { data: pr } = await octokit.pulls.get({ owner, @@ -40,6 +46,23 @@ async function run() { }); console.log(comments); + + if (allowRepeats === false) { + core.debug(`NOT ALLOWING REPEATS, CHECK FOR DUPES`); + } + + // duplicate = coms.find { | c | c["user"]["login"] == "github-actions[bot]" && c["body"] == message } + // if duplicate + // puts "The PR already contains a database change notification" + // exit(0) + // end + + octokit.issues.createComment({ + owner, + repo, + issue_number: pullNumber, + body: msg + }); } catch (error) { core.setFailed(error.message); }