Skip to content

Commit

Permalink
Merge pull request #10 from radtriste/issue_9
Browse files Browse the repository at this point in the history
Allow to update title/body and option for labels inheritance
  • Loading branch information
carloscastrojumo authored Sep 20, 2022
2 parents 6c01602 + cce8758 commit bb0869d
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 29 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,7 @@ Thumbs.db

# Ignore built ts files
__tests__/runner/*
lib/**/*
lib/**/*

# VSCode files
.vscode
10 changes: 10 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,19 @@ inputs:
branch:
description: "Name of the branch to merge the cherry pick"
required: true
title:
description: "Override the default generated PR title"
required: false
body:
description: "Override the default generated PR body"
required: false
labels:
description: "A comma or newline separated list of labels."
required: false
inherit_labels:
description: "Set to false if you want to inherit labels from parent PR"
required: false
default: "true"
assignees:
description: "A comma or newline separated list of assignees (GitHub usernames)."
required: false
Expand Down
49 changes: 37 additions & 12 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

43 changes: 28 additions & 15 deletions src/github-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ export interface Inputs {
committer: string
author: string
branch: string
title?: string
body?: string
labels: string[]
inherit_labels?: boolean
assignees: string[]
reviewers: string[]
teamReviewers: string[]
Expand All @@ -24,17 +27,25 @@ export async function createPullRequest(
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/')

// Get PR title
const title =
github.context.payload &&
github.context.payload.pull_request &&
github.context.payload.pull_request.title
core.info(`Using body '${title}'`)
core.info(`Input title is '${inputs.title}'`)
let title = inputs.title
if (title === undefined || title === '') {
title =
github.context.payload &&
github.context.payload.pull_request &&
github.context.payload.pull_request.title
}
core.info(`Using title '${title}'`)

// Get PR body
const body =
github.context.payload &&
github.context.payload.pull_request &&
github.context.payload.pull_request.body
core.info(`Input body is '${inputs.body}'`)
let body = inputs.body
if (body === undefined || body === '') {
body =
github.context.payload &&
github.context.payload.pull_request &&
github.context.payload.pull_request.body
}
core.info(`Using body '${body}'`)

// Create PR
Expand All @@ -48,26 +59,28 @@ export async function createPullRequest(
})

// Apply labels
if (inputs.labels.length > 0) {
const appliedLabels = inputs.labels

if (inputs.inherit_labels) {
const prLabels =
github.context.payload &&
github.context.payload.pull_request &&
github.context.payload.pull_request.labels

if (prLabels) {
for (const item of prLabels) {
if (item.name !== inputs.branch) {
inputs.labels.push(item.name)
appliedLabels.push(item.name)
}
}
}

core.info(`Applying labels '${inputs.labels}'`)
}
if (appliedLabels.length > 0) {
core.info(`Applying labels '${appliedLabels}'`)
await octokit.issues.addLabels({
owner,
repo,
issue_number: pull.data.number,
labels: inputs.labels
labels: appliedLabels
})
}

Expand Down
3 changes: 3 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ export async function run(): Promise<void> {
committer: core.getInput('committer'),
author: core.getInput('author'),
branch: core.getInput('branch'),
title: core.getInput('title'),
body: core.getInput('body'),
labels: utils.getInputAsArray('labels'),
inherit_labels: utils.getInputAsBoolean('inherit_labels'),
assignees: utils.getInputAsArray('assignees'),
reviewers: utils.getInputAsArray('reviewers'),
teamReviewers: utils.getInputAsArray('teamReviewers')
Expand Down
11 changes: 11 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ export function getInputAsArray(
return getStringAsArray(core.getInput(name, options))
}

export function getInputAsBoolean(
name: string,
options?: core.InputOptions
): boolean | undefined {
try {
return JSON.parse(core.getInput(name, options))
} catch (e) {
return undefined
}
}

export function getStringAsArray(str: string): string[] {
return str
.split(/[\n,]+/)
Expand Down

0 comments on commit bb0869d

Please sign in to comment.