Skip to content

Commit

Permalink
add more options
Browse files Browse the repository at this point in the history
  • Loading branch information
thatkookooguy committed Nov 25, 2021
1 parent 0ae8de7 commit 74ac9a3
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 12 deletions.
8 changes: 7 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@ branding:
inputs:
token: # change this
required: true
description: 'github token'
description: github token to run the action against
hotfixAgainstBranch:
required: true
description: 1st branch (usually master\main)
openPrAgainstBranch:
required: true
description: 2nd branch (usually develop)
labels:
required: false
description: comma separated list of labels to add to the PR
titlePrefix:
required: false
description: title prefix (default is [AUTO])
runs:
using: 'node12'
main: 'dist/index.js'
26 changes: 21 additions & 5 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.

37 changes: 32 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,20 @@ async function run(): Promise<void> {
const githubToken = core.getInput('token')
const hotfixAgainstBranch = core.getInput('hotfixAgainstBranch')
const openPrAgainstBranch = core.getInput('openPrAgainstBranch')
await openPRIfHotfix(githubToken, hotfixAgainstBranch, openPrAgainstBranch)
const labelsInputString = core.getInput('labels') || ''
const labels = (
labelsInputString
? labelsInputString.split(',')
: ['auto-created', 'hotfix']
).map(label => label.trim())
const titlePrefix = core.getInput('titlePrefix') || '[AUTO]'
await openPRIfHotfix(
githubToken,
hotfixAgainstBranch,
openPrAgainstBranch,
titlePrefix,
labels
)
} catch (error) {
if (error instanceof Error) core.setFailed(error.message)
}
Expand All @@ -17,7 +30,9 @@ async function run(): Promise<void> {
async function openPRIfHotfix(
githubToken: string,
hotfixAgainstBranch: string,
openPrAgainstBranch: string
openPrAgainstBranch: string,
titlePrefix: string,
labels: string[]
): Promise<void> {
const pullRequest = context.payload.pull_request

Expand Down Expand Up @@ -49,19 +64,31 @@ async function openPRIfHotfix(
const isPrAlreadyExists = isPrAlreadyExistsCall.data

if (isPrAlreadyExists.length === 1) {
core.info(`ONE PR exists for ${branch}. Creating the second one...`)
core.info(
`ONE PR exists for ${branch}. Creating the second one against ${openPrAgainstBranch}`
)
// only one exists, this should be the right one!
const existingPR = isPrAlreadyExists[0]
const createdPR = await octokit.rest.pulls.create({
const createdPRCall = await octokit.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
head: branch,
base: openPrAgainstBranch,
title: `[AUTO]${existingPR.title}`,
title: `${titlePrefix} ${existingPR.title}`,
body: existingPR.body as string
})
const createdPR = createdPRCall.data
await octokit.rest.issues.addLabels({
owner: context.repo.owner,
issue_number: createdPR.number,
repo: context.repo.repo,
labels
})

core.info(JSON.stringify(createdPR, null, 2))
core.info(`${createdPR.head.ref} was created`)
} else {
core.info('More than 1 PR already exists. doing nothing...')
}

core.setOutput('branch', branch)
Expand Down

0 comments on commit 74ac9a3

Please sign in to comment.