@soos-io/soos-scm-audit 0.2.0-pre.2 → 0.2.0-pre.3

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/bin/index.js CHANGED
@@ -9,16 +9,11 @@ const utilities_1 = require("@soos-io/api-client/dist/utilities");
9
9
  const ContributorAuditArgumentParser_1 = tslib_1.__importDefault(require("./services/ContributorAuditArgumentParser"));
10
10
  const ContributorAuditService_1 = tslib_1.__importDefault(require("./services/ContributorAuditService/ContributorAuditService"));
11
11
  const enums_1 = require("./enums");
12
- class SOOSSCMAudit {
12
+ class SOOSContributorAudit {
13
13
  args;
14
14
  constructor(args) {
15
15
  this.args = args;
16
16
  }
17
- static parseArgs() {
18
- const contributorAuditArgumentParser = ContributorAuditArgumentParser_1.default.create();
19
- api_client_1.soosLogger.info("Parsing arguments");
20
- return contributorAuditArgumentParser.parseArguments();
21
- }
22
17
  async runAudit() {
23
18
  const contributingDeveloperService = ContributorAuditService_1.default.create(this.args.apiKey, this.args.apiURL, this.args.scmType);
24
19
  let auditParams;
@@ -51,15 +46,15 @@ class SOOSSCMAudit {
51
46
  contributingDeveloperService.saveResults(contributingDevelopers, this.args.saveResults);
52
47
  }
53
48
  static async createAndRun() {
54
- api_client_1.soosLogger.info("Starting SOOS SCM Contributor Audit");
55
- api_client_1.soosLogger.logLineSeparator();
56
49
  try {
57
- const args = this.parseArgs();
50
+ const contributorAuditArgumentParser = ContributorAuditArgumentParser_1.default.create();
51
+ const args = contributorAuditArgumentParser.parseArguments();
58
52
  api_client_1.soosLogger.setMinLogLevel(args.logLevel);
53
+ api_client_1.soosLogger.info("Starting SOOS SCM Contributor Audit");
59
54
  api_client_1.soosLogger.debug(JSON.stringify((0, utilities_1.obfuscateProperties)(args, ["apiKey", "secret"]), null, 2));
60
55
  api_client_1.soosLogger.logLineSeparator();
61
- const soosSCMAudit = new SOOSSCMAudit(args);
62
- await soosSCMAudit.runAudit();
56
+ const soosContributorAudit = new SOOSContributorAudit(args);
57
+ await soosContributorAudit.runAudit();
63
58
  }
64
59
  catch (error) {
65
60
  api_client_1.soosLogger.error(`Error on createAndRun: ${error}`);
@@ -67,4 +62,4 @@ class SOOSSCMAudit {
67
62
  }
68
63
  }
69
64
  }
70
- SOOSSCMAudit.createAndRun();
65
+ SOOSContributorAudit.createAndRun();
@@ -1,6 +1,5 @@
1
- import { ArgumentParserBase, ICommonArguments } from "@soos-io/api-client";
1
+ import { ArgumentParserBase, ICommonArguments, ParsedOptions } from "@soos-io/api-client";
2
2
  import { ScmResultsFormat, ScmType } from "../enums";
3
- import { Command, OptionValues } from "commander";
4
3
  interface IContributorAuditArguments extends ICommonArguments {
5
4
  days: number;
6
5
  secret: string;
@@ -8,10 +7,12 @@ interface IContributorAuditArguments extends ICommonArguments {
8
7
  scmType: ScmType;
9
8
  }
10
9
  declare class ContributorAuditArgumentParser extends ArgumentParserBase {
11
- constructor(argumentParser: Command);
10
+ constructor(description: string);
12
11
  static create(): ContributorAuditArgumentParser;
13
12
  addBaseContributorArguments(): void;
14
- parseArguments<T extends OptionValues>(): T;
13
+ parseArguments<T extends ParsedOptions>(argv?: string[]): {
14
+ [k: string]: string;
15
+ } & T;
15
16
  }
16
17
  export default ContributorAuditArgumentParser;
17
18
  export { IContributorAuditArguments };
@@ -5,45 +5,48 @@ const GitHubContributorAuditProvider_1 = tslib_1.__importDefault(require("./Cont
5
5
  const BitbucketCloudContributorAuditProvider_1 = tslib_1.__importDefault(require("./ContributorAuditService/providers/BitbucketCloud/BitbucketCloudContributorAuditProvider"));
6
6
  const api_client_1 = require("@soos-io/api-client");
7
7
  const enums_1 = require("../enums");
8
- const commander_1 = require("commander");
9
8
  const constants_1 = require("../constants");
9
+ const package_json_1 = require("../../package.json");
10
10
  class ContributorAuditArgumentParser extends api_client_1.ArgumentParserBase {
11
- constructor(argumentParser) {
12
- super(argumentParser);
11
+ constructor(description) {
12
+ super(description, api_client_1.ScanType.SCA, package_json_1.version, api_client_1.IntegrationName.SoosScmAudit, api_client_1.IntegrationType.Script);
13
+ this.addBaseContributorArguments();
13
14
  }
14
15
  static create() {
15
- const parser = commander_1.program.description("SOOS SCM Audit");
16
- return new ContributorAuditArgumentParser(parser);
16
+ return new ContributorAuditArgumentParser("SOOS SCM Audit");
17
17
  }
18
18
  addBaseContributorArguments() {
19
- this.argumentParser.option("--days", "Number of days to look back for commits.", (value) => {
20
- const parsedValue = parseInt(value, 10);
21
- if (isNaN(parsedValue) || parsedValue <= 0) {
22
- throw new Error(`Invalid value for days: ${value}`);
23
- }
24
- return parsedValue;
25
- }, constants_1.SOOS_SCM_AUDIT_CONSTANTS.Parameters.DefaultDaysAgo);
26
- this.addEnumArgument("--saveResults", enums_1.ScmResultsFormat, "Save results to file, options available: JSON, TXT.", enums_1.ScmResultsFormat.TXT);
27
- this.addEnumArgument("--scmType", enums_1.ScmType, "Scm Type to use for the audit. Options: GitHub, Bitbucket.", enums_1.ScmType.GitHub);
19
+ this.addArgument("days", "Number of days to look back for commits.", {
20
+ defaultValue: constants_1.SOOS_SCM_AUDIT_CONSTANTS.Parameters.DefaultDaysAgo,
21
+ argParser: (value) => {
22
+ const parsedValue = parseInt(value, 10);
23
+ if (isNaN(parsedValue) || parsedValue <= 0) {
24
+ throw new Error(`Invalid value for days, use a positive integer: ${value}`);
25
+ }
26
+ return parsedValue;
27
+ },
28
+ });
29
+ this.addEnumArgument("saveResults", enums_1.ScmResultsFormat, "Save results to file.", {
30
+ defaultValue: enums_1.ScmResultsFormat.TXT,
31
+ });
32
+ this.addEnumArgument("scmType", enums_1.ScmType, "Scm Type to use for the audit.", {
33
+ required: true,
34
+ defaultValue: enums_1.ScmType.GitHub,
35
+ });
28
36
  }
29
- parseArguments() {
30
- this.addCommonArguments();
31
- this.addBaseContributorArguments();
32
- this.argumentParser.parse();
33
- const preProviderArgs = this.argumentParser.opts();
34
- switch (preProviderArgs.scmType) {
37
+ parseArguments(argv) {
38
+ const preArgs = this.preParseArguments(argv);
39
+ switch (preArgs.scmType) {
35
40
  case enums_1.ScmType.GitHub:
36
- GitHubContributorAuditProvider_1.default.addProviderArgs(this.argumentParser);
41
+ GitHubContributorAuditProvider_1.default.addProviderArgs(this);
37
42
  break;
38
43
  case enums_1.ScmType.BitbucketCloud:
39
- BitbucketCloudContributorAuditProvider_1.default.addProviderArgs(this.argumentParser);
44
+ BitbucketCloudContributorAuditProvider_1.default.addProviderArgs(this);
40
45
  break;
41
46
  default:
42
- throw new Error("Unsupported scmType");
47
+ throw new Error("Unsupported scmType: " + preArgs.scmType);
43
48
  }
44
- this.argumentParser.parse();
45
- const args = this.argumentParser.opts();
46
- return args;
49
+ return super.parseArguments(argv);
47
50
  }
48
51
  }
49
52
  exports.default = ContributorAuditArgumentParser;
@@ -1,8 +1,4 @@
1
1
  import { IContributorAuditRepositories } from "@soos-io/api-client/dist/api/SOOSHooksApiClient";
2
- export interface BitbucketRepositoryApiResponse {
3
- values: BitbucketCloudRepository[];
4
- next?: string;
5
- }
6
2
  export interface BitbucketCloudRepository {
7
3
  uuid: string;
8
4
  full_name: string;
@@ -11,32 +7,12 @@ export interface BitbucketCloudRepository {
11
7
  updated_on: string;
12
8
  workspace: BitbucketCloudWorkspace;
13
9
  }
14
- export interface BitbucketCloudWorkspace {
10
+ interface BitbucketCloudWorkspace {
15
11
  type: string;
16
12
  uuid: string;
17
13
  name: string;
18
14
  slug: string;
19
15
  }
20
- export interface BitbucketCloudCommitsApiResponse {
21
- values: BitbucketCloudCommit[];
22
- next?: string;
23
- }
24
- export interface BitbucketCloudCommit {
25
- author: BitbucketCloudAuthor;
26
- date: string;
27
- }
28
- export interface BitbucketCloudAuthor {
29
- raw: string;
30
- name: string;
31
- emailAddress: string;
32
- displayName: string;
33
- user: BitbucketCloudUser;
34
- }
35
- interface BitbucketCloudUser {
36
- display_name: string;
37
- type: string;
38
- nickname: string;
39
- }
40
16
  declare class BitbucketCloudApiClient {
41
17
  private readonly client;
42
18
  private readonly workspace;
@@ -1,14 +1,13 @@
1
1
  import { IContributorAuditProvider } from "../../ContributorAuditService";
2
- import { IContributorAuditArguments } from "../../../ContributorAuditArgumentParser";
2
+ import ContributorAuditArgumentParser, { IContributorAuditArguments } from "../../../ContributorAuditArgumentParser";
3
3
  import { IContributorAuditModel } from "@soos-io/api-client/dist/api/SOOSHooksApiClient";
4
- import { Command } from "commander";
5
4
  interface IBitBucketContributorAuditArguments extends IContributorAuditArguments {
6
5
  username: string;
7
6
  workspace: string;
8
7
  }
9
8
  declare class BitbucketCloudContributorAuditProvider implements IContributorAuditProvider {
10
9
  audit(implementationParams: Record<string, string | number>): Promise<IContributorAuditModel>;
11
- static addProviderArgs(argumentParser: Command): void;
10
+ static addProviderArgs(argumentParser: ContributorAuditArgumentParser): void;
12
11
  private getBitbucketCloudRepositoryContributors;
13
12
  }
14
13
  export default BitbucketCloudContributorAuditProvider;
@@ -27,9 +27,11 @@ class BitbucketCloudContributorAuditProvider {
27
27
  return finalContributors;
28
28
  }
29
29
  static addProviderArgs(argumentParser) {
30
- argumentParser.requiredOption("--workspace", "Organization name to use for the audit.");
31
- argumentParser.requiredOption("--secret", "Secret to use for api calls, it should be an app password.");
32
- argumentParser.requiredOption("--username", "Username for audit.");
30
+ argumentParser.addArgument("workspace", "Organization name to use for the audit.", {
31
+ required: true,
32
+ });
33
+ argumentParser.addArgument("secret", "Secret to use for api calls, it should be an app password.", { required: true });
34
+ argumentParser.addArgument("username", "Username for audit.", { required: true });
33
35
  }
34
36
  async getBitbucketCloudRepositoryContributors(bitbucketApiClient, repositories, batchSize) {
35
37
  const contributorsArray = [];
@@ -1,5 +1,5 @@
1
1
  import { IContributorAuditRepositories } from "@soos-io/api-client/dist/api/SOOSHooksApiClient";
2
- export interface GitHubOrganization {
2
+ interface GitHubOrganization {
3
3
  login: string;
4
4
  }
5
5
  export interface GitHubRepository {
@@ -10,16 +10,6 @@ export interface GitHubRepository {
10
10
  owner: GitHubOrganization;
11
11
  pushed_at: string;
12
12
  }
13
- export interface GitHubCommits {
14
- commit: {
15
- author: GitHubAuthor;
16
- };
17
- }
18
- export interface GitHubAuthor {
19
- name: string;
20
- email: string;
21
- date: string;
22
- }
23
13
  declare class GitHubApiClient {
24
14
  private readonly client;
25
15
  private readonly organizationName;
@@ -1,13 +1,12 @@
1
1
  import { IContributorAuditProvider } from "../../ContributorAuditService";
2
- import { IContributorAuditArguments } from "../../../ContributorAuditArgumentParser";
2
+ import ContributorAuditArgumentParser, { IContributorAuditArguments } from "../../../ContributorAuditArgumentParser";
3
3
  import { IContributorAuditModel } from "@soos-io/api-client/dist/api/SOOSHooksApiClient";
4
- import { Command } from "commander";
5
4
  interface IGitHubContributorAuditArguments extends IContributorAuditArguments {
6
5
  organizationName: string;
7
6
  }
8
7
  declare class GitHubContributorAuditProvider implements IContributorAuditProvider {
9
8
  audit(implementationParams: Record<string, string | number>): Promise<IContributorAuditModel>;
10
- static addProviderArgs(argumentParser: Command): void;
9
+ static addProviderArgs(argumentParser: ContributorAuditArgumentParser): void;
11
10
  private getGitHubRepositoryContributors;
12
11
  }
13
12
  export default GitHubContributorAuditProvider;
@@ -30,8 +30,12 @@ class GitHubContributorAuditProvider {
30
30
  return finalContributors;
31
31
  }
32
32
  static addProviderArgs(argumentParser) {
33
- argumentParser.requiredOption("--organizationName", "Organization name to use for the audit.");
34
- argumentParser.requiredOption("--secret", "Secret to use for api calls, it should be a GPAT.");
33
+ argumentParser.addArgument("organizationName", "Organization name to use for the audit.", {
34
+ required: true,
35
+ });
36
+ argumentParser.addArgument("secret", "Secret to use for api calls, it should be a GPAT.", {
37
+ required: true,
38
+ });
35
39
  }
36
40
  async getGitHubRepositoryContributors(gitHubApiClient, repositories, batchSize) {
37
41
  const contributorsArray = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soos-io/soos-scm-audit",
3
- "version": "0.2.0-pre.2",
3
+ "version": "0.2.0-pre.3",
4
4
  "description": "SOOS SCM Audit CLI",
5
5
  "main": "bin/index.js",
6
6
  "scripts": {
@@ -9,7 +9,7 @@
9
9
  "setup:update": "npx npm-check -u",
10
10
  "setup:clean": "npx rimraf node_modules && npx rimraf package-lock.json",
11
11
  "build": "tsc",
12
- "build:clean": "npx rimraf build",
12
+ "build:clean": "npx rimraf bin",
13
13
  "format": "prettier ./src --check",
14
14
  "format:fix": "prettier ./src --write",
15
15
  "lint": "eslint --max-warnings 0",
@@ -18,7 +18,8 @@
18
18
  "check": "npm run format && npm run lint && npm run typecheck && (npm outdated || exit 0)",
19
19
  "patch": "npm version patch --no-git-tag-version",
20
20
  "patch-api-client": "npm run patch && npm run setup:clean && npm install @soos-io/api-client@latest --save-exact && npm install && npm run check",
21
- "link:local": "npm link @soos-io/api-client && npm run build && npm link"
21
+ "link:local": "npm link @soos-io/api-client && npm run build && npm link",
22
+ "knip": "knip"
22
23
  },
23
24
  "repository": {
24
25
  "type": "git",
@@ -31,8 +32,8 @@
31
32
  },
32
33
  "homepage": "https://github.com/soos-io/soos-scm-audit#readme",
33
34
  "dependencies": {
34
- "@soos-io/api-client": "1.3.0-pre.3",
35
- "commander": "^13.1.0",
35
+ "@soos-io/api-client": "1.3.0",
36
+ "axios": "^1.8.3",
36
37
  "tslib": "^2.6.2"
37
38
  },
38
39
  "devDependencies": {
@@ -40,6 +41,7 @@
40
41
  "@types/node": "^20.11.30",
41
42
  "eslint": "^9.21.0",
42
43
  "globals": "^16.0.0",
44
+ "knip": "^5.46.0",
43
45
  "prettier": "^3.2.5",
44
46
  "typescript": "^5.4.3",
45
47
  "typescript-eslint": "^8.24.1"