@socketsecurity/cli-with-sentry 1.0.36 → 1.0.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -3096,7 +3096,22 @@ async function gitCleanFdx(cwd = process.cwd()) {
3096
3096
  // TODO: propagate CResult?
3097
3097
  await spawn.spawn('git', ['clean', '-fdx'], stdioIgnoreOptions);
3098
3098
  }
3099
+ async function gitCheckoutBranch(branch, cwd = process.cwd()) {
3100
+ const stdioIgnoreOptions = {
3101
+ cwd,
3102
+ stdio: debug.isDebug('stdio') ? 'inherit' : 'ignore'
3103
+ };
3104
+ try {
3105
+ await spawn.spawn('git', ['checkout', branch], stdioIgnoreOptions);
3106
+ return true;
3107
+ } catch {}
3108
+ return false;
3109
+ }
3099
3110
  async function gitCreateAndPushBranch(branch, commitMsg, filepaths, options) {
3111
+ if (!filepaths.length) {
3112
+ debug.debugFn('notice', `miss: no filepaths to add`);
3113
+ return false;
3114
+ }
3100
3115
  const {
3101
3116
  cwd = process.cwd(),
3102
3117
  // Lazily access constants.ENV.SOCKET_CLI_GIT_USER_EMAIL.
@@ -3124,9 +3139,17 @@ async function gitCreateAndPushBranch(branch, commitMsg, filepaths, options) {
3124
3139
  error: e
3125
3140
  });
3126
3141
  }
3142
+ return false;
3143
+ }
3144
+ async function gitDeleteBranch(branch, cwd = process.cwd()) {
3145
+ const stdioIgnoreOptions = {
3146
+ cwd,
3147
+ stdio: debug.isDebug('stdio') ? 'inherit' : 'ignore'
3148
+ };
3127
3149
  try {
3128
3150
  // Will throw with exit code 1 if branch does not exist.
3129
3151
  await spawn.spawn('git', ['branch', '-D', branch], stdioIgnoreOptions);
3152
+ return true;
3130
3153
  } catch {}
3131
3154
  return false;
3132
3155
  }
@@ -3479,6 +3502,7 @@ async function getSocketPrsWithContext(owner, repo, options) {
3479
3502
  __proto__: null,
3480
3503
  ...options
3481
3504
  };
3505
+ const branchPattern = getSocketBranchPattern(options);
3482
3506
  const checkAuthor = strings.isNonEmptyString(author);
3483
3507
  const octokit = getOctokit();
3484
3508
  const octokitGraphql = getOctokitGraphql();
