Skip to content

Commit

Permalink
Merge pull request #10 from github/closed-pr-fixes
Browse files Browse the repository at this point in the history
Re-Open Closed PRs
  • Loading branch information
GrantBirki committed Mar 20, 2023
2 parents 1defd8b + 62bc3f7 commit 0c491f1
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 1 deletion.
97 changes: 97 additions & 0 deletions __tests__/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,103 @@ test('runs the action and finds the combine branch already exists and the PR als
expect(setOutputMock).toHaveBeenCalledWith('pr_number', 100)
})

test('runs the action and finds the combine branch already exists and the PR also exists and the PR is in a closed state', async () => {
jest.spyOn(github, 'getOctokit').mockImplementation(() => {
return {
paginate: jest.fn().mockImplementation(() => {
return [
{
number: 1,
title: 'Update dependency 1',
head: {
ref: 'dependabot-1'
},
base: {
ref: 'main'
},
labels: [
{
name: 'question'
}
]
},
{
number: 2,
title: 'Update dependency 2',
head: {
ref: 'dependabot-2'
},
base: {
ref: 'main'
},
labels: []
}
]
}),
graphql: jest.fn().mockImplementation(() => {
return {
repository: {
pullRequest: {
commits: {
nodes: [
{
commit: {
statusCheckRollup: {
state: 'SUCCESS'
}
}
}
]
}
}
}
}
}),
rest: {
issues: {
createComment: jest.fn().mockReturnValueOnce({
data: {}
})
},
git: {
createRef: jest
.fn()
.mockRejectedValueOnce(
new AlreadyExistsError('Reference already exists')
)
},
repos: {
merge: jest.fn().mockReturnValueOnce({
data: {}
})
},
pulls: {
create: jest
.fn()
.mockRejectedValueOnce(new AlreadyExistsError('PR already exists')),
list: jest.fn().mockReturnValueOnce({
data: [
{
number: 100,
state: 'closed'
}
]
}),
update: jest.fn().mockReturnValue({
data: {}
})
}
}
}
})

expect(await run()).toBe('success')
expect(warningMock).toHaveBeenCalledWith(
'Branch already exists - will try to merge into it'
)
expect(setOutputMock).toHaveBeenCalledWith('pr_number', 100)
})

test('runs the action and does not find any branches to merge together', async () => {
jest.spyOn(github, 'getOctokit').mockImplementation(() => {
return {
Expand Down
12 changes: 12 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.

12 changes: 12 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,18 @@ export async function run() {
}
}

// check the combined PR's state to see if it is closed
const combinedPRState = pullRequest.data.state
if (combinedPRState === 'closed') {
core.info('Combined PR is closed - attempting to reopen')
await octokit.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pullRequest.data.number,
state: 'open'
})
}

// output pull request url
core.info('Combined PR url: ' + pullRequest.data.html_url)
core.setOutput('pr_url', pullRequest.data.html_url)
Expand Down

0 comments on commit 0c491f1

Please sign in to comment.