@codacy/analysis-runner 0.1.0
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/LICENSE +21 -0
- package/README.md +55 -0
- package/dist/index.d.ts +364 -0
- package/dist/index.js +4888 -0
- package/package.json +41 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Codacy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# @codacy/analysis-runner
|
|
2
|
+
|
|
3
|
+
## Table of Contents
|
|
4
|
+
- [Overview](#overview)
|
|
5
|
+
- [API](#api)
|
|
6
|
+
- [Pipeline steps](#pipeline-steps)
|
|
7
|
+
- [Output formats](#output-formats)
|
|
8
|
+
- [Execution modes](#execution-modes)
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Overview
|
|
13
|
+
|
|
14
|
+
Core orchestration engine for the Codacy Analysis CLI. Discovers tools, checks capabilities, calls `analyze()` on each adapter, aggregates results, and transforms output. Usable programmatically by both the CLI and IDE integrations.
|
|
15
|
+
|
|
16
|
+
## API
|
|
17
|
+
|
|
18
|
+
| Export | Purpose |
|
|
19
|
+
|--------|---------|
|
|
20
|
+
| `analyze(options)` | Main entry point — runs the full analysis pipeline |
|
|
21
|
+
| `registerAdapter(adapter)` | Register a tool adapter |
|
|
22
|
+
| `clearAdapters()` | Reset adapter registry (for tests) |
|
|
23
|
+
| `getRegisteredAdapters()` | List registered adapters |
|
|
24
|
+
| `formatOutput(result, format)` | Transform AnalysisResult into a formatted string |
|
|
25
|
+
| `buildToolConfig()` | Assemble CodacyToolConfig from CodacyConfig + local config |
|
|
26
|
+
| `readCodacyConfig()` / `writeCodacyConfig()` | Read/write `.codacy/codacy.config.json` |
|
|
27
|
+
|
|
28
|
+
## Pipeline steps
|
|
29
|
+
|
|
30
|
+
1. Discover registered adapters (filtered by `options.tools` if set)
|
|
31
|
+
2. Check availability → build CapabilityReport
|
|
32
|
+
3. Apply execution mode rules (standard/strict/auto-install/inspect)
|
|
33
|
+
4. Discover files via git, apply exclusion layers, route to tools
|
|
34
|
+
5. Check local config + build CodacyToolConfig per tool
|
|
35
|
+
6. Execute `adapter.analyze()` with timeout and concurrency control
|
|
36
|
+
7. Aggregate results into AnalysisResult
|
|
37
|
+
8. Format output
|
|
38
|
+
|
|
39
|
+
## Output formats
|
|
40
|
+
|
|
41
|
+
| Format | Description |
|
|
42
|
+
|--------|-------------|
|
|
43
|
+
| `json` | Pretty-printed AnalysisResult (default) |
|
|
44
|
+
| `sarif` | SARIF v2.1.0 document |
|
|
45
|
+
| `container` | One JSON object per line (Codacy Docker runners) |
|
|
46
|
+
| `text` | Human-readable terminal summary with colors and grouping |
|
|
47
|
+
|
|
48
|
+
## Execution modes
|
|
49
|
+
|
|
50
|
+
| Mode | Behavior |
|
|
51
|
+
|------|----------|
|
|
52
|
+
| `standard` | Skip unavailable tools, report them (default) |
|
|
53
|
+
| `strict` | Fail if any configured tool is unavailable |
|
|
54
|
+
| `auto-install` | Attempt to install missing tools before analysis |
|
|
55
|
+
| `inspect` | Dry-run: report capability without running analysis |
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
import { OutputFormat, Logger, AnalysisResult, ToolAdapter, CodacyConfig, ConfigurationFileCheckResult, CodacyToolConfig, Language, LogLevel } from '@codacy/tooling';
|
|
2
|
+
export { AnalysisResult, OutputFormat } from '@codacy/tooling';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Main analysis entry point — orchestrates the full analysis pipeline.
|
|
6
|
+
*
|
|
7
|
+
* Pipeline steps:
|
|
8
|
+
* 1. Discover registered adapters (filtered by options.tools if set)
|
|
9
|
+
* 2. Check availability of each adapter → CapabilityReport
|
|
10
|
+
* 3. Apply execution mode rules (standard/strict/auto-install/inspect)
|
|
11
|
+
* 4. Discover files, apply exclusions, route to tools
|
|
12
|
+
* 5. Check local config + build CodacyToolConfig per tool
|
|
13
|
+
* 6. Execute tools (sequential or parallel)
|
|
14
|
+
* 7. Aggregate results into AnalysisResult
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** Execution mode controls how the runner handles unavailable tools. */
|
|
18
|
+
type ExecutionMode = "standard" | "strict" | "auto-install" | "inspect";
|
|
19
|
+
interface AnalyzeOptions {
|
|
20
|
+
/** Absolute path to the repository to analyze. */
|
|
21
|
+
repositoryRoot: string;
|
|
22
|
+
/** Restrict analysis to these tool IDs. If empty/undefined, all registered tools run. */
|
|
23
|
+
tools?: string[];
|
|
24
|
+
/** Specific files to analyze (relative to repositoryRoot). If empty, all files. */
|
|
25
|
+
files?: string[];
|
|
26
|
+
/** Output format for the analysis results. Defaults to "json". */
|
|
27
|
+
outputFormat?: OutputFormat;
|
|
28
|
+
/** Execution mode. Defaults to "standard". */
|
|
29
|
+
mode?: ExecutionMode;
|
|
30
|
+
/** Maximum time in ms for each tool invocation. Defaults to 300000 (5 minutes). */
|
|
31
|
+
toolTimeout?: number;
|
|
32
|
+
/** Maximum number of tools to run in parallel. 1 = sequential. Defaults to 1. */
|
|
33
|
+
parallelTools?: number;
|
|
34
|
+
/** Target execution environment. "local" = developer machine, "container" = Codacy Docker runner.
|
|
35
|
+
* Phase 9 implements the actual container path; this field is accepted but currently ignored. */
|
|
36
|
+
runner?: "local" | "container";
|
|
37
|
+
/** Logger for pipeline progress messages (install status, etc.). Defaults to no-op. */
|
|
38
|
+
logger?: Logger;
|
|
39
|
+
/** Called when a tool starts executing. */
|
|
40
|
+
onToolStart?: (toolId: string, displayName: string) => void;
|
|
41
|
+
/** Called when a tool finishes executing. */
|
|
42
|
+
onToolComplete?: (toolId: string, displayName: string, issueCount: number, durationMs: number) => void;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Runs analysis on the given repository and returns the unified result.
|
|
46
|
+
* This is the main entry point used by both the CLI and IDE integrations.
|
|
47
|
+
*/
|
|
48
|
+
declare function analyze(options: AnalyzeOptions): Promise<AnalysisResult>;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Tool adapter registry — stores registered adapters for discovery by the runner.
|
|
52
|
+
*
|
|
53
|
+
* Adapters must be registered before calling analyze(). The registry is a simple
|
|
54
|
+
* in-memory map keyed by adapter ID. clearAdapters() is provided for testing.
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
/** Register a tool adapter so the runner can discover and invoke it. */
|
|
58
|
+
declare function registerAdapter(adapter: Readonly<ToolAdapter>): void;
|
|
59
|
+
/** Returns all registered adapters, optionally filtered by tool ID list. */
|
|
60
|
+
declare function getRegisteredAdapters(toolIds?: string[]): Readonly<ToolAdapter>[];
|
|
61
|
+
/** Remove all registered adapters. Used in tests to reset state between runs. */
|
|
62
|
+
declare function clearAdapters(): void;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Output format transformations — converts AnalysisResult into the requested
|
|
66
|
+
* output format string.
|
|
67
|
+
*
|
|
68
|
+
* This is the single place where output transformation happens, so that both
|
|
69
|
+
* CLI and IDE consumers share the same formatting logic.
|
|
70
|
+
*
|
|
71
|
+
* Supported formats:
|
|
72
|
+
* - json: AnalysisResult as pretty-printed JSON (default)
|
|
73
|
+
* - sarif: SARIF v2.1.0 document
|
|
74
|
+
* - container: one JSON object per line on stdout (Codacy Docker runners)
|
|
75
|
+
* - text: human-readable summary with colors and grouping
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Transforms an AnalysisResult into the specified output format string.
|
|
80
|
+
* This function never throws — format errors are returned as descriptive strings.
|
|
81
|
+
*/
|
|
82
|
+
declare function formatOutput(result: AnalysisResult, format: OutputFormat): string;
|
|
83
|
+
/**
|
|
84
|
+
* Builds the summary portion of the text output: header line, tools table,
|
|
85
|
+
* and install hints. Exported separately so the CLI can print it to stdout
|
|
86
|
+
* even when the full output is written to a file via `-o`.
|
|
87
|
+
*/
|
|
88
|
+
declare function formatTextSummary(result: AnalysisResult, isInspect?: boolean): string;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Configuration resolution — manages the .codacy/ directory structure and
|
|
92
|
+
* assembles per-tool CodacyToolConfig from config + local config checks.
|
|
93
|
+
*
|
|
94
|
+
* Precedence order:
|
|
95
|
+
* 1. Explicit CodacyConfig entry for the tool
|
|
96
|
+
* 2. Local native config file detected by the adapter
|
|
97
|
+
* 3. Default (empty patterns, no local config)
|
|
98
|
+
*/
|
|
99
|
+
|
|
100
|
+
/** Reads a CodacyConfig from disk. Returns null if the file doesn't exist. */
|
|
101
|
+
declare function readCodacyConfig(repositoryRoot: string): Promise<CodacyConfig | null>;
|
|
102
|
+
/** Writes a CodacyConfig to disk, creating the .codacy/ directory if needed. */
|
|
103
|
+
declare function writeCodacyConfig(repositoryRoot: string, config: CodacyConfig): Promise<string>;
|
|
104
|
+
/**
|
|
105
|
+
* Assembles a CodacyToolConfig from the global CodacyConfig and a local config check.
|
|
106
|
+
*
|
|
107
|
+
* Logic:
|
|
108
|
+
* - If `codacyConfig` has an entry for this tool, start with it
|
|
109
|
+
* - If no entry, create a default (empty patterns, no local config)
|
|
110
|
+
* - If `configCheck.found` and the existing config doesn't explicitly disable
|
|
111
|
+
* local config, set `localConfigurationFile` and `useLocalConfigurationFile`
|
|
112
|
+
*/
|
|
113
|
+
declare function buildToolConfig(codacyConfig: CodacyConfig | null, adapter: Readonly<ToolAdapter>, configCheck: ConfigurationFileCheckResult): CodacyToolConfig;
|
|
114
|
+
/**
|
|
115
|
+
* Creates a new CodacyConfig.
|
|
116
|
+
* Used by the init functions to build configs for all init modes.
|
|
117
|
+
*/
|
|
118
|
+
declare function createCodacyConfig(params?: {
|
|
119
|
+
source?: CodacyConfig["metadata"]["source"];
|
|
120
|
+
provider?: string | null;
|
|
121
|
+
organization?: string | null;
|
|
122
|
+
languages?: string[];
|
|
123
|
+
tools?: CodacyToolConfig[];
|
|
124
|
+
repositoryId?: string | null;
|
|
125
|
+
repositoryName?: string | null;
|
|
126
|
+
includeFiles?: string[];
|
|
127
|
+
}): CodacyConfig;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Init mode logic — builds a CodacyConfig from four distinct sources:
|
|
131
|
+
*
|
|
132
|
+
* - `initLocalConfig` — detect languages + tools with a local config file
|
|
133
|
+
* - `initDefaultConfig` — same as local, enriched with API-sourced pattern defaults
|
|
134
|
+
* - `initRemoteConfig` — fetch the full tool/pattern config from a remote Codacy repository
|
|
135
|
+
* - `initContainerConfig`— read .codacyrc file (container run input) and extract file list
|
|
136
|
+
*
|
|
137
|
+
* All four functions return a `CodacyConfig` ready to be written by `writeCodacyConfig`.
|
|
138
|
+
* None of them write to disk — that is the caller's responsibility.
|
|
139
|
+
*/
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Detects programming languages present in the repository by listing git-tracked
|
|
143
|
+
* files and matching their extensions/filenames against LANGUAGE_CONFIG.
|
|
144
|
+
* Returns languages sorted alphabetically for deterministic output.
|
|
145
|
+
*/
|
|
146
|
+
declare function detectLanguages(repositoryRoot: string): Promise<Language[]>;
|
|
147
|
+
/** Stats returned alongside the config from `initLocalConfig`. */
|
|
148
|
+
interface InitLocalStats {
|
|
149
|
+
/** Whether a .codacy.yaml file was found and its exclude paths were applied. */
|
|
150
|
+
codacyYamlApplied: boolean;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Default init mode (no options).
|
|
154
|
+
* Detects languages from git-tracked files and adds tool entries only for adapters
|
|
155
|
+
* that have a local configuration file present in the repository.
|
|
156
|
+
* If a .codacy.yaml file is present, its exclude paths are merged into the config.
|
|
157
|
+
*/
|
|
158
|
+
declare function initLocalConfig(repositoryRoot: string, adapters: Readonly<ToolAdapter>[]): Promise<{
|
|
159
|
+
config: CodacyConfig;
|
|
160
|
+
stats: InitLocalStats;
|
|
161
|
+
}>;
|
|
162
|
+
/** Stats returned alongside the config from `initDefaultConfig`. */
|
|
163
|
+
interface InitDefaultStats {
|
|
164
|
+
/** Total number of tools listed by the Codacy API. */
|
|
165
|
+
totalApiTools: number;
|
|
166
|
+
/** Number of tool entries added to the config from API defaults. */
|
|
167
|
+
addedTools: number;
|
|
168
|
+
/** Whether a .codacy.yaml file was found and its exclude paths were applied. */
|
|
169
|
+
codacyYamlApplied: boolean;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* `--default` mode.
|
|
173
|
+
* Runs local detection first, then enriches the config with API-sourced default
|
|
174
|
+
* patterns for every registered adapter. Tools that already have a local config
|
|
175
|
+
* file are left as-is (local config takes precedence).
|
|
176
|
+
*
|
|
177
|
+
* Uses only public Codacy API endpoints — no API token required.
|
|
178
|
+
*
|
|
179
|
+
* Returns both the config and stats so the caller can report what happened.
|
|
180
|
+
*/
|
|
181
|
+
declare function initDefaultConfig(repositoryRoot: string, adapters: Readonly<ToolAdapter>[]): Promise<{
|
|
182
|
+
config: CodacyConfig;
|
|
183
|
+
stats: InitDefaultStats;
|
|
184
|
+
}>;
|
|
185
|
+
/** Stats returned alongside the config from `initRemoteConfig`. */
|
|
186
|
+
interface InitRemoteStats {
|
|
187
|
+
/** Number of enabled tools returned by the remote repository's configuration. */
|
|
188
|
+
totalRemoteTools: number;
|
|
189
|
+
/** Number of those tools that have a registered local adapter. */
|
|
190
|
+
matchedAdapters: number;
|
|
191
|
+
/** Whether a .codacy.yaml file was found and its exclude paths were applied. */
|
|
192
|
+
codacyYamlApplied: boolean;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* `--remote <provider> <org> <repo>` mode.
|
|
196
|
+
* Fetches the full tool/pattern configuration from the repository's Codacy settings.
|
|
197
|
+
* The remote config is treated as the source of truth — only tools with a registered
|
|
198
|
+
* adapter are included.
|
|
199
|
+
*
|
|
200
|
+
* @param onRemoteToolsFound - Optional callback invoked once after the list of enabled
|
|
201
|
+
* remote tools is fetched. Receives the total count of enabled tools and the count
|
|
202
|
+
* that have a registered local adapter. Fires before per-tool pattern fetching begins.
|
|
203
|
+
* @param onToolProcessed - Optional callback invoked after each tool's patterns are
|
|
204
|
+
* fetched. Receives the adapter's display name, the number of patterns configured, and
|
|
205
|
+
* whether the tool uses a local configuration file. Useful for real-time CLI progress.
|
|
206
|
+
*/
|
|
207
|
+
declare function initRemoteConfig(repositoryRoot: string, provider: string, organization: string, repositoryName: string, adapters: Readonly<ToolAdapter>[], apiToken: string, onRemoteToolsFound?: (totalEnabledTools: number, matchedAdapters: number) => void, onToolProcessed?: (displayName: string, patternCount: number, usesConfigFile: boolean) => void): Promise<{
|
|
208
|
+
config: CodacyConfig;
|
|
209
|
+
stats: InitRemoteStats;
|
|
210
|
+
}>;
|
|
211
|
+
/**
|
|
212
|
+
* `--container` mode.
|
|
213
|
+
* Reads `.codacyrc` from the repository root (the container run input file).
|
|
214
|
+
* Parses the `files` list into `includeFiles` and maps `tools` entries to adapters.
|
|
215
|
+
*
|
|
216
|
+
* `.codacyrc` format (from codacy-engine-typescript-seed):
|
|
217
|
+
* ```json
|
|
218
|
+
* { "tools": [...], "files": ["src/main.rs", "src/lib.rs"], "options": {...} }
|
|
219
|
+
* ```
|
|
220
|
+
*/
|
|
221
|
+
declare function initContainerConfig(repositoryRoot: string, adapters: Readonly<ToolAdapter>[]): Promise<CodacyConfig>;
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* .codacy.yaml ingestion — reads the standard Codacy configuration file from
|
|
225
|
+
* the repository root and extracts exclude paths for use during init.
|
|
226
|
+
*
|
|
227
|
+
* The .codacy.yaml file is the user-facing configuration file documented at
|
|
228
|
+
* https://docs.codacy.com/repositories-configure/codacy-configuration-file/
|
|
229
|
+
*
|
|
230
|
+
* During init, this module:
|
|
231
|
+
* - Reads global `exclude_paths` → maps to `CodacyConfig.exclude`
|
|
232
|
+
* - Reads per-engine `exclude_paths` → maps to `CodacyToolConfig.exclude`
|
|
233
|
+
* - Parses but defers `include_paths` (no support yet in CodacyConfig)
|
|
234
|
+
*/
|
|
235
|
+
|
|
236
|
+
/** Per-engine configuration extracted from .codacy.yaml. */
|
|
237
|
+
interface CodacyYamlEngineConfig {
|
|
238
|
+
excludePaths: string[];
|
|
239
|
+
includePaths: string[];
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Parsed representation of a .codacy.yaml file, containing only the fields
|
|
243
|
+
* relevant to the analysis CLI. Unknown fields are silently ignored.
|
|
244
|
+
*/
|
|
245
|
+
interface CodacyYamlConfig {
|
|
246
|
+
/** Global exclude paths (glob patterns). */
|
|
247
|
+
excludePaths: string[];
|
|
248
|
+
/** Global include paths (glob patterns). Reserved for future use. */
|
|
249
|
+
includePaths: string[];
|
|
250
|
+
/** Per-engine overrides keyed by engine name as it appears in .codacy.yaml. */
|
|
251
|
+
engines: Map<string, CodacyYamlEngineConfig>;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Reads and parses a .codacy.yaml (or .codacy.yml) file from the repository root.
|
|
255
|
+
* Returns null if neither file exists. Throws on malformed YAML.
|
|
256
|
+
*/
|
|
257
|
+
declare function readCodacyYaml(repositoryRoot: string): Promise<CodacyYamlConfig | null>;
|
|
258
|
+
/**
|
|
259
|
+
* Resolves a .codacy.yaml engine name to a registered adapter ID using fuzzy matching.
|
|
260
|
+
*
|
|
261
|
+
* Resolution order (same as registry.ts:resolveAdapter):
|
|
262
|
+
* 1. Exact match on adapter ID
|
|
263
|
+
* 2. Case-insensitive substring match on adapter ID or displayName
|
|
264
|
+
* — only resolves if exactly one adapter matches (ambiguous = no match)
|
|
265
|
+
*
|
|
266
|
+
* Returns the adapter ID or undefined if no unique match is found.
|
|
267
|
+
*/
|
|
268
|
+
declare function resolveEngineToAdapter(engineName: string, adapters: Readonly<ToolAdapter>[]): string | undefined;
|
|
269
|
+
/**
|
|
270
|
+
* Applies parsed .codacy.yaml excludes to a CodacyConfig.
|
|
271
|
+
*
|
|
272
|
+
* - Global `exclude_paths` are appended to `config.exclude` (deduplicated)
|
|
273
|
+
* - Per-engine `exclude_paths` are appended to the matching tool's `exclude` (deduplicated)
|
|
274
|
+
* - Per-engine excludes only apply to tools already present in the config
|
|
275
|
+
* - Logs warnings for unresolved engine names and unsupported include_paths
|
|
276
|
+
*
|
|
277
|
+
* Returns a new config object (does not mutate the input).
|
|
278
|
+
*/
|
|
279
|
+
declare function applyCodacyYamlExcludes(config: CodacyConfig, yamlConfig: CodacyYamlConfig, adapters: Readonly<ToolAdapter>[], logger?: Logger): CodacyConfig;
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Codacy API client — thin wrappers around the generated OpenAPI client.
|
|
283
|
+
*
|
|
284
|
+
* The generated client (src/api/client/) is produced from the Codacy OpenAPI spec
|
|
285
|
+
* and should never be edited by hand. All API interactions go through this file.
|
|
286
|
+
*
|
|
287
|
+
* Authentication: Codacy uses an `api-token` header (not Bearer). We set it via
|
|
288
|
+
* `OpenAPI.HEADERS` before each call group. `configureApiToken()` must be called
|
|
289
|
+
* before any authenticated endpoint is used.
|
|
290
|
+
*
|
|
291
|
+
* Pagination: all list endpoints use cursor-based pagination. `fetchAllPages()`
|
|
292
|
+
* follows cursors until the response contains no next cursor.
|
|
293
|
+
*/
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Configures the API token used for authenticated requests.
|
|
297
|
+
* Must be called before `getRepository`, `listRepositoryTools`, or
|
|
298
|
+
* `listRepositoryToolPatterns`. Public endpoints (listTools, listPatterns)
|
|
299
|
+
* do not require a token.
|
|
300
|
+
*/
|
|
301
|
+
declare function configureApiToken(token: string): void;
|
|
302
|
+
/**
|
|
303
|
+
* Validates an API token by calling the authenticated user endpoint.
|
|
304
|
+
* Returns user info on success; caller should catch errors for invalid tokens.
|
|
305
|
+
*/
|
|
306
|
+
declare function validateApiToken(token: string): Promise<{
|
|
307
|
+
valid: boolean;
|
|
308
|
+
name?: string;
|
|
309
|
+
email?: string;
|
|
310
|
+
}>;
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Structured file + stderr logger for the analysis pipeline.
|
|
314
|
+
*
|
|
315
|
+
* Creates a Logger (as defined in @codacy/tooling) that writes:
|
|
316
|
+
* 1. JSON lines to a log file at `~/.codacy/logs/analysis-<timestamp>.log`
|
|
317
|
+
* 2. Human-readable messages to stderr
|
|
318
|
+
*
|
|
319
|
+
* Both outputs share a single level threshold controlled by `--log-level`.
|
|
320
|
+
* Log rotation deletes the oldest files beyond the configured retention count.
|
|
321
|
+
*/
|
|
322
|
+
|
|
323
|
+
/** Configuration for the logger factory. */
|
|
324
|
+
interface LoggerOptions {
|
|
325
|
+
/** Minimum level for both stderr and file output. Defaults to "info". */
|
|
326
|
+
level?: LogLevel;
|
|
327
|
+
/** Whether to write to a log file. Defaults to true. */
|
|
328
|
+
fileEnabled?: boolean;
|
|
329
|
+
/** Directory for log files. Defaults to `~/.codacy/logs/`. */
|
|
330
|
+
logsDir?: string;
|
|
331
|
+
/** Maximum log file size in bytes before mid-run rotation. Defaults to 10 MB. */
|
|
332
|
+
maxFileSize?: number;
|
|
333
|
+
/** Number of rotated log files to keep. Defaults to 5. */
|
|
334
|
+
maxFiles?: number;
|
|
335
|
+
/**
|
|
336
|
+
* Optional callback invoked instead of writing to stderr.
|
|
337
|
+
*
|
|
338
|
+
* When set, the logger calls this with the enriched human-readable message
|
|
339
|
+
* (message + key fields) instead of writing to stderr directly. This allows
|
|
340
|
+
* the CLI to integrate log messages with the spinner without interleaving.
|
|
341
|
+
*
|
|
342
|
+
* When not set, the logger writes to stderr as before.
|
|
343
|
+
*/
|
|
344
|
+
onStderrMessage?: (text: string, level: LogLevel) => void;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Removes old log files beyond the retention limit.
|
|
348
|
+
*
|
|
349
|
+
* Keeps the most recent `maxFiles` log files sorted by filename (which embeds
|
|
350
|
+
* an ISO timestamp, giving natural chronological order). Called at logger
|
|
351
|
+
* creation and after mid-run size rotation.
|
|
352
|
+
*/
|
|
353
|
+
declare function rotateLogFiles(logsDir: string, maxFiles: number): void;
|
|
354
|
+
/**
|
|
355
|
+
* Creates a Logger that writes structured JSON lines to a file and
|
|
356
|
+
* human-readable messages to stderr (or to a callback), both filtered
|
|
357
|
+
* by a single log level.
|
|
358
|
+
*
|
|
359
|
+
* The returned logger conforms to the Logger interface from @codacy/tooling,
|
|
360
|
+
* so it can be passed directly into `analyze()` options and through ToolContext.
|
|
361
|
+
*/
|
|
362
|
+
declare function createLogger(options?: LoggerOptions): Logger;
|
|
363
|
+
|
|
364
|
+
export { type AnalyzeOptions, type CodacyYamlConfig, type CodacyYamlEngineConfig, type ExecutionMode, type InitDefaultStats, type InitLocalStats, type InitRemoteStats, type LoggerOptions, analyze, applyCodacyYamlExcludes, buildToolConfig, clearAdapters, configureApiToken, createCodacyConfig, createLogger, detectLanguages, formatOutput, formatTextSummary, getRegisteredAdapters, initContainerConfig, initDefaultConfig, initLocalConfig, initRemoteConfig, readCodacyConfig, readCodacyYaml, registerAdapter, resolveEngineToAdapter, rotateLogFiles, validateApiToken, writeCodacyConfig };
|