From a598a672484a10fd176026b488acc9dd695c844f Mon Sep 17 00:00:00 2001 From: Djun Kim Date: Thu, 3 Oct 2019 13:02:14 -0700 Subject: [PATCH] Get PR base branch from context --- src/main.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main.ts b/src/main.ts index 1433f6b9a..2c8594047 100644 --- a/src/main.ts +++ b/src/main.ts @@ -14,6 +14,15 @@ async function run() { return; } + const prBase = getPrBase(); + if (!prBase) { + console.log('Could not get pull request base branch from context, exiting'); + return; + } + else { + core.debug(`Base branch is #${prBase}`); + } + const client = new github.GitHub(token); core.debug(`fetching changed files for pr #${prNumber}`); @@ -49,6 +58,15 @@ function getPrNumber(): number | undefined { return pullRequest.number; } +function getPrBase(): string[] | undefined { + const pullRequest = github.context.payload.pull_request; + if (!pullRequest) { + return undefined; + } + + return pullRequest.base.ref; +} + async function getChangedFiles( client: github.GitHub, prNumber: number