Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: github comment optional #20

Merged
merged 6 commits into from
Jan 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -14,4 +14,5 @@ jobs:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
zeit-token: ${{ secrets.ZEIT_TOKEN }}
github-comment: false
#ZEIT_TEAMID: amond
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -24,15 +24,19 @@ This action make a ZEIT Now deployment with github actions.

### `zeit-team-id`

This is required if your deployment is made on team project. example: `team_asdf1234`
**optional** This is required if your deployment is made on team project and `github-comment` is true. example: `team_asdf1234`

### `github-comment`

**optional** This is required if you don't want to comment on pull request. default: true

### `github-token`

**required** This is required to comment on pull request.
**optional** This is required if you want to comment on pull request.

### `now-args`

This is optional args for `now` cli. Example: `--prod`
**optional** This is optional args for `now` cli. Example: `--prod`

## Outputs

@@ -72,10 +76,10 @@ jobs:
- uses: actions/checkout@v1
- uses: amondnet/now-deployment@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
zeit-token: ${{ secrets.ZEIT_TOKEN }}
zeit-team-id: team_XXXXXXXXXXX
now-args: '--prod'
zeit-token: ${{ secrets.ZEIT_TOKEN }} # Required
github-token: ${{ secrets.GITHUB_TOKEN }} #Optional
zeit-team-id: team_XXXXXXXXXXX #Optional
now-args: '--prod' #Optional
```
8 changes: 6 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
@@ -11,9 +11,13 @@ inputs:
description: ''
required: false
default: ''

github-comment:
required: false
default: 'true'
description: 'if you want to comment on pr and commit, set true, default: true'
github-token:
required: true
required: false
description: 'if you want to comment on pr and commit, set token'
github-deployment:
required: false
default: 'false'
35 changes: 25 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
@@ -11,7 +11,8 @@ const zeitToken = core.getInput('zeit-token')
const zeitTeamId = core.getInput('zeit-team-id')
const nowArgs = core.getInput('now-args')
const githubToken = core.getInput('github-token')
const githubDeployment = core.getInput('github-deployment')
const githubComment = core.getInput('github-comment') === 'true'
const githubDeployment = core.getInput('github-deployment') === 'true'
const workingDirectory = core.getInput('working-directory')

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

const octokit = new github.GitHub(githubToken)
let octokit
if ( githubToken ) {
octokit = new github.GitHub(githubToken)
}

async function run () {
await nowDeploy()
if (context.issue.number) {
core.info('this is related issue or pull_request ')
await createCommentOnPullRequest()
} else if (context.eventName === 'push') {
core.info('this is push event')
await createCommentOnCommit()
if ( githubComment && githubToken ) {
if (context.issue.number) {
core.info('this is related issue or pull_request ')
await createCommentOnPullRequest()
} else if (context.eventName === 'push') {
core.info('this is push event')
await createCommentOnCommit()
}
} else {
core.info('comment : disabled')
}
}

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

async function listCommentsForCommit() {
if (!octokit) {
return;
}
const {
data: comments,
} = await octokit.repos.listCommentsForCommit({
@@ -90,7 +101,9 @@ async function listCommentsForCommit() {
}

async function createCommentOnCommit () {

if (!octokit) {
return;
}
const {
data: comments,
} = await octokit.repos.listCommentsForCommit({
@@ -170,7 +183,9 @@ async function createCommentOnCommit () {
}

async function createCommentOnPullRequest () {

if (!octokit) {
return;
}
const {
data: comments,
} = await octokit.issues.listComments({
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
{
"name": "now-deployment",
"private": true,
"repository": {
"type": "git",
"url": "https://github.com/amondnet/now-deployment"
},
"author": {
"name": "Minsu Lee",
"email": "[email protected]",
"url": "https://amond.dev"
},
"version": "1.1.0",
"main": "index.js",
"scripts": {
"start": "node ./index.js"