Skip to content

Commit

Permalink
chore: build dist conventional-release-labels (#12)
Browse files Browse the repository at this point in the history
Co-authored-by: actions-bot <github-actions-bot@google.com>
  • Loading branch information
1 parent bf65853 commit b21e2be
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ const { readFile } = fs.promises
const { parser } = __nccwpck_require__(4523)

const api = module.exports = {
addLabel,
addLabels,
isPullRequest,
main
main,
removeLabels
}

async function main () {
const { visit } = await __nccwpck_require__.e(/* import() */ 946).then(__nccwpck_require__.bind(__nccwpck_require__, 7946))
const labelMap = JSON.parse(core.getInput('type_labels'))
if (!process.env.GITHUB_EVENT_PATH) {
console.warn('no event payload found')
return
Expand All @@ -28,7 +30,13 @@ async function main () {
if (!api.isPullRequest(payload)) {
console.info('skipping non pull_request')
}
const titleAst = parser(payload.pull_request.title)
let titleAst
try {
titleAst = parser(payload.pull_request.title)
} catch (err) {
console.warn(err.message)
return
}
const cc = {
breaking: false
}
Expand All @@ -49,22 +57,36 @@ async function main () {
}
})

if (cc.type === 'feat') {
await api.addLabel(cc.type, payload)
const labels = []
if (cc.breaking) labels.push(labelMap.breaking)
if (labelMap[cc.type]) labels.push(labelMap[cc.type])
if (labels.length) {
await api.removeLabels(Object.values(labelMap), payload)
await api.addLabels(labels, payload)
}
}

function isPullRequest (payload) {
return !!payload.pull_request
}

async function addLabel (type, payload) {
async function addLabels (labels, payload) {
const octokit = getOctokit()
await octokit.rest.issues.addLabels({
owner: payload.repository.owner.login,
repo: payload.repository.name,
issue_number: payload.pull_request.number,
labels: ['feature']
labels
})
}

async function removeLabels (labels, payload) {
const octokit = getOctokit()
await octokit.rest.issues.removeLabels({
owner: payload.repository.owner.login,
repo: payload.repository.name,
issue_number: payload.pull_request.number,
labels
})
}

Expand Down

0 comments on commit b21e2be

Please sign in to comment.