Skip to content

Commit ae6decb

Browse files
authored
Merge pull request #377 from github/deployment-confirmation-commit-metadata
Committer metadata on confirmation comments
2 parents a48c420 + 66e9d38 commit ae6decb

File tree

7 files changed

+50
-17
lines changed

7 files changed

+50
-17
lines changed

__tests__/functions/deployment-confirmation.test.js

+3
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ beforeEach(() => {
8080
log_url: 'https://github.com/corp/test/actions/runs/12345',
8181
ref: 'cool-branch',
8282
sha: 'abc123',
83+
committer: 'monalisa',
84+
commit_html_url: 'https://github.com/corp/test/commit/abc123',
8385
isVerified: true,
8486
noopMode: false,
8587
isFork: false,
@@ -143,6 +145,7 @@ test('successfully prompts for deployment confirmation and gets confirmed by the
143145
data.params = null
144146
data.parsed_params = null
145147
data.environmentUrl = null
148+
data.isVerified = false
146149

147150
// Mock that the user adds a +1 reaction
148151
octokit.rest.reactions.listForIssueComment.mockResolvedValueOnce({

__tests__/main.test.js

+8
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,15 @@ beforeEach(() => {
130130
return {
131131
data: {
132132
sha: mock_sha,
133+
html_url: `https://github.com/corp/test/commit/${mock_sha}`,
133134
commit: {
134135
author: {
135136
date: '2024-10-15T12:00:00Z'
136137
},
137138
verification: no_verification
139+
},
140+
committer: {
141+
login: 'monalisa'
138142
}
139143
}
140144
}
@@ -1083,11 +1087,15 @@ test('detects an out of date branch and exits', async () => {
10831087
return {
10841088
data: {
10851089
sha: mock_sha,
1090+
html_url: `https://github.com/corp/test/commit/${mock_sha}`,
10861091
commit: {
10871092
author: {
10881093
date: '2024-10-15T12:00:00Z'
10891094
},
10901095
verification: no_verification
1096+
},
1097+
committer: {
1098+
login: 'monalisa'
10911099
}
10921100
}
10931101
}

dist/index.js

+19-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/functions/deployment-confirmation.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as core from '@actions/core'
22
import dedent from 'dedent-js'
33
import {COLORS} from './colors'
44
import {API_HEADERS} from './api-headers'
5+
import {timestamp} from './timestamp'
56

67
const thumbsUp = '+1'
78
const thumbsDown = '-1'
@@ -16,7 +17,8 @@ export async function deploymentConfirmation(context, octokit, data) {
1617
1718
In order to proceed with this deployment, __${context.actor}__ must react to this comment with either a 👍 or a 👎.
1819
19-
- Commit: \`${data.sha}\`
20+
- Commit: [\`${data.sha}\`](${data.commit_html_url})
21+
- Committer: \`${data.committer}\` - **${data.isVerified ? 'verified' : 'unverified'}**
2022
- Environment: \`${data.environment}\`
2123
- Branch: \`${data.ref}\`
2224
- Deployment Type: \`${data.deploymentType}\`
@@ -40,7 +42,9 @@ export async function deploymentConfirmation(context, octokit, data) {
4042
"git": {
4143
"branch": "${data.ref}",
4244
"commit": "${data.sha}",
43-
"verified": ${data.isVerified}
45+
"verified": ${data.isVerified},
46+
"committer": "${data.committer}",
47+
"html_url": "${data.commit_html_url}"
4448
},
4549
"context": {
4650
"actor": "${context.actor}",
@@ -102,7 +106,7 @@ export async function deploymentConfirmation(context, octokit, data) {
102106
await octokit.rest.issues.updateComment({
103107
...context.repo,
104108
comment_id: commentId,
105-
body: `${message}\n\n✅ Deployment confirmed by __${context.actor}__.`,
109+
body: `${message}\n\n✅ Deployment confirmed by __${context.actor}__ at \`${timestamp()}\` UTC.`,
106110
headers: API_HEADERS
107111
})
108112

@@ -116,7 +120,7 @@ export async function deploymentConfirmation(context, octokit, data) {
116120
await octokit.rest.issues.updateComment({
117121
...context.repo,
118122
comment_id: commentId,
119-
body: `${message}\n\n❌ Deployment rejected by __${context.actor}__.`,
123+
body: `${message}\n\n❌ Deployment rejected by __${context.actor}__ at \`${timestamp()}\` UTC.`,
120124
headers: API_HEADERS
121125
})
122126

@@ -149,7 +153,7 @@ export async function deploymentConfirmation(context, octokit, data) {
149153
await octokit.rest.issues.updateComment({
150154
...context.repo,
151155
comment_id: commentId,
152-
body: `${message}\n\n⏱️ Deployment confirmation timed out after \`${data.deployment_confirmation_timeout}\` seconds. The deployment request has been rejected.`,
156+
body: `${message}\n\n⏱️ Deployment confirmation timed out after \`${data.deployment_confirmation_timeout}\` seconds. The deployment request has been rejected at \`${timestamp()}\` UTC.`,
153157
headers: API_HEADERS
154158
})
155159

src/functions/timestamp.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Helper function to generate an ISO 8601 formatted timestamp string
1+
// Helper function to generate an ISO 8601 formatted timestamp string in UTC
22
// :returns: An ISO 8601 formatted timestamp string (ex: 2025-01-01T00:00:00.000Z)
33
export function timestamp() {
44
const now = new Date()

src/main.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,9 @@ export async function run() {
466466
headers: API_HEADERS
467467
})
468468

469+
const committer = commitData.data.committer.login
470+
const commit_html_url = commitData.data.html_url
471+
469472
// Run commit safety checks
470473
const commitSafetyCheckResults = await commitSafetyChecks(context, {
471474
commit: commitData.data.commit,
@@ -627,7 +630,9 @@ export async function run() {
627630
parsed_params: parsed_params,
628631
github_run_id: github_run_id,
629632
noopMode: precheckResults.noopMode,
630-
isFork: precheckResults.isFork
633+
isFork: precheckResults.isFork,
634+
committer: committer,
635+
commit_html_url: commit_html_url
631636
}
632637
)
633638
if (deploymentConfirmed === true) {
@@ -675,7 +680,9 @@ export async function run() {
675680
"git": {
676681
"branch": "${precheckResults.ref}",
677682
"commit": "${precheckResults.sha}",
678-
"verified": ${commitSafetyCheckResults.isVerified}
683+
"verified": ${commitSafetyCheckResults.isVerified},
684+
"committer": "${committer}",
685+
"html_url": "${commit_html_url}"
679686
},
680687
"context": {
681688
"actor": "${context.actor}",

0 commit comments

Comments
 (0)