How snyk-tech-services/snyk-scm-contributors-count works
Project Overview
• This is a command-line interface (CLI) utility built in TypeScript that interacts with multiple Source Code Management (SCM) systems. It counts contributors with commits in the last 90 days and optionally verifies if repositories are monitored by Snyk.
• The tool supports several SCM platforms, each implemented as a distinct command and integration module.
• The provided README details how the commands work and lists examples for using the tool.
Key Components
a. CLI Entry & Command Parsing:
– Represent the main entry point from src/index.ts that initiates the CLI.
– Include a command-line parser that dispatches commands based on user input (e.g., reading options and the command name).
b. Command Handlers:
– Each SCM command lives under src/cmds (for example, azure-devops.ts, bitbucket-cloud.ts, github.ts, etc.).
– Each command handler is responsible for reading command-line arguments and coordinating further operations.
c. SCM Integration Modules:
– In src/lib, see separate directories for each SCM (such as azure-devops, bitbucket-cloud, bitbucket-server, github, github-enterprise, and gitlab).
– Each module implements the logic to interact with the corresponding SCM’s API (e.g., fetching contributors data).
– For new command integrations, the developer simply adds a new command handler and corresponding integration module.
d. Common Utilities and Shared Logic:
– Under src/lib/common there are utilities such as the SCMHandler base class, exclusion handling, and output formatting.
– Represent a shared common layer that the individual SCM modules extend or build upon.
e. Snyk Integration:
– The src/lib/snyk directory contains the code related to validating whether repositories are monitored by Snyk.
– Show that this component may be optionally invoked by some command handlers depending on the provided flags (such as --skipSnykMonitoredRepos).
f. Consolidate Results Module:
– The consolidation logic (found in src/lib/consolidateResults) is used to aggregate or process the results across multiple SCM queries.
Relationships & Data Flows
• All modules should then feed back into a “Results Consolidation” component (if used) and finally push the data back to an “Output Formatter” (likely leveraging shared common utilities).
Architectural Patterns & Design Principles
• Modularity: The design separates access to different SCM systems into independent modules.
• Abstraction: There’s a common abstraction (SCMHandler and shared common utilities) that allows for consistent operation across different integrations.
• Extensibility: With clearly defined command and integration modules, new SCM support can be added by following existing patterns.
• CLI-first design: Emphasize that this is a command-line tool with clearly defined commands and options.