Skip to content

Commit 9aed14e

Browse files
authored
fix: logs and env urls empty on finishing a deployment (#3)
* fix: logs and environment url * fix: logs and environment url
1 parent b559d9d commit 9aed14e

File tree

5 files changed

+36
-15
lines changed

5 files changed

+36
-15
lines changed

dist/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3603,7 +3603,7 @@ function run() {
36033603
break;
36043604
case 'finish':
36053605
try {
3606-
yield finish_1.finish(client, Number(deploymentId), status, logsUrl, environmentUrl);
3606+
yield finish_1.finish(client, Number(deploymentId), status);
36073607
}
36083608
catch (error) {
36093609
core.error(error);
@@ -3658,9 +3658,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
36583658
Object.defineProperty(exports, "__esModule", { value: true });
36593659
exports.finish = void 0;
36603660
const github_1 = __webpack_require__(469);
3661-
function finish(client, deploymentId, status, logUrl, environmentUrl) {
3661+
function finish(client, deploymentId, status) {
36623662
return __awaiter(this, void 0, void 0, function* () {
3663-
const statusResult = yield client.repos.createDeploymentStatus(Object.assign(Object.assign({}, github_1.context.repo), { deployment_id: deploymentId, state: status, log_url: logUrl, environment_url: environmentUrl }));
3663+
const statuses = yield client.repos.listDeploymentStatuses(Object.assign(Object.assign({}, github_1.context.repo), { deployment_id: deploymentId }));
3664+
const lastStatus = statuses.data.sort((a, b) => a.id - b.id).slice(-1)[0];
3665+
console.log(`last status for deployment_id '${deploymentId}': ${JSON.stringify(lastStatus, null, 2)}`);
3666+
const statusResult = yield client.repos.createDeploymentStatus(Object.assign(Object.assign({}, github_1.context.repo), { deployment_id: deploymentId, state: status, environment_url: lastStatus.environment_url, log_url: lastStatus.log_url }));
36643667
console.log(`created deployment status: ${JSON.stringify(statusResult.data, null, 2)}`);
36653668
});
36663669
}
@@ -8668,7 +8671,7 @@ function invalidatePreviousDeployments(client, environment) {
86688671
// invalidate the deployment
86698672
if ((lastStatus === null || lastStatus === void 0 ? void 0 : lastStatus.state) === 'success') {
86708673
console.log(`invalidating deployment: ${JSON.stringify(deployment, null, 2)}`);
8671-
yield client.repos.createDeploymentStatus(Object.assign(Object.assign({}, github_1.context.repo), { deployment_id: deployment.id, state: 'inactive' }));
8674+
yield client.repos.createDeploymentStatus(Object.assign(Object.assign({}, github_1.context.repo), { deployment_id: deployment.id, state: 'inactive', environment_url: lastStatus.environment_url, log_url: lastStatus.log_url }));
86728675
}
86738676
})));
86748677
});

src/create.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ async function invalidatePreviousDeployments (
3333
await client.repos.createDeploymentStatus({
3434
...context.repo,
3535
deployment_id: deployment.id,
36-
state: 'inactive'
36+
state: 'inactive',
37+
environment_url: lastStatus.environment_url,
38+
log_url: lastStatus.log_url
3739
})
3840
}
3941
})

src/finish.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,28 @@ import { DeploymentStatus } from './deployment-status'
44
export async function finish (
55
client: GitHub,
66
deploymentId: number,
7-
status: DeploymentStatus,
8-
logUrl: string,
9-
environmentUrl: string
7+
status: DeploymentStatus
108
): Promise<void> {
9+
const statuses = await client.repos.listDeploymentStatuses({
10+
...context.repo,
11+
deployment_id: deploymentId
12+
})
13+
14+
const lastStatus = statuses.data.sort((a, b) => a.id - b.id).slice(-1)[0]
15+
console.log(
16+
`last status for deployment_id '${deploymentId}': ${JSON.stringify(
17+
lastStatus,
18+
null,
19+
2
20+
)}`
21+
)
22+
1123
const statusResult = await client.repos.createDeploymentStatus({
1224
...context.repo,
1325
deployment_id: deploymentId,
1426
state: status,
15-
log_url: logUrl,
16-
environment_url: environmentUrl
27+
environment_url: lastStatus.environment_url,
28+
log_url: lastStatus.log_url
1729
})
1830
console.log(`created deployment status: ${JSON.stringify(statusResult.data, null, 2)}`)
1931
}

src/main.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,7 @@ export async function run (): Promise<void> {
102102
await finish(
103103
client,
104104
Number(deploymentId),
105-
status,
106-
logsUrl,
107-
environmentUrl
105+
status
108106
)
109107
} catch (error) {
110108
core.error(error)

tests/main.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ describe('create', () => {
8585

8686
const postDeployment = nock('https://api.github.com')
8787
.post('/repos/owner/repo/deployments')
88-
.reply(400, {"resource":"DeploymentStatus","code":"custom","field":"environment_url","message":"environment_url must use http(s) scheme"})
88+
.reply(400, { "resource": "DeploymentStatus", "code": "custom", "field": "environment_url", "message": "environment_url must use http(s) scheme" })
8989

9090
// act
9191
try {
@@ -114,6 +114,7 @@ describe('finish', () => {
114114
inputs = {
115115
'token': 'fake-token',
116116
'type': 'finish',
117+
'deployment_id': '42'
117118
}
118119
inputSpy = jest.spyOn(core, 'getInput')
119120
inputSpy.mockImplementation(name => inputs[name])
@@ -130,14 +131,19 @@ describe('finish', () => {
130131

131132
it('200', async () => {
132133
// arrange
134+
const listDeploymentStatus = nock('https://api.github.com')
135+
.get('/repos/owner/repo/deployments/42/statuses')
136+
.reply(200, [{ id: 10, environment_url: 'http://env.url', log_url: 'http://logs.url' }])
137+
133138
const postDeploymentStatus = nock('https://api.github.com')
134-
.post('/repos/owner/repo/deployments/0/statuses')
139+
.post('/repos/owner/repo/deployments/42/statuses')
135140
.reply(200, postStatusReply)
136141

137142
// act
138143
await main.run()
139144

140145
// assert
146+
listDeploymentStatus.done()
141147
postDeploymentStatus.done()
142148
})
143149
})

0 commit comments

Comments
 (0)