@soos-io/soos-scm-audit 0.2.4 → 0.2.6
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/README.md +4 -4
- package/bin/index.js +2 -3
- package/bin/services/ContributorAuditArgumentParser.d.ts +1 -1
- package/bin/services/ContributorAuditArgumentParser.js +2 -2
- package/bin/services/ContributorAuditService/ContributorAuditService.d.ts +1 -1
- package/bin/services/ContributorAuditService/ContributorAuditService.js +17 -10
- package/bin/services/ContributorAuditService/providers/GitHub/GitHubApiClient.js +3 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -38,10 +38,10 @@ NOTE: you can find values for the `--apiKey` and `--clientId` at [app.soos.io](h
|
|
|
38
38
|
|
|
39
39
|
| General Parameters | Default | Description |
|
|
40
40
|
|------------------------|---------|----------------------------------------------------------|
|
|
41
|
-
| --apiKey | | SOOS API Key - get yours from SOOS Integration.
|
|
42
|
-
| --clientId | | SOOS Client ID - get yours from SOOS Integration.
|
|
41
|
+
| --apiKey | | SOOS API Key - get yours from SOOS Integration. |
|
|
42
|
+
| --clientId | | SOOS Client ID - get yours from SOOS Integration. |
|
|
43
43
|
| --logLevel | | Minimum level to show logs: DEBUG, INFO, WARN, FAIL, ERROR. |
|
|
44
|
-
| --
|
|
44
|
+
| --resultsFormat | | Results format: TXT or JSON |
|
|
45
45
|
| --scmType | | Scm Type to use for the audit. Options: GitHub, BitBucketCloud |
|
|
46
46
|
|
|
47
47
|
| BitBucket Cloud Parameters | Default | Description |
|
|
@@ -53,4 +53,4 @@ NOTE: you can find values for the `--apiKey` and `--clientId` at [app.soos.io](h
|
|
|
53
53
|
| GitHub Parameters | Default | Description |
|
|
54
54
|
|----------------------------|---------|----------------------------------------------------------|
|
|
55
55
|
| --organizationName | | Organization name to run audit for GitHub. |
|
|
56
|
-
| --secret | | Secret to use for API calls. It should be a GPAT
|
|
56
|
+
| --secret | | Secret to use for API calls. It should be a classic GPAT that has access to all repositories for the organization |
|
package/bin/index.js
CHANGED
|
@@ -43,7 +43,7 @@ class SOOSContributorAudit {
|
|
|
43
43
|
api_client_1.soosLogger.info(`Running Contributing Developer audit for ${this.args.scmType}`);
|
|
44
44
|
const contributingDevelopers = await contributingDeveloperService.audit(auditParams);
|
|
45
45
|
await contributingDeveloperService.uploadContributorAudits(this.args.clientId, contributingDevelopers);
|
|
46
|
-
contributingDeveloperService.saveResults(contributingDevelopers, this.args.
|
|
46
|
+
contributingDeveloperService.saveResults(contributingDevelopers, this.args.resultsFormat);
|
|
47
47
|
}
|
|
48
48
|
static async createAndRun() {
|
|
49
49
|
try {
|
|
@@ -52,12 +52,11 @@ class SOOSContributorAudit {
|
|
|
52
52
|
api_client_1.soosLogger.setMinLogLevel(args.logLevel);
|
|
53
53
|
api_client_1.soosLogger.always("Starting SOOS SCM Contributor Audit");
|
|
54
54
|
api_client_1.soosLogger.debug(JSON.stringify((0, utilities_1.obfuscateProperties)(args, ["apiKey", "secret"]), null, 2));
|
|
55
|
-
api_client_1.soosLogger.logLineSeparator();
|
|
56
55
|
const soosContributorAudit = new SOOSContributorAudit(args);
|
|
57
56
|
await soosContributorAudit.runAudit();
|
|
58
57
|
}
|
|
59
58
|
catch (error) {
|
|
60
|
-
api_client_1.soosLogger.error(
|
|
59
|
+
api_client_1.soosLogger.error(error);
|
|
61
60
|
(0, process_1.exit)(1);
|
|
62
61
|
}
|
|
63
62
|
}
|
|
@@ -3,7 +3,7 @@ import { ScmResultsFormat, ScmType } from "../enums";
|
|
|
3
3
|
interface IContributorAuditArguments extends ICommonArguments {
|
|
4
4
|
days: number;
|
|
5
5
|
secret: string;
|
|
6
|
-
|
|
6
|
+
resultsFormat: ScmResultsFormat;
|
|
7
7
|
scmType: ScmType;
|
|
8
8
|
}
|
|
9
9
|
declare class ContributorAuditArgumentParser extends ArgumentParserBase {
|
|
@@ -26,10 +26,10 @@ class ContributorAuditArgumentParser extends api_client_1.ArgumentParserBase {
|
|
|
26
26
|
return parsedValue;
|
|
27
27
|
},
|
|
28
28
|
});
|
|
29
|
-
this.addEnumArgument("
|
|
29
|
+
this.addEnumArgument("resultsFormat", enums_1.ScmResultsFormat, "Format of results file: JSON or TXT. Default is TXT.", {
|
|
30
30
|
defaultValue: enums_1.ScmResultsFormat.TXT,
|
|
31
31
|
});
|
|
32
|
-
this.addEnumArgument("scmType", enums_1.ScmType, "Scm Type to use for the audit.", {
|
|
32
|
+
this.addEnumArgument("scmType", enums_1.ScmType, "Scm Type to use for the audit. Default is GitHub.", {
|
|
33
33
|
required: true,
|
|
34
34
|
defaultValue: enums_1.ScmType.GitHub,
|
|
35
35
|
});
|
|
@@ -10,7 +10,7 @@ declare class ContributorAuditService {
|
|
|
10
10
|
static create(apiKey: string, apiURL: string, scmType: ScmType): ContributorAuditService;
|
|
11
11
|
audit(implementationParams: Record<string, string | number>): Promise<IContributorAuditModel>;
|
|
12
12
|
uploadContributorAudits(clientHash: string, contributorAudit: IContributorAuditModel): Promise<void>;
|
|
13
|
-
saveResults(results: IContributorAuditModel,
|
|
13
|
+
saveResults(results: IContributorAuditModel, resultsFormat: ScmResultsFormat): Promise<void>;
|
|
14
14
|
private saveResultsAsJSON;
|
|
15
15
|
private saveResultsAsTXT;
|
|
16
16
|
private validateCommonParams;
|
|
@@ -46,9 +46,9 @@ class ContributorAuditService {
|
|
|
46
46
|
await this.hooksApiClient.postContributorAudits(clientHash, contributorAudit);
|
|
47
47
|
api_client_1.soosLogger.info(`Results uploaded successfully.`);
|
|
48
48
|
}
|
|
49
|
-
async saveResults(results,
|
|
50
|
-
api_client_1.soosLogger.info(`Saving results.`);
|
|
51
|
-
switch (
|
|
49
|
+
async saveResults(results, resultsFormat) {
|
|
50
|
+
api_client_1.soosLogger.info(`Saving results to ${resultsFormat} file.`);
|
|
51
|
+
switch (resultsFormat) {
|
|
52
52
|
case enums_1.ScmResultsFormat.JSON: {
|
|
53
53
|
await this.saveResultsAsJSON(results);
|
|
54
54
|
break;
|
|
@@ -58,23 +58,30 @@ class ContributorAuditService {
|
|
|
58
58
|
break;
|
|
59
59
|
}
|
|
60
60
|
default: {
|
|
61
|
-
throw new Error(`Unsupported format: ${
|
|
61
|
+
throw new Error(`Unsupported format: ${resultsFormat}`);
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
async saveResultsAsJSON(results) {
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
const outputFile = Path.join(process.cwd(), `${constants_1.SOOS_SCM_AUDIT_CONSTANTS.Files.ContributorAuditResults}.json`);
|
|
67
|
+
fs_1.default.writeFileSync(outputFile, JSON.stringify(results, null, 2));
|
|
68
|
+
api_client_1.soosLogger.info(`Results saved successfully to ${outputFile}`);
|
|
68
69
|
}
|
|
69
70
|
async saveResultsAsTXT(results) {
|
|
70
|
-
|
|
71
|
+
let output = `soos-scm-audit ${results.metadata.scriptVersion} - ${results.metadata.days} days - ${results.organizationName} - ${new Date().toISOString()}\n\n`;
|
|
71
72
|
results.contributors
|
|
72
73
|
.sort((a, b) => a.username.localeCompare(b.username))
|
|
73
74
|
.forEach((contributor) => {
|
|
74
|
-
|
|
75
|
+
output += `${contributor.username} - ${contributor.repositories.length} repositories:\n`;
|
|
76
|
+
contributor.repositories
|
|
77
|
+
.sort((a, b) => a.name.localeCompare(b.name))
|
|
78
|
+
.forEach((repository) => {
|
|
79
|
+
output += ` - ${repository.name} (${repository.id}), ${repository.lastCommit}\n`;
|
|
80
|
+
});
|
|
75
81
|
});
|
|
76
|
-
|
|
77
|
-
|
|
82
|
+
const outputFile = Path.join(process.cwd(), `${constants_1.SOOS_SCM_AUDIT_CONSTANTS.Files.ContributorAuditResults}.txt`);
|
|
83
|
+
fs_1.default.writeFileSync(outputFile, output);
|
|
84
|
+
api_client_1.soosLogger.info(`Results saved successfully to ${outputFile}`);
|
|
78
85
|
}
|
|
79
86
|
validateCommonParams(implementationParams) {
|
|
80
87
|
if (!implementationParams["days"]) {
|
|
@@ -49,6 +49,9 @@ class GitHubApiClient {
|
|
|
49
49
|
return response;
|
|
50
50
|
}, async (error) => {
|
|
51
51
|
const { config, response } = error;
|
|
52
|
+
if (response?.status === 401) {
|
|
53
|
+
throw new Error("Unauthorized: Please check your GitHub PAT.");
|
|
54
|
+
}
|
|
52
55
|
const maxRetries = 3;
|
|
53
56
|
config.retryCount = config.retryCount || 0;
|
|
54
57
|
if ((response?.status === 429 || response?.status === 403) &&
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soos-io/soos-scm-audit",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"description": "SOOS SCM Audit CLI",
|
|
5
5
|
"main": "bin/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
},
|
|
33
33
|
"homepage": "https://github.com/soos-io/soos-scm-audit#readme",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@soos-io/api-client": "1.
|
|
35
|
+
"@soos-io/api-client": "1.5.1",
|
|
36
36
|
"axios": "^1.8.3",
|
|
37
37
|
"tslib": "^2.6.2"
|
|
38
38
|
},
|