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

ENH: Support optional separators between prefixes #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ inputs:
description: 'The path for the label configurations'
default: '.github/pr-prefix-labeler.yml'
required: false
prefix-title-separator:
description: 'Separator between the prefixes and the title'
default: ':'
required: true
separator-between-prefixes:
description: 'Separator between prefixes'
default: '/'
required: false
runs:
using: 'node12'
main: 'index.js'
20 changes: 13 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,16 @@ async function run() {
"Payload doesn't contain `pull_request`. Make sure this Action is being triggered by a pull_request event (https://help.github.com/en/articles/events-that-trigger-workflows#pull-request-event-pull_request)."
)
}
const title = github.context.payload.pull_request.title

const title = github.context.payload.pull_request.title.split(":", 1)[0]
core.info(title)

const prefixTitleSeparator = core.getInput('prefix-title-separator')
const separatorBetweenPrefixes = core.getInput('separator-between-prefixes');
const prefixes = title.split(prefixTitleSeparator, 0)[0].split(separatorBetweenPrefixes)

core.info(prefixes)

let prefix_map = {
"API": "api",
"BENCH": "bench",
Expand Down Expand Up @@ -45,11 +52,10 @@ async function run() {
}
core.info(prefix_map)

let label = [];
for (const [key, value ] of Object.entries(prefix_map)) {
if (title.startsWith(key)) {
label.push(value)
break
let labels = [];
for (let prefix in prefixes) {
if (prefix in prefix_map) {
labels.push(prefix)
}
}

Expand All @@ -58,7 +64,7 @@ async function run() {
owner: github.context.repo.owner,
repo: github.context.repo.repo,
issue_number: github.context.payload.pull_request.number,
labels: label
labels: labels
})
}
}
Expand Down