Skip to content
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
1 change: 1 addition & 0 deletions __tests__/functions/check.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ beforeEach(() => {
jest.spyOn(core, 'warning').mockImplementation(() => {})
jest.spyOn(core, 'info').mockImplementation(() => {})
jest.spyOn(core, 'setOutput').mockImplementation(() => {})
jest.spyOn(core, 'debug').mockImplementation(() => {})
})

const lockBase64Octocat =
Expand Down
18 changes: 15 additions & 3 deletions __tests__/functions/unlock.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ test('throws an error if an unhandled exception occurs - headless mode', async (
test('Does not find a deployment lock branch so it lets the user know - headless mode', async () => {
octokit.rest.git.deleteRef = jest
.fn()
.mockRejectedValue(new NotFoundError('Reference does not exist'))
.mockRejectedValue(
new NotFoundError(
'Reference does not exist - https://docs.github.com/rest/git/refs#delete-a-reference'
)
)
expect(await unlock(octokit, context, environment, 123, true)).toBe(
'no deployment lock currently set - headless'
)
Expand Down Expand Up @@ -163,7 +167,11 @@ test('Does not find a deployment lock branch so it lets the user know', async ()
})
octokit.rest.git.deleteRef = jest
.fn()
.mockRejectedValue(new NotFoundError('Reference does not exist'))
.mockRejectedValue(
new NotFoundError(
'Reference does not exist - https://docs.github.com/rest/git/refs#delete-a-reference'
)
)
expect(await unlock(octokit, context, environment, 123)).toBe(true)
expect(actionStatusSpy).toHaveBeenCalledWith(
context,
Expand All @@ -183,7 +191,11 @@ test('Does not find a GLOBAL deployment lock branch so it lets the user know', a
})
octokit.rest.git.deleteRef = jest
.fn()
.mockRejectedValue(new NotFoundError('Reference does not exist'))
.mockRejectedValue(
new NotFoundError(
'Reference does not exist - https://docs.github.com/rest/git/refs#delete-a-reference'
)
)
expect(await unlock(octokit, context, 'global', 123)).toBe(true)
expect(actionStatusSpy).toHaveBeenCalledWith(
context,
Expand Down
12 changes: 11 additions & 1 deletion 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.

1 change: 1 addition & 0 deletions src/functions/checkLockFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export async function checkLockFile(octokit, context, branch) {
branch: branch
})
} catch (error) {
core.debug(`checkLockFile() error.status: ${error.status}`)
// If the lock file doesn't exist, return
if (error.status === 404) {
return false
Expand Down
1 change: 1 addition & 0 deletions src/functions/lock.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ async function checkBranch(octokit, context, branchName) {

return true
} catch (error) {
core.debug(`checkBranch() error.status: ${error.status}`)
// Create the lock branch if it doesn't exist
if (error.status === 404) {
return false
Expand Down
10 changes: 9 additions & 1 deletion src/functions/unlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,15 @@ export async function unlock(
}
} catch (error) {
// The the error caught was a 422 - Reference does not exist, this is OK - It means the lock branch does not exist
if (error.status === 422 && error.message === 'Reference does not exist') {

// debug the error msg
core.debug(`unlock() error.status: ${error.status}`)
core.debug(`unlock() error.message: ${error.message}`)

if (
error.status === 422 &&
error.message.startsWith('Reference does not exist')
) {
// If headless, exit here
if (headless) {
core.info('no deployment lock currently set - headless')
Expand Down