Skip to content

Commit 21c8b7f

Browse files
committed
feat: add assignees feature
1 parent 20d70f9 commit 21c8b7f

File tree

6 files changed

+123
-1
lines changed

6 files changed

+123
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ As mentioned above is this README, a core reason why this Action exists is to "c
3333
| `ignore_label` | The label to ignore when combining PRs | `"nocombine"` | `true` |
3434
| `select_label` | The label which marks PRs that should be combined. Leave empty to consider all PRs. | `""` | `false` |
3535
| `labels` | A comma separated list of labels to add to the combined PR - Example: `dependencies,combined-pr,etc` | `""` | `false` |
36+
| `assignees` | A comma separated list of assignees the combined PR is assigned to - Example: `octocat` | `""` | `false` |
3637
| `autoclose` | Whether or not to close combined PRs if the combined PR is merged - can be `"true"` or `"false"` | `"true"` | `false` |
3738
| `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` |
3839
| `create_from_scratch` | Whether or not to start from a clean base branch when (re)creating the combined PR | `"false"` | `false` |

__tests__/main.test.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ beforeEach(() => {
4949
process.env.GITHUB_REPOSITORY = 'test-owner/test-repo'
5050
process.env.INPUT_MIN_COMBINE_NUMBER = '2'
5151
process.env.INPUT_LABELS = ''
52+
process.env.INPUT_ASSIGNEES = ''
5253
process.env.INPUT_AUTOCLOSE = 'true'
5354
process.env.INPUT_UPDATE_BRANCH = 'true'
5455
process.env.INPUT_CREATE_FROM_SCRATCH = 'false'
@@ -1773,6 +1774,88 @@ test('runs the action and fails to create a working branch', async () => {
17731774
expect(setFailedMock).toHaveBeenCalledWith('Failed to create working branch')
17741775
})
17751776

1777+
test('successfully runs the action and sets assignees', async () => {
1778+
jest.spyOn(github, 'getOctokit').mockImplementation(() => {
1779+
return {
1780+
paginate: jest.fn().mockImplementation(() => {
1781+
return [
1782+
buildPR(1, 'dependabot-1', ['question']),
1783+
buildPR(2, 'dependabot-2')
1784+
]
1785+
}),
1786+
graphql: jest.fn().mockImplementation((_query, params) => {
1787+
switch (params.pull_number) {
1788+
case 1:
1789+
case 2:
1790+
case 3:
1791+
return buildStatusResponse('APPROVED', 'SUCCESS')
1792+
case 4:
1793+
return buildStatusResponse('APPROVED', 'FAILURE')
1794+
case 5:
1795+
return buildStatusResponse(null, 'SUCCESS')
1796+
case 6:
1797+
return buildStatusResponse('REVIEW_REQUIRED', 'SUCCESS')
1798+
default:
1799+
throw new Error(
1800+
`params.pull_number of ${params.pull_number} is not configured.`
1801+
)
1802+
}
1803+
}),
1804+
rest: {
1805+
issues: {
1806+
addAssignees: jest.fn().mockReturnValueOnce({
1807+
data: {}
1808+
}),
1809+
addLabels: jest.fn().mockReturnValueOnce({
1810+
data: {}
1811+
})
1812+
},
1813+
git: {
1814+
createRef: jest.fn().mockReturnValueOnce({
1815+
data: {}
1816+
}),
1817+
updateRef: jest.fn().mockReturnValueOnce({
1818+
data: {}
1819+
}),
1820+
getRef: jest.fn().mockReturnValueOnce({
1821+
data: {
1822+
object: {
1823+
sha: randomSha1()
1824+
}
1825+
}
1826+
})
1827+
},
1828+
repos: {
1829+
// mock the first value of merge to be a success and the second to be an exception
1830+
merge: jest.fn().mockReturnValueOnce({
1831+
data: {
1832+
merged: true
1833+
}
1834+
})
1835+
},
1836+
pulls: {
1837+
create: jest.fn().mockReturnValueOnce({
1838+
data: {
1839+
number: 100,
1840+
html_url: 'https://github.com/test-owner/test-repo/pull/100'
1841+
}
1842+
})
1843+
}
1844+
}
1845+
}
1846+
})
1847+
1848+
process.env.INPUT_REVIEW_REQUIRED = 'true'
1849+
process.env.INPUT_ASSIGNEES = 'octocat ,another-user, kolossal'
1850+
expect(await run()).toBe('success')
1851+
1852+
expect(infoMock).toHaveBeenCalledWith(
1853+
`Adding assignees to combined PR: octocat,another-user,kolossal`
1854+
)
1855+
1856+
expect(setOutputMock).toHaveBeenCalledWith('pr_number', 100)
1857+
})
1858+
17761859
function buildStatusResponse(reviewDecision, ciStatus) {
17771860
return {
17781861
repository: {

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ inputs:
5353
description: A comma seperated list of labels to add to the combined PR
5454
required: false
5555
default: ""
56+
assignees:
57+
description: A comma seperated list of assignees to add to the combined PR
58+
required: false
59+
default: ""
5660
autoclose:
5761
description: Whether or not to close combined PRs if the combined PR is merged
5862
required: false

dist/index.js

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export async function run() {
1717
const ignoreLabel = core.getInput('ignore_label')
1818
const selectLabel = core.getInput('select_label')
1919
const labels = core.getInput('labels').trim()
20+
const assignees = core.getInput('assignees').trim()
2021
const token = core.getInput('github_token', {required: true})
2122
const prTitle = core.getInput('pr_title', {required: true})
2223
const prBodyHeader = core.getInput('pr_body_header', {required: true})
@@ -295,6 +296,22 @@ export async function run() {
295296
}
296297
}
297298

299+
if (assignees !== '') {
300+
// split and trim assignees
301+
const assigneesArray = assignees.split(',').map(label => label.trim())
302+
303+
// add assignees to the combined PR if specified
304+
if (assigneesArray.length > 0) {
305+
core.info(`Adding assignees to combined PR: ${assigneesArray}`)
306+
await octokit.rest.issues.addAssignees({
307+
owner: context.repo.owner,
308+
repo: context.repo.repo,
309+
issue_number: pullRequest.data.number,
310+
assignees: assigneesArray
311+
})
312+
}
313+
}
314+
298315
// lastly, if the pull request's branch can be updated cleanly, update it
299316
if (updateBranch === true) {
300317
core.info('Attempting to update branch')

0 commit comments

Comments
 (0)