Skip to content

Commit 0fd9718

Browse files
authoredJan 28, 2020
feat: github comment optional (#20)
* feat: github comment optional
1 parent c334a92 commit 0fd9718

File tree

5 files changed

+53
-19
lines changed

5 files changed

+53
-19
lines changed
 

‎.github/workflows/deploy.yml

+1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ jobs:
1414
with:
1515
github-token: ${{ secrets.GITHUB_TOKEN }}
1616
zeit-token: ${{ secrets.ZEIT_TOKEN }}
17+
github-comment: false
1718
#ZEIT_TEAMID: amond

‎README.md

+11-7
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,19 @@ This action make a ZEIT Now deployment with github actions.
2424

2525
### `zeit-team-id`
2626

27-
This is required if your deployment is made on team project. example: `team_asdf1234`
27+
**optional** This is required if your deployment is made on team project and `github-comment` is true. example: `team_asdf1234`
28+
29+
### `github-comment`
30+
31+
**optional** This is required if you don't want to comment on pull request. default: true
2832

2933
### `github-token`
3034

31-
**required** This is required to comment on pull request.
35+
**optional** This is required if you want to comment on pull request.
3236

3337
### `now-args`
3438

35-
This is optional args for `now` cli. Example: `--prod`
39+
**optional** This is optional args for `now` cli. Example: `--prod`
3640

3741
## Outputs
3842

@@ -72,10 +76,10 @@ jobs:
7276
- uses: actions/checkout@v1
7377
- uses: amondnet/now-deployment@v1
7478
with:
75-
github-token: ${{ secrets.GITHUB_TOKEN }}
76-
zeit-token: ${{ secrets.ZEIT_TOKEN }}
77-
zeit-team-id: team_XXXXXXXXXXX
78-
now-args: '--prod'
79+
zeit-token: ${{ secrets.ZEIT_TOKEN }} # Required
80+
github-token: ${{ secrets.GITHUB_TOKEN }} #Optional
81+
zeit-team-id: team_XXXXXXXXXXX #Optional
82+
now-args: '--prod' #Optional
7983
```
8084
8185

‎action.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@ inputs:
1111
description: ''
1212
required: false
1313
default: ''
14-
14+
github-comment:
15+
required: false
16+
default: 'true'
17+
description: 'if you want to comment on pr and commit, set true, default: true'
1518
github-token:
16-
required: true
19+
required: false
20+
description: 'if you want to comment on pr and commit, set token'
1721
github-deployment:
1822
required: false
1923
default: 'false'

‎index.js

+25-10
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ const zeitToken = core.getInput('zeit-token')
1111
const zeitTeamId = core.getInput('zeit-team-id')
1212
const nowArgs = core.getInput('now-args')
1313
const githubToken = core.getInput('github-token')
14-
const githubDeployment = core.getInput('github-deployment')
14+
const githubComment = core.getInput('github-comment') === 'true'
15+
const githubDeployment = core.getInput('github-deployment') === 'true'
1516
const workingDirectory = core.getInput('working-directory')
1617

1718
const zeitAPIClient = axios.create({
@@ -22,16 +23,23 @@ const zeitAPIClient = axios.create({
2223
},
2324
})
2425

25-
const octokit = new github.GitHub(githubToken)
26+
let octokit
27+
if ( githubToken ) {
28+
octokit = new github.GitHub(githubToken)
29+
}
2630

2731
async function run () {
2832
await nowDeploy()
29-
if (context.issue.number) {
30-
core.info('this is related issue or pull_request ')
31-
await createCommentOnPullRequest()
32-
} else if (context.eventName === 'push') {
33-
core.info('this is push event')
34-
await createCommentOnCommit()
33+
if ( githubComment && githubToken ) {
34+
if (context.issue.number) {
35+
core.info('this is related issue or pull_request ')
36+
await createCommentOnPullRequest()
37+
} else if (context.eventName === 'push') {
38+
core.info('this is push event')
39+
await createCommentOnCommit()
40+
}
41+
} else {
42+
core.info('comment : disabled')
3543
}
3644
}
3745

@@ -81,6 +89,9 @@ async function nowDeploy () {
8189
}
8290

8391
async function listCommentsForCommit() {
92+
if (!octokit) {
93+
return;
94+
}
8495
const {
8596
data: comments,
8697
} = await octokit.repos.listCommentsForCommit({
@@ -90,7 +101,9 @@ async function listCommentsForCommit() {
90101
}
91102

92103
async function createCommentOnCommit () {
93-
104+
if (!octokit) {
105+
return;
106+
}
94107
const {
95108
data: comments,
96109
} = await octokit.repos.listCommentsForCommit({
@@ -170,7 +183,9 @@ async function createCommentOnCommit () {
170183
}
171184

172185
async function createCommentOnPullRequest () {
173-
186+
if (!octokit) {
187+
return;
188+
}
174189
const {
175190
data: comments,
176191
} = await octokit.issues.listComments({

‎package.json

+10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
{
22
"name": "now-deployment",
33
"private": true,
4+
"repository": {
5+
"type": "git",
6+
"url": "https://github.com/amondnet/now-deployment"
7+
},
8+
"author": {
9+
"name": "Minsu Lee",
10+
"email": "amond@amond.net",
11+
"url": "https://amond.dev"
12+
},
13+
"version": "1.1.0",
414
"main": "index.js",
515
"scripts": {
616
"start": "node ./index.js"

1 commit comments

Comments
 (1)

github-actions[bot] commented on Jan 28, 2020

@github-actions[bot]

Deploy preview for website ready!

Built with commit cc23202

https://zeit-now-deployment-action-4o0ygfp7x.now.sh

Please sign in to comment.