@@ -3518,8 +3542,8 @@ async function getSocketPrsWithContext(owner, repo, options) {
3518
3542
  const node = nodes[i];
3519
3543
  const login = node.author?.login;
3520
3544
  const matchesAuthor = checkAuthor ? login === author : true;
3521
- const parsedBranch = genericSocketBranchParser(node.headRefName);
3522
- if (matchesAuthor && parsedBranch) {
3545
+ const matchesBranch = branchPattern.test(node.headRefName);
3546
+ if (matchesAuthor && matchesBranch) {
3523
3547
  contextualMatches.push({
3524
3548
  context: {
3525
3549
  apiType: 'graphql',
@@ -3531,8 +3555,7 @@ async function getSocketPrsWithContext(owner, repo, options) {
3531
3555
  },
3532
3556
  match: {
3533
3557
  ...node,
3534
- author: login ?? '<unknown>',
3535
- parsedBranch
3558
+ author: login ?? '<unknown>'
3536
3559
  }
3537
3560
  });
3538
3561
  }
@@ -3563,8 +3586,8 @@ async function getSocketPrsWithContext(owner, repo, options) {
3563
3586
  const login = pr.user?.login;
3564
3587
  const headRefName = pr.head.ref;
3565
3588
  const matchesAuthor = checkAuthor ? login === author : true;
3566
- const parsedBranch = genericSocketBranchParser(headRefName);
3567
- if (matchesAuthor && parsedBranch) {
3589
+ const matchesBranch = branchPattern.test(headRefName);
3590
+ if (matchesAuthor && matchesBranch) {
3568
3591
  // Upper cased mergeable_state is equivalent to mergeStateStatus.
3569
3592
  // https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#get-a-pull-request
3570
3593
  const mergeStateStatus = pr.mergeable_state?.toUpperCase?.() ?? 'UNKNOWN';
@@ -3587,7 +3610,6 @@ async function getSocketPrsWithContext(owner, repo, options) {
3587
3610
  headRefName,
3588
3611
  mergeStateStatus,
3589
3612
  number: pr.number,
3590
- parsedBranch,
3591
3613
  state,
3592
3614
  title: pr.title
3593
3615
  }
@@ -3906,7 +3928,6 @@ async function agentFix(pkgEnvDetails, actualTree, alertsMap, installer, {
3906
3928
  const pkgPath = path.dirname(pkgJsonPath);
3907
3929
  const isWorkspaceRoot = pkgJsonPath === pkgEnvDetails.editablePkgJson.filename;
3908
3930
  const workspace = isWorkspaceRoot ? 'root' : path.relative(rootPath, pkgPath);
3909
- const branchWorkspace = fixEnv.isCi ? getSocketBranchWorkspaceComponent(workspace) : '';
3910
3931
  // actualTree may not be defined on the first iteration of pkgJsonPathsLoop.
3911
3932
  if (!actualTree) {
3912
3933
  if (!fixEnv.isCi) {
@@ -3980,9 +4001,7 @@ async function agentFix(pkgEnvDetails, actualTree, alertsMap, installer, {
3980
4001
  continue infosLoop;
3981
4002
  }
3982
4003
  const branch = getSocketBranchName(oldPurl, newVersion, workspace);
3983
- const pr = prs.find(({
3984
- parsedBranch: b
3985
- }) => b.workspace === branchWorkspace && b.newVersion === newVersion);
4004
+ const pr = prs.find(p => p.headRefName === branch);
3986
4005
  if (pr) {
3987
4006
  debug.debugFn('notice', `skip: PR #${pr.number} for ${name} exists`);
3988
4007
  if (++count >= limit) {
@@ -4033,6 +4052,8 @@ async function agentFix(pkgEnvDetails, actualTree, alertsMap, installer, {
4033
4052
  if (fixEnv.isCi) {
4034
4053
  // eslint-disable-next-line no-await-in-loop
4035
4054
  await gitResetAndClean(fixEnv.baseBranch, cwd);
4055
+ // eslint-disable-next-line no-await-in-loop
4056
+ await gitCheckoutBranch(fixEnv.baseBranch, cwd);
4036
4057
  }
4037
4058
  continue infosLoop;
4038
4059
  }
@@ -4098,6 +4119,10 @@ async function agentFix(pkgEnvDetails, actualTree, alertsMap, installer, {
4098
4119
  // eslint-disable-next-line no-await-in-loop
4099
4120
  await gitResetAndClean(fixEnv.baseBranch, cwd);
4100
4121
  // eslint-disable-next-line no-await-in-loop
4122
+ await gitCheckoutBranch(fixEnv.baseBranch, cwd);
4123
+ // eslint-disable-next-line no-await-in-loop
4124
+ await gitDeleteBranch(branch, cwd);
4125
+ // eslint-disable-next-line no-await-in-loop
4101
4126
  const maybeActualTree = await installer(pkgEnvDetails, {
4102
4127
  cwd,
4103
4128
  spinner
@@ -4154,7 +4179,9 @@ async function agentFix(pkgEnvDetails, actualTree, alertsMap, installer, {
4154
4179
  if (fixEnv.isCi) {
4155
4180
  spinner?.start();
4156
4181
  // eslint-disable-next-line no-await-in-loop
4157
- await gitResetAndClean(fixEnv.baseBranch, cwd);
4182
+ await gitResetAndClean(branch, cwd);
4183
+ // eslint-disable-next-line no-await-in-loop
4184
+ await gitCheckoutBranch(fixEnv.baseBranch, cwd);
4158
4185
  // eslint-disable-next-line no-await-in-loop
4159
4186
  const maybeActualTree = await installer(pkgEnvDetails, {
4160
4187
  cwd,
@@ -14266,5 +14293,5 @@ void (async () => {
14266
14293
  await utils.captureException(e);
14267
14294
  }
14268
14295
  })();
14269
- //# debugId=de722ff7-23df-4530-81e3-f05cc7c7a02e
14296
+ //# debugId=cb6e977b-e9db-4f34-bf64-f5a47c14882c
14270
14297
  //# sourceMappingURL=cli.js.map