mobbdev 0.0.139 → 0.0.141

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 +814 -869
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -267,13 +267,12 @@ var GetVulByNodesMetadataDocument = `
267
267
  }
268
268
  `;
269
269
  var UpdateScmTokenDocument = `
270
- mutation updateScmToken($scmType: String!, $url: String!, $token: String!, $org: String, $username: String, $refreshToken: String) {
270
+ mutation updateScmToken($scmType: String!, $url: String!, $token: String!, $org: String, $refreshToken: String) {
271
271
  updateScmToken(
272
272
  scmType: $scmType
273
273
  url: $url
274
274
  token: $token
275
275
  org: $org
276
- username: $username
277
276
  refreshToken: $refreshToken
278
277
  ) {
279
278
  __typename
@@ -523,11 +522,11 @@ import chalk4 from "chalk";
523
522
  import Configstore from "configstore";
524
523
  import Debug12 from "debug";
525
524
  import extract from "extract-zip";
526
- import fetch3 from "node-fetch";
525
+ import fetch4 from "node-fetch";
527
526
  import open2 from "open";
528
527
  import semver from "semver";
529
528
  import tmp2 from "tmp";
530
- import { z as z12 } from "zod";
529
+ import { z as z11 } from "zod";
531
530
 
532
531
  // src/features/analysis/add_fix_comments_for_pr/add_fix_comments_for_pr.ts
533
532
  import Debug4 from "debug";
@@ -1208,13 +1207,67 @@ var AdoSdk = {
1208
1207
  // src/features/analysis/scm/bitbucket/bitbucket.ts
1209
1208
  import querystring3 from "node:querystring";
1210
1209
  import * as bitbucketPkg from "bitbucket";
1211
- import { z as z9 } from "zod";
1210
+ import { z as z8 } from "zod";
1212
1211
 
1213
1212
  // src/features/analysis/scm/scm.ts
1214
- import { Octokit as Octokit2 } from "@octokit/core";
1215
- import { z as z8 } from "zod";
1213
+ import { z as z7 } from "zod";
1214
+
1215
+ // src/features/analysis/scm/github/github.ts
1216
+ import { RequestError } from "@octokit/request-error";
1217
+
1218
+ // src/features/analysis/scm/github/consts.ts
1219
+ var POST_COMMENT_PATH = "POST /repos/{owner}/{repo}/pulls/{pull_number}/comments";
1220
+ var DELETE_COMMENT_PATH = "DELETE /repos/{owner}/{repo}/pulls/comments/{comment_id}";
1221
+ var UPDATE_COMMENT_PATH = "PATCH /repos/{owner}/{repo}/pulls/comments/{comment_id}";
1222
+ var GET_PR_COMMENTS_PATH = "GET /repos/{owner}/{repo}/pulls/{pull_number}/comments";
1223
+ var GET_PR_COMMENT_PATH = "GET /repos/{owner}/{repo}/pulls/comments/{comment_id}";
1224
+ var REPLY_TO_CODE_REVIEW_COMMENT_PATH = "POST /repos/{owner}/{repo}/pulls/{pull_number}/comments/{comment_id}/replies";
1225
+ var GET_PR = "GET /repos/{owner}/{repo}/pulls/{pull_number}";
1226
+ var POST_GENERAL_PR_COMMENT = "POST /repos/{owner}/{repo}/issues/{issue_number}/comments";
1227
+ var GET_GENERAL_PR_COMMENTS = "GET /repos/{owner}/{repo}/issues/{issue_number}/comments";
1228
+ var DELETE_GENERAL_PR_COMMENT = "DELETE /repos/{owner}/{repo}/issues/comments/{comment_id}";
1229
+ var CREATE_OR_UPDATE_A_REPOSITORY_SECRET = "PUT /repos/{owner}/{repo}/actions/secrets/{secret_name}";
1230
+ var GET_A_REPOSITORY_PUBLIC_KEY = "GET /repos/{owner}/{repo}/actions/secrets/public-key";
1231
+ var GET_USER = "GET /user";
1232
+ var GET_USER_REPOS = "GET /user/repos";
1233
+ var GET_REPO_BRANCHES = "GET /repos/{owner}/{repo}/branches";
1234
+ var GET_BLAME_DOCUMENT = `
1235
+ query GetBlame(
1236
+ $owner: String!
1237
+ $repo: String!
1238
+ $ref: String!
1239
+ $path: String!
1240
+ ) {
1241
+ repository(name: $repo, owner: $owner) {
1242
+ # branch name
1243
+ object(expression: $ref) {
1244
+ # cast Target to a Commit
1245
+ ... on Commit {
1246
+ # full repo-relative path to blame file
1247
+ blame(path: $path) {
1248
+ ranges {
1249
+ commit {
1250
+ author {
1251
+ user {
1252
+ name
1253
+ login
1254
+ }
1255
+ }
1256
+ authoredDate
1257
+ }
1258
+ startingLine
1259
+ endingLine
1260
+ age
1261
+ }
1262
+ }
1263
+ }
1264
+
1265
+ }
1266
+ }
1267
+ }
1268
+ `;
1216
1269
 
1217
- // src/features/analysis/scm/github/encryptSecret.ts
1270
+ // src/features/analysis/scm/github/utils/encrypt_secret.ts
1218
1271
  import sodium from "libsodium-wrappers";
1219
1272
  async function encryptSecret(secret, key) {
1220
1273
  await sodium.ready;
@@ -1224,10 +1277,464 @@ async function encryptSecret(secret, key) {
1224
1277
  return sodium.to_base64(encBytes, sodium.base64_variants.ORIGINAL);
1225
1278
  }
1226
1279
 
1227
- // src/features/analysis/scm/github/github.ts
1228
- import { RequestError } from "@octokit/request-error";
1280
+ // src/features/analysis/scm/github/utils/utils.ts
1229
1281
  import { Octokit } from "octokit";
1282
+ import { fetch as fetch2, ProxyAgent } from "undici";
1283
+ function parseGithubOwnerAndRepo(gitHubUrl) {
1284
+ gitHubUrl = normalizeUrl(gitHubUrl);
1285
+ const parsingResult = parseScmURL(gitHubUrl, "GitHub" /* GitHub */);
1286
+ if (!parsingResult) {
1287
+ throw new InvalidUrlPatternError(`invalid github repo Url ${gitHubUrl}`);
1288
+ }
1289
+ const { organization, repoName } = parsingResult;
1290
+ if (!organization || !repoName) {
1291
+ throw new InvalidUrlPatternError(`invalid github repo Url ${gitHubUrl}`);
1292
+ }
1293
+ return { owner: organization, repo: repoName };
1294
+ }
1295
+ function isGithubOnPrem(url) {
1296
+ if (!url) {
1297
+ return false;
1298
+ }
1299
+ return !url.includes(scmCloudUrl.GitHub);
1300
+ }
1301
+ function getFetch(url) {
1302
+ if (url && BROKERED_HOSTS.includes(new URL(url).origin)) {
1303
+ const dispatcher = new ProxyAgent({
1304
+ uri: process.env["GIT_PROXY_HOST"] || "http://tinyproxy:8888",
1305
+ requestTls: {
1306
+ rejectUnauthorized: false
1307
+ }
1308
+ });
1309
+ return (input, init) => {
1310
+ return fetch2(input, {
1311
+ ...init,
1312
+ dispatcher
1313
+ });
1314
+ };
1315
+ }
1316
+ return fetch2;
1317
+ }
1318
+ function getOktoKit(options) {
1319
+ const token = !options?.auth && !isGithubOnPrem(options?.url) ? GITHUB_API_TOKEN : options?.auth;
1320
+ const baseUrl = options?.url && isGithubOnPrem(options.url) ? `${new URL(options.url).origin}/api/v3` : void 0;
1321
+ return new Octokit({
1322
+ ...options,
1323
+ auth: token,
1324
+ baseUrl,
1325
+ request: {
1326
+ fetch: getFetch(baseUrl)
1327
+ }
1328
+ });
1329
+ }
1330
+ function isGithubActionActionToken(token) {
1331
+ return token.startsWith("ghs_");
1332
+ }
1333
+ async function githubValidateParams(url, accessToken) {
1334
+ try {
1335
+ const oktoKit = getOktoKit({ auth: accessToken, url });
1336
+ if (accessToken && !isGithubActionActionToken(accessToken)) {
1337
+ await oktoKit.rest.users.getAuthenticated();
1338
+ }
1339
+ if (url && shouldValidateUrl(url)) {
1340
+ const { owner, repo } = parseGithubOwnerAndRepo(url);
1341
+ await oktoKit.request(GET_REPO_BRANCHES, {
1342
+ owner,
1343
+ repo,
1344
+ per_page: 1
1345
+ });
1346
+ }
1347
+ } catch (e) {
1348
+ console.log("could not init github scm", e);
1349
+ const error = e;
1350
+ const code = error.status || error.statusCode || error.response?.status || error.response?.statusCode || error.response?.code;
1351
+ if (code === 401 || code === 403) {
1352
+ throw new InvalidAccessTokenError(`invalid github access token`);
1353
+ }
1354
+ if (code === 404) {
1355
+ throw new InvalidRepoUrlError(`invalid github repo Url ${url}`);
1356
+ }
1357
+ throw e;
1358
+ }
1359
+ }
1360
+
1361
+ // src/features/analysis/scm/github/github.ts
1362
+ function getGithubSdk(parmas = {}) {
1363
+ const octokit = getOktoKit(parmas);
1364
+ return {
1365
+ async postPrComment(params) {
1366
+ return octokit.request(POST_COMMENT_PATH, params);
1367
+ },
1368
+ async updatePrComment(params) {
1369
+ return octokit.request(UPDATE_COMMENT_PATH, params);
1370
+ },
1371
+ async getPrComments(params) {
1372
+ return octokit.request(GET_PR_COMMENTS_PATH, params);
1373
+ },
1374
+ async getPrComment(params) {
1375
+ return octokit.request(GET_PR_COMMENT_PATH, params);
1376
+ },
1377
+ async deleteComment(params) {
1378
+ return octokit.request(DELETE_COMMENT_PATH, params);
1379
+ },
1380
+ async replyToCodeReviewComment(params) {
1381
+ return octokit.request(REPLY_TO_CODE_REVIEW_COMMENT_PATH, params);
1382
+ },
1383
+ async getPrDiff(params) {
1384
+ return octokit.request(GET_PR, {
1385
+ ...params,
1386
+ mediaType: { format: "diff" }
1387
+ });
1388
+ },
1389
+ async getPr(params) {
1390
+ return octokit.request(GET_PR, { ...params });
1391
+ },
1392
+ async createOrUpdateRepositorySecret(params) {
1393
+ return octokit.request(CREATE_OR_UPDATE_A_REPOSITORY_SECRET, params);
1394
+ },
1395
+ async getRepositoryPublicKey(params) {
1396
+ return octokit.request(GET_A_REPOSITORY_PUBLIC_KEY, params);
1397
+ },
1398
+ async postGeneralPrComment(params) {
1399
+ return octokit.request(POST_GENERAL_PR_COMMENT, params);
1400
+ },
1401
+ async getGeneralPrComments(params) {
1402
+ return octokit.request(GET_GENERAL_PR_COMMENTS, params);
1403
+ },
1404
+ async deleteGeneralPrComment(params) {
1405
+ return octokit.request(DELETE_GENERAL_PR_COMMENT, params);
1406
+ },
1407
+ async getGithubUsername() {
1408
+ const res = await octokit.rest.users.getAuthenticated();
1409
+ return res.data.login;
1410
+ },
1411
+ async getGithubIsUserCollaborator(params) {
1412
+ const { username, repoUrl } = params;
1413
+ try {
1414
+ const { owner, repo } = parseGithubOwnerAndRepo(repoUrl);
1415
+ const res = await octokit.rest.repos.checkCollaborator({
1416
+ owner,
1417
+ repo,
1418
+ username
1419
+ });
1420
+ if (res.status === 204) {
1421
+ return true;
1422
+ }
1423
+ } catch (e) {
1424
+ return false;
1425
+ }
1426
+ return false;
1427
+ },
1428
+ async getGithubPullRequestStatus(params) {
1429
+ const { repoUrl, prNumber } = params;
1430
+ const { owner, repo } = parseGithubOwnerAndRepo(repoUrl);
1431
+ const res = await octokit.rest.pulls.get({
1432
+ owner,
1433
+ repo,
1434
+ pull_number: prNumber
1435
+ });
1436
+ if (res.data.merged) {
1437
+ return "merged";
1438
+ }
1439
+ if (res.data.draft) {
1440
+ return "draft";
1441
+ }
1442
+ return res.data.state;
1443
+ },
1444
+ async getGithubIsRemoteBranch(params) {
1445
+ const { repoUrl, branch } = params;
1446
+ const { owner, repo } = parseGithubOwnerAndRepo(repoUrl);
1447
+ try {
1448
+ const res = await octokit.rest.repos.getBranch({
1449
+ owner,
1450
+ repo,
1451
+ branch
1452
+ });
1453
+ return branch === res.data.name;
1454
+ } catch (e) {
1455
+ return false;
1456
+ }
1457
+ },
1458
+ async getGithubRepoList() {
1459
+ try {
1460
+ const githubRepos = await octokit.request(GET_USER_REPOS, {
1461
+ sort: "updated"
1462
+ });
1463
+ return githubRepos.data.map((repo) => ({
1464
+ repoName: repo.name,
1465
+ repoUrl: repo.html_url,
1466
+ repoOwner: repo.owner.login,
1467
+ repoLanguages: repo.language ? [repo.language] : [],
1468
+ repoIsPublic: !repo.private,
1469
+ repoUpdatedAt: repo.updated_at
1470
+ }));
1471
+ } catch (e) {
1472
+ if (e instanceof RequestError && e.status === 401) {
1473
+ return [];
1474
+ }
1475
+ if (e instanceof RequestError && e.status === 404) {
1476
+ return [];
1477
+ }
1478
+ throw e;
1479
+ }
1480
+ },
1481
+ async getGithubRepoDefaultBranch(repoUrl) {
1482
+ const { owner, repo } = parseGithubOwnerAndRepo(repoUrl);
1483
+ const repos = await octokit.rest.repos.get({ repo, owner });
1484
+ return repos.data.default_branch;
1485
+ },
1486
+ async getGithubReferenceData({
1487
+ ref,
1488
+ gitHubUrl
1489
+ }) {
1490
+ const { owner, repo } = parseGithubOwnerAndRepo(gitHubUrl);
1491
+ let res;
1492
+ try {
1493
+ res = await Promise.any([
1494
+ this.getBranch({ owner, repo, branch: ref }).then((result) => ({
1495
+ date: result.data.commit.commit.committer?.date ? new Date(result.data.commit.commit.committer?.date) : void 0,
1496
+ type: "BRANCH" /* BRANCH */,
1497
+ sha: result.data.commit.sha
1498
+ })),
1499
+ this.getCommit({ commitSha: ref, repo, owner }).then((commit) => ({
1500
+ date: new Date(commit.data.committer.date),
1501
+ type: "COMMIT" /* COMMIT */,
1502
+ sha: commit.data.sha
1503
+ })),
1504
+ this.getTagDate({ owner, repo, tag: ref }).then((data) => ({
1505
+ date: new Date(data.date),
1506
+ type: "TAG" /* TAG */,
1507
+ sha: data.sha
1508
+ }))
1509
+ ]);
1510
+ return res;
1511
+ } catch (e) {
1512
+ if (e instanceof AggregateError) {
1513
+ throw new RefNotFoundError(`ref: ${ref} does not exist`);
1514
+ }
1515
+ throw e;
1516
+ }
1517
+ },
1518
+ async getBranch({
1519
+ branch,
1520
+ owner,
1521
+ repo
1522
+ }) {
1523
+ return octokit.rest.repos.getBranch({
1524
+ branch,
1525
+ owner,
1526
+ repo
1527
+ });
1528
+ },
1529
+ async getCommit({
1530
+ commitSha,
1531
+ owner,
1532
+ repo
1533
+ }) {
1534
+ return octokit.rest.git.getCommit({
1535
+ repo,
1536
+ owner,
1537
+ commit_sha: commitSha
1538
+ });
1539
+ },
1540
+ async getTagDate({
1541
+ tag,
1542
+ owner,
1543
+ repo
1544
+ }) {
1545
+ const refResponse = await octokit.rest.git.getRef({
1546
+ ref: `tags/${tag}`,
1547
+ owner,
1548
+ repo
1549
+ });
1550
+ const tagSha = refResponse.data.object.sha;
1551
+ if (refResponse.data.object.type === "commit") {
1552
+ const res2 = await octokit.rest.git.getCommit({
1553
+ commit_sha: tagSha,
1554
+ owner,
1555
+ repo
1556
+ });
1557
+ return {
1558
+ date: res2.data.committer.date,
1559
+ sha: res2.data.sha
1560
+ };
1561
+ }
1562
+ const res = await octokit.rest.git.getTag({
1563
+ tag_sha: tagSha,
1564
+ owner,
1565
+ repo
1566
+ });
1567
+ return {
1568
+ date: res.data.tagger.date,
1569
+ sha: res.data.sha
1570
+ };
1571
+ },
1572
+ async getGithubBlameRanges(params) {
1573
+ const { ref, gitHubUrl, path: path9 } = params;
1574
+ const { owner, repo } = parseGithubOwnerAndRepo(gitHubUrl);
1575
+ const res = await octokit.graphql(
1576
+ GET_BLAME_DOCUMENT,
1577
+ {
1578
+ owner,
1579
+ repo,
1580
+ path: path9,
1581
+ ref
1582
+ }
1583
+ );
1584
+ if (!res?.repository?.object?.blame?.ranges) {
1585
+ return [];
1586
+ }
1587
+ return res.repository.object.blame.ranges.map((range) => ({
1588
+ startingLine: range.startingLine,
1589
+ endingLine: range.endingLine,
1590
+ email: range.commit.author.user?.email || "",
1591
+ name: range.commit.author.user?.name || "",
1592
+ login: range.commit.author.user?.login || ""
1593
+ }));
1594
+ },
1595
+ // todo: refactor the name for this function
1596
+ async createPr(params) {
1597
+ const { sourceRepoUrl, filesPaths, userRepoUrl, title, body } = params;
1598
+ const { owner: sourceOwner, repo: sourceRepo } = parseGithubOwnerAndRepo(sourceRepoUrl);
1599
+ const { owner, repo } = parseGithubOwnerAndRepo(userRepoUrl);
1600
+ const [sourceFilePath, secondFilePath] = filesPaths;
1601
+ const sourceFileContentResponse = await octokit.rest.repos.getContent({
1602
+ owner: sourceOwner,
1603
+ repo: sourceRepo,
1604
+ path: "/" + sourceFilePath
1605
+ });
1606
+ const { data: repository } = await octokit.rest.repos.get({ owner, repo });
1607
+ const defaultBranch = repository.default_branch;
1608
+ const newBranchName = `mobb/workflow-${Date.now()}`;
1609
+ await octokit.rest.git.createRef({
1610
+ owner,
1611
+ repo,
1612
+ ref: `refs/heads/${newBranchName}`,
1613
+ sha: await octokit.rest.git.getRef({ owner, repo, ref: `heads/${defaultBranch}` }).then((response) => response.data.object.sha)
1614
+ });
1615
+ const decodedContent = Buffer.from(
1616
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1617
+ // @ts-ignore
1618
+ sourceFileContentResponse.data.content,
1619
+ "base64"
1620
+ ).toString("utf-8");
1621
+ const tree = [
1622
+ {
1623
+ path: sourceFilePath,
1624
+ mode: "100644",
1625
+ type: "blob",
1626
+ content: decodedContent
1627
+ }
1628
+ ];
1629
+ if (secondFilePath) {
1630
+ const secondFileContentResponse = await octokit.rest.repos.getContent({
1631
+ owner: sourceOwner,
1632
+ repo: sourceRepo,
1633
+ path: "/" + secondFilePath
1634
+ });
1635
+ const secondDecodedContent = Buffer.from(
1636
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1637
+ // @ts-ignore
1638
+ secondFileContentResponse.data.content,
1639
+ "base64"
1640
+ ).toString("utf-8");
1641
+ tree.push({
1642
+ path: secondFilePath,
1643
+ mode: "100644",
1644
+ type: "blob",
1645
+ content: secondDecodedContent
1646
+ });
1647
+ }
1648
+ const createTreeResponse = await octokit.rest.git.createTree({
1649
+ owner,
1650
+ repo,
1651
+ base_tree: await octokit.rest.git.getRef({ owner, repo, ref: `heads/${defaultBranch}` }).then((response) => response.data.object.sha),
1652
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1653
+ // @ts-ignore
1654
+ tree
1655
+ });
1656
+ const createCommitResponse = await octokit.rest.git.createCommit({
1657
+ owner,
1658
+ repo,
1659
+ message: "Add new yaml file",
1660
+ tree: createTreeResponse.data.sha,
1661
+ parents: [
1662
+ await octokit.rest.git.getRef({ owner, repo, ref: `heads/${defaultBranch}` }).then((response) => response.data.object.sha)
1663
+ ]
1664
+ });
1665
+ await octokit.rest.git.updateRef({
1666
+ owner,
1667
+ repo,
1668
+ ref: `heads/${newBranchName}`,
1669
+ sha: createCommitResponse.data.sha
1670
+ });
1671
+ const createPRResponse = await octokit.rest.pulls.create({
1672
+ owner,
1673
+ repo,
1674
+ title,
1675
+ head: newBranchName,
1676
+ head_repo: sourceRepo,
1677
+ body,
1678
+ base: defaultBranch
1679
+ });
1680
+ return {
1681
+ pull_request_url: createPRResponse.data.html_url
1682
+ };
1683
+ },
1684
+ async getGithubBranchList(repoUrl) {
1685
+ const { owner, repo } = parseGithubOwnerAndRepo(repoUrl);
1686
+ return octokit.rest.repos.listBranches({
1687
+ owner,
1688
+ repo,
1689
+ per_page: 1e3,
1690
+ page: 1
1691
+ });
1692
+ },
1693
+ async createPullRequest(options) {
1694
+ const { owner, repo } = parseGithubOwnerAndRepo(options.repoUrl);
1695
+ return octokit.rest.pulls.create({
1696
+ owner,
1697
+ repo,
1698
+ title: options.title,
1699
+ body: options.body,
1700
+ head: options.sourceBranchName,
1701
+ base: options.targetBranchName,
1702
+ draft: false,
1703
+ maintainer_can_modify: true
1704
+ });
1705
+ },
1706
+ async forkRepo(options) {
1707
+ const { owner, repo } = parseGithubOwnerAndRepo(options.repoUrl);
1708
+ const createForkRes = await octokit.rest.repos.createFork({
1709
+ owner,
1710
+ repo,
1711
+ default_branch_only: false
1712
+ });
1713
+ return { url: createForkRes.data.html_url };
1714
+ },
1715
+ async getUserInfo() {
1716
+ return octokit.request(GET_USER);
1717
+ }
1718
+ };
1719
+ }
1720
+
1721
+ // src/features/analysis/scm/gitlab/gitlab.ts
1722
+ import querystring2 from "node:querystring";
1723
+ import {
1724
+ Gitlab
1725
+ } from "@gitbeaker/rest";
1726
+ import { ProxyAgent as ProxyAgent2 } from "undici";
1727
+
1728
+ // src/features/analysis/scm/env.ts
1230
1729
  import { z as z3 } from "zod";
1730
+ var EnvVariablesZod = z3.object({
1731
+ GITLAB_API_TOKEN: z3.string().optional(),
1732
+ BROKERED_HOSTS: z3.string().toLowerCase().transform(
1733
+ (x) => x.split(",").map((url) => url.trim(), []).filter(Boolean)
1734
+ ).default(""),
1735
+ GITHUB_API_TOKEN: z3.string().optional()
1736
+ });
1737
+ var { GITLAB_API_TOKEN, BROKERED_HOSTS, GITHUB_API_TOKEN } = EnvVariablesZod.parse(process.env);
1231
1738
 
1232
1739
  // src/features/analysis/scm/utils/get_issue_type.ts
1233
1740
  var getIssueType = (issueType) => {
@@ -1336,594 +1843,108 @@ var getIssueType = (issueType) => {
1336
1843
  return "Missing equals or hashcode method";
1337
1844
  case "WCF_MISCONFIGURATION_INSUFFICIENT_LOGGING" /* WcfMisconfigurationInsufficientLogging */:
1338
1845
  return "WCF Misconfiguration: Insufficient Logging";
1339
- case "WCF_MISCONFIGURATION_THROTTLING_NOT_ENABLED" /* WcfMisconfigurationThrottlingNotEnabled */:
1340
- return "WCF Misconfiguration: Throttling Not Enabled";
1341
- case "USELESS_REGEXP_CHAR_ESCAPE" /* UselessRegexpCharEscape */:
1342
- return "Useless regular-expression character escape";
1343
- case "INCOMPLETE_HOSTNAME_REGEX" /* IncompleteHostnameRegex */:
1344
- return "Incomplete Hostname Regex";
1345
- case "OVERLY_LARGE_RANGE" /* OverlyLargeRange */:
1346
- return "Regex: Overly Large Range";
1347
- case "INSUFFICIENT_LOGGING" /* InsufficientLogging */:
1348
- return "Insufficient Logging of Sensitive Operations";
1349
- case "PRIVACY_VIOLATION" /* PrivacyViolation */:
1350
- return "Privacy Violation";
1351
- case "INCOMPLETE_URL_SCHEME_CHECK" /* IncompleteUrlSchemeCheck */:
1352
- return "Incomplete URL Scheme Check";
1353
- case "VALUE_SHADOWING" /* ValueShadowing */:
1354
- return "Value Shadowing";
1355
- default: {
1356
- return issueType ? issueType.replaceAll("_", " ") : "Other";
1357
- }
1358
- }
1359
- };
1360
-
1361
- // src/features/analysis/scm/utils/index.ts
1362
- function getFixUrlWithRedirect(params) {
1363
- const {
1364
- fixId,
1365
- projectId,
1366
- organizationId,
1367
- analysisId,
1368
- redirectUrl,
1369
- appBaseUrl,
1370
- commentId
1371
- } = params;
1372
- const searchParams = new URLSearchParams();
1373
- searchParams.append("commit_redirect_url", redirectUrl);
1374
- searchParams.append("comment_id", commentId.toString());
1375
- return `${getFixUrl({
1376
- appBaseUrl,
1377
- fixId,
1378
- projectId,
1379
- organizationId,
1380
- analysisId
1381
- })}?${searchParams.toString()}`;
1382
- }
1383
- function getFixUrl({
1384
- appBaseUrl,
1385
- fixId,
1386
- projectId,
1387
- organizationId,
1388
- analysisId
1389
- }) {
1390
- return `${appBaseUrl}/organization/${organizationId}/project/${projectId}/report/${analysisId}/fix/${fixId}`;
1391
- }
1392
- function getCommitUrl(params) {
1393
- const {
1394
- fixId,
1395
- projectId,
1396
- organizationId,
1397
- analysisId,
1398
- redirectUrl,
1399
- appBaseUrl,
1400
- commentId
1401
- } = params;
1402
- const searchParams = new URLSearchParams();
1403
- searchParams.append("redirect_url", redirectUrl);
1404
- searchParams.append("comment_id", commentId.toString());
1405
- return `${getFixUrl({
1406
- appBaseUrl,
1407
- fixId,
1408
- projectId,
1409
- organizationId,
1410
- analysisId
1411
- })}/commit?${searchParams.toString()}`;
1412
- }
1413
- var userNamePattern = /^(https?:\/\/)([^@]+@)?([^/]+\/.+)$/;
1414
- var sshPattern = /^git@([\w.-]+):([\w./-]+)$/;
1415
- function normalizeUrl(repoUrl) {
1416
- let trimmedUrl = repoUrl.trim().replace(/\/+$/, "");
1417
- if (repoUrl.endsWith(".git")) {
1418
- trimmedUrl = trimmedUrl.slice(0, -".git".length);
1419
- }
1420
- const usernameMatch = trimmedUrl.match(userNamePattern);
1421
- if (usernameMatch) {
1422
- const [_all, protocol, _username, repoPath] = usernameMatch;
1423
- trimmedUrl = `${protocol}${repoPath}`;
1424
- }
1425
- const sshMatch = trimmedUrl.match(sshPattern);
1426
- if (sshMatch) {
1427
- const [_all, hostname, reporPath] = sshMatch;
1428
- trimmedUrl = `https://${hostname}/${reporPath}`;
1429
- }
1430
- return trimmedUrl;
1431
- }
1432
-
1433
- // src/features/analysis/scm/github/github.ts
1434
- var EnvVariablesZod = z3.object({
1435
- GITHUB_API_TOKEN: z3.string().optional()
1436
- });
1437
- var { GITHUB_API_TOKEN } = EnvVariablesZod.parse(process.env);
1438
- var GetBlameDocument = `
1439
- query GetBlame(
1440
- $owner: String!
1441
- $repo: String!
1442
- $ref: String!
1443
- $path: String!
1444
- ) {
1445
- repository(name: $repo, owner: $owner) {
1446
- # branch name
1447
- object(expression: $ref) {
1448
- # cast Target to a Commit
1449
- ... on Commit {
1450
- # full repo-relative path to blame file
1451
- blame(path: $path) {
1452
- ranges {
1453
- commit {
1454
- author {
1455
- user {
1456
- name
1457
- login
1458
- }
1459
- }
1460
- authoredDate
1461
- }
1462
- startingLine
1463
- endingLine
1464
- age
1465
- }
1466
- }
1467
- }
1468
-
1469
- }
1470
- }
1471
- }
1472
- `;
1473
- function getOktoKit(options) {
1474
- const token = options?.githubAuthToken ?? GITHUB_API_TOKEN ?? "";
1475
- return new Octokit({ auth: token });
1476
- }
1477
- function isGithbActionActionToken(token) {
1478
- return token.startsWith("ghs_");
1479
- }
1480
- async function githubValidateParams(url, accessToken) {
1481
- try {
1482
- const oktoKit = getOktoKit({ githubAuthToken: accessToken });
1483
- if (accessToken) {
1484
- isGithbActionActionToken(accessToken) ? null : await oktoKit.rest.users.getAuthenticated();
1485
- }
1486
- if (url) {
1487
- const { owner, repo } = parseGithubOwnerAndRepo(url);
1488
- await oktoKit.request("GET /repos/{owner}/{repo}/branches", {
1489
- owner,
1490
- repo,
1491
- per_page: 1
1492
- });
1493
- }
1494
- } catch (e) {
1495
- console.log("could not init github scm", e);
1496
- const error = e;
1497
- const code = error.status || error.statusCode || error.response?.status || error.response?.statusCode || error.response?.code;
1498
- if (code === 401 || code === 403) {
1499
- throw new InvalidAccessTokenError(`invalid github access token`);
1500
- }
1501
- if (code === 404) {
1502
- throw new InvalidRepoUrlError(`invalid github repo Url ${url}`);
1503
- }
1504
- throw e;
1505
- }
1506
- }
1507
- async function getGithubUsername(accessToken) {
1508
- const oktoKit = getOktoKit({ githubAuthToken: accessToken });
1509
- const res = await oktoKit.rest.users.getAuthenticated();
1510
- return res.data.login;
1511
- }
1512
- async function getGithubIsUserCollaborator(username, accessToken, repoUrl) {
1513
- try {
1514
- const { owner, repo } = parseGithubOwnerAndRepo(repoUrl);
1515
- const oktoKit = getOktoKit({ githubAuthToken: accessToken });
1516
- const res = await oktoKit.rest.repos.checkCollaborator({
1517
- owner,
1518
- repo,
1519
- username
1520
- });
1521
- if (res.status === 204) {
1522
- return true;
1523
- }
1524
- } catch (e) {
1525
- return false;
1526
- }
1527
- return false;
1528
- }
1529
- async function getGithubPullRequestStatus(accessToken, repoUrl, prNumber) {
1530
- const { owner, repo } = parseGithubOwnerAndRepo(repoUrl);
1531
- const oktoKit = getOktoKit({ githubAuthToken: accessToken });
1532
- const res = await oktoKit.rest.pulls.get({
1533
- owner,
1534
- repo,
1535
- pull_number: prNumber
1536
- });
1537
- if (res.data.merged) {
1538
- return "merged";
1539
- }
1540
- if (res.data.draft) {
1541
- return "draft";
1542
- }
1543
- return res.data.state;
1544
- }
1545
- async function getGithubIsRemoteBranch(accessToken, repoUrl, branch) {
1546
- const { owner, repo } = parseGithubOwnerAndRepo(repoUrl);
1547
- const oktoKit = getOktoKit({ githubAuthToken: accessToken });
1548
- try {
1549
- const res = await oktoKit.rest.repos.getBranch({
1550
- owner,
1551
- repo,
1552
- branch
1553
- });
1554
- return branch === res.data.name;
1555
- } catch (e) {
1556
- return false;
1557
- }
1558
- }
1559
- async function getGithubRepoList(accessToken) {
1560
- const oktoKit = getOktoKit({ githubAuthToken: accessToken });
1561
- try {
1562
- const githubRepos = await getRepos(oktoKit);
1563
- return githubRepos.map(
1564
- (repo) => {
1565
- const repoLanguages = [];
1566
- if (repo.language) {
1567
- repoLanguages.push(repo.language);
1568
- }
1569
- return {
1570
- repoName: repo.name,
1571
- repoUrl: repo.html_url,
1572
- repoOwner: repo.owner.login,
1573
- repoLanguages,
1574
- repoIsPublic: !repo.private,
1575
- repoUpdatedAt: repo.updated_at
1576
- };
1577
- }
1578
- );
1579
- } catch (e) {
1580
- if (e instanceof RequestError && e.status === 401) {
1581
- return [];
1582
- }
1583
- if (e instanceof RequestError && e.status === 404) {
1584
- return [];
1585
- }
1586
- throw e;
1587
- }
1588
- }
1589
- async function getGithubBranchList(accessToken, repoUrl) {
1590
- const { owner, repo } = parseGithubOwnerAndRepo(repoUrl);
1591
- const oktoKit = getOktoKit({ githubAuthToken: accessToken });
1592
- const res = await oktoKit.rest.repos.listBranches({
1593
- owner,
1594
- repo,
1595
- per_page: 1e3,
1596
- page: 1
1597
- });
1598
- return res.data.map((branch) => branch.name);
1599
- }
1600
- async function createPullRequest(options) {
1601
- const { owner, repo } = parseGithubOwnerAndRepo(options.repoUrl);
1602
- const oktoKit = getOktoKit({ githubAuthToken: options.accessToken });
1603
- const res = await oktoKit.rest.pulls.create({
1604
- owner,
1605
- repo,
1606
- title: options.title,
1607
- body: options.body,
1608
- head: options.sourceBranchName,
1609
- base: options.targetBranchName,
1610
- draft: false,
1611
- maintainer_can_modify: true
1612
- });
1613
- return res.data.number;
1614
- }
1615
- async function forkRepo(options) {
1616
- const { owner, repo } = parseGithubOwnerAndRepo(options.repoUrl);
1617
- const oktoKit = getOktoKit({ githubAuthToken: options.accessToken });
1618
- const res = await oktoKit.rest.repos.createFork({
1619
- owner,
1620
- repo,
1621
- default_branch_only: false
1622
- });
1623
- return { url: res.data.html_url ? String(res.data.html_url) : null };
1624
- }
1625
- async function getRepos(oktoKit) {
1626
- const res = await oktoKit.request("GET /user/repos?sort=updated", {
1627
- headers: {
1628
- "X-GitHub-Api-Version": "2022-11-28",
1629
- per_page: 100
1630
- }
1631
- });
1632
- return res.data;
1633
- }
1634
- async function getGithubRepoDefaultBranch(repoUrl, options) {
1635
- const oktoKit = getOktoKit(options);
1636
- const { owner, repo } = parseGithubOwnerAndRepo(repoUrl);
1637
- return (await oktoKit.rest.repos.get({ repo, owner })).data.default_branch;
1638
- }
1639
- async function getGithubReferenceData({ ref, gitHubUrl }, options) {
1640
- const { owner, repo } = parseGithubOwnerAndRepo(gitHubUrl);
1641
- let res;
1642
- try {
1643
- const oktoKit = getOktoKit(options);
1644
- res = await Promise.any([
1645
- getBranch({ owner, repo, branch: ref }, oktoKit).then((result) => ({
1646
- date: result.data.commit.commit.committer?.date ? new Date(result.data.commit.commit.committer?.date) : void 0,
1647
- type: "BRANCH" /* BRANCH */,
1648
- sha: result.data.commit.sha
1649
- })),
1650
- getCommit({ commitSha: ref, repo, owner }, oktoKit).then((commit) => ({
1651
- date: new Date(commit.data.committer.date),
1652
- type: "COMMIT" /* COMMIT */,
1653
- sha: commit.data.sha
1654
- })),
1655
- getTagDate({ owner, repo, tag: ref }, oktoKit).then((data) => ({
1656
- date: new Date(data.date),
1657
- type: "TAG" /* TAG */,
1658
- sha: data.sha
1659
- }))
1660
- ]);
1661
- return res;
1662
- } catch (e) {
1663
- if (e instanceof AggregateError) {
1664
- throw new RefNotFoundError(`ref: ${ref} does not exist`);
1665
- }
1666
- throw e;
1667
- }
1668
- }
1669
- async function getBranch({ branch, owner, repo }, oktoKit) {
1670
- return oktoKit.rest.repos.getBranch({
1671
- branch,
1672
- owner,
1673
- repo
1674
- });
1675
- }
1676
- async function getTagDate({ tag, owner, repo }, oktoKit) {
1677
- const refResponse = await oktoKit.rest.git.getRef({
1678
- ref: `tags/${tag}`,
1679
- owner,
1680
- repo
1681
- });
1682
- const tagSha = refResponse.data.object.sha;
1683
- if (refResponse.data.object.type === "commit") {
1684
- const res2 = await oktoKit.rest.git.getCommit({
1685
- commit_sha: tagSha,
1686
- owner,
1687
- repo
1688
- });
1689
- return {
1690
- date: res2.data.committer.date,
1691
- sha: res2.data.sha
1692
- };
1693
- }
1694
- const res = await oktoKit.rest.git.getTag({
1695
- tag_sha: tagSha,
1696
- owner,
1697
- repo
1698
- });
1699
- return {
1700
- date: res.data.tagger.date,
1701
- sha: res.data.sha
1702
- };
1703
- }
1704
- async function getCommit({
1705
- commitSha,
1706
- owner,
1707
- repo
1708
- }, oktoKit) {
1709
- return oktoKit.rest.git.getCommit({
1710
- repo,
1711
- owner,
1712
- commit_sha: commitSha
1713
- });
1714
- }
1715
- function parseGithubOwnerAndRepo(gitHubUrl) {
1716
- gitHubUrl = normalizeUrl(gitHubUrl);
1717
- const parsingResult = parseScmURL(gitHubUrl, "GitHub" /* GitHub */);
1718
- if (!parsingResult || parsingResult.hostname !== "github.com") {
1719
- throw new InvalidUrlPatternError(`invalid github repo Url ${gitHubUrl}`);
1720
- }
1721
- const { organization, repoName } = parsingResult;
1722
- if (!organization || !repoName) {
1723
- throw new InvalidUrlPatternError(`invalid github repo Url ${gitHubUrl}`);
1724
- }
1725
- return { owner: organization, repo: repoName };
1726
- }
1727
- async function queryGithubGraphql(query, variables, options) {
1728
- const token = options?.githubAuthToken ?? GITHUB_API_TOKEN ?? "";
1729
- const parameters = variables ?? {};
1730
- const authorizationHeader = {
1731
- headers: {
1732
- authorization: `bearer ${token}`
1733
- }
1734
- };
1735
- try {
1736
- const oktoKit = getOktoKit(options);
1737
- const res = await oktoKit.graphql(query, {
1738
- ...parameters,
1739
- ...authorizationHeader
1740
- });
1741
- return res;
1742
- } catch (e) {
1743
- if (e instanceof RequestError) {
1744
- return null;
1846
+ case "WCF_MISCONFIGURATION_THROTTLING_NOT_ENABLED" /* WcfMisconfigurationThrottlingNotEnabled */:
1847
+ return "WCF Misconfiguration: Throttling Not Enabled";
1848
+ case "USELESS_REGEXP_CHAR_ESCAPE" /* UselessRegexpCharEscape */:
1849
+ return "Useless regular-expression character escape";
1850
+ case "INCOMPLETE_HOSTNAME_REGEX" /* IncompleteHostnameRegex */:
1851
+ return "Incomplete Hostname Regex";
1852
+ case "OVERLY_LARGE_RANGE" /* OverlyLargeRange */:
1853
+ return "Regex: Overly Large Range";
1854
+ case "INSUFFICIENT_LOGGING" /* InsufficientLogging */:
1855
+ return "Insufficient Logging of Sensitive Operations";
1856
+ case "PRIVACY_VIOLATION" /* PrivacyViolation */:
1857
+ return "Privacy Violation";
1858
+ case "INCOMPLETE_URL_SCHEME_CHECK" /* IncompleteUrlSchemeCheck */:
1859
+ return "Incomplete URL Scheme Check";
1860
+ case "VALUE_NEVER_READ" /* ValueNeverRead */:
1861
+ return "Value Never Read";
1862
+ case "VALUE_SHADOWING" /* ValueShadowing */:
1863
+ return "Value Shadowing";
1864
+ default: {
1865
+ return issueType ? issueType.replaceAll("_", " ") : "Other";
1745
1866
  }
1746
- throw e;
1747
- }
1748
- }
1749
- async function getGithubBlameRanges({ ref, gitHubUrl, path: path9 }, options) {
1750
- const { owner, repo } = parseGithubOwnerAndRepo(gitHubUrl);
1751
- const variables = {
1752
- owner,
1753
- repo,
1754
- path: path9,
1755
- ref
1756
- };
1757
- const res = await queryGithubGraphql(
1758
- GetBlameDocument,
1759
- variables,
1760
- options
1761
- );
1762
- if (!res?.repository?.object?.blame?.ranges) {
1763
- return [];
1764
- }
1765
- return res.repository.object.blame.ranges.map((range) => ({
1766
- startingLine: range.startingLine,
1767
- endingLine: range.endingLine,
1768
- email: range.commit.author.user?.email || "",
1769
- name: range.commit.author.user?.name || "",
1770
- login: range.commit.author.user?.login || ""
1771
- }));
1772
- }
1773
- async function createPr({
1774
- sourceRepoUrl,
1775
- filesPaths,
1776
- userRepoUrl,
1777
- title,
1778
- body
1779
- }, options) {
1780
- const oktoKit = getOktoKit(options);
1781
- const { owner: sourceOwner, repo: sourceRepo } = parseGithubOwnerAndRepo(sourceRepoUrl);
1782
- const { owner, repo } = parseGithubOwnerAndRepo(userRepoUrl);
1783
- const [sourceFilePath, secondFilePath] = filesPaths;
1784
- const sourceFileContentResponse = await oktoKit.rest.repos.getContent({
1785
- owner: sourceOwner,
1786
- repo: sourceRepo,
1787
- path: "/" + sourceFilePath
1788
- });
1789
- const { data: repository } = await oktoKit.rest.repos.get({ owner, repo });
1790
- const defaultBranch = repository.default_branch;
1791
- const newBranchName = `mobb/workflow-${Date.now()}`;
1792
- await oktoKit.rest.git.createRef({
1793
- owner,
1794
- repo,
1795
- ref: `refs/heads/${newBranchName}`,
1796
- sha: await oktoKit.rest.git.getRef({ owner, repo, ref: `heads/${defaultBranch}` }).then((response) => response.data.object.sha)
1797
- });
1798
- const decodedContent = Buffer.from(
1799
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1800
- // @ts-ignore
1801
- sourceFileContentResponse.data.content,
1802
- "base64"
1803
- ).toString("utf-8");
1804
- const tree = [
1805
- {
1806
- path: sourceFilePath,
1807
- mode: "100644",
1808
- type: "blob",
1809
- content: decodedContent
1810
- }
1811
- ];
1812
- if (secondFilePath) {
1813
- const secondFileContentResponse = await oktoKit.rest.repos.getContent({
1814
- owner: sourceOwner,
1815
- repo: sourceRepo,
1816
- path: "/" + secondFilePath
1817
- });
1818
- const secondDecodedContent = Buffer.from(
1819
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1820
- // @ts-ignore
1821
- secondFileContentResponse.data.content,
1822
- "base64"
1823
- ).toString("utf-8");
1824
- tree.push({
1825
- path: secondFilePath,
1826
- mode: "100644",
1827
- type: "blob",
1828
- content: secondDecodedContent
1829
- });
1830
1867
  }
1831
- const createTreeResponse = await oktoKit.rest.git.createTree({
1832
- owner,
1833
- repo,
1834
- base_tree: await oktoKit.rest.git.getRef({ owner, repo, ref: `heads/${defaultBranch}` }).then((response) => response.data.object.sha),
1835
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1836
- // @ts-ignore
1837
- tree
1838
- });
1839
- const createCommitResponse = await oktoKit.rest.git.createCommit({
1840
- owner,
1841
- repo,
1842
- message: "Add new yaml file",
1843
- tree: createTreeResponse.data.sha,
1844
- parents: [
1845
- await oktoKit.rest.git.getRef({ owner, repo, ref: `heads/${defaultBranch}` }).then((response) => response.data.object.sha)
1846
- ]
1847
- });
1848
- await oktoKit.rest.git.updateRef({
1849
- owner,
1850
- repo,
1851
- ref: `heads/${newBranchName}`,
1852
- sha: createCommitResponse.data.sha
1853
- });
1854
- const createPRResponse = await oktoKit.rest.pulls.create({
1855
- owner,
1856
- repo,
1857
- title,
1858
- head: newBranchName,
1859
- head_repo: sourceRepo,
1860
- body,
1861
- base: defaultBranch
1862
- });
1863
- return {
1864
- pull_request_url: createPRResponse.data.html_url
1865
- };
1866
- }
1867
-
1868
- // src/features/analysis/scm/github/consts.ts
1869
- var POST_COMMENT_PATH = "POST /repos/{owner}/{repo}/pulls/{pull_number}/comments";
1870
- var DELETE_COMMENT_PATH = "DELETE /repos/{owner}/{repo}/pulls/comments/{comment_id}";
1871
- var UPDATE_COMMENT_PATH = "PATCH /repos/{owner}/{repo}/pulls/comments/{comment_id}";
1872
- var GET_PR_COMMENTS_PATH = "GET /repos/{owner}/{repo}/pulls/{pull_number}/comments";
1873
- var GET_PR_COMMENT_PATH = "GET /repos/{owner}/{repo}/pulls/comments/{comment_id}";
1874
- var GET_PR = "GET /repos/{owner}/{repo}/pulls/{pull_number}";
1875
- var POST_GENERAL_PR_COMMENT = "POST /repos/{owner}/{repo}/issues/{issue_number}/comments";
1876
- var GET_GENERAL_PR_COMMENTS = "GET /repos/{owner}/{repo}/issues/{issue_number}/comments";
1877
- var DELETE_GENERAL_PR_COMMENT = "DELETE /repos/{owner}/{repo}/issues/comments/{comment_id}";
1878
- var CREATE_OR_UPDATE_A_REPOSITORY_SECRET = "PUT /repos/{owner}/{repo}/actions/secrets/{secret_name}";
1879
- var GET_A_REPOSITORY_PUBLIC_KEY = "GET /repos/{owner}/{repo}/actions/secrets/public-key";
1868
+ };
1880
1869
 
