mobbdev 0.0.61 → 0.0.62

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.
Files changed (2) hide show
  1. package/dist/index.mjs +60 -17
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -952,6 +952,56 @@ import { z as z5 } from "zod";
952
952
  import { RequestError } from "@octokit/request-error";
953
953
  import { Octokit } from "octokit";
954
954
  import { z as z3 } from "zod";
955
+
956
+ // src/features/analysis/scm/urlParser.ts
957
+ var pathnameParsingMap = {
958
+ "gitlab.com": (pathname) => {
959
+ if (pathname.length < 2)
960
+ return null;
961
+ return {
962
+ organization: pathname[0],
963
+ repoName: pathname[pathname.length - 1]
964
+ };
965
+ },
966
+ "github.com": (pathname) => {
967
+ if (pathname.length !== 2)
968
+ return null;
969
+ return {
970
+ organization: pathname[0],
971
+ repoName: pathname[1]
972
+ };
973
+ }
974
+ };
975
+ var NAME_REGEX = /[a-z0-9\-_.+]+/i;
976
+ var parseScmURL = (scmURL) => {
977
+ try {
978
+ const url = new URL(scmURL);
979
+ const hostname = url.hostname.toLowerCase();
980
+ if (!(hostname in pathnameParsingMap))
981
+ return null;
982
+ const projectPath = url.pathname.substring(1).replace(/.git$/i, "");
983
+ const repo = pathnameParsingMap[hostname](
984
+ projectPath.split("/")
985
+ );
986
+ if (!repo)
987
+ return null;
988
+ const { organization, repoName } = repo;
989
+ if (!organization || !repoName)
990
+ return null;
991
+ if (!organization.match(NAME_REGEX) || !repoName.match(NAME_REGEX))
992
+ return null;
993
+ return {
994
+ hostname: url.hostname,
995
+ organization,
996
+ projectPath,
997
+ repoName
998
+ };
999
+ } catch (e) {
1000
+ return null;
1001
+ }
1002
+ };
1003
+
1004
+ // src/features/analysis/scm/github.ts
955
1005
  function removeTrailingSlash(str) {
956
1006
  return str.trim().replace(/\/+$/, "");
957
1007
  }
@@ -994,7 +1044,6 @@ var GetBlameDocument = `
994
1044
  }
995
1045
  }
996
1046
  `;
997
- var githubUrlRegex = /^http[s]?:\/\/[^/\s]+\/([^/.\s]+\/[^/.\s]+)(\.git)?(\/)?$/i;
998
1047
  function getOktoKit(options) {
999
1048
  const token = options?.githubAuthToken ?? GITHUB_API_TOKEN ?? "";
1000
1049
  return new Octokit({ auth: token });
@@ -1221,17 +1270,15 @@ async function getCommit({
1221
1270
  }
1222
1271
  function parseOwnerAndRepo(gitHubUrl) {
1223
1272
  gitHubUrl = removeTrailingSlash(gitHubUrl);
1224
- if (!githubUrlRegex.test(gitHubUrl)) {
1273
+ const parsingResult = parseScmURL(gitHubUrl);
1274
+ if (!parsingResult || parsingResult.hostname !== "github.com") {
1225
1275
  throw new InvalidUrlPatternError(`invalid github repo Url ${gitHubUrl}`);
1226
1276
  }
1227
- const groups = gitHubUrl.split(githubUrlRegex).filter((res) => res);
1228
- const ownerAndRepo = groups[0]?.split("/");
1229
- const owner = ownerAndRepo?.at(0);
1230
- const repo = ownerAndRepo?.at(1);
1231
- if (!owner || !repo) {
1277
+ const { organization, repoName } = parsingResult;
1278
+ if (!organization || !repoName) {
1232
1279
  throw new InvalidUrlPatternError(`invalid github repo Url ${gitHubUrl}`);
1233
1280
  }
1234
- return { owner, repo };
1281
+ return { owner: organization, repo: repoName };
1235
1282
  }
1236
1283
  async function queryGithubGraphql(query, variables, options) {
1237
1284
  const token = options?.githubAuthToken ?? GITHUB_API_TOKEN ?? "";
@@ -1801,7 +1848,6 @@ var EnvVariablesZod2 = z5.object({
1801
1848
  GITLAB_API_TOKEN: z5.string().optional()
1802
1849
  });
1803
1850
  var { GITLAB_API_TOKEN } = EnvVariablesZod2.parse(process.env);
1804
- var gitlabUrlRegex = /^http[s]?:\/\/[^/\s]+\/(([^/.\s]+[/])+)([^/.\s]+)(\.git)?(\/)?$/i;
1805
1851
  function getGitBeaker(options) {
1806
1852
  const token = options?.gitlabAuthToken ?? GITLAB_API_TOKEN ?? "";
1807
1853
  if (token?.startsWith("glpat-") || token === "") {
@@ -2001,14 +2047,12 @@ async function getGitlabReferenceData({ ref, gitlabUrl }, options) {
2001
2047
  }
2002
2048
  function parseOwnerAndRepo2(gitlabUrl) {
2003
2049
  gitlabUrl = removeTrailingSlash2(gitlabUrl);
2004
- if (!gitlabUrlRegex.test(gitlabUrl)) {
2050
+ const parsingResult = parseScmURL(gitlabUrl);
2051
+ if (!parsingResult || parsingResult.hostname !== "gitlab.com") {
2005
2052
  throw new InvalidUrlPatternError(`invalid gitlab repo Url ${gitlabUrl}`);
2006
2053
  }
2007
- const groups = gitlabUrl.split(gitlabUrlRegex).filter((res) => res);
2008
- const owner = groups[0]?.split("/")[0];
2009
- const repo = groups[2];
2010
- const projectPath = `${groups[0]}${repo}`;
2011
- return { owner, repo, projectPath };
2054
+ const { organization, repoName, projectPath } = parsingResult;
2055
+ return { owner: organization, repo: repoName, projectPath };
2012
2056
  }
2013
2057
  async function getGitlabBlameRanges({ ref, gitlabUrl, path: path8 }, options) {
2014
2058
  const { projectPath } = parseOwnerAndRepo2(gitlabUrl);
@@ -2604,10 +2648,9 @@ Example:
2604
2648
  )}`;
2605
2649
  throw new CliError(formattedErrorMessage);
2606
2650
  }
2607
- var GIT_REPO_URL_PATTERN = /^https:\/\/(gitlab|github)\.com\/(([^/.\s]+[/])+)([^/.\s]+)(\.git)?(\/)?$/i;
2608
2651
  var UrlZ = z6.string({
2609
2652
  invalid_type_error: "is not a valid GitHub / GitLab URL"
2610
- }).regex(GIT_REPO_URL_PATTERN, {
2653
+ }).refine((data) => !!parseScmURL(data), {
2611
2654
  message: "is not a valid GitHub / GitLab URL"
2612
2655
  });
2613
2656
  function validateRepoUrl(args) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mobbdev",
3
- "version": "0.0.61",
3
+ "version": "0.0.62",
4
4
  "description": "Automated secure code remediation tool",
5
5
  "repository": "https://github.com/mobb-dev/bugsy",
6
6
  "main": "dist/index.js",