mobbdev 0.0.82 → 0.0.84
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/index.mjs +220 -83
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -94,8 +94,8 @@ var errorMessages = {
|
|
|
94
94
|
missingCxProjectName: `project name ${chalk.bold(
|
|
95
95
|
"(--cx-project-name)"
|
|
96
96
|
)} is needed if you're using checkmarx`,
|
|
97
|
-
|
|
98
|
-
"(--
|
|
97
|
+
missingUrl: `url ${chalk.bold(
|
|
98
|
+
"(--url)"
|
|
99
99
|
)} is needed if you're adding an SCM token`,
|
|
100
100
|
invalidScmType: `SCM type ${chalk.bold(
|
|
101
101
|
"(--scm-type)"
|
|
@@ -237,23 +237,33 @@ import { v4 as uuidv4 } from "uuid";
|
|
|
237
237
|
import { gql } from "graphql-request";
|
|
238
238
|
var UPDATE_SCM_TOKEN = gql`
|
|
239
239
|
mutation updateScmToken(
|
|
240
|
-
$
|
|
240
|
+
$scmType: String!
|
|
241
|
+
$url: String!
|
|
241
242
|
$token: String!
|
|
242
243
|
$org: String
|
|
243
244
|
$username: String
|
|
244
245
|
$refreshToken: String
|
|
245
246
|
) {
|
|
246
247
|
updateScmToken(
|
|
247
|
-
|
|
248
|
+
scmType: $scmType
|
|
249
|
+
url: $url
|
|
248
250
|
token: $token
|
|
249
251
|
org: $org
|
|
250
252
|
username: $username
|
|
251
253
|
refreshToken: $refreshToken
|
|
252
254
|
) {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
255
|
+
__typename
|
|
256
|
+
... on ScmAccessTokenUpdateSuccess {
|
|
257
|
+
token
|
|
258
|
+
}
|
|
259
|
+
... on InvalidScmTypeError {
|
|
260
|
+
status
|
|
261
|
+
error
|
|
262
|
+
}
|
|
263
|
+
... on BadScmCredentials {
|
|
264
|
+
status
|
|
265
|
+
error
|
|
266
|
+
}
|
|
257
267
|
}
|
|
258
268
|
}
|
|
259
269
|
`;
|
|
@@ -368,10 +378,20 @@ var ME = gql2`
|
|
|
368
378
|
me {
|
|
369
379
|
id
|
|
370
380
|
email
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
381
|
+
scmConfigs {
|
|
382
|
+
id
|
|
383
|
+
isBroker
|
|
384
|
+
orgId
|
|
385
|
+
refreshToken
|
|
386
|
+
scmType
|
|
387
|
+
scmUrl
|
|
388
|
+
scmUsername
|
|
389
|
+
token
|
|
390
|
+
tokenLastUpdate
|
|
391
|
+
userId
|
|
392
|
+
scmOrg
|
|
393
|
+
isTokenAvailable
|
|
394
|
+
}
|
|
375
395
|
}
|
|
376
396
|
}
|
|
377
397
|
`;
|
|
@@ -565,10 +585,7 @@ function subscribe(query, variables, callback, wsClientOptions) {
|
|
|
565
585
|
import { z as z2 } from "zod";
|
|
566
586
|
var UpdateScmTokenZ = z2.object({
|
|
567
587
|
updateScmToken: z2.object({
|
|
568
|
-
|
|
569
|
-
gitHubAccessToken: z2.string().nullable(),
|
|
570
|
-
gitlabAccessToken: z2.string().nullable(),
|
|
571
|
-
adoAccessToken: z2.string().nullable()
|
|
588
|
+
token: z2.string()
|
|
572
589
|
})
|
|
573
590
|
});
|
|
574
591
|
var UploadFieldsZ = z2.object({
|
|
@@ -803,9 +820,10 @@ var GQLClient = class {
|
|
|
803
820
|
}
|
|
804
821
|
}
|
|
805
822
|
async updateScmToken(args) {
|
|
806
|
-
const {
|
|
823
|
+
const { scmType, url, token, org, username, refreshToken } = args;
|
|
807
824
|
const updateScmTokenResult = await this._client.request(UPDATE_SCM_TOKEN, {
|
|
808
|
-
|
|
825
|
+
scmType,
|
|
826
|
+
url,
|
|
809
827
|
token,
|
|
810
828
|
org,
|
|
811
829
|
username,
|
|
@@ -1402,9 +1420,9 @@ async function getGithubBlameRanges({ ref, gitHubUrl, path: path9 }, options) {
|
|
|
1402
1420
|
return res.repository.object.blame.ranges.map((range) => ({
|
|
1403
1421
|
startingLine: range.startingLine,
|
|
1404
1422
|
endingLine: range.endingLine,
|
|
1405
|
-
email: range.commit.author.user
|
|
1406
|
-
name: range.commit.author.user
|
|
1407
|
-
login: range.commit.author.user
|
|
1423
|
+
email: range.commit.author.user?.email || "",
|
|
1424
|
+
name: range.commit.author.user?.name || "",
|
|
1425
|
+
login: range.commit.author.user?.login || ""
|
|
1408
1426
|
}));
|
|
1409
1427
|
}
|
|
1410
1428
|
async function createPr({
|
|
@@ -1531,6 +1549,9 @@ function deleteComment(client, params) {
|
|
|
1531
1549
|
function getPrDiff(client, params) {
|
|
1532
1550
|
return client.request(GET_PR, { ...params, mediaType: { format: "diff" } });
|
|
1533
1551
|
}
|
|
1552
|
+
function getPr(client, params) {
|
|
1553
|
+
return client.request(GET_PR, { ...params });
|
|
1554
|
+
}
|
|
1534
1555
|
function createOrUpdateRepositorySecret(client, params) {
|
|
1535
1556
|
return client.request(CREATE_OR_UPDATE_A_REPOSITORY_SECRET, params);
|
|
1536
1557
|
}
|
|
@@ -1878,7 +1899,7 @@ var isValidBranchName = async (branchName) => {
|
|
|
1878
1899
|
var FixesZ = z6.array(z6.object({ fixId: z6.string(), diff: z6.string() })).nonempty();
|
|
1879
1900
|
|
|
1880
1901
|
// src/features/analysis/scm/scm.ts
|
|
1881
|
-
function
|
|
1902
|
+
function getCloudScmLibTypeFromUrl(url) {
|
|
1882
1903
|
if (!url) {
|
|
1883
1904
|
return void 0;
|
|
1884
1905
|
}
|
|
@@ -1895,19 +1916,92 @@ function getScmLibTypeFromUrl(url) {
|
|
|
1895
1916
|
}
|
|
1896
1917
|
return void 0;
|
|
1897
1918
|
}
|
|
1919
|
+
function getScmTypeFromScmLibType(scmLibType) {
|
|
1920
|
+
if (scmLibType === "GITLAB" /* GITLAB */) {
|
|
1921
|
+
return "GitLab" /* GitLab */;
|
|
1922
|
+
}
|
|
1923
|
+
if (scmLibType === "GITHUB" /* GITHUB */) {
|
|
1924
|
+
return "GitHub" /* GitHub */;
|
|
1925
|
+
}
|
|
1926
|
+
if (scmLibType === "ADO" /* ADO */) {
|
|
1927
|
+
return "Ado" /* Ado */;
|
|
1928
|
+
}
|
|
1929
|
+
throw new Error(`unknown scm lib type: ${scmLibType}`);
|
|
1930
|
+
}
|
|
1931
|
+
function getScmLibTypeFromScmType(scmType) {
|
|
1932
|
+
if (scmType === "GitLab" /* GitLab */) {
|
|
1933
|
+
return "GITLAB" /* GITLAB */;
|
|
1934
|
+
}
|
|
1935
|
+
if (scmType === "GitHub" /* GitHub */) {
|
|
1936
|
+
return "GITHUB" /* GITHUB */;
|
|
1937
|
+
}
|
|
1938
|
+
if (scmType === "Ado" /* Ado */) {
|
|
1939
|
+
return "ADO" /* ADO */;
|
|
1940
|
+
}
|
|
1941
|
+
throw new Error(`unknown scm type: ${scmType}`);
|
|
1942
|
+
}
|
|
1943
|
+
function getScmConfig({
|
|
1944
|
+
url,
|
|
1945
|
+
scmConfigs,
|
|
1946
|
+
includeOrgTokens = true
|
|
1947
|
+
}) {
|
|
1948
|
+
const filteredScmConfigs = scmConfigs.filter((scm) => {
|
|
1949
|
+
const urlObject = new URL(url);
|
|
1950
|
+
const configUrl = new URL(scm.scmUrl);
|
|
1951
|
+
return (
|
|
1952
|
+
//if we the user does an ADO oauth flow then the token is saved for dev.azure.com but
|
|
1953
|
+
//sometimes the user uses the url dev.azure.com and sometimes the url visualstudio.com
|
|
1954
|
+
//so we need to check both
|
|
1955
|
+
(urlObject.hostname === configUrl.hostname || urlObject.hostname.endsWith(".visualstudio.com") && configUrl.hostname === "dev.azure.com") && urlObject.protocol === configUrl.protocol && urlObject.port === configUrl.port
|
|
1956
|
+
);
|
|
1957
|
+
});
|
|
1958
|
+
const scmOrgConfig = filteredScmConfigs.find((scm) => scm.orgId && scm.token);
|
|
1959
|
+
if (scmOrgConfig && includeOrgTokens) {
|
|
1960
|
+
return {
|
|
1961
|
+
id: scmOrgConfig.id,
|
|
1962
|
+
accessToken: scmOrgConfig.token || void 0,
|
|
1963
|
+
scmLibType: getScmLibTypeFromScmType(scmOrgConfig.scmType),
|
|
1964
|
+
scmOrg: scmOrgConfig.scmOrg || void 0
|
|
1965
|
+
};
|
|
1966
|
+
}
|
|
1967
|
+
const scmUserConfig = filteredScmConfigs.find(
|
|
1968
|
+
(scm) => scm.userId && scm.token
|
|
1969
|
+
);
|
|
1970
|
+
if (scmUserConfig) {
|
|
1971
|
+
return {
|
|
1972
|
+
id: scmUserConfig.id,
|
|
1973
|
+
accessToken: scmUserConfig.token || void 0,
|
|
1974
|
+
scmLibType: getScmLibTypeFromScmType(scmUserConfig.scmType),
|
|
1975
|
+
scmOrg: scmUserConfig.scmOrg || void 0
|
|
1976
|
+
};
|
|
1977
|
+
}
|
|
1978
|
+
const type2 = getCloudScmLibTypeFromUrl(url);
|
|
1979
|
+
if (type2) {
|
|
1980
|
+
return {
|
|
1981
|
+
id: void 0,
|
|
1982
|
+
accessToken: void 0,
|
|
1983
|
+
scmLibType: type2,
|
|
1984
|
+
scmOrg: void 0
|
|
1985
|
+
};
|
|
1986
|
+
}
|
|
1987
|
+
return {
|
|
1988
|
+
id: void 0,
|
|
1989
|
+
accessToken: void 0,
|
|
1990
|
+
scmLibType: void 0,
|
|
1991
|
+
scmOrg: void 0
|
|
1992
|
+
};
|
|
1993
|
+
}
|
|
1898
1994
|
async function scmCanReachRepo({
|
|
1899
1995
|
repoUrl,
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
adoToken,
|
|
1996
|
+
scmType,
|
|
1997
|
+
accessToken,
|
|
1903
1998
|
scmOrg
|
|
1904
1999
|
}) {
|
|
1905
2000
|
try {
|
|
1906
|
-
const scmLibType = getScmLibTypeFromUrl(repoUrl);
|
|
1907
2001
|
await SCMLib.init({
|
|
1908
2002
|
url: repoUrl,
|
|
1909
|
-
accessToken
|
|
1910
|
-
scmType:
|
|
2003
|
+
accessToken,
|
|
2004
|
+
scmType: getScmLibTypeFromScmType(scmType),
|
|
1911
2005
|
scmOrg
|
|
1912
2006
|
});
|
|
1913
2007
|
return true;
|
|
@@ -1958,7 +2052,7 @@ var SCMLib = class {
|
|
|
1958
2052
|
if (!this.accessToken) {
|
|
1959
2053
|
return trimmedUrl;
|
|
1960
2054
|
}
|
|
1961
|
-
const scmLibType =
|
|
2055
|
+
const scmLibType = this.getScmLibType();
|
|
1962
2056
|
if (scmLibType === "ADO" /* ADO */) {
|
|
1963
2057
|
return `https://${this.accessToken}@${trimmedUrl.toLowerCase().replace("https://", "")}`;
|
|
1964
2058
|
}
|
|
@@ -2085,6 +2179,9 @@ var AdoSCMLib = class extends SCMLib {
|
|
|
2085
2179
|
repoUrl: this.url
|
|
2086
2180
|
});
|
|
2087
2181
|
}
|
|
2182
|
+
getScmLibType() {
|
|
2183
|
+
return "ADO" /* ADO */;
|
|
2184
|
+
}
|
|
2088
2185
|
getAuthHeaders() {
|
|
2089
2186
|
if (this.accessToken) {
|
|
2090
2187
|
if (getAdoTokenType(this.accessToken) === "OAUTH" /* OAUTH */) {
|
|
@@ -2185,6 +2282,9 @@ var AdoSCMLib = class extends SCMLib {
|
|
|
2185
2282
|
accessToken: this.accessToken
|
|
2186
2283
|
});
|
|
2187
2284
|
}
|
|
2285
|
+
getPr() {
|
|
2286
|
+
throw new Error("Method not implemented.");
|
|
2287
|
+
}
|
|
2188
2288
|
};
|
|
2189
2289
|
var GitlabSCMLib = class extends SCMLib {
|
|
2190
2290
|
async createSubmitRequest(targetBranchName, sourceBranchName, title, body) {
|
|
@@ -2243,6 +2343,9 @@ var GitlabSCMLib = class extends SCMLib {
|
|
|
2243
2343
|
repoUrl: this.url
|
|
2244
2344
|
});
|
|
2245
2345
|
}
|
|
2346
|
+
getScmLibType() {
|
|
2347
|
+
return "GITLAB" /* GITLAB */;
|
|
2348
|
+
}
|
|
2246
2349
|
getAuthHeaders() {
|
|
2247
2350
|
if (this?.accessToken?.startsWith("glpat-")) {
|
|
2248
2351
|
return {
|
|
@@ -2353,6 +2456,9 @@ var GitlabSCMLib = class extends SCMLib {
|
|
|
2353
2456
|
updatePrComment(_params, _oktokit) {
|
|
2354
2457
|
throw new Error("updatePrComment not implemented.");
|
|
2355
2458
|
}
|
|
2459
|
+
getPr() {
|
|
2460
|
+
throw new Error("Method not implemented.");
|
|
2461
|
+
}
|
|
2356
2462
|
};
|
|
2357
2463
|
var GithubSCMLib = class extends SCMLib {
|
|
2358
2464
|
// we don't always need a url, what's important is that we have an access token
|
|
@@ -2503,6 +2609,9 @@ var GithubSCMLib = class extends SCMLib {
|
|
|
2503
2609
|
}
|
|
2504
2610
|
return getGithubBranchList(this.accessToken, this.url);
|
|
2505
2611
|
}
|
|
2612
|
+
getScmLibType() {
|
|
2613
|
+
return "GITHUB" /* GITHUB */;
|
|
2614
|
+
}
|
|
2506
2615
|
getAuthHeaders() {
|
|
2507
2616
|
if (this.accessToken) {
|
|
2508
2617
|
return { authorization: `Bearer ${this.accessToken}` };
|
|
@@ -2606,12 +2715,28 @@ var GithubSCMLib = class extends SCMLib {
|
|
|
2606
2715
|
githubAuthToken: this.accessToken
|
|
2607
2716
|
});
|
|
2608
2717
|
}
|
|
2718
|
+
async getPr(prNumber) {
|
|
2719
|
+
if (!this.url || !this.oktokit) {
|
|
2720
|
+
console.error("no url");
|
|
2721
|
+
throw new Error("no url");
|
|
2722
|
+
}
|
|
2723
|
+
const { owner, repo } = parseGithubOwnerAndRepo(this.url);
|
|
2724
|
+
return getPr(this.oktokit, {
|
|
2725
|
+
owner,
|
|
2726
|
+
repo,
|
|
2727
|
+
pull_number: prNumber
|
|
2728
|
+
});
|
|
2729
|
+
}
|
|
2609
2730
|
};
|
|
2610
2731
|
var StubSCMLib = class extends SCMLib {
|
|
2611
2732
|
async createSubmitRequest(_targetBranchName, _sourceBranchName, _title, _body) {
|
|
2612
2733
|
console.error("createSubmitRequest() not implemented");
|
|
2613
2734
|
throw new Error("createSubmitRequest() not implemented");
|
|
2614
2735
|
}
|
|
2736
|
+
getScmLibType() {
|
|
2737
|
+
console.error("getScmLibType() not implemented");
|
|
2738
|
+
throw new Error("getScmLibType() not implemented");
|
|
2739
|
+
}
|
|
2615
2740
|
getAuthHeaders() {
|
|
2616
2741
|
console.error("getAuthHeaders() not implemented");
|
|
2617
2742
|
throw new Error("getAuthHeaders() not implemented");
|
|
@@ -2684,6 +2809,10 @@ var StubSCMLib = class extends SCMLib {
|
|
|
2684
2809
|
console.error("updatePrComment() not implemented");
|
|
2685
2810
|
throw new Error("updatePrComment() not implemented");
|
|
2686
2811
|
}
|
|
2812
|
+
async getPr() {
|
|
2813
|
+
console.error("getPr() not implemented");
|
|
2814
|
+
throw new Error("getPr() not implemented");
|
|
2815
|
+
}
|
|
2687
2816
|
};
|
|
2688
2817
|
|
|
2689
2818
|
// src/features/analysis/scm/ado.ts
|
|
@@ -3888,11 +4017,8 @@ async function runAnalysis(params, options) {
|
|
|
3888
4017
|
tmpObj.removeCallback();
|
|
3889
4018
|
}
|
|
3890
4019
|
}
|
|
3891
|
-
function
|
|
3892
|
-
scmLibType
|
|
3893
|
-
githubToken,
|
|
3894
|
-
gitlabToken,
|
|
3895
|
-
adoToken
|
|
4020
|
+
function _getUrlForScmType({
|
|
4021
|
+
scmLibType
|
|
3896
4022
|
}) {
|
|
3897
4023
|
const githubAuthUrl = `${WEB_APP_URL}/github-auth`;
|
|
3898
4024
|
const gitlabAuthUrl = `${WEB_APP_URL}/gitlab-auth`;
|
|
@@ -3900,22 +4026,18 @@ function _getTokenAndUrlForScmType({
|
|
|
3900
4026
|
switch (scmLibType) {
|
|
3901
4027
|
case "GITHUB" /* GITHUB */:
|
|
3902
4028
|
return {
|
|
3903
|
-
token: githubToken,
|
|
3904
4029
|
authUrl: githubAuthUrl
|
|
3905
4030
|
};
|
|
3906
4031
|
case "GITLAB" /* GITLAB */:
|
|
3907
4032
|
return {
|
|
3908
|
-
token: gitlabToken,
|
|
3909
4033
|
authUrl: gitlabAuthUrl
|
|
3910
4034
|
};
|
|
3911
4035
|
case "ADO" /* ADO */:
|
|
3912
4036
|
return {
|
|
3913
|
-
token: adoToken,
|
|
3914
4037
|
authUrl: adoAuthUrl
|
|
3915
4038
|
};
|
|
3916
4039
|
default:
|
|
3917
4040
|
return {
|
|
3918
|
-
token: void 0,
|
|
3919
4041
|
authUrl: void 0
|
|
3920
4042
|
};
|
|
3921
4043
|
}
|
|
@@ -3958,35 +4080,34 @@ async function _scan(params, { skipPrompts = false } = {}) {
|
|
|
3958
4080
|
throw new Error("repo is required in case srcPath is not provided");
|
|
3959
4081
|
}
|
|
3960
4082
|
const userInfo = await gqlClient.getUserInfo();
|
|
3961
|
-
const
|
|
4083
|
+
const tokenInfo = getScmConfig({
|
|
4084
|
+
url: repo,
|
|
4085
|
+
scmConfigs: userInfo.scmConfigs,
|
|
4086
|
+
includeOrgTokens: false
|
|
4087
|
+
});
|
|
3962
4088
|
const isRepoAvailable = await scmCanReachRepo({
|
|
3963
4089
|
repoUrl: repo,
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
scmOrg: adoOrg
|
|
4090
|
+
accessToken: tokenInfo.accessToken,
|
|
4091
|
+
scmOrg: tokenInfo.scmOrg,
|
|
4092
|
+
scmType: getScmTypeFromScmLibType(tokenInfo.scmLibType)
|
|
3968
4093
|
});
|
|
3969
|
-
const
|
|
3970
|
-
const { authUrl: scmAuthUrl
|
|
3971
|
-
scmLibType
|
|
3972
|
-
githubToken,
|
|
3973
|
-
gitlabToken,
|
|
3974
|
-
adoToken
|
|
4094
|
+
const cloudScmLibType = getCloudScmLibTypeFromUrl(repo);
|
|
4095
|
+
const { authUrl: scmAuthUrl } = _getUrlForScmType({
|
|
4096
|
+
scmLibType: cloudScmLibType
|
|
3975
4097
|
});
|
|
3976
|
-
let myToken =
|
|
4098
|
+
let myToken = tokenInfo.accessToken;
|
|
3977
4099
|
if (!isRepoAvailable) {
|
|
3978
|
-
if (ci || !
|
|
4100
|
+
if (ci || !cloudScmLibType || !scmAuthUrl) {
|
|
3979
4101
|
const errorMessage = scmAuthUrl ? `Cannot access repo ${repo}` : `Cannot access repo ${repo} with the provided token, please visit ${scmAuthUrl} to refresh your source control management system token`;
|
|
3980
4102
|
throw new Error(errorMessage);
|
|
3981
4103
|
}
|
|
3982
|
-
if (
|
|
3983
|
-
myToken = await handleScmIntegration(
|
|
4104
|
+
if (cloudScmLibType && scmAuthUrl) {
|
|
4105
|
+
myToken = await handleScmIntegration(tokenInfo.accessToken, scmAuthUrl, repo) || "";
|
|
3984
4106
|
const isRepoAvailable2 = await scmCanReachRepo({
|
|
3985
4107
|
repoUrl: repo,
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
scmOrg: adoOrg
|
|
4108
|
+
accessToken: myToken,
|
|
4109
|
+
scmOrg: tokenInfo.scmOrg,
|
|
4110
|
+
scmType: getScmTypeFromScmLibType(tokenInfo.scmLibType)
|
|
3990
4111
|
});
|
|
3991
4112
|
if (!isRepoAvailable2) {
|
|
3992
4113
|
throw new Error(
|
|
@@ -3997,9 +4118,9 @@ async function _scan(params, { skipPrompts = false } = {}) {
|
|
|
3997
4118
|
}
|
|
3998
4119
|
const scm = await SCMLib.init({
|
|
3999
4120
|
url: repo,
|
|
4000
|
-
accessToken:
|
|
4001
|
-
|
|
4002
|
-
|
|
4121
|
+
accessToken: myToken,
|
|
4122
|
+
scmOrg: tokenInfo.scmOrg,
|
|
4123
|
+
scmType: tokenInfo.scmLibType
|
|
4003
4124
|
});
|
|
4004
4125
|
const reference = ref ?? await scm.getRepoDefaultBranch();
|
|
4005
4126
|
const { sha } = await scm.getReferenceData(reference);
|
|
@@ -4171,8 +4292,9 @@ async function _scan(params, { skipPrompts = false } = {}) {
|
|
|
4171
4292
|
throw new CliError2();
|
|
4172
4293
|
}
|
|
4173
4294
|
}
|
|
4174
|
-
async function handleScmIntegration(oldToken,
|
|
4175
|
-
const
|
|
4295
|
+
async function handleScmIntegration(oldToken, scmAuthUrl2, repoUrl) {
|
|
4296
|
+
const scmLibType = getCloudScmLibTypeFromUrl(repoUrl);
|
|
4297
|
+
const scmName = scmLibType === "GITHUB" /* GITHUB */ ? "Github" : scmLibType === "GITLAB" /* GITLAB */ ? "Gitlab" : scmLibType === "ADO" /* ADO */ ? "Azure DevOps" : "";
|
|
4176
4298
|
const addScmIntegration = skipPrompts ? true : await scmIntegrationPrompt(scmName);
|
|
4177
4299
|
const scmSpinner = createSpinner4(
|
|
4178
4300
|
`\u{1F517} Waiting for ${scmName} integration...`
|
|
@@ -4186,14 +4308,15 @@ async function _scan(params, { skipPrompts = false } = {}) {
|
|
|
4186
4308
|
);
|
|
4187
4309
|
await open2(scmAuthUrl2);
|
|
4188
4310
|
for (let i = 0; i < LOGIN_MAX_WAIT / LOGIN_CHECK_DELAY; i++) {
|
|
4189
|
-
const
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
|
|
4195
|
-
|
|
4196
|
-
|
|
4311
|
+
const userInfo2 = await gqlClient.getUserInfo();
|
|
4312
|
+
const tokenInfo2 = getScmConfig({
|
|
4313
|
+
url: repoUrl,
|
|
4314
|
+
scmConfigs: userInfo2.scmConfigs,
|
|
4315
|
+
includeOrgTokens: false
|
|
4316
|
+
});
|
|
4317
|
+
if (tokenInfo2.accessToken && tokenInfo2.accessToken !== oldToken) {
|
|
4318
|
+
scmSpinner.success({ text: `\u{1F517} ${scmName} integration successful!` });
|
|
4319
|
+
return tokenInfo2.accessToken;
|
|
4197
4320
|
}
|
|
4198
4321
|
scmSpinner.spin();
|
|
4199
4322
|
await sleep(LOGIN_CHECK_DELAY);
|
|
@@ -4348,12 +4471,16 @@ var packageJson2 = JSON.parse(
|
|
|
4348
4471
|
);
|
|
4349
4472
|
var config3 = new Configstore2(packageJson2.name, { apiToken: "" });
|
|
4350
4473
|
async function addScmToken(addScmTokenOptions) {
|
|
4351
|
-
const { apiKey, token, organization,
|
|
4474
|
+
const { apiKey, token, organization, scmType, url, username, refreshToken } = addScmTokenOptions;
|
|
4352
4475
|
const gqlClient = new GQLClient({
|
|
4353
4476
|
apiKey: apiKey || config3.get("apiToken")
|
|
4354
4477
|
});
|
|
4478
|
+
if (!scmType) {
|
|
4479
|
+
throw new CliError(errorMessages.invalidScmType);
|
|
4480
|
+
}
|
|
4355
4481
|
await gqlClient.updateScmToken({
|
|
4356
|
-
|
|
4482
|
+
scmType,
|
|
4483
|
+
url,
|
|
4357
4484
|
token,
|
|
4358
4485
|
org: organization,
|
|
4359
4486
|
username,
|
|
@@ -4437,9 +4564,16 @@ var commitHashOption = {
|
|
|
4437
4564
|
type: "string"
|
|
4438
4565
|
};
|
|
4439
4566
|
var scmTypeOption = {
|
|
4567
|
+
demandOption: true,
|
|
4440
4568
|
describe: chalk5.bold("SCM type (GitHub, GitLab, Ado)"),
|
|
4441
4569
|
type: "string"
|
|
4442
4570
|
};
|
|
4571
|
+
var urlOption = {
|
|
4572
|
+
describe: chalk5.bold(
|
|
4573
|
+
"URL of the repository (used in GitHub, GitLab, Azure DevOps)"
|
|
4574
|
+
),
|
|
4575
|
+
type: "string"
|
|
4576
|
+
};
|
|
4443
4577
|
var scmOrgOption = {
|
|
4444
4578
|
describe: chalk5.bold("Organization name in SCM (used in Azure DevOps)"),
|
|
4445
4579
|
type: "string"
|
|
@@ -4626,29 +4760,32 @@ async function scanHandler(args) {
|
|
|
4626
4760
|
|
|
4627
4761
|
// src/args/commands/token.ts
|
|
4628
4762
|
function addScmTokenBuilder(args) {
|
|
4629
|
-
return args.option("scm", scmTypeOption).option("token", scmTokenOption).option("organization", scmOrgOption).option("username", scmUsernameOption).option("refresh-token", scmRefreshTokenOption).option("api-key", apiKeyOption).example(
|
|
4630
|
-
"$0 add-scm-token --scm
|
|
4763
|
+
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(
|
|
4764
|
+
"$0 add-scm-token --scm-type Ado --url https://dev.azure.com/adoorg/test/_git/repo --token abcdef0123456 --organization myOrg",
|
|
4631
4765
|
"Add your SCM (Github, Gitlab, Azure DevOps) token to Mobb to enable automated fixes."
|
|
4632
|
-
).help().demandOption(["
|
|
4766
|
+
).help().demandOption(["url", "token"]);
|
|
4633
4767
|
}
|
|
4634
4768
|
function validateAddScmTokenOptions(argv) {
|
|
4635
|
-
if (!argv.
|
|
4636
|
-
throw new CliError(errorMessages.
|
|
4637
|
-
}
|
|
4638
|
-
if (!Object.values(ScmTypes).includes(argv.scm)) {
|
|
4639
|
-
throw new CliError(errorMessages.invalidScmType);
|
|
4769
|
+
if (!argv.url) {
|
|
4770
|
+
throw new CliError(errorMessages.missingUrl);
|
|
4640
4771
|
}
|
|
4641
4772
|
if (!argv.token) {
|
|
4642
4773
|
throw new CliError(errorMessages.missingToken);
|
|
4643
4774
|
}
|
|
4644
|
-
if (argv.
|
|
4775
|
+
if ("GitHub" /* GitHub */ !== argv.scmType && "Ado" /* Ado */ !== argv.scmType && "GitLab" /* GitLab */ !== argv.scmType) {
|
|
4645
4776
|
throw new CliError(
|
|
4646
|
-
"\nError: --
|
|
4777
|
+
"\nError: --scm-type must reference a valid SCM type (GitHub, GitLab, Ado)"
|
|
4647
4778
|
);
|
|
4648
4779
|
}
|
|
4649
|
-
|
|
4780
|
+
const urlObj = new URL(argv.url);
|
|
4781
|
+
if (urlObj.hostname === "github.com" && !argv.username) {
|
|
4650
4782
|
throw new CliError("\nError: --username flag is required for GitHub");
|
|
4651
4783
|
}
|
|
4784
|
+
if ((urlObj.hostname === "dev.azure.com" || urlObj.hostname.endsWith(".visualstudio.com")) && !argv.organization) {
|
|
4785
|
+
throw new CliError(
|
|
4786
|
+
"\nError: --organization flag is required for Azure DevOps"
|
|
4787
|
+
);
|
|
4788
|
+
}
|
|
4652
4789
|
}
|
|
4653
4790
|
async function addScmTokenHandler(args) {
|
|
4654
4791
|
validateAddScmTokenOptions(args);
|