Skip to content

Commit 022258d

Browse files
committed
Add SOCKET_DEFAULT_BRANCH and SOCKET_DEFAULT_REPOSITORY
1 parent bea2c71 commit 022258d

File tree

5 files changed

+28
-10
lines changed

5 files changed

+28
-10
lines changed

src/commands/ci/handle-ci.mts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { logger } from '@socketsecurity/registry/lib/logger'
22

33
import { getDefaultOrgSlug } from './fetch-default-org-slug.mts'
4+
import constants from '../../constants.mts'
45
import { getRepoName, gitBranch } from '../../utils/git.mts'
56
import { serializeResultJson } from '../../utils/serialize-result-json.mts'
67
import { handleCreateNewScan } from '../scan/handle-create-new-scan.mts'
78

9+
const { SOCKET_DEFAULT_BRANCH, SOCKET_DEFAULT_REPOSITORY } = constants
10+
811
export async function handleCI(autoManifest: boolean): Promise<void> {
912
// ci: {
1013
// description: 'Alias for "report create --view --strict"',
@@ -23,7 +26,7 @@ export async function handleCI(autoManifest: boolean): Promise<void> {
2326
// TODO: does it makes sense to use custom branch/repo names here? probably socket.yml, right
2427
await handleCreateNewScan({
2528
autoManifest,
26-
branchName: (await gitBranch(cwd)) || 'socket-default-branch',
29+
branchName: (await gitBranch(cwd)) || SOCKET_DEFAULT_BRANCH,
2730
commitMessage: '',
2831
commitHash: '',
2932
committers: '',
@@ -35,7 +38,7 @@ export async function handleCI(autoManifest: boolean): Promise<void> {
3538
// When 'pendingHead' is true, it requires 'branchName' set and 'tmp' false.
3639
pendingHead: true,
3740
pullRequest: 0,
38-
repoName: (await getRepoName(cwd)) || 'socket-default-repository',
41+
repoName: (await getRepoName(cwd)) || SOCKET_DEFAULT_REPOSITORY,
3942
readOnly: false,
4043
report: true,
4144
targets: ['.'],

src/commands/scan/cmd-scan-create.mts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ import { detectManifestActions } from '../manifest/detect-manifest-actions.mts'
2020

2121
import type { CliCommandConfig } from '../../utils/meow-with-subcommands.mts'
2222

23-
const { DRY_RUN_BAILING_NOW } = constants
23+
const {
24+
DRY_RUN_BAILING_NOW,
25+
SOCKET_DEFAULT_BRANCH,
26+
SOCKET_DEFAULT_REPOSITORY,
27+
} = constants
2428

2529
const config: CliCommandConfig = {
2630
commandName: 'create',
@@ -256,15 +260,15 @@ async function run(
256260
branchName = sockJson.defaults.scan.create.branch
257261
logger.info('Using default --branch from socket.json:', branchName)
258262
} else {
259-
branchName = (await gitBranch(cwd)) || 'socket-default-branch'
263+
branchName = (await gitBranch(cwd)) || SOCKET_DEFAULT_BRANCH
260264
}
261265
}
262266
if (!repoName) {
263267
if (sockJson.defaults?.scan?.create?.repo) {
264268
repoName = sockJson.defaults.scan.create.repo
265269
logger.info('Using default --repo from socket.json:', repoName)
266270
} else {
267-
repoName = (await getRepoName(cwd)) || 'socket-default-repository'
271+
repoName = (await getRepoName(cwd)) || SOCKET_DEFAULT_REPOSITORY
268272
}
269273
}
270274
if (typeof report !== 'boolean') {

src/commands/scan/fetch-create-org-full-scan.mts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
import constants from '../../constants.mts'
12
import { handleApiCall } from '../../utils/api.mts'
23
import { getRepoName } from '../../utils/git.mts'
34
import { setupSdk } from '../../utils/sdk.mts'
45

56
import type { CResult } from '../../types.mts'
67
import type { SocketSdkReturnType } from '@socketsecurity/sdk'
78

9+
const { SOCKET_DEFAULT_REPOSITORY } = constants
10+
811
export async function fetchCreateOrgFullScan(
912
packagePaths: string[],
1013
orgSlug: string,
@@ -33,7 +36,7 @@ export async function fetchCreateOrgFullScan(
3336
return sockSdkCResult
3437
}
3538
const sockSdk = sockSdkCResult.data
36-
const repo = repoName || (await getRepoName(cwd)) || 'socket-default-repository'
39+
const repo = repoName || (await getRepoName(cwd)) || SOCKET_DEFAULT_REPOSITORY
3740

3841
return await handleApiCall(
3942
sockSdk.createOrgFullScan(

src/commands/scan/setup-scan-config.mts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {
1414

1515
import type { CResult } from '../../types.mts'
1616

17+
const { SOCKET_DEFAULT_BRANCH, SOCKET_DEFAULT_REPOSITORY } = constants
18+
1719
export async function setupScanConfig(
1820
cwd: string,
1921
defaultOnReadError = false,
@@ -136,15 +138,15 @@ async function configureScan(
136138
message:
137139
'(--repo) What repo name (slug) should be reported to Socket for this dir?',
138140
default:
139-
config.repo || (await getRepoName(cwd)) || 'socket-default-repository',
141+
config.repo || (await getRepoName(cwd)) || SOCKET_DEFAULT_REPOSITORY,
140142
required: false,
141143
// validate: async string => bool
142144
})
143145
if (defaultRepoName === undefined) {
144146
return canceledByUser()
145147
}
146148
if (defaultRepoName) {
147-
// Even if it's 'socket-default-repository' store it because if we change
149+
// Even if it's SOCKET_DEFAULT_REPOSITORY store it because if we change
148150
// this default then an existing user probably would not expect the change?
149151
config.repo = defaultRepoName
150152
} else {
@@ -154,15 +156,15 @@ async function configureScan(
154156
const defaultBranchName = await input({
155157
message:
156158
'(--branch) What branch name (slug) should be reported to Socket for this dir?',
157-
default: config.branch || (await gitBranch(cwd)) || 'socket-default-branch',
159+
default: config.branch || (await gitBranch(cwd)) || SOCKET_DEFAULT_BRANCH,
158160
required: false,
159161
// validate: async string => bool
160162
})
161163
if (defaultBranchName === undefined) {
162164
return canceledByUser()
163165
}
164166
if (defaultBranchName) {
165-
// Even if it's 'socket-default-branch' store it because if we change
167+
// Even if it's SOCKET_DEFAULT_BRANCH store it because if we change
166168
// this default then an existing user probably would not expect the change?
167169
config.branch = defaultBranchName
168170
} else {

src/constants.mts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ type Constants = Remap<
132132
readonly SOCKET_CLI_SENTRY_NPX_BIN_NAME: 'socket-npx-with-sentry'
133133
readonly SOCKET_CLI_SENTRY_PACKAGE_NAME: '@socketsecurity/cli-with-sentry'
134134
readonly SOCKET_CLI_VIEW_ALL_RISKS: 'SOCKET_CLI_VIEW_ALL_RISKS'
135+
readonly SOCKET_DEFAULT_BRANCH: 'socket-default-branch'
136+
readonly SOCKET_DEFAULT_REPOSITORY: 'socket-default-repository'
135137
readonly SOCKET_WEBSITE_URL: 'https://socket.dev'
136138
readonly VLT: 'vlt'
137139
readonly WITH_SENTRY: 'with-sentry'
@@ -209,6 +211,8 @@ const SOCKET_CLI_SENTRY_NPM_BIN_NAME = 'socket-npm-with-sentry'
209211
const SOCKET_CLI_SENTRY_NPX_BIN_NAME = 'socket-npx-with-sentry'
210212
const SOCKET_CLI_SENTRY_PACKAGE_NAME = '@socketsecurity/cli-with-sentry'
211213
const SOCKET_CLI_VIEW_ALL_RISKS = 'SOCKET_CLI_VIEW_ALL_RISKS'
214+
const SOCKET_DEFAULT_BRANCH = 'socket-default-branch'
215+
const SOCKET_DEFAULT_REPOSITORY = 'socket-default-repository'
212216
const SOCKET_WEBSITE_URL = 'https://socket.dev'
213217
const VLT = 'vlt'
214218
const WITH_SENTRY = 'with-sentry'
@@ -607,6 +611,8 @@ const constants: Constants = createConstantsObject(
607611
SOCKET_CLI_SENTRY_NPX_BIN_NAME,
608612
SOCKET_CLI_SENTRY_PACKAGE_NAME,
609613
SOCKET_CLI_VIEW_ALL_RISKS,
614+
SOCKET_DEFAULT_BRANCH,
615+
SOCKET_DEFAULT_REPOSITORY,
610616
SOCKET_WEBSITE_URL,
611617
VLT,
612618
WITH_SENTRY,

0 commit comments

Comments
 (0)