Skip to content

Commit 16a4d90

Browse files
committed
adding approved_reviews_count as a new deployment message variable
1 parent 430d820 commit 16a4d90

File tree

12 files changed

+65
-14
lines changed

12 files changed

+65
-14
lines changed

__tests__/functions/post-deploy-message.test.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var environment_url_simple
1111
var status
1212
var noop
1313
var ref
14+
var approved_reviews_count
1415

1516
beforeEach(() => {
1617
jest.clearAllMocks()
@@ -27,6 +28,7 @@ beforeEach(() => {
2728
status = 'success'
2829
noop = false
2930
ref = 'test-ref'
31+
approved_reviews_count = '4'
3032

3133
context = {
3234
actor: 'monalisa',
@@ -52,7 +54,8 @@ test('successfully constructs a post deploy message with the defaults', async ()
5254
environment_url, // environment_url
5355
status, // status
5456
noop, // noop
55-
ref // ref
57+
ref, // ref
58+
approved_reviews_count // approved_reviews_count
5659
)
5760
).toStrictEqual(
5861
dedent(`
@@ -72,7 +75,8 @@ test('successfully constructs a post deploy message with the defaults during a "
7275
environment_url, // environment_url
7376
status, // status
7477
true, // noop
75-
ref // ref
78+
ref, // ref
79+
approved_reviews_count // approved_reviews_count
7680
)
7781
).toStrictEqual(
7882
dedent(`
@@ -90,7 +94,8 @@ test('successfully constructs a post deploy message with the defaults during a d
9094
environment_url, // environment_url
9195
'failure', // status
9296
noop, // noop
93-
ref // ref
97+
ref, // ref
98+
approved_reviews_count // approved_reviews_count
9499
)
95100
).toStrictEqual(
96101
dedent(`
@@ -108,7 +113,8 @@ test('successfully constructs a post deploy message with the defaults during a d
108113
environment_url, // environment_url
109114
'unknown', // status
110115
noop, // noop
111-
ref // ref
116+
ref, // ref
117+
approved_reviews_count // approved_reviews_count
112118
)
113119
).toStrictEqual(
114120
dedent(`
@@ -128,7 +134,8 @@ test('successfully constructs a post deploy message with a custom env var', asyn
128134
environment_url, // environment_url
129135
status, // status
130136
noop, // noop
131-
ref // ref
137+
ref, // ref
138+
approved_reviews_count // approved_reviews_count
132139
)
133140
).toStrictEqual(
134141
dedent(`
@@ -156,7 +163,8 @@ test('successfully constructs a post deploy message with a custom markdown file'
156163
environment_url, // environment_url
157164
status, // status
158165
noop, // noop
159-
ref // ref
166+
ref, // ref
167+
approved_reviews_count // approved_reviews_count
160168
)
161169
).toStrictEqual(
162170
dedent(`### Deployment Results :rocket:
@@ -169,6 +177,7 @@ test('successfully constructs a post deploy message with a custom markdown file'
169177
- \`noop\` - Whether or not the deployment is a noop (Boolean)
170178
- \`ref\` - The ref of the deployment (String)
171179
- \`actor\` - The GitHub username of the actor who triggered the deployment (String)
180+
- \`approved_reviews_count\` - The number of approved reviews on the pull request at the time of deployment (String of a number)
172181
173182
Here is an example:
174183
@@ -178,6 +187,8 @@ test('successfully constructs a post deploy message with a custom markdown file'
178187
179188
180189
190+
> This deployment had \`4\` approvals.
191+
181192
`)
182193
)
183194
})

__tests__/functions/post-deploy.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ test('successfully completes a production branch deployment', async () => {
8989
456,
9090
'production',
9191
null, // environment_url
92+
1, // approved_reviews_count
9293
labels
9394
)
9495
).toBe('success')
@@ -155,6 +156,7 @@ test('successfully completes a production branch deployment that fails', async (
155156
456,
156157
'production',
157158
null, // environment_url
159+
1, // approved_reviews_count
158160
labels
159161
)
160162
).toBe('success')
@@ -221,6 +223,7 @@ test('successfully completes a production branch deployment with an environment
221223
456,
222224
'production',
223225
'https://example.com', // environment_url
226+
1, // approved_reviews_count
224227
labels
225228
)
226229
).toBe('success')
@@ -293,6 +296,7 @@ test('successfully completes a production branch deployment and removes a non-st
293296
456,
294297
'production',
295298
null, // environment_url
299+
1, // approved_reviews_count
296300
labels
297301
)
298302
).toBe('success')
@@ -365,6 +369,7 @@ test('successfully completes a noop branch deployment and removes a non-sticky l
365369
456,
366370
'production',
367371
null, // environment_url
372+
1, // approved_reviews_count
368373
labels
369374
)
370375
).toBe('success - noop')
@@ -412,6 +417,7 @@ test('successfully completes a noop branch deployment but does not get any lock
412417
456,
413418
'production',
414419
null, // environment_url
420+
1, // approved_reviews_count
415421
labels
416422
)
417423
).toBe('success - noop')
@@ -456,6 +462,7 @@ test('successfully completes a production branch deployment with no custom messa
456462
456,
457463
'production',
458464
null, // environment_url
465+
1, // approved_reviews_count
459466
labels
460467
)
461468
).toBe('success')
@@ -494,6 +501,7 @@ test('successfully completes a noop branch deployment', async () => {
494501
456,
495502
'production',
496503
null, // environment_url
504+
1, // approved_reviews_count
497505
labels
498506
)
499507
).toBe('success - noop')
@@ -514,6 +522,7 @@ test('successfully completes a noop branch deployment and applies success labels
514522
456,
515523
'production',
516524
null, // environment_url
525+
1, // approved_reviews_count
517526
labels
518527
)
519528
).toBe('success - noop')
@@ -534,6 +543,7 @@ test('successfully completes a noop branch deployment that fails and applies suc
534543
456,
535544
'production',
536545
null, // environment_url
546+
1, // approved_reviews_count
537547
labels
538548
)
539549
).toBe('success - noop')
@@ -552,6 +562,7 @@ test('updates with a failure for a production branch deployment', async () => {
552562
456,
553563
'production',
554564
null, // environment_url
565+
1, // approved_reviews_count
555566
labels
556567
)
557568
).toBe('success')
@@ -570,6 +581,7 @@ test('updates with an unknown for a production branch deployment', async () => {
570581
456,
571582
'production',
572583
null, // environment_url
584+
1, // approved_reviews_count
573585
labels
574586
)
575587
).toBe('success')

