diff options
| author | eric sciple <ericsciple@users.noreply.github.com> | 2021-11-01 11:43:18 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-11-01 11:43:18 -0500 |
| commit | 0fc042ca35b9ee6d4c6dc650662d40f189018a49 (patch) | |
| tree | b357edb1a8f6da9760e4dc15a179d0db27d9bcaa /src/workflow-context-helper.ts | |
| parent | d7a4963ed25cda3df63783c22befd89dcbc4508d (diff) | |
set insteadOf url for org-id (#621)v2.4.0
Diffstat (limited to 'src/workflow-context-helper.ts')
| -rw-r--r-- | src/workflow-context-helper.ts | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/workflow-context-helper.ts b/src/workflow-context-helper.ts new file mode 100644 index 0000000..c7d7918 --- /dev/null +++ b/src/workflow-context-helper.ts @@ -0,0 +1,30 @@ +import * as core from '@actions/core' +import * as fs from 'fs' + +/** + * Gets the organization ID of the running workflow or undefined if the value cannot be loaded from the GITHUB_EVENT_PATH + */ +export async function getOrganizationId(): Promise<number | undefined> { + try { + const eventPath = process.env.GITHUB_EVENT_PATH + if (!eventPath) { + core.debug(`GITHUB_EVENT_PATH is not defined`) + return + } + + const content = await fs.promises.readFile(eventPath, {encoding: 'utf8'}) + const event = JSON.parse(content) + const id = event?.repository?.owner?.id + if (typeof id !== 'number') { + core.debug('Repository owner ID not found within GITHUB event info') + return + } + + return id as number + } catch (err) { + core.debug( + `Unable to load organization ID from GITHUB_EVENT_PATH: ${(err as any) + .message || err}` + ) + } +} |
