diff --git a/.github/workflows/comment_on_push.yml b/.github/workflows/comment_on_push.yml new file mode 100644 index 0000000..6524873 --- /dev/null +++ b/.github/workflows/comment_on_push.yml @@ -0,0 +1,19 @@ +name: Comment on Push +on: + - push + +jobs: + comment: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: jwalton/gh-find-current-pr@v1 + id: finder + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + - uses: ./ + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + number: ${{ steps.finder.outputs.pr }} + message: | + Test ${{ github.sha }} is successfully ended. diff --git a/action.yml b/action.yml index a11908f..bd2533e 100644 --- a/action.yml +++ b/action.yml @@ -4,8 +4,13 @@ author: "marocchino" inputs: message: description: "comment message" + required: true + number: + description: "pull request number for push event" + required: false GITHUB_TOKEN: description: "set secrets.GITHUB_TOKEN here" + required: true runs: using: "node12" main: "lib/main.js" diff --git a/lib/main.js b/lib/main.js index c6d36b6..0f2808d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,11 +24,11 @@ function run() { return __awaiter(this, void 0, void 0, function* () { try { const repo = github_1.context.repo; - const number = (_c = (_b = (_a = github_1.context) === null || _a === void 0 ? void 0 : _a.payload) === null || _b === void 0 ? void 0 : _b.pull_request) === null || _c === void 0 ? void 0 : _c.number; + const number = ((_c = (_b = (_a = github_1.context) === null || _a === void 0 ? void 0 : _a.payload) === null || _b === void 0 ? void 0 : _b.pull_request) === null || _c === void 0 ? void 0 : _c.number) || +core.getInput("number"); const body = core.getInput("message"); const githubToken = core.getInput("GITHUB_TOKEN"); - if (!number) { - core.setFailed("This action only works for pull_request"); + if (isNaN(number)) { + core.setFailed("not found pull request number"); return; } if (!body || !githubToken) { diff --git a/src/main.ts b/src/main.ts index 7e6d160..94b8ef5 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,11 +4,12 @@ import { findPreviousComment, createComment, updateComment } from "./comment"; async function run() { try { const repo = context.repo; - const number = context?.payload?.pull_request?.number; + const number = + context?.payload?.pull_request?.number || +core.getInput("number"); const body = core.getInput("message"); const githubToken = core.getInput("GITHUB_TOKEN"); - if (!number) { - core.setFailed("This action only works for pull_request"); + if (isNaN(number)) { + core.setFailed("not found pull request number"); return; } if (!body || !githubToken) {