diff --git a/action.yml b/action.yml index 4b1963b..07c2409 100644 --- a/action.yml +++ b/action.yml @@ -4,6 +4,10 @@ description: | See: https://conventionalcommits.org/ author: "taskmedia" inputs: + label: + default: "false" + description: "indicate if semVer labels should be added to the PR" + required: false token: default: "${{ github.token }}" description: "token to access GitHub API to receive PR commits" diff --git a/src/label.ts b/src/label.ts new file mode 100644 index 0000000..2f92be3 --- /dev/null +++ b/src/label.ts @@ -0,0 +1,14 @@ +import {octokit, owner, repo} from './main' + +export function addLabels(versionType: string): void { + octokit.rest.issues.addLabels({ + owner, + repo, + issue_number: 1, + labels: [ + { + name: `${versionType}` + } + ] + }) +} diff --git a/src/main.ts b/src/main.ts index 88d8a44..d189562 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,13 @@ import * as github from '@actions/github' import * as core from '@actions/core' import * as cc from './conventionalcommit' +import {addLabels} from './label' + +const gh_token = core.getInput('token') +export const octokit = github.getOctokit(gh_token) + +export const owner = github.context.repo.owner +export const repo = github.context.repo.repo async function run(): Promise { try { @@ -67,6 +74,18 @@ async function run(): Promise { commits.push(commit) } + const isLabel = core.getInput('label') + if (isLabel) { + if (!github.context.payload.pull_request) { + core.info( + `🔖 action was not triggered from pull request - skipping labeling` + ) + } + + core.info(`🔖 labeling semVer to pull request`) + addLabels(versionType) + } + core.setOutput('breaking_commit', hasBreakingCommit) core.setOutput('breaking_msg', breaking_msg) core.setOutput('commits', JSON.stringify(commits)) @@ -85,9 +104,6 @@ async function run(): Promise { async function receiveCommits(): Promise { const commits: String[] = [] - const gh_token = core.getInput('token') - const octokit = github.getOctokit(gh_token) - // Extract commits from push event if (github.context.payload.commits != null) { core.debug('Extracting commits from push event') @@ -100,8 +116,8 @@ async function receiveCommits(): Promise { // Extract commits from pull request core.debug('Extracting commits from pull request') const {data: commit_list} = await octokit.rest.pulls.listCommits({ - owner: github.context.repo.owner, - repo: github.context.repo.repo, + owner, + repo, pull_number: github.context.issue.number })