Skip to content

Commit 73c6391

Browse files
committed
Store params and parsed params into deployment payload
1 parent ba490b1 commit 73c6391

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

__tests__/main.test.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ const validDeploymentOrderMock = jest.spyOn(
2626
validDeploymentOrder,
2727
'validDeploymentOrder'
2828
)
29+
const createDeploymentMock = jest.fn().mockImplementation((data) => {
30+
return {
31+
data: {id: 123}
32+
}
33+
})
2934

3035
const permissionsMsg =
3136
'👋 __monalisa__, seems as if you have not admin/write permissions in this repo, permissions: read'
@@ -91,11 +96,7 @@ beforeEach(() => {
9196
})
9297
},
9398
repos: {
94-
createDeployment: jest.fn().mockImplementation(() => {
95-
return {
96-
data: {id: 123}
97-
}
98-
}),
99+
createDeployment: createDeploymentMock,
99100
createDeploymentStatus: jest.fn().mockImplementation(() => {
100101
return {data: {}}
101102
}),
@@ -1058,3 +1059,23 @@ test('handles and unexpected error and exits', async () => {
10581059
expect(setFailedMock.toHaveBeenCalled())
10591060
}
10601061
})
1062+
1063+
test('stores params and parsed params into context', async() => {
1064+
github.context.payload.comment.body = '.deploy | something1 --foo=bar'
1065+
const params = 'something1 --foo=bar'
1066+
const parsed_params = {
1067+
_: ['something1'],
1068+
foo: 'bar'
1069+
}
1070+
const data = expect.objectContaining({
1071+
auto_merge: true,
1072+
payload: expect.objectContaining({
1073+
params,
1074+
parsed_params
1075+
})
1076+
})
1077+
expect(await run()).toBe('success')
1078+
expect(createDeploymentMock).toHaveBeenCalledWith(data);
1079+
expect(setOutputMock).toHaveBeenCalledWith('params', params);
1080+
expect(setOutputMock).toHaveBeenCalledWith('parsed_params', parsed_params);
1081+
});

src/main.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {getInputs} from './functions/inputs'
2727
import {constructValidBranchName} from './functions/valid-branch-name'
2828
import {validDeploymentOrder} from './functions/valid-deployment-order'
2929
import {commitSafetyChecks} from './functions/commit-safety-checks'
30+
import {parseParams} from './functions/params'
3031

3132
// :returns: 'success', 'success - noop', 'success - merge deploy mode', 'failure', 'safe-exit', 'success - unlock on merge mode' or raises an error
3233
export async function run() {
@@ -645,6 +646,8 @@ export async function run() {
645646
? false
646647
: true
647648

649+
// Final params computed by environment
650+
const params = environmentObj.environmentObj.params
648651
// Create a new deployment
649652
const {data: createDeploy} = await octokit.rest.repos.createDeployment({
650653
owner: owner,
@@ -659,7 +662,9 @@ export async function run() {
659662
// :production_environment note: specifies if the given environment is one that end-users directly interact with. Default: true when environment is production and false otherwise.
660663
payload: {
661664
type: 'branch-deploy',
662-
sha: precheckResults.sha
665+
sha: precheckResults.sha,
666+
params,
667+
parsed_params: parseParams(params) // Reparse them to avoid to pass them around
663668
}
664669
})
665670
core.setOutput('deployment_id', createDeploy.id)

0 commit comments

Comments
 (0)