From ad0bd50c16b6b226d868290e5becaf92188284d7 Mon Sep 17 00:00:00 2001 From: Vladimir Starkov Date: Tue, 5 Jul 2022 17:39:22 +0200 Subject: [PATCH] Expose pull request id as CI_PR_NUMBER and CI_PR_ID Right now the closest this action offers `CI_REF_NAME_SLUG` which is `42-merge`, but its not clean and more importantly cannot be used in numerical contexts which would benefit from having that as `42`. if current event is not a pull-request, it should be empty --- README.md | 2 ++ index.js | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/README.md b/README.md index 9af032f..c222b17 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,8 @@ A [GitHub Action](https://github.com/features/actions) to expose useful environm | `CI_BASE_REF` | Only set for forked repositories / pull request. The branch of the base repository / the base branch name. Copy of `GITHUB_BASE_REF` - for reasons of completeness. | `main` | | `CI_SHA_SHORT` | The shortened commit SHA (8 characters) that triggered the workflow. | `ffac537e` | | `CI_SHA` | The commit SHA that triggered the workflow. Copy of `GITHUB_SHA` - for reasons of completeness. | `ffac537e6cbbf934b08745a378932722df287a53` | +| `CI_PR_NUMBER` | The number of the pull request. Only set for pull requests. | `42` | +| `CI_PR_ID` | Copy of `CI_PR_NUMBER` for completeness. | `42` | | `CI_PR_TITLE` | The title of the pull request. Only set for pull requests. | `Add feature xyz.` | | `CI_PR_DESCRIPTION` | The description of the pull request. Only set for pull requests. | `The feature xyz is the [...]` | | `CI_ACTOR` | The name of the person or app that initiated the workflow. Copy of `GITHUB_ACTOR` - for reasons of completeness. | `octocat` | diff --git a/index.js b/index.js index 0b5361e..36bbea4 100644 --- a/index.js +++ b/index.js @@ -186,6 +186,13 @@ try { const pullRequest = github.context.payload && github.context.payload.pull_request; if (pullRequest) { + const prNumber = pullRequest.number; + core.exportVariable('CI_PR_NUMBER', prNumber); + core.info(`Set CI_PR_NUMBER=${process.env.CI_PR_NUMBER}`); + + core.exportVariable('CI_PR_ID', prNumber); + core.info(`Set CI_PR_ID=${process.env.CI_PR_ID}`); + const prTitle = pullRequest.title; core.exportVariable('CI_PR_TITLE', prTitle); core.info(`Set CI_PR_TITLE=${process.env.CI_PR_TITLE}`);