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
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,12 @@ If you wish to use this Action via a comment on a pull request, simply omit the
| `type` | The type of trigger which was found - 'lock', 'unlock', or 'info-info-alias' |
| `comment_body` | The comment body which triggered this action (if it was not headless) |
| `headless` | The string "true" if the run was headless, otherwise the string "false" - Headless in this context would be if the "mode" was set and the Action was not invoked by a comment on a pull request |
| `locked` | If the 'mode' is set to 'check', this output is exported to show if the lock is set in a headless run |
| `locked` | If the "mode" is set to "check", this output is exported to show if the lock is set in a headless run |
| `branch` | If the mode is set to "check", this output will be the branch name that holds the lock, otherwise it will be empty |
| `created_by` | If the mode is set to "check", this output will be the user that holds the lock, otherwise it will be empty |
| `created_at` | If the mode is set to "check", this output will be the ISO 8601 format date that the lock was claimed, otherwise it will be empty |
| `reason` | If the mode is set to "check", this output will be the reason the deployment lock was claimed, otherwise it will be empty |
| `link` | If the mode is set to "check", this output will be the link to the GitHub issue comment or action run that claimed the lock, otherwise it will be empty |
| `global_lock_claimed` | The string "true" if the global lock was claimed |
| `global_lock_released` | The string "true" if the global lock was released |
| `lock_environment` | When running in headless mode and the "mode" is set to "check", this output will be the environment name that holds the lock, otherwise it will be empty |
Expand Down
26 changes: 26 additions & 0 deletions __tests__/functions/check.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@ test('successfully checks for a production lock and finds a lock', async () => {
expect(await check(octokit, context, environment)).toBe(true)
expect(setOutputMock).toHaveBeenCalledWith('locked', 'true')
expect(setOutputMock).toHaveBeenCalledWith('lock_environment', environment)
expect(setOutputMock).toHaveBeenCalledWith('created_by', 'octocat')
expect(setOutputMock).toHaveBeenCalledWith(
'created_at',
'2022-06-14T21:12:14.041Z'
)
expect(setOutputMock).toHaveBeenCalledWith(
'reason',
'Testing my new feature with lots of cats'
)
expect(setOutputMock).toHaveBeenCalledWith(
'link',
'https://github.com/test-org/test-repo/pull/2#issuecomment-456'
)
expect(infoMock).toHaveBeenCalledWith('global lock does not exist')
expect(infoMock).toHaveBeenCalledWith('production lock exists')
})
Expand All @@ -81,6 +94,19 @@ test('successfully checks for a production lock and finds a global lock instead'
expect(await check(octokit, context, environment)).toBe(true)
expect(setOutputMock).toHaveBeenCalledWith('locked', 'true')
expect(setOutputMock).toHaveBeenCalledWith('lock_environment', 'global')
expect(setOutputMock).toHaveBeenCalledWith('created_by', 'octocat')
expect(setOutputMock).toHaveBeenCalledWith(
'created_at',
'2022-06-14T21:12:14.041Z'
)
expect(setOutputMock).toHaveBeenCalledWith(
'reason',
'Testing my new feature with lots of cats'
)
expect(setOutputMock).toHaveBeenCalledWith(
'link',
'https://github.com/test-org/test-repo/pull/2#issuecomment-456'
)
expect(infoMock).toHaveBeenCalledWith('global lock exists')
})

Expand Down
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ outputs:
description: When running in headless mode and the "mode" is set to "check", this output will be the environment name that holds the lock, otherwise it will be empty
branch:
description: 'If the mode is set to "check", this output will be the branch name that holds the lock, otherwise it will be empty'
created_by:
description: 'If the mode is set to "check", this output will be the user that holds the lock, otherwise it will be empty'
created_at:
description: 'If the mode is set to "check", this output will be the ISO 8601 format date that the lock was claimed, otherwise it will be empty'
reason:
description: 'If the mode is set to "check", this output will be the reason the deployment lock was claimed, otherwise it will be empty'
link:
description: 'If the mode is set to "check", this output will be the link to the GitHub issue comment or action run that claimed the lock, otherwise it will be empty'
global_lock_claimed:
description: 'The string "true" if the global lock was claimed'
global_lock_released:
Expand Down
16 changes: 16 additions & 0 deletions src/functions/checkLockFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ export async function checkLockFile(octokit, context, branch) {
core.setOutput('branch', lockData['branch'])
}

if (Object.prototype.hasOwnProperty.call(lockData, 'created_by')) {
core.setOutput('created_by', lockData['created_by'])
}

if (Object.prototype.hasOwnProperty.call(lockData, 'created_at')) {
core.setOutput('created_at', lockData['created_at'])
}

if (Object.prototype.hasOwnProperty.call(lockData, 'reason')) {
core.setOutput('reason', lockData['reason'])
}

if (Object.prototype.hasOwnProperty.call(lockData, 'link')) {
core.setOutput('link', lockData['link'])
}

return true
} catch (error) {
// If the lock file doesn't exist, return false
Expand Down