Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions src/commands/fix/open-pr.mts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ let _octokit: Octokit | undefined
function getOctokit() {
if (_octokit === undefined) {
_octokit = new Octokit({
// Lazily access constants.ENV.SOCKET_SECURITY_GITHUB_PAT.
auth: constants.ENV.SOCKET_SECURITY_GITHUB_PAT
// Lazily access constants.ENV properties.
auth:
constants.ENV.SOCKET_SECURITY_GITHUB_PAT || constants.ENV.GITHUB_TOKEN
})
}
return _octokit
Expand All @@ -40,8 +41,8 @@ export function getOctokitGraphql() {
if (!_octokitGraphql) {
_octokitGraphql = OctokitGraphql.defaults({
headers: {
// Lazily access constants.ENV.SOCKET_SECURITY_GITHUB_PAT.
authorization: `token ${constants.ENV.SOCKET_SECURITY_GITHUB_PAT}`
// Lazily access constants.ENV properties.
authorization: `token ${constants.ENV.SOCKET_SECURITY_GITHUB_PAT || constants.ENV.GITHUB_TOKEN}`
}
})
}
Expand Down Expand Up @@ -364,12 +365,10 @@ export async function openPr(
} as OpenPrOptions
// Lazily access constants.ENV.GITHUB_ACTIONS.
if (constants.ENV.GITHUB_ACTIONS) {
// Lazily access constants.ENV.SOCKET_SECURITY_GITHUB_PAT.
const pat = constants.ENV.SOCKET_SECURITY_GITHUB_PAT
if (!pat) {
throw new Error('Missing SOCKET_SECURITY_GITHUB_PAT environment variable')
}
const url = `https://x-access-token:${pat}@github.com/${owner}/${repo}`
// Lazily access constants.ENV properties.
const token =
constants.ENV.SOCKET_SECURITY_GITHUB_PAT || constants.ENV.GITHUB_TOKEN
const url = `https://x-access-token:${token}@github.com/${owner}/${repo}`
await spawn('git', ['remote', 'set-url', 'origin', url], {
cwd
})
Expand Down
5 changes: 5 additions & 0 deletions src/constants.mts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type ENV = Remap<
GITHUB_REF_NAME: string
GITHUB_REF_TYPE: string
GITHUB_REPOSITORY: string
GITHUB_TOKEN: string
INLINED_CYCLONEDX_CDXGEN_VERSION: string
INLINED_SOCKET_CLI_HOMEPAGE: string
INLINED_SOCKET_CLI_LEGACY_BUILD: string
Expand Down Expand Up @@ -239,6 +240,10 @@ const LAZY_ENV = () => {
// The owner and repository name. For example, octocat/Hello-World.
// https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/store-information-in-variables#default-environment-variables
GITHUB_REPOSITORY: envAsString(env['GITHUB_REPOSITORY']),
// The GITHUB_TOKEN secret is a GitHub App installation access token. The token's
// permissions are limited to the repository that contains the workflow.
// https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication#about-the-github_token-secret
GITHUB_TOKEN: envAsString(env['GITHUB_TOKEN']),
// Comp-time inlined @cyclonedx/cdxgen package version.
// The '@rollup/plugin-replace' will replace "process.env['INLINED_CYCLONEDX_CDXGEN_VERSION']".
INLINED_CYCLONEDX_CDXGEN_VERSION: envAsString(
Expand Down