Skip to content

Commit 9771e7f

Browse files
committed
use payload for PR details
1 parent 0b40ad4 commit 9771e7f

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

src/action.ts

+12-15
Original file line numberDiff line numberDiff line change
@@ -278,23 +278,24 @@ export class Action {
278278
debug(`GITHUB_REF: ${GITHUB_REF}`);
279279
debug(`GITHUB_BASE_REF: ${GITHUB_BASE_REF}`);
280280
debug(`GITHUB_HEAD_REF: ${GITHUB_HEAD_REF}`);
281-
debug(`Is PR: ${this.isPr}`);
282281
debug(`Branch Type: ${branchType}`);
283282
debug(`Branch ID: ${branchId}`);
283+
debug(`PR Number: ${this.prNumber}`);
284284

285285
if (!branchId) {
286-
debug(`GITHUB_REF: ${GITHUB_REF}`);
287-
debug(`branchType: ${branchType}`);
288-
debug(`branchId: ${branchId}`);
289286
throw new Error('Unable to determine branch from GITHUB_REF');
290287
}
291288

292289
let deploymentStage = branchId;
293-
if (branchType === 'pull') {
290+
if (this.prNumber) {
294291
if (!GITHUB_BASE_REF) {
295292
throw new Error('Unable to determine base ref from GITHUB_BASE_REF');
296293
}
297-
deploymentStage = `${GITHUB_BASE_REF.replaceAll('/', '-')}-pr-${branchId}`;
294+
295+
const normalizedBaseRef = GITHUB_BASE_REF.replaceAll('/', '-');
296+
debug('Normalized Base Ref: ' + normalizedBaseRef);
297+
298+
deploymentStage = `${normalizedBaseRef}-pr-${this.prNumber}`;
298299
}
299300

300301
return deploymentStage;
@@ -349,18 +350,14 @@ export class Action {
349350

350351
get prNumber(): number | undefined {
351352
if (context.eventName === 'pull_request') {
353+
if (!context.payload.pull_request || !context.payload.pull_request.number) {
354+
throw new Error('Unable to determine PR number');
355+
}
352356
return context.payload.pull_request?.number;
353357
}
354358
return undefined;
355359
}
356360

357-
get isPr(): boolean {
358-
if (!GITHUB_REF) {
359-
throw new Error('Unable to determine Pull Request from GITHUB_REF');
360-
}
361-
return GITHUB_REF.endsWith('/merge');
362-
}
363-
364361
get workflowInputs(): { [key: string]: string } {
365362
return context.payload.inputs || {};
366363
}
@@ -398,7 +395,7 @@ export class Action {
398395
ref: this.deploymentRef,
399396
required_contexts: [],
400397
environment: this.stage,
401-
transient_environment: this.isPr,
398+
transient_environment: !!this.prNumber,
402399
auto_merge: false,
403400
owner: this.owner,
404401
repo: this.repo,
@@ -502,7 +499,7 @@ export class Action {
502499
}),
503500
);
504501

505-
if (this.isPr) {
502+
if (this.prNumber) {
506503
await Promise.all(
507504
deployments.map(async (deployment) => {
508505
try {

0 commit comments

Comments
 (0)