-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: add GitHub context in reporter #15
Conversation
d9a0595
to
612c6c6
Compare
This comment was marked as resolved.
This comment was marked as resolved.
const hasContext = () => { | ||
const { env: { GITHUB_ACTIONS } } = process; | ||
|
||
return !!GITHUB_ACTIONS; | ||
}; | ||
|
||
const getContext = () => { | ||
if (!hasContext()) { | ||
throw new GitHubActionsUnavailableError(); | ||
} | ||
|
||
const { env: { | ||
GITHUB_REPOSITORY, | ||
GITHUB_WORKFLOW_REF, | ||
GITHUB_RUN_ID, | ||
GITHUB_RUN_ATTEMPT, | ||
GITHUB_HEAD_REF, | ||
GITHUB_REF, | ||
GITHUB_SHA | ||
} } = process; | ||
const [owner, repo] = GITHUB_REPOSITORY.split('/'); | ||
const [workflowPath] = GITHUB_WORKFLOW_REF.split('@'); | ||
const workflowRegex = new RegExp(`^${owner}/${repo}/.github/workflows/`); | ||
const branchRef = GITHUB_HEAD_REF || GITHUB_REF; | ||
|
||
return { | ||
githubOrganization: owner, | ||
githubRepository: repo, | ||
githubWorkflow: workflowPath.replace(workflowRegex, ''), | ||
githubRunId: parseInt(GITHUB_RUN_ID, 10), | ||
githubRunAttempt: parseInt(GITHUB_RUN_ATTEMPT, 10), | ||
gitBranch: branchRef.replace(/^refs\/heads\//i, ''), | ||
gitSha: GITHUB_SHA | ||
}; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These purposefully don't use the @actions/github
package since it's harder to test. This is modeled after what it does internally at global script level but within a function so testing is easier and errors are better caught.
🎉 This PR is included in version 0.0.7 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This means that at report generation time the github context will sourced. Helps with data consistency/accuracy.