Skip to content

Commit

Permalink
Merge pull request #59 from marijoo/assignees
Browse files Browse the repository at this point in the history
Add `assignees` Feature
  • Loading branch information
GrantBirki authored Oct 10, 2024
2 parents 20d70f9 + 21c8b7f commit e7a7e23
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ As mentioned above is this README, a core reason why this Action exists is to "c
| `ignore_label` | The label to ignore when combining PRs | `"nocombine"` | `true` |
| `select_label` | The label which marks PRs that should be combined. Leave empty to consider all PRs. | `""` | `false` |
| `labels` | A comma separated list of labels to add to the combined PR - Example: `dependencies,combined-pr,etc` | `""` | `false` |
| `assignees` | A comma separated list of assignees the combined PR is assigned to - Example: `octocat` | `""` | `false` |
| `autoclose` | Whether or not to close combined PRs if the combined PR is merged - can be `"true"` or `"false"` | `"true"` | `false` |
| `update_branch` | Whether or not to update the combined branch with the latest changes from the base branch after creating the combined pull request | `"true"` | `false` |
| `create_from_scratch` | Whether or not to start from a clean base branch when (re)creating the combined PR | `"false"` | `false` |
Expand Down
83 changes: 83 additions & 0 deletions __tests__/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ beforeEach(() => {
process.env.GITHUB_REPOSITORY = 'test-owner/test-repo'
process.env.INPUT_MIN_COMBINE_NUMBER = '2'
process.env.INPUT_LABELS = ''
process.env.INPUT_ASSIGNEES = ''
process.env.INPUT_AUTOCLOSE = 'true'
process.env.INPUT_UPDATE_BRANCH = 'true'
process.env.INPUT_CREATE_FROM_SCRATCH = 'false'
Expand Down Expand Up @@ -1773,6 +1774,88 @@ test('runs the action and fails to create a working branch', async () => {
expect(setFailedMock).toHaveBeenCalledWith('Failed to create working branch')
})

test('successfully runs the action and sets assignees', async () => {
jest.spyOn(github, 'getOctokit').mockImplementation(() => {
return {
paginate: jest.fn().mockImplementation(() => {
return [
buildPR(1, 'dependabot-1', ['question']),
buildPR(2, 'dependabot-2')
]
}),
graphql: jest.fn().mockImplementation((_query, params) => {
switch (params.pull_number) {
case 1:
case 2:
case 3:
return buildStatusResponse('APPROVED', 'SUCCESS')
case 4:
return buildStatusResponse('APPROVED', 'FAILURE')
case 5:
return buildStatusResponse(null, 'SUCCESS')
case 6:
return buildStatusResponse('REVIEW_REQUIRED', 'SUCCESS')
default:
throw new Error(
`params.pull_number of ${params.pull_number} is not configured.`
)
}
}),
rest: {
issues: {
addAssignees: jest.fn().mockReturnValueOnce({
data: {}
}),
addLabels: jest.fn().mockReturnValueOnce({
data: {}
})
},
git: {
createRef: jest.fn().mockReturnValueOnce({
data: {}
}),
updateRef: jest.fn().mockReturnValueOnce({
data: {}
}),
getRef: jest.fn().mockReturnValueOnce({
data: {
object: {
sha: randomSha1()
}
}
})
},
repos: {
// mock the first value of merge to be a success and the second to be an exception
merge: jest.fn().mockReturnValueOnce({
data: {
merged: true
}
})
},
pulls: {
create: jest.fn().mockReturnValueOnce({
data: {
number: 100,
html_url: 'https://github.com/test-owner/test-repo/pull/100'
}
})
}
}
}
})

process.env.INPUT_REVIEW_REQUIRED = 'true'
process.env.INPUT_ASSIGNEES = 'octocat ,another-user, kolossal'
expect(await run()).toBe('success')

expect(infoMock).toHaveBeenCalledWith(
`Adding assignees to combined PR: octocat,another-user,kolossal`
)

expect(setOutputMock).toHaveBeenCalledWith('pr_number', 100)
})

function buildStatusResponse(reviewDecision, ciStatus) {
return {
repository: {
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ inputs:
description: A comma seperated list of labels to add to the combined PR
required: false
default: ""
assignees:
description: A comma seperated list of assignees to add to the combined PR
required: false
default: ""
autoclose:
description: Whether or not to close combined PRs if the combined PR is merged
required: false
Expand Down
17 changes: 17 additions & 0 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: 17 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export async function run() {
const ignoreLabel = core.getInput('ignore_label')
const selectLabel = core.getInput('select_label')
const labels = core.getInput('labels').trim()
const assignees = core.getInput('assignees').trim()
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})
Expand Down Expand Up @@ -295,6 +296,22 @@ export async function run() {
}
}

if (assignees !== '') {
// split and trim assignees
const assigneesArray = assignees.split(',').map(label => label.trim())

// add assignees to the combined PR if specified
if (assigneesArray.length > 0) {
core.info(`Adding assignees to combined PR: ${assigneesArray}`)
await octokit.rest.issues.addAssignees({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pullRequest.data.number,
assignees: assigneesArray
})
}
}

// lastly, if the pull request's branch can be updated cleanly, update it
if (updateBranch === true) {
core.info('Attempting to update branch')
Expand Down

0 comments on commit e7a7e23

Please sign in to comment.