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

PR Enhancements #8

Merged
merged 3 commits into from
Mar 15, 2023
Merged
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ This Action is customizable so you can use it for your own purposes and it doesn
| ---- | ----------- | ------- | -------- |
| `github_token` | GitHub token to use for authentication within this Action | `${{ github.token }}` | `true` |
| `branch_prefix` | Prefix for the branch name to use for the combined PR | `dependabot` | `true` |
| `pr_title` | The title of the pull request to create | `Combined PRs` | `true` |
| `pr_body_header` | The header of the pull request body | `# Combined PRs ➡️📦⬅️` | `true` |
| `branch_regex` | The regex to match the branches to combine - more control than branch_prefix | `""` | `false` |
| `ci_required` | Whether or not CI should be passing to combine the PR - can be `"true"` or `"false"` | `"true"` | `true` |
| `review_required` | Whether or not reviews should be passing to combine the PR - can be `"true"` or `"false"` | `"false"` | `false` |
Expand Down
6 changes: 4 additions & 2 deletions __tests__/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ beforeEach(() => {
jest.spyOn(core, 'error').mockImplementation(() => {})
process.env.INPUT_GITHUB_TOKEN = 'faketoken'
process.env.INPUT_CI_REQUIRED = 'true'
process.env.INPUT_PR_TITLE = 'Combined PRs'
process.env.INPUT_PR_BODY_HEADER = '# Combined PRs ➡️📦⬅️'
process.env.INPUT_REVIEW_REQUIRED = 'false'
process.env.INPUT_COMBINE_BRANCH_NAME = 'combined-prs-branch'
process.env.INPUT_BRANCH_PREFIX = 'dependabot'
Expand Down Expand Up @@ -339,7 +341,7 @@ test('successfully runs the action', async () => {
expect(infoMock).toHaveBeenCalledWith('Merged branch dependabot-5')
expect(infoMock).toHaveBeenCalledWith('Creating combined PR')
expect(debugMock).toHaveBeenCalledWith(
'PR body: ✅ This PR was created by the Combine PRs action by combining the following PRs:\n#1 Update dependency 1\n#5 Update dependency 5\n\n⚠️ The following PRs were left out due to merge conflicts:\n#2 Update dependency 2'
'PR body: # Combined PRs ➡️📦⬅️\n\n✅ The following pull requests have been successfully combined on this PR:\n- #1 Update dependency 1\n- #5 Update dependency 5\n\n⚠️ The following PRs were left out due to merge conflicts:\n- #2 Update dependency 2\n\n> This PR was created by the [`github/combine-prs`](https://github.com/github/combine-prs) action'
)
expect(infoMock).toHaveBeenCalledWith(
'Combined PR created: https://github.com/test-owner/test-repo/pull/100'
Expand Down Expand Up @@ -408,7 +410,7 @@ test('successfully runs the action with the branch_regex option', async () => {
expect(infoMock).toHaveBeenCalledWith('Merged branch dependabot-5')
expect(infoMock).toHaveBeenCalledWith('Creating combined PR')
expect(debugMock).toHaveBeenCalledWith(
'PR body: ✅ This PR was created by the Combine PRs action by combining the following PRs:\n#1 Update dependency 1\n#5 Update dependency 5\n\n⚠️ The following PRs were left out due to merge conflicts:\n#2 Update dependency 2'
'PR body: # Combined PRs ➡️📦⬅️\n\n✅ The following pull requests have been successfully combined on this PR:\n- #1 Update dependency 1\n- #5 Update dependency 5\n\n⚠️ The following PRs were left out due to merge conflicts:\n- #2 Update dependency 2\n\n> This PR was created by the [`github/combine-prs`](https://github.com/github/combine-prs) action'
)
expect(infoMock).toHaveBeenCalledWith(
'Combined PR created: https://github.com/test-owner/test-repo/pull/100'
Expand Down
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ inputs:
description: The prefix of the branches to combine
required: true
default: dependabot
pr_title:
description: The title of the pull request to create
required: true
default: "Combined PRs"
pr_body_header:
description: The header of the pull request body
required: true
default: "# Combined PRs ➡️📦⬅️"
branch_regex:
description: The regex to match the branches to combine - more control than branch_prefix
required: false
Expand Down
17 changes: 11 additions & 6 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.

17 changes: 11 additions & 6 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import * as core from '@actions/core'
import * as github from '@actions/github'
import {context} from '@actions/github'

const repoName = 'github/combine-prs'
const repoUrl = 'https://github.com/github/combine-prs'

export async function run() {
// Get configuration inputs
const branchPrefix = core.getInput('branch_prefix')
Expand All @@ -11,6 +14,8 @@ export async function run() {
const combineBranchName = core.getInput('combine_branch_name')
const ignoreLabel = core.getInput('ignore_label')
const token = core.getInput('github_token', {required: true})
const prTitle = core.getInput('pr_title', {required: true})
const prBodyHeader = core.getInput('pr_body_header', {required: true})

// check for either prefix or regex
if (branchPrefix === '' && branchRegex === '') {
Expand Down Expand Up @@ -175,23 +180,23 @@ export async function run() {

// Create a new PR with the combined branch
core.info('Creating combined PR')
const combinedPRsString = combinedPRs.join('\n')
let body =
'✅ This PR was created by the Combine PRs action by combining the following PRs:\n' +
combinedPRsString
const combinedPRsString = `- ${combinedPRs.join('\n- ')}`
let body = `${prBodyHeader}\n\n✅ The following pull requests have been successfully combined on this PR:\n${combinedPRsString}`
if (mergeFailedPRs.length > 0) {
const mergeFailedPRsString = mergeFailedPRs.join('\n')
const mergeFailedPRsString = `- ${mergeFailedPRs.join('\n- ')}`
body +=
'\n\n⚠️ The following PRs were left out due to merge conflicts:\n' +
mergeFailedPRsString
}

body += `\n\n> This PR was created by the [\`${repoName}\`](${repoUrl}) action`

core.debug('PR body: ' + body)

const pullRequest = await octokit.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: 'Combined PR',
title: prTitle,
head: combineBranchName,
base: baseBranch,
body: body
Expand Down