Skip to content

Commit

Permalink
✨ Add label to PR [skip-ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
BetaHuhn committed Jan 29, 2021
1 parent 8d02dfe commit 789ec9f
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 6 deletions.
33 changes: 30 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25448,6 +25448,9 @@ const getVar = ({ key, default: dft, required = false, type = 'string' }) => {
envVar = process.env[key]
}

if (key === 'PR_LABELS' && (coreVar === false || envVar === 'false'))
return undefined

if (coreVar !== undefined && coreVar.length >= 1) {
if (type === 'array') return coreVar.split('\n')

Expand Down Expand Up @@ -25500,6 +25503,11 @@ const context = {
type: 'boolean',
default: true
}),
PR_LABELS: getVar({
key: 'PR_LABELS',
default: [ 'deployed' ],
type: 'array'
}),
VERCEL_SCOPE: getVar({
key: 'VERCEL_SCOPE'
}),
Expand Down Expand Up @@ -25564,7 +25572,8 @@ const {
PRODUCTION,
PR_NUMBER,
REF,
LOG_URL
LOG_URL,
PR_LABELS
} = __nccwpck_require__(4570)

const init = () => {
Expand Down Expand Up @@ -25629,11 +25638,23 @@ const init = () => {
return comment.data
}

const addLabel = async () => {
const label = await client.issues.addLabels({
owner: USER,
repo: REPOSITORY,
issue_number: PR_NUMBER,
labels: PR_LABELS
})

return label.data
}

return {
client,
createDeployment,
updateDeployment,
createComment
createComment,
addLabel
}
}

Expand Down Expand Up @@ -25703,7 +25724,8 @@ const vercel = __nccwpck_require__(847)

const {
GITHUB_DEPLOYMENT,
IS_PR
IS_PR,
PR_LABELS
} = __nccwpck_require__(4570)

const run = async () => {
Expand Down Expand Up @@ -25737,6 +25759,11 @@ const run = async () => {
log.info(`Created comment on PR: ${ comment.html_url }`)
}

if (IS_PR && PR_LABELS) {
const labels = await github.addLabel()
log.info(`Added label(s) ${ labels.map((label) => label.name).join(', ') } to PR`)
}

// Set Action output
core.setOutput('PREVIEW_URL', previewUrl)
core.setOutput('DEPLOYMENT_CREATED', GITHUB_DEPLOYMENT)
Expand Down
8 changes: 8 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ const getVar = ({ key, default: dft, required = false, type = 'string' }) => {
envVar = process.env[key]
}

if (key === 'PR_LABELS' && (coreVar === false || envVar === 'false'))
return undefined

if (coreVar !== undefined && coreVar.length >= 1) {
if (type === 'array') return coreVar.split('\n')

Expand Down Expand Up @@ -77,6 +80,11 @@ const context = {
type: 'boolean',
default: true
}),
PR_LABELS: getVar({
key: 'PR_LABELS',
default: [ 'deployed' ],
type: 'array'
}),
VERCEL_SCOPE: getVar({
key: 'VERCEL_SCOPE'
}),
Expand Down
17 changes: 15 additions & 2 deletions src/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const {
PRODUCTION,
PR_NUMBER,
REF,
LOG_URL
LOG_URL,
PR_LABELS
} = require('./config')

const init = () => {
Expand Down Expand Up @@ -74,11 +75,23 @@ const init = () => {
return comment.data
}

const addLabel = async () => {
const label = await client.issues.addLabels({
owner: USER,
repo: REPOSITORY,
issue_number: PR_NUMBER,
labels: PR_LABELS
})

return label.data
}

return {
client,
createDeployment,
updateDeployment,
createComment
createComment,
addLabel
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const vercel = require('./vercel')

const {
GITHUB_DEPLOYMENT,
IS_PR
IS_PR,
PR_LABELS
} = require('./config')

const run = async () => {
Expand Down Expand Up @@ -46,6 +47,11 @@ const run = async () => {
log.info(`Created comment on PR: ${ comment.html_url }`)
}

if (IS_PR && PR_LABELS) {
const labels = await github.addLabel()
log.info(`Added label(s) ${ labels.map((label) => label.name).join(', ') } to PR`)
}

// Set Action output
core.setOutput('PREVIEW_URL', previewUrl)
core.setOutput('DEPLOYMENT_CREATED', GITHUB_DEPLOYMENT)
Expand Down

0 comments on commit 789ec9f

Please sign in to comment.