1881
- // src/features/analysis/scm/github/github-v2.ts
1882
- function postPrComment(client, params) {
1883
- return client.request(POST_COMMENT_PATH, params);
1884
- }
1885
- function updatePrComment(client, params) {
1886
- return client.request(UPDATE_COMMENT_PATH, params);
1887
- }
1888
- function getPrComments(client, params) {
1889
- return client.request(GET_PR_COMMENTS_PATH, params);
1890
- }
1891
- function getPrComment(client, params) {
1892
- return client.request(GET_PR_COMMENT_PATH, params);
1893
- }
1894
- function deleteComment(client, params) {
1895
- return client.request(DELETE_COMMENT_PATH, params);
1896
- }
1897
- function getPrDiff(client, params) {
1898
- return client.request(GET_PR, { ...params, mediaType: { format: "diff" } });
1899
- }
1900
- function getPr(client, params) {
1901
- return client.request(GET_PR, { ...params });
1902
- }
1903
- function createOrUpdateRepositorySecret(client, params) {
1904
- return client.request(CREATE_OR_UPDATE_A_REPOSITORY_SECRET, params);
1870
+ // src/features/analysis/scm/utils/index.ts
1871
+ function getFixUrlWithRedirect(params) {
1872
+ const {
1873
+ fixId,
1874
+ projectId,
1875
+ organizationId,
1876
+ analysisId,
1877
+ redirectUrl,
1878
+ appBaseUrl,
1879
+ commentId
1880
+ } = params;
1881
+ const searchParams = new URLSearchParams();
1882
+ searchParams.append("commit_redirect_url", redirectUrl);
1883
+ searchParams.append("comment_id", commentId.toString());
1884
+ return `${getFixUrl({
1885
+ appBaseUrl,
1886
+ fixId,
1887
+ projectId,
1888
+ organizationId,
1889
+ analysisId
1890
+ })}?${searchParams.toString()}`;
1905
1891
  }
1906
- function getARepositoryPublicKey(client, params) {
1907
- return client.request(GET_A_REPOSITORY_PUBLIC_KEY, params);
1892
+ function getFixUrl({
1893
+ appBaseUrl,
1894
+ fixId,
1895
+ projectId,
1896
+ organizationId,
1897
+ analysisId
1898
+ }) {
1899
+ return `${appBaseUrl}/organization/${organizationId}/project/${projectId}/report/${analysisId}/fix/${fixId}`;
1908
1900
  }
1909
- function postGeneralPrComment(client, params) {
1910
- return client.request(POST_GENERAL_PR_COMMENT, params);
1901
+ function getCommitUrl(params) {
1902
+ const {
1903
+ fixId,
1904
+ projectId,
1905
+ organizationId,
1906
+ analysisId,
1907
+ redirectUrl,
1908
+ appBaseUrl,
1909
+ commentId
1910
+ } = params;
1911
+ const searchParams = new URLSearchParams();
1912
+ searchParams.append("redirect_url", redirectUrl);
1913
+ searchParams.append("comment_id", commentId.toString());
1914
+ return `${getFixUrl({
1915
+ appBaseUrl,
1916
+ fixId,
1917
+ projectId,
1918
+ organizationId,
1919
+ analysisId
1920
+ })}/commit?${searchParams.toString()}`;
1911
1921
  }
1912
- function getGeneralPrComments(client, params) {
1913
- return client.request(GET_GENERAL_PR_COMMENTS, params);
1922
+ var userNamePattern = /^(https?:\/\/)([^@]+@)?([^/]+\/.+)$/;
1923
+ var sshPattern = /^git@([\w.-]+):([\w./-]+)$/;
1924
+ function normalizeUrl(repoUrl) {
1925
+ let trimmedUrl = repoUrl.trim().replace(/\/+$/, "");
1926
+ if (repoUrl.endsWith(".git")) {
1927
+ trimmedUrl = trimmedUrl.slice(0, -".git".length);
1928
+ }
1929
+ const usernameMatch = trimmedUrl.match(userNamePattern);
1930
+ if (usernameMatch) {
1931
+ const [_all, protocol, _username, repoPath] = usernameMatch;
1932
+ trimmedUrl = `${protocol}${repoPath}`;
1933
+ }
1934
+ const sshMatch = trimmedUrl.match(sshPattern);
1935
+ if (sshMatch) {
1936
+ const [_all, hostname, reporPath] = sshMatch;
1937
+ trimmedUrl = `https://${hostname}/${reporPath}`;
1938
+ }
1939
+ return trimmedUrl;
1914
1940
  }
1915
- function deleteGeneralPrComment(client, params) {
1916
- return client.request(DELETE_GENERAL_PR_COMMENT, params);
1941
+ var isUrlHasPath = (url) => {
1942
+ return new URL(url).origin !== url;
1943
+ };
1944
+ function shouldValidateUrl(repoUrl) {
1945
+ return repoUrl && isUrlHasPath(repoUrl);
1917
1946
  }
1918
1947
 
1919
- // src/features/analysis/scm/gitlab/gitlab.ts
1920
- import querystring2 from "node:querystring";
1921
- import {
1922
- Gitlab
1923
- } from "@gitbeaker/rest";
1924
- import { ProxyAgent } from "undici";
1925
- import { z as z5 } from "zod";
1926
-
1927
1948
  // src/features/analysis/scm/gitlab/types.ts
1928
1949
  import { z as z4 } from "zod";
1929
1950
  var GitlabAuthResultZ = z4.object({
@@ -1933,13 +1954,6 @@ var GitlabAuthResultZ = z4.object({
1933
1954
  });
1934
1955
 
1935
1956
  // src/features/analysis/scm/gitlab/gitlab.ts
1936
- var EnvVariablesZod2 = z5.object({
1937
- GITLAB_API_TOKEN: z5.string().optional(),
1938
- BROKERED_HOSTS: z5.string().toLowerCase().transform(
1939
- (x) => x.split(",").map((url) => url.trim(), []).filter(Boolean)
1940
- ).default("")
1941
- });
1942
- var { GITLAB_API_TOKEN, BROKERED_HOSTS } = EnvVariablesZod2.parse(process.env);
1943
1957
  function removeTrailingSlash2(str) {
1944
1958
  return str.trim().replace(/\/+$/, "");
1945
1959
  }
@@ -1961,7 +1975,7 @@ async function gitlabValidateParams({
1961
1975
  if (accessToken) {
1962
1976
  await api2.Users.showCurrentUser();
1963
1977
  }
1964
- if (url) {
1978
+ if (url && shouldValidateUrl(url)) {
1965
1979
  const { projectPath } = parseGitlabOwnerAndRepo(url);
1966
1980
  await api2.Projects.show(projectPath);
1967
1981
  }
@@ -2214,7 +2228,7 @@ function initGitlabFetchMock() {
2214
2228
  if (urlParsed && BROKERED_HOSTS.includes(
2215
2229
  `${urlParsed.protocol?.toLowerCase()}//${urlParsed.host?.toLowerCase()}`
2216
2230
  )) {
2217
- const dispatcher = new ProxyAgent({
2231
+ const dispatcher = new ProxyAgent2({
2218
2232
  uri: process.env["GIT_PROXY_HOST"] || "http://tinyproxy:8888",
2219
2233
  requestTls: {
2220
2234
  rejectUnauthorized: false
@@ -2234,88 +2248,88 @@ import parseDiff from "parse-diff";
2234
2248
  import path3 from "path";
2235
2249
  import { simpleGit } from "simple-git";
2236
2250
  import tmp from "tmp";
2237
- import { z as z7 } from "zod";
2251
+ import { z as z6 } from "zod";
2238
2252
 
2239
2253
  // src/features/analysis/scm/scmSubmit/types.ts
2240
- import { z as z6 } from "zod";
2241
- var BaseSubmitToScmMessageZ = z6.object({
2242
- submitFixRequestId: z6.string().uuid(),
2243
- fixes: z6.array(
2244
- z6.object({
2245
- fixId: z6.string().uuid(),
2246
- patches: z6.array(z6.string())
2254
+ import { z as z5 } from "zod";
2255
+ var BaseSubmitToScmMessageZ = z5.object({
2256
+ submitFixRequestId: z5.string().uuid(),
2257
+ fixes: z5.array(
2258
+ z5.object({
2259
+ fixId: z5.string().uuid(),
2260
+ patches: z5.array(z5.string())
2247
2261
  })
2248
2262
  ),
2249
- commitHash: z6.string(),
2250
- repoUrl: z6.string()
2263
+ commitHash: z5.string(),
2264
+ repoUrl: z5.string()
2251
2265
  });
2252
2266
  var submitToScmMessageType = {
2253
2267
  commitToSameBranch: "commitToSameBranch",
2254
2268
  submitFixesForDifferentBranch: "submitFixesForDifferentBranch"
2255
2269
  };
2256
2270
  var CommitToSameBranchParamsZ = BaseSubmitToScmMessageZ.merge(
2257
- z6.object({
2258
- type: z6.literal(submitToScmMessageType.commitToSameBranch),
2259
- branch: z6.string(),
2260
- commitMessage: z6.string(),
2261
- commitDescription: z6.string().nullish(),
2262
- githubCommentId: z6.number().nullish()
2271
+ z5.object({
2272
+ type: z5.literal(submitToScmMessageType.commitToSameBranch),
2273
+ branch: z5.string(),
2274
+ commitMessage: z5.string(),
2275
+ commitDescription: z5.string().nullish(),
2276
+ githubCommentId: z5.number().nullish()
2263
2277
  })
2264
2278
  );
2265
- var SubmitFixesToDifferentBranchParamsZ = z6.object({
2266
- type: z6.literal(submitToScmMessageType.submitFixesForDifferentBranch),
2267
- submitBranch: z6.string(),
2268
- baseBranch: z6.string()
2279
+ var SubmitFixesToDifferentBranchParamsZ = z5.object({
2280
+ type: z5.literal(submitToScmMessageType.submitFixesForDifferentBranch),
2281
+ submitBranch: z5.string(),
2282
+ baseBranch: z5.string()
2269
2283
  }).merge(BaseSubmitToScmMessageZ);
2270
- var SubmitFixesMessageZ = z6.union([
2284
+ var SubmitFixesMessageZ = z5.union([
2271
2285
  CommitToSameBranchParamsZ,
2272
2286
  SubmitFixesToDifferentBranchParamsZ
2273
2287
  ]);
2274
- var FixResponseArrayZ = z6.array(
2275
- z6.object({
2276
- fixId: z6.string().uuid()
2288
+ var FixResponseArrayZ = z5.array(
2289
+ z5.object({
2290
+ fixId: z5.string().uuid()
2277
2291
  })
2278
2292
  );
2279
- var SubmitFixesBaseResponseMessageZ = z6.object({
2280
- submitFixRequestId: z6.string().uuid(),
2281
- submitBranches: z6.array(
2282
- z6.object({
2283
- branchName: z6.string(),
2293
+ var SubmitFixesBaseResponseMessageZ = z5.object({
2294
+ submitFixRequestId: z5.string().uuid(),
2295
+ submitBranches: z5.array(
2296
+ z5.object({
2297
+ branchName: z5.string(),
2284
2298
  fixes: FixResponseArrayZ
2285
2299
  })
2286
2300
  ),
2287
- error: z6.object({
2288
- type: z6.enum([
2301
+ error: z5.object({
2302
+ type: z5.enum([
2289
2303
  "InitialRepoAccessError",
2290
2304
  "PushBranchError",
2291
2305
  "UnknownError"
2292
2306
  ]),
2293
- info: z6.object({
2294
- message: z6.string(),
2295
- pushBranchName: z6.string().optional()
2307
+ info: z5.object({
2308
+ message: z5.string(),
2309
+ pushBranchName: z5.string().optional()
2296
2310
  })
2297
2311
  }).optional()
2298
2312
  });
2299
- var SubmitFixesToSameBranchResponseMessageZ = z6.object({
2300
- type: z6.literal(submitToScmMessageType.commitToSameBranch),
2301
- githubCommentId: z6.number().nullish()
2313
+ var SubmitFixesToSameBranchResponseMessageZ = z5.object({
2314
+ type: z5.literal(submitToScmMessageType.commitToSameBranch),
2315
+ githubCommentId: z5.number().nullish()
2302
2316
  }).merge(SubmitFixesBaseResponseMessageZ);
2303
- var SubmitFixesToDifferentBranchResponseMessageZ = z6.object({
2304
- type: z6.literal(submitToScmMessageType.submitFixesForDifferentBranch),
2305
- githubCommentId: z6.number().optional()
2317
+ var SubmitFixesToDifferentBranchResponseMessageZ = z5.object({
2318
+ type: z5.literal(submitToScmMessageType.submitFixesForDifferentBranch),
2319
+ githubCommentId: z5.number().optional()
2306
2320
  }).merge(SubmitFixesBaseResponseMessageZ);
2307
- var SubmitFixesResponseMessageZ = z6.discriminatedUnion("type", [
2321
+ var SubmitFixesResponseMessageZ = z5.discriminatedUnion("type", [
2308
2322
  SubmitFixesToSameBranchResponseMessageZ,
2309
2323
  SubmitFixesToDifferentBranchResponseMessageZ
2310
2324
  ]);
2311
2325
 
2312
2326
  // src/features/analysis/scm/scmSubmit/index.ts
2313
- var EnvVariablesZod3 = z7.object({
2314
- BROKERED_HOSTS: z7.string().toLowerCase().transform(
2327
+ var EnvVariablesZod2 = z6.object({
2328
+ BROKERED_HOSTS: z6.string().toLowerCase().transform(
2315
2329
  (x) => x.split(",").map((url) => url.trim(), []).filter(Boolean)
2316
2330
  ).default("")
2317
2331
  });
2318
- var { BROKERED_HOSTS: BROKERED_HOSTS2 } = EnvVariablesZod3.parse(process.env);
2332
+ var { BROKERED_HOSTS: BROKERED_HOSTS2 } = EnvVariablesZod2.parse(process.env);
2319
2333
  var isValidBranchName = async (branchName) => {
2320
2334
  const git = simpleGit();
2321
2335
  try {
@@ -2328,18 +2342,18 @@ var isValidBranchName = async (branchName) => {
2328
2342
  return false;
2329
2343
  }
2330
2344
  };
2331
- var FixesZ = z7.array(
2332
- z7.object({
2333
- fixId: z7.string(),
2334
- patches: z7.array(z7.string())
2345
+ var FixesZ = z6.array(
2346
+ z6.object({
2347
+ fixId: z6.string(),
2348
+ patches: z6.array(z6.string())
2335
2349
  })
2336
2350
  ).nonempty();
2337
2351
 
2338
2352
  // src/features/analysis/scm/scm.ts
2339
- var GetRefererenceResultZ = z8.object({
2340
- date: z8.date().optional(),
2341
- sha: z8.string(),
2342
- type: z8.nativeEnum(ReferenceType)
2353
+ var GetRefererenceResultZ = z7.object({
2354
+ date: z7.date().optional(),
2355
+ sha: z7.string(),
2356
+ type: z7.nativeEnum(ReferenceType)
2343
2357
  });
2344
2358
  function getCloudScmLibTypeFromUrl(url) {
2345
2359
  if (!url) {
@@ -2380,11 +2394,11 @@ var scmTypeToScmLibScmType = {
2380
2394
  ["Bitbucket" /* Bitbucket */]: "BITBUCKET" /* BITBUCKET */
2381
2395
  };
2382
2396
  function getScmTypeFromScmLibType(scmLibType) {
2383
- const parsedScmLibType = z8.nativeEnum(ScmLibScmType).parse(scmLibType);
2397
+ const parsedScmLibType = z7.nativeEnum(ScmLibScmType).parse(scmLibType);
2384
2398
  return scmLibScmTypeToScmType[parsedScmLibType];
2385
2399
  }
2386
2400
  function getScmLibTypeFromScmType(scmType) {
2387
- const parsedScmType = z8.nativeEnum(ScmType).parse(scmType);
2401
+ const parsedScmType = z7.nativeEnum(ScmType).parse(scmType);
2388
2402
  return scmTypeToScmLibScmType[parsedScmType];
2389
2403
  }
2390
2404
  function getScmConfig({
@@ -2579,10 +2593,7 @@ var SCMLib = class {
2579
2593
  scmType,
2580
2594
  scmOrg
2581
2595
  }) {
2582
- let trimmedUrl = void 0;
2583
- if (url) {
2584
- trimmedUrl = url.trim().replace(/\/$/, "").replace(/.git$/i, "");
2585
- }
2596
+ const trimmedUrl = url ? url.trim().replace(/\/$/, "").replace(/.git$/i, "") : void 0;
2586
2597
  try {
2587
2598
  switch (scmType) {
2588
2599
  case "GITHUB" /* GITHUB */: {
@@ -2610,7 +2621,7 @@ var SCMLib = class {
2610
2621
  if (e instanceof InvalidRepoUrlError && url) {
2611
2622
  throw new RepoNoTokenAccessError(
2612
2623
  "no access to repo",
2613
- scmLibScmTypeToScmType[z8.nativeEnum(ScmLibScmType).parse(scmType)]
2624
+ scmLibScmTypeToScmType[z7.nativeEnum(ScmLibScmType).parse(scmType)]
2614
2625
  );
2615
2626
  }
2616
2627
  }
@@ -2905,46 +2916,37 @@ var GithubSCMLib = class extends SCMLib {
2905
2916
  // we don't always need a url, what's important is that we have an access token
2906
2917
  constructor(url, accessToken, scmOrg) {
2907
2918
  super(url, accessToken, scmOrg);
2908
- __publicField(this, "oktokit");
2909
- this.oktokit = new Octokit2({ auth: accessToken });
2919
+ __publicField(this, "githubSdk");
2920
+ this.githubSdk = getGithubSdk({
2921
+ auth: accessToken,
2922
+ url
2923
+ });
2910
2924
  }
2911
2925
  async createSubmitRequest(params) {
2912
2926
  this._validateAccessTokenAndUrl();
2913
2927
  const { targetBranchName, sourceBranchName, title, body } = params;
2914
- return String(
2915
- await createPullRequest({
2916
- title,
2917
- body,
2918
- targetBranchName,
2919
- sourceBranchName,
2920
- repoUrl: this.url,
2921
- accessToken: this.accessToken
2922
- })
2923
- );
2928
+ const pullRequestResult = await this.githubSdk.createPullRequest({
2929
+ title,
2930
+ body,
2931
+ targetBranchName,
2932
+ sourceBranchName,
2933
+ repoUrl: this.url
2934
+ });
2935
+ return String(pullRequestResult.data.number);
2924
2936
  }
2925
2937
  async forkRepo(repoUrl) {
2926
2938
  this._validateToken();
2927
- return forkRepo({
2928
- repoUrl,
2929
- accessToken: this.accessToken
2939
+ return this.githubSdk.forkRepo({
2940
+ repoUrl
2930
2941
  });
2931
2942
  }
2932
- async createOrUpdateRepositorySecret(params, _oktokit) {
2933
- if (!_oktokit && !this.accessToken || !this.url) {
2934
- throw new Error("cannot delete comment without access token or url");
2935
- }
2936
- const oktokit = _oktokit || this.oktokit;
2943
+ async createOrUpdateRepositorySecret(params) {
2944
+ this._validateAccessTokenAndUrl();
2937
2945
  const { owner, repo } = parseGithubOwnerAndRepo(this.url);
2938
- const { data: repositoryPublicKeyResponse } = await getARepositoryPublicKey(
2939
- oktokit,
2940
- {
2941
- owner,
2942
- repo
2943
- }
2944
- );
2946
+ const { data: repositoryPublicKeyResponse } = await this.githubSdk.getRepositoryPublicKey({ owner, repo });
2945
2947
  const { key_id, key } = repositoryPublicKeyResponse;
2946
2948
  const encryptedValue = await encryptSecret(params.value, key);
2947
- return createOrUpdateRepositorySecret(oktokit, {
2949
+ return this.githubSdk.createOrUpdateRepositorySecret({
2948
2950
  encrypted_value: encryptedValue,
2949
2951
  secret_name: params.name,
2950
2952
  key_id,
@@ -2953,66 +2955,49 @@ var GithubSCMLib = class extends SCMLib {
2953
2955
  });
2954
2956
  }
2955
2957
  async createPullRequestWithNewFile(sourceRepoUrl, filesPaths, userRepoUrl, title, body) {
2956
- const { pull_request_url } = await createPr(
2957
- {
2958
- sourceRepoUrl,
2959
- filesPaths,
2960
- userRepoUrl,
2961
- title,
2962
- body
2963
- },
2964
- {
2965
- githubAuthToken: this.accessToken
2966
- }
2967
- );
2958
+ const { pull_request_url } = await this.githubSdk.createPr({
2959
+ sourceRepoUrl,
2960
+ filesPaths,
2961
+ userRepoUrl,
2962
+ title,
2963
+ body
2964
+ });
2968
2965
  return { pull_request_url };
2969
2966
  }
2970
2967
  async validateParams() {
2971
2968
  return githubValidateParams(this.url, this.accessToken);
2972
2969
  }
2973
- async postPrComment(params, _oktokit) {
2974
- if (!_oktokit && !this.accessToken || !this.url) {
2975
- throw new Error("cannot post on PR without access token or url");
2976
- }
2977
- const oktokit = _oktokit || this.oktokit;
2970
+ async postPrComment(params) {
2971
+ this._validateAccessTokenAndUrl();
2978
2972
  const { owner, repo } = parseGithubOwnerAndRepo(this.url);
2979
- return postPrComment(oktokit, {
2973
+ return this.githubSdk.postPrComment({
2980
2974
  ...params,
2981
2975
  owner,
2982
2976
  repo
2983
2977
  });
2984
2978
  }
2985
- async updatePrComment(params, _oktokit) {
2986
- if (!_oktokit && !this.accessToken || !this.url) {
2987
- throw new Error("cannot update on PR without access token or url");
2988
- }
2989
- const oktokit = _oktokit || this.oktokit;
2979
+ async updatePrComment(params) {
2980
+ this._validateAccessTokenAndUrl();
2990
2981
  const { owner, repo } = parseGithubOwnerAndRepo(this.url);
2991
- return updatePrComment(oktokit, {
2982
+ return this.githubSdk.updatePrComment({
2992
2983
  ...params,
2993
2984
  owner,
2994
2985
  repo
2995
2986
  });
2996
2987
  }
2997
- async deleteComment(params, _oktokit) {
2998
- if (!_oktokit && !this.accessToken || !this.url) {
2999
- throw new Error("cannot delete comment without access token or url");
3000
- }
3001
- const oktokit = _oktokit || this.oktokit;
2988
+ async deleteComment(params) {
2989
+ this._validateAccessTokenAndUrl();
3002
2990
  const { owner, repo } = parseGithubOwnerAndRepo(this.url);
3003
- return deleteComment(oktokit, {
2991
+ return this.githubSdk.deleteComment({
3004
2992
  ...params,
3005
2993
  owner,
3006
2994
  repo
3007
2995
  });
3008
2996
  }
3009
- async getPrComments(params, _oktokit) {
3010
- if (!_oktokit && !this.accessToken || !this.url) {
3011
- throw new Error("cannot get Pr Comments without access token or url");
3012
- }
3013
- const oktokit = _oktokit || this.oktokit;
2997
+ async getPrComments(params) {
2998
+ this._validateAccessTokenAndUrl();
3014
2999
  const { owner, repo } = parseGithubOwnerAndRepo(this.url);
3015
- return getPrComments(oktokit, {
3000
+ return this.githubSdk.getPrComments({
3016
3001
  per_page: 100,
3017
3002
  ...params,
3018
3003
  owner,
@@ -3020,27 +3005,23 @@ var GithubSCMLib = class extends SCMLib {
3020
3005
  });
3021
3006
  }
3022
3007
  async getPrDiff(params) {
3023
- if (!this.accessToken || !this.url) {
3024
- throw new Error("cannot get Pr Comments without access token or url");
3025
- }
3008
+ this._validateAccessTokenAndUrl();
3026
3009
  const { owner, repo } = parseGithubOwnerAndRepo(this.url);
3027
- const prRes = await getPrDiff(this.oktokit, {
3010
+ const prRes = await this.githubSdk.getPrDiff({
3028
3011
  ...params,
3029
3012
  owner,
3030
3013
  repo
3031
3014
  });
3032
- return z8.string().parse(prRes.data);
3015
+ return z7.string().parse(prRes.data);
3033
3016
  }
3034
3017
  async getRepoList(_scmOrg) {
3035
- if (!this.accessToken) {
3036
- console.error("no access token");
3037
- throw new Error("no access token");
3038
- }
3039
- return getGithubRepoList(this.accessToken);
3018
+ this._validateToken();
3019
+ return this.githubSdk.getGithubRepoList();
3040
3020
  }
3041
3021
  async getBranchList() {
3042
3022
  this._validateAccessTokenAndUrl();
3043
- return getGithubBranchList(this.accessToken, this.url);
3023
+ const branches = await this.githubSdk.getGithubBranchList(this.url);
3024
+ return branches.data.map((branch) => branch.name);
3044
3025
  }
3045
3026
  getScmLibType() {
3046
3027
  return "GITHUB" /* GITHUB */;
@@ -3052,73 +3033,57 @@ var GithubSCMLib = class extends SCMLib {
3052
3033
  return {};
3053
3034
  }
3054
3035
  getDownloadUrl(sha) {
3055
- this.url;
3056
3036
  this._validateUrl();
3057
3037
  const res = parseScmURL(this.url, "GitHub" /* GitHub */);
3058
3038
  if (!res) {
3059
3039
  throw new InvalidRepoUrlError("invalid repo url");
3060
3040
  }
3061
- const { hostname, organization, repoName } = res;
3062
- return Promise.resolve(
3063
- `https://api.${hostname}/repos/${organization}/${repoName}/zipball/${sha}`
3064
- );
3041
+ const { protocol, hostname, organization, repoName } = res;
3042
+ const downloadUrl = isGithubOnPrem(this.url) ? `${protocol}//${hostname}/api/v3/repos/${organization}/${repoName}/zipball/${sha}` : `https://api.${hostname}/repos/${organization}/${repoName}/zipball/${sha}`;
3043
+ return Promise.resolve(downloadUrl);
3065
3044
  }
3066
3045
  async _getUsernameForAuthUrl() {
3067
3046
  return this.getUsername();
3068
3047
  }
3069
3048
  async getIsRemoteBranch(branch) {
3070
- this._validateAccessTokenAndUrl();
3071
- return getGithubIsRemoteBranch(this.accessToken, this.url, branch);
3049
+ this._validateUrl();
3050
+ return this.githubSdk.getGithubIsRemoteBranch({ branch, repoUrl: this.url });
3072
3051
  }
3073
3052
  async getUserHasAccessToRepo() {
3074
- if (!this.accessToken || !this.url) {
3075
- console.error("no access token or no url");
3076
- throw new Error("no access token or no url");
3077
- }
3053
+ this._validateAccessTokenAndUrl();
3078
3054
  const username = await this.getUsername();
3079
- return getGithubIsUserCollaborator(username, this.accessToken, this.url);
3055
+ return this.githubSdk.getGithubIsUserCollaborator({
3056
+ repoUrl: this.url,
3057
+ username
3058
+ });
3080
3059
  }
3081
3060
  async getUsername() {
3082
- if (!this.accessToken) {
3083
- console.error("no access token");
3084
- throw new Error("no access token");
3085
- }
3086
- return getGithubUsername(this.accessToken);
3061
+ this._validateToken();
3062
+ return this.githubSdk.getGithubUsername();
3087
3063
  }
3088
3064
  async getSubmitRequestStatus(scmSubmitRequestId) {
3089
- if (!this.accessToken || !this.url) {
3090
- console.error("no access token or no url");
3091
- throw new Error("no access token or no url");
3092
- }
3093
- const state = await getGithubPullRequestStatus(
3094
- this.accessToken,
3095
- this.url,
3096
- Number(scmSubmitRequestId)
3097
- );
3098
- return state;
3065
+ this._validateAccessTokenAndUrl();
3066
+ return this.githubSdk.getGithubPullRequestStatus({
3067
+ repoUrl: this.url,
3068
+ prNumber: Number(scmSubmitRequestId)
3069
+ });
3099
3070
  }
3100
3071
  async getRepoBlameRanges(ref, path9) {
3101
3072
  this._validateUrl();
3102
- return await getGithubBlameRanges(
3103
- { ref, path: path9, gitHubUrl: this.url },
3104
- {
3105
- githubAuthToken: this.accessToken
3106
- }
3107
- );
3073
+ return await this.githubSdk.getGithubBlameRanges({
3074
+ ref,
3075
+ path: path9,
3076
+ gitHubUrl: this.url
3077
+ });
3108
3078
  }
3109
3079
  async getReferenceData(ref) {
3110
3080
  this._validateUrl();
3111
- return await getGithubReferenceData(
3112
- { ref, gitHubUrl: this.url },
3113
- {
3114
- githubAuthToken: this.accessToken
3115
- }
3116
- );
3081
+ return this.githubSdk.getGithubReferenceData({ ref, gitHubUrl: this.url });
3117
3082
  }
3118
3083
  async getPrComment(commentId) {
3119
3084
  this._validateUrl();
3120
3085
  const { owner, repo } = parseGithubOwnerAndRepo(this.url);
3121
- return await getPrComment(this.oktokit, {
3086
+ return await this.githubSdk.getPrComment({
3122
3087
  repo,
3123
3088
  owner,
3124
3089
  comment_id: commentId
@@ -3126,17 +3091,12 @@ var GithubSCMLib = class extends SCMLib {
3126
3091
  }
3127
3092
  async getRepoDefaultBranch() {
3128
3093
  this._validateUrl();
3129
- return await getGithubRepoDefaultBranch(this.url, {
3130
- githubAuthToken: this.accessToken
3131
- });
3094
+ return await this.githubSdk.getGithubRepoDefaultBranch(this.url);
3132
3095
  }
3133
3096
  async getPrUrl(prNumber) {
3134
- if (!this.url || !this.oktokit) {
3135
- console.error("no url");
3136
- throw new Error("no url");
3137
- }
3097
+ this._validateAccessTokenAndUrl();
3138
3098
  const { owner, repo } = parseGithubOwnerAndRepo(this.url);
3139
- const getPrRes = await getPr(this.oktokit, {
3099
+ const getPrRes = await this.githubSdk.getPr({
3140
3100
  owner,
3141
3101
  repo,
3142
3102
  pull_number: prNumber
@@ -3145,21 +3105,20 @@ var GithubSCMLib = class extends SCMLib {
3145
3105
  }
3146
3106
  async postGeneralPrComment(params) {
3147
3107
  const { prNumber, body } = params;
3148
- this._validateUrl();
3108
+ this._validateAccessTokenAndUrl();
3149
3109
  const { owner, repo } = parseGithubOwnerAndRepo(this.url);
3150
- return await postGeneralPrComment(this.oktokit, {
3110
+ return await this.githubSdk.postGeneralPrComment({
3151
3111
  issue_number: prNumber,
3152
3112
  owner,
3153
3113
  repo,
3154
3114
  body
3155
3115
  });
3156
3116
  }
3157
- async getGeneralPrComments(params, auth) {
3117
+ async getGeneralPrComments(params) {
3158
3118
  const { prNumber } = params;
3159
- this._validateUrl();
3160
- const oktoKit = auth ? new Octokit2({ auth: auth.authToken }) : this.oktokit;
3119
+ this._validateAccessTokenAndUrl();
3161
3120
  const { owner, repo } = parseGithubOwnerAndRepo(this.url);
3162
- return await getGeneralPrComments(oktoKit, {
3121
+ return await this.githubSdk.getGeneralPrComments({
3163
3122
  issue_number: prNumber,
3164
3123
  owner,
3165
3124
  repo
@@ -3168,9 +3127,9 @@ var GithubSCMLib = class extends SCMLib {
3168
3127
  async deleteGeneralPrComment({
3169
3128
  commentId
3170
3129
  }) {
3171
- this._validateUrl();
3130
+ this._validateAccessTokenAndUrl();
3172
3131
  const { owner, repo } = parseGithubOwnerAndRepo(this.url);
3173
- return deleteGeneralPrComment(this.oktokit, {
3132
+ return this.githubSdk.deleteGeneralPrComment({
3174
3133
  owner,
3175
3134
  repo,
3176
3135
  comment_id: commentId
@@ -3244,7 +3203,7 @@ var StubSCMLib = class extends SCMLib {
3244
3203
  };
3245
3204
  function getUserAndPassword(token) {
3246
3205
  const [username, password] = token.split(":");
3247
- const safePasswordAndUsername = z8.object({ username: z8.string(), password: z8.string() }).parse({ username, password });
3206
+ const safePasswordAndUsername = z7.object({ username: z7.string(), password: z7.string() }).parse({ username, password });
3248
3207
  return {
3249
3208
  username: safePasswordAndUsername.username,
3250
3209
  password: safePasswordAndUsername.password
@@ -3280,7 +3239,7 @@ var BitbucketSCMLib = class extends SCMLib {
3280
3239
  return { username, password, authType };
3281
3240
  }
3282
3241
  case "token": {
3283
- return { authType, token: z8.string().parse(this.accessToken) };
3242
+ return { authType, token: z7.string().parse(this.accessToken) };
3284
3243
  }
3285
3244
  case "public":
3286
3245
  return { authType };
@@ -3292,7 +3251,7 @@ var BitbucketSCMLib = class extends SCMLib {
3292
3251
  ...params,
3293
3252
  repoUrl: this.url
3294
3253
  });
3295
- return String(z8.number().parse(pullRequestRes.id));
3254
+ return String(z7.number().parse(pullRequestRes.id));
3296
3255
  }
3297
3256
  async validateParams() {
3298
3257
  return validateBitbucketParams({
@@ -3364,7 +3323,7 @@ var BitbucketSCMLib = class extends SCMLib {
3364
3323
  async getUsername() {
3365
3324
  this._validateToken();
3366
3325
  const res = await this.bitbucketSdk.getUser();
3367
- return z8.string().parse(res.username);
3326
+ return z7.string().parse(res.username);
3368
3327
  }
3369
3328
  async getSubmitRequestStatus(_scmSubmitRequestId) {
3370
3329
  this._validateAccessTokenAndUrl();
@@ -3393,7 +3352,7 @@ var BitbucketSCMLib = class extends SCMLib {
3393
3352
  async getRepoDefaultBranch() {
3394
3353
  this._validateUrl();
3395
3354
  const repoRes = await this.bitbucketSdk.getRepo({ repoUrl: this.url });
3396
- return z8.string().parse(repoRes.mainbranch?.name);
3355
+ return z7.string().parse(repoRes.mainbranch?.name);
3397
3356
  }
3398
3357
  getPrUrl(prNumber) {
3399
3358
  this._validateUrl();
@@ -3417,25 +3376,25 @@ var BitbucketSCMLib = class extends SCMLib {
3417
3376
  // src/features/analysis/scm/bitbucket/bitbucket.ts
3418
3377
  var { Bitbucket } = bitbucketPkg;
3419
3378
  var BITBUCKET_HOSTNAME = "bitbucket.org";
3420
- var TokenExpiredErrorZ = z9.object({
3421
- status: z9.number(),
3422
- error: z9.object({
3423
- type: z9.string(),
3424
- error: z9.object({
3425
- message: z9.string()
3379
+ var TokenExpiredErrorZ = z8.object({
3380
+ status: z8.number(),
3381
+ error: z8.object({
3382
+ type: z8.string(),
3383
+ error: z8.object({
3384
+ message: z8.string()
3426
3385
  })
3427
3386
  })
3428
3387
  });
3429
3388
  var BITBUCKET_ACCESS_TOKEN_URL = `https://${BITBUCKET_HOSTNAME}/site/oauth2/access_token`;
3430
- var BitbucketAuthResultZ = z9.object({
3431
- access_token: z9.string(),
3432
- token_type: z9.string(),
3433
- refresh_token: z9.string()
3389
+ var BitbucketAuthResultZ = z8.object({
3390
+ access_token: z8.string(),
3391
+ token_type: z8.string(),
3392
+ refresh_token: z8.string()
3434
3393
  });
3435
- var BitbucketParseResultZ = z9.object({
3436
- organization: z9.string(),
3437
- repoName: z9.string(),
3438
- hostname: z9.literal(BITBUCKET_HOSTNAME)
3394
+ var BitbucketParseResultZ = z8.object({
3395
+ organization: z8.string(),
3396
+ repoName: z8.string(),
3397
+ hostname: z8.literal(BITBUCKET_HOSTNAME)
3439
3398
  });
3440
3399
  function parseBitbucketOrganizationAndRepo(bitbucketUrl) {
3441
3400
  const parsedGitHubUrl = normalizeUrl(bitbucketUrl);
@@ -3513,7 +3472,7 @@ function getBitbucketSdk(params) {
3513
3472
  if (!res.data.values) {
3514
3473
  return [];
3515
3474
  }
3516
- return res.data.values.filter((branch) => !!branch.name).map((branch) => z9.string().parse(branch.name));
3475
+ return res.data.values.filter((branch) => !!branch.name).map((branch) => z8.string().parse(branch.name));
3517
3476
  },
3518
3477
  async getIsUserCollaborator(params2) {
3519
3478
  const { repoUrl } = params2;
@@ -3628,7 +3587,7 @@ function getBitbucketSdk(params) {
3628
3587
  return GetRefererenceResultZ.parse({
3629
3588
  sha: tagRes.data.target?.hash,
3630
3589
  type: "TAG" /* TAG */,
3631
- date: new Date(z9.string().parse(tagRes.data.target?.date))
3590
+ date: new Date(z8.string().parse(tagRes.data.target?.date))
3632
3591
  });
3633
3592
  },
3634
3593
  async getBranchRef(params2) {
@@ -3636,7 +3595,7 @@ function getBitbucketSdk(params) {
3636
3595
  return GetRefererenceResultZ.parse({
3637
3596
  sha: getBranchRes.target?.hash,
3638
3597
  type: "BRANCH" /* BRANCH */,
3639
- date: new Date(z9.string().parse(getBranchRes.target?.date))
3598
+ date: new Date(z8.string().parse(getBranchRes.target?.date))
3640
3599
  });
3641
3600
  },
3642
3601
  async getCommitRef(params2) {
@@ -3644,13 +3603,13 @@ function getBitbucketSdk(params) {
3644
3603
  return GetRefererenceResultZ.parse({
3645
3604
  sha: getCommitRes.hash,
3646
3605
  type: "COMMIT" /* COMMIT */,
3647
- date: new Date(z9.string().parse(getCommitRes.date))
3606
+ date: new Date(z8.string().parse(getCommitRes.date))
3648
3607
  });
3649
3608
  },
3650
3609
  async getDownloadUrl({ url, sha }) {
3651
3610
  this.getReferenceData({ ref: sha, url });
3652
3611
  const repoRes = await this.getRepo({ repoUrl: url });
3653
- const parsedRepoUrl = z9.string().url().parse(repoRes.links?.html?.href);
3612
+ const parsedRepoUrl = z8.string().url().parse(repoRes.links?.html?.href);
3654
3613
  return `${parsedRepoUrl}/get/${sha}.zip`;
3655
3614
  },
3656
3615
  async getPullRequest(params2) {
@@ -3673,7 +3632,7 @@ async function validateBitbucketParams(params) {
3673
3632
  if (authType !== "public") {
3674
3633
  await bitbucketClient.getUser();
3675
3634
  }
3676
- if (params.url) {
3635
+ if (params.url && shouldValidateUrl(params.url)) {
3677
3636
  await bitbucketClient.getRepo({ repoUrl: params.url });
3678
3637
  }
3679
3638
  } catch (e) {
@@ -3693,7 +3652,7 @@ async function validateBitbucketParams(params) {
3693
3652
  }
3694
3653
  async function getUsersworkspacesSlugs(bitbucketClient) {
3695
3654
  const res = await bitbucketClient.workspaces.getWorkspaces({});
3696
- return res.data.values?.map((v) => z9.string().parse(v.slug));
3655
+ return res.data.values?.map((v) => z8.string().parse(v.slug));
3697
3656
  }
3698
3657
  async function getllUsersrepositories(bitbucketClient) {
3699
3658
  const userWorspacesSlugs = await getUsersworkspacesSlugs(bitbucketClient);
@@ -3725,7 +3684,7 @@ var MOBB_ICON_IMG = "https://app.mobb.ai/gh-action/Logo_Rounded_Icon.svg";
3725
3684
  // src/features/analysis/add_fix_comments_for_pr/utils.ts
3726
3685
  import Debug3 from "debug";
3727
3686
  import parseDiff2 from "parse-diff";
3728
- import { z as z10 } from "zod";
3687
+ import { z as z9 } from "zod";
3729
3688
 
3730
3689
  // src/features/analysis/utils/by_key.ts
3731
3690
  function keyBy(array, keyBy2) {
@@ -3956,7 +3915,7 @@ async function getRelevantVulenrabilitiesFromDiff(params) {
3956
3915
  });
3957
3916
  const lineAddedRanges = calculateRanges(fileNumbers);
3958
3917
  const fileFilter = {
3959
- path: z10.string().parse(file.to),
3918
+ path: z9.string().parse(file.to),
3960
3919
  ranges: lineAddedRanges.map(([startLine, endLine]) => ({
3961
3920
  endLine,
3962
3921
  startLine
@@ -4263,30 +4222,30 @@ function subscribe(query, variables, callback, wsClientOptions) {
4263
4222
  }
4264
4223
 
4265
4224
  // src/features/analysis/graphql/types.ts
4266
- import { z as z11 } from "zod";
4267
- var VulnerabilityReportIssueCodeNodeZ = z11.object({
4268
- vulnerabilityReportIssueId: z11.string(),
4269
- path: z11.string(),
4270
- startLine: z11.number(),
4271
- vulnerabilityReportIssue: z11.object({
4272
- fixId: z11.string()
4225
+ import { z as z10 } from "zod";
4226
+ var VulnerabilityReportIssueCodeNodeZ = z10.object({
4227
+ vulnerabilityReportIssueId: z10.string(),
4228
+ path: z10.string(),
4229
+ startLine: z10.number(),
4230
+ vulnerabilityReportIssue: z10.object({
4231
+ fixId: z10.string()
4273
4232
  })
4274
4233
  });
4275
- var GetVulByNodesMetadataZ = z11.object({
4276
- vulnerabilityReportIssueCodeNodes: z11.array(VulnerabilityReportIssueCodeNodeZ),
4277
- nonFixablePrVuls: z11.object({
4278
- aggregate: z11.object({
4279
- count: z11.number()
4234
+ var GetVulByNodesMetadataZ = z10.object({
4235
+ vulnerabilityReportIssueCodeNodes: z10.array(VulnerabilityReportIssueCodeNodeZ),
4236
+ nonFixablePrVuls: z10.object({
4237
+ aggregate: z10.object({
4238
+ count: z10.number()
4280
4239
  })
4281
4240
  }),
4282
- fixablePrVuls: z11.object({
4283
- aggregate: z11.object({
4284
- count: z11.number()
4241
+ fixablePrVuls: z10.object({
4242
+ aggregate: z10.object({
4243
+ count: z10.number()
4285
4244
  })
4286
4245
  }),
4287
- totalScanVulnerabilities: z11.object({
4288
- aggregate: z11.object({
4289
- count: z11.number()
4246
+ totalScanVulnerabilities: z10.object({
4247
+ aggregate: z10.object({
4248
+ count: z10.number()
4290
4249
  })
4291
4250
  })
4292
4251
  });
@@ -4381,13 +4340,12 @@ var GQLClient = class {
4381
4340
  }
4382
4341
  }
4383
4342
  async updateScmToken(args) {
4384
- const { scmType, url, token, org, username, refreshToken } = args;
4343
+ const { scmType, url, token, org, refreshToken } = args;
4385
4344
  const updateScmTokenResult = await this._clientSdk.updateScmToken({
4386
4345
  scmType,
4387
4346
  url,
4388
4347
  token,
4389
4348
  org,
4390
- username,
4391
4349
  refreshToken
4392
4350
  });
4393
4351
  return updateScmTokenResult;
@@ -4917,7 +4875,7 @@ async function getSnykReport(reportPath, repoRoot, { skipPrompts = false }) {
4917
4875
 
4918
4876
  // src/features/analysis/upload-file.ts
4919
4877
  import Debug11 from "debug";
4920
- import fetch2, { File, fileFrom, FormData } from "node-fetch";
4878
+ import fetch3, { File, fileFrom, FormData } from "node-fetch";
4921
4879
  var debug10 = Debug11("mobbdev:upload-file");
4922
4880
  async function uploadFile({
4923
4881
  file,
@@ -4942,7 +4900,7 @@ async function uploadFile({
4942
4900
  debug10("upload file from buffer");
4943
4901
  form.append("file", new File([file], "file"));
4944
4902
  }
4945
- const response = await fetch2(url, {
4903
+ const response = await fetch3(url, {
4946
4904
  method: "POST",
4947
4905
  body: form
4948
4906
  });
@@ -4973,7 +4931,7 @@ async function downloadRepo({
4973
4931
  debug11("download repo %s %s %s", repoUrl, dirname);
4974
4932
  const zipFilePath = path6.join(dirname, "repo.zip");
4975
4933
  debug11("download URL: %s auth headers: %o", downloadUrl, authHeaders);
4976
- const response = await fetch3(downloadUrl, {
4934
+ const response = await fetch4(downloadUrl, {
4977
4935
  method: "GET",
4978
4936
  headers: {
4979
4937
  ...authHeaders
@@ -5184,7 +5142,7 @@ async function _scan(params, { skipPrompts = false } = {}) {
5184
5142
  spinner: mobbSpinner,
5185
5143
  submitVulnerabilityReportVariables: {
5186
5144
  fixReportId: reportUploadInfo.fixReportId,
5187
- repoUrl: z12.string().parse(repo),
5145
+ repoUrl: z11.string().parse(repo),
5188
5146
  reference,
5189
5147
  projectId,
5190
5148
  vulnerabilityReportFileName: "report.json",
@@ -5436,9 +5394,9 @@ async function _scan(params, { skipPrompts = false } = {}) {
5436
5394
  }
5437
5395
  });
5438
5396
  if (command === "review") {
5439
- const params2 = z12.object({
5440
- repo: z12.string().url(),
5441
- githubActionToken: z12.string()
5397
+ const params2 = z11.object({
5398
+ repo: z11.string().url(),
5399
+ githubActionToken: z11.string()
5442
5400
  }).parse({ repo, githubActionToken });
5443
5401
  const scm2 = await SCMLib.init({
5444
5402
  url: params2.repo,
@@ -5455,7 +5413,7 @@ async function _scan(params, { skipPrompts = false } = {}) {
5455
5413
  analysisId,
5456
5414
  gqlClient,
5457
5415
  scm: scm2,
5458
- scanner: z12.nativeEnum(SCANNERS).parse(scanner)
5416
+ scanner: z11.nativeEnum(SCANNERS).parse(scanner)
5459
5417
  });
5460
5418
  },
5461
5419
  callbackStates: ["Finished" /* Finished */]
@@ -5539,7 +5497,7 @@ var packageJson2 = JSON.parse(
5539
5497
  );
5540
5498
  var config3 = new Configstore2(packageJson2.name, { apiToken: "" });
5541
5499
  async function addScmToken(addScmTokenOptions) {
5542
- const { apiKey, token, organization, scmType, url, username, refreshToken } = addScmTokenOptions;
5500
+ const { apiKey, token, organization, scmType, url, refreshToken } = addScmTokenOptions;
5543
5501
  const gqlClient = new GQLClient({
5544
5502
  apiKey: apiKey || config3.get("apiToken"),
5545
5503
  type: "apiKey"
@@ -5552,7 +5510,6 @@ async function addScmToken(addScmTokenOptions) {
5552
5510
  url,
5553
5511
  token,
5554
5512
  org: organization,
5555
- username,
5556
5513
  refreshToken
5557
5514
  });
5558
5515
  }
@@ -5648,10 +5605,6 @@ var scmOrgOption = {
5648
5605
  describe: chalk5.bold("Organization name in SCM (used in Azure DevOps)"),
5649
5606
  type: "string"
5650
5607
  };
5651
- var scmUsernameOption = {
5652
- describe: chalk5.bold("Username in SCM (used in GitHub, Bitbucket)"),
5653
- type: "string"
5654
- };
5655
5608
  var scmRefreshTokenOption = {
5656
5609
  describe: chalk5.bold("SCM refresh token (used in GitLab)"),
5657
5610
  type: "string"
@@ -5665,7 +5618,7 @@ var scmTokenOption = {
5665
5618
  // src/args/validation.ts
5666
5619
  import chalk6 from "chalk";
5667
5620
  import path8 from "path";
5668
- import { z as z13 } from "zod";
5621
+ import { z as z12 } from "zod";
5669
5622
  function throwRepoUrlErrorMessage({
5670
5623
  error,
5671
5624
  repoUrl,
@@ -5682,7 +5635,7 @@ Example:
5682
5635
  )}`;
5683
5636
  throw new CliError(formattedErrorMessage);
5684
5637
  }
5685
- var UrlZ = z13.string({
5638
+ var UrlZ = z12.string({
5686
5639
  invalid_type_error: "is not a valid GitHub / GitLab / ADO URL"
5687
5640
  }).refine((data) => !!sanityRepoURL(data), {
5688
5641
  message: "is not a valid GitHub / GitLab / ADO URL"
@@ -5837,15 +5790,15 @@ async function scanHandler(args) {
5837
5790
  }
5838
5791
 
5839
5792
  // src/args/commands/token.ts
5840
- import { z as z14 } from "zod";
5793
+ import { z as z13 } from "zod";
5841
5794
  function addScmTokenBuilder(args) {
5842
- return args.option("scm-type", scmTypeOption).option("url", urlOption).option("token", scmTokenOption).option("organization", scmOrgOption).option("username", scmUsernameOption).option("refresh-token", scmRefreshTokenOption).option("api-key", apiKeyOption).example(
5795
+ return args.option("scm-type", scmTypeOption).option("url", urlOption).option("token", scmTokenOption).option("organization", scmOrgOption).option("refresh-token", scmRefreshTokenOption).option("api-key", apiKeyOption).example(
5843
5796
  "$0 add-scm-token --scm-type Ado --url https://dev.azure.com/adoorg/test/_git/repo --token abcdef0123456 --organization myOrg",
5844
5797
  "Add your SCM (Github, Gitlab, Azure DevOps) token to Mobb to enable automated fixes."
5845
5798
  ).help().demandOption(["url", "token"]);
5846
5799
  }
5847
5800
  function validateAddScmTokenOptions(argv) {
5848
- if (!z14.nativeEnum(ScmType).safeParse(argv.scmType).success) {
5801
+ if (!z13.nativeEnum(ScmType).safeParse(argv.scmType).success) {
5849
5802
  throw new CliError(
5850
5803
  "\nError: --scm-type must reference a valid SCM type (GitHub, GitLab, Ado, Bitbutcket)"
5851
5804
  );
@@ -5853,25 +5806,17 @@ function validateAddScmTokenOptions(argv) {
5853
5806
  Object.values(scmValidationMap).forEach((validate) => validate(argv));
5854
5807
  }
5855
5808
  var scmValidationMap = {
5856
- ["GitHub" /* GitHub */]: validateGithub,
5809
+ ["GitHub" /* GitHub */]: () => {
5810
+ return;
5811
+ },
5857
5812
  ["GitLab" /* GitLab */]: () => {
5858
5813
  return;
5859
5814
  },
5860
5815
  ["Ado" /* Ado */]: validateAdo,
5861
- ["Bitbucket" /* Bitbucket */]: validateBitbucket
5862
- };
5863
- function validateBitbucket(argv) {
5864
- const urlObj = new URL(argv.url);
5865
- if (urlObj.hostname.toLowerCase() === scmCloudHostname.Bitbucket && !argv.username) {
5866
- throw new CliError("\nError: --username flag is required for Bitbucket");
5867
- }
5868
- }
5869
- function validateGithub(argv) {
5870
- const urlObj = new URL(argv.url);
5871
- if (urlObj.hostname.toLowerCase() === scmCloudHostname.GitHub && !argv.username) {
5872
- throw new CliError("\nError: --username flag is required for GitHub");
5816
+ ["Bitbucket" /* Bitbucket */]: () => {
5817
+ return;
5873
5818
  }
5874
- }
5819
+ };
5875
5820
  function validateAdo(argv) {
5876
5821
  const urlObj = new URL(argv.url);
5877
5822
  if ((urlObj.hostname.toLowerCase() === scmCloudHostname.Ado || urlObj.hostname.toLowerCase().endsWith(".visualstudio.com")) && !argv.organization) {