Skip to content
Draft
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 14 additions & 0 deletions src/label.ts
Original file line number Diff line number Diff line change
@@ -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}`
}
]
})
}
26 changes: 21 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
try {
Expand Down Expand Up @@ -67,6 +74,18 @@ async function run(): Promise<void> {
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))
Expand All @@ -85,9 +104,6 @@ async function run(): Promise<void> {
async function receiveCommits(): Promise<String[]> {
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')
Expand All @@ -100,8 +116,8 @@ async function receiveCommits(): Promise<String[]> {
// 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
})

Expand Down