diff --git a/src/config.js b/src/config.js index f79939c..290fcb4 100644 --- a/src/config.js +++ b/src/config.js @@ -1,13 +1,31 @@ const core = require("@actions/core"); const github = require("@actions/github"); +const PULL_REQUEST_EVENT = 'pull_request'; +const PUSH_EVENT = 'push'; const DEFAULT_BRANCH_NAME = github.context.payload?.repository?.default_branch; +const getRef = () => { + + switch (github.context.eventName) { + case PULL_REQUEST_EVENT: { + return github.context.payload?.pull_request?.head?.ref; + } + case PUSH_EVENT: { + return github.context.payload?.ref; + } + default: { + core.warning(`Received unexpected github event ${github.context.eventName}`); + return github.context.payload?.ref; + } + } +} + const thisBranchName = () => { - core.info('Checking branch name'); - core.info(JSON.stringify(github.context.payload, null, 2)); - const refParts = github.context.payload.ref.split('/'); + const ref = getRef(); + + const refParts = ref.split('/'); return refParts[refParts.length-1]; }; @@ -63,6 +81,7 @@ const token = core.getInput("token"); core.debug(`Default branch name : ${DEFAULT_BRANCH_NAME}`); core.debug(`This branch name : ${thisBranchName()}`); core.debug(`Default branch resolved setting : ${defaultBranch}`) +core.info(JSON.stringify(github.context.payload, null, 2)); module.exports = { apiUrl,