__tests__/functions/post.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ const validStates = {
2323
noop: 'false',
2424
deployment_id: '456',
2525
environment: 'production',
26-
token: 'test-token'
26+
token: 'test-token',
27+
approved_reviews_count: '1'
2728
}
2829

2930
const setFailedMock = jest.spyOn(core, 'setFailed').mockImplementation(() => {})

__tests__/functions/prechecks.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ beforeEach(() => {
2323
jest.spyOn(core, 'debug').mockImplementation(() => {})
2424
jest.spyOn(core, 'warning').mockImplementation(() => {})
2525
jest.spyOn(core, 'setOutput').mockImplementation(() => {})
26+
jest.spyOn(core, 'saveState').mockImplementation(() => {})
2627
process.env.INPUT_PERMISSIONS = 'admin,write,maintain'
2728

2829
data = {

__tests__/templates/test_deployment_message.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The following variables are available to use in this template:
88
- `noop` - Whether or not the deployment is a noop (Boolean)
99
- `ref` - The ref of the deployment (String)
1010
- `actor` - The GitHub username of the actor who triggered the deployment (String)
11+
- `approved_reviews_count` - The number of approved reviews on the pull request at the time of deployment (String of a number)
1112

1213
Here is an example:
1314

@@ -16,3 +17,5 @@ Here is an example:
1617
{% if environment_url %}You can view the deployment [here]({{ environment_url }}).{% endif %}
1718

1819
{% if noop %}This was a noop deployment.{% endif %}
20+
21+
> This deployment had `{{ approved_reviews_count }}` approvals.

dist/index.js

Lines changed: 14 additions & 3 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.

docs/custom-deployment-messages.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ If a markdown file exists at the designated path, it will be used and rendered w
1818
- `noop` - Whether or not the deployment is a noop (Boolean)
1919
- `ref` - The ref of the deployment (String)
2020
- `actor` - The GitHub username of the actor who triggered the deployment (String)
21+
- `approved_reviews_count` - The number of approved reviews on the pull request at the time of deployment (String of a number)
2122

2223
If you wish to see a live example of how this works, and how to use the variables, you can check out this [example](https://github.com/github/branch-deploy/blob/37b50ea86202af7b5505b62bf3eb326da0614b60/__tests__/templates/test_deployment_message.md) which is used in this repo's unit tests and is self-documenting.
2324

src/functions/post-deploy-message.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ import nunjucks from 'nunjucks'
1111
// :param status: The status of the deployment (String)
1212
// :param noop: Indicates whether the deployment is a noop or not (Boolean)
1313
// :param ref: The ref (branch) which is being used for deployment (String)
14+
// :param approved_reviews_count: The count of approved reviews for the deployment (String representation of an int or null)
1415
// :returns: The formatted message (String)
1516
export async function postDeployMessage(
1617
context,
1718
environment,
1819
environment_url,
1920
status,
2021
noop,
21-
ref
22+
ref,
23+
approved_reviews_count
2224
) {
2325
// fetch the inputs
2426
const environment_url_in_comment = core.getBooleanInput(
@@ -38,7 +40,8 @@ export async function postDeployMessage(
3840
status,
3941
noop,
4042
ref,
41-
actor: context.actor
43+
actor: context.actor,
44+
approved_reviews_count
4245
}
4346
return nunjucks.render(deployMessagePath, vars)
4447
}

src/functions/post-deploy.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const nonStickyMsg = `🧹 ${COLORS.highlight}non-sticky${COLORS.reset} lock det
2323
// :param deployment_id: The id of the deployment (String)
2424
// :param environment: The environment of the deployment (String)
2525
// :param environment_url: The environment url of the deployment (String)
26+
// :param approved_reviews_count: The count of approved reviews for the deployment (String representation of an int or null)
2627
// :param labels: A dictionary of labels to apply to the issue (Object)
2728
// :returns: 'success' if the deployment was successful, 'success - noop' if a noop, throw error otherwise
2829
export async function postDeploy(
@@ -36,6 +37,7 @@ export async function postDeploy(
3637
deployment_id,
3738
environment,
3839
environment_url,
40+
approved_reviews_count,
3941
labels
4042
) {
4143
// check the inputs to ensure they are valid
@@ -70,7 +72,8 @@ export async function postDeploy(
7072
environment_url,
7173
status,
7274
noop,
73-
ref
75+
ref,
76+
approved_reviews_count
7477
)
7578

7679
// update the action status to indicate the result of the deployment as a comment

0 commit comments

Comments
 (0)