Skip to content

Commit

Permalink
Merge pull request #16 from marocchino/14
Browse files Browse the repository at this point in the history
feat: can receive number as input
  • Loading branch information
marocchino authored Dec 18, 2019
2 parents 3aea117 + 6ecc72b commit 074e780
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/comment_on_push.yml
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
6 changes: 3 additions & 3 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 4 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 074e780

Please sign in to comment.