From 586d3c53b9daa978dfb149a41a624f9311ebf5c9 Mon Sep 17 00:00:00 2001 From: Aaron Adams Date: Thu, 20 Apr 2023 04:56:16 -0400 Subject: [PATCH] Create GitHub deployment using correct branch name (#70) --- index.js | 4 ++-- src/index.ts | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index cfade9e..4d25674 100644 --- a/index.js +++ b/index.js @@ -22095,11 +22095,12 @@ try { } = await response.json(); return deployment; }; + const githubBranch = import_process.env.GITHUB_HEAD_REF || import_process.env.GITHUB_REF_NAME; const createGitHubDeployment = async (octokit, productionEnvironment, environment) => { const deployment = await octokit.rest.repos.createDeployment({ owner: import_github.context.repo.owner, repo: import_github.context.repo.repo, - ref: import_github.context.ref, + ref: githubBranch || import_github.context.ref, auto_merge: false, description: "Cloudflare Pages", required_contexts: [], @@ -22156,7 +22157,6 @@ try { const project = await getProject(); if (!project) throw new Error("Unable to find pages project"); - const githubBranch = import_process.env.GITHUB_REF_NAME; const productionEnvironment = githubBranch === project.production_branch; const environmentName = `${projectName} (${productionEnvironment ? "Production" : "Preview"})`; let gitHubDeployment; diff --git a/src/index.ts b/src/index.ts index 8e7fe88..a6fed3f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -48,11 +48,13 @@ try { return deployment; }; + const githubBranch = env.GITHUB_HEAD_REF || env.GITHUB_REF_NAME; + const createGitHubDeployment = async (octokit: Octokit, productionEnvironment: boolean, environment: string) => { const deployment = await octokit.rest.repos.createDeployment({ owner: context.repo.owner, repo: context.repo.repo, - ref: context.ref, + ref: githubBranch || context.ref, auto_merge: false, description: "Cloudflare Pages", required_contexts: [], @@ -125,7 +127,6 @@ try { const project = await getProject(); if (!project) throw new Error("Unable to find pages project"); - const githubBranch = env.GITHUB_REF_NAME; const productionEnvironment = githubBranch === project.production_branch; const environmentName = `${projectName} (${productionEnvironment ? "Production" : "Preview"})`;