Skip to content

Commit 6b4d599

Browse files
committed
add pull request command
1 parent 794f573 commit 6b4d599

File tree

10 files changed

+1530
-121
lines changed

10 files changed

+1530
-121
lines changed

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ codacy-cloud-cli/
3333
│ │ └── services/ # 28 service classes wrapping API endpoints
3434
│ ├── commands/ # One file per command (see Command Pattern below)
3535
│ │ └── CLAUDE.md # Design decisions for commands
36-
│ └── utils/ # Shared utilities (auth, error handling, output formatting)
36+
│ └── utils/ # Shared utilities (auth, error handling, output formatting, formatting helpers)
3737
├── api-v3/
3838
│ └── api-swagger.yaml # OpenAPI 3.0.1 spec (source of truth for client generation)
3939
├── dist/ # Compiled JS output (gitignored)

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,29 @@ Displays a multi-section dashboard:
8787
- **Open Pull Requests** -- status, issues, coverage, complexity, duplication deltas
8888
- **Issues Overview** -- totals by category, severity, and language
8989

90+
#### `pull-request <provider> <organization> <repository> <prNumber>`
91+
92+
Show details, analysis status, issues, and changed files for a specific pull request.
93+
94+
```bash
95+
codacy-cloud-cli pull-request gh my-org my-repo 42
96+
codacy-cloud-cli pull-request gh my-org my-repo 42 --output json
97+
```
98+
99+
| Argument | Description |
100+
|---|---|
101+
| `provider` | Git provider: `gh` (GitHub), `gl` (GitLab), or `bb` (Bitbucket) |
102+
| `organization` | Organization name on the provider |
103+
| `repository` | Repository name |
104+
| `prNumber` | Pull request number |
105+
106+
Displays:
107+
- **About** -- PR title, status, author, branches, head commit
108+
- **Analysis** -- up-to-standards status, issues, coverage, complexity, duplication with gate pass/fail details
109+
- **New Issues** -- issues introduced by the PR, sorted by severity, with file path, line content, and detection tool
110+
- **New Potential Issues** -- potential issues that may need review
111+
- **Files** -- changed files with metric deltas (issues, coverage, complexity, duplication)
112+
90113
## Development
91114

92115
```bash

TODO.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,66 @@ Important information to show:
9292
- [x] 2026-02-18 Implement `repository` command - show details, status, and metrics for a specific repository
9393
- [x] 2026-02-18 Write tests for `repository` command
9494

95+
### Pull Request Command
96+
> Show details for a specific pull request.
97+
> API Endpoints to use:
98+
- [getRepositoryPullRequest](https://api.codacy.com/api/api-docs#getrepositorypullrequest)
99+
- [listPullRequestIssues](https://api.codacy.com/api/api-docs#listpullrequestissues)
100+
- [listPullRequestFiles](https://api.codacy.com/api/api-docs#listpullrequestfiles)
101+
102+
Important information to show:
103+
- About the pull request
104+
- Provider / Organization / Repository Name / Visibility
105+
- Pull Request Number
106+
- Title
107+
- Created At
108+
- Updated At
109+
- Last Analysis (Time and Commit SHA)
110+
- From Branch to Target Branch
111+
- Status (Open, Closed, Merged)
112+
- Author
113+
- About the analysis
114+
- Is it currently being analyzed?
115+
- Is it up to standards?
116+
- Issues (New and Fixed)
117+
- Coverage Diff and Delta
118+
- Complex Delta
119+
- Duplication Delta
120+
- General considerations
121+
- use again `resultReasons` to color the metrics, and this time, if a metric is not up to the standards, show why (e.g. "Fails <= 2 medium issues")
122+
- if in `resultReasons` there is a gate value expected for a metric that still has no data, also show it next to the metric saying for example "To check >= 50% gate"
123+
- Issues List: show new and new potential issues only (`onlyPotential` false for non potential, true for only potential -- new issues have `deltaType` = 'Added'); sort by severity level, showing the most sever first
124+
- File Path, Line Number
125+
- Line content
126+
- Issue message
127+
- Category
128+
- Severity (red for critical/error, orange for high, yellow for medium/warning, blue for low/info)
129+
- Subcategory (only for security issues)
130+
- Detected by (Tool + Pattern title; e.g. "ESLint: no undef vars")
131+
- Files List: list only files with any metric delta change
132+
- File Path
133+
- Issues +{New Issues} / -{Fixed Issues}
134+
- Coverage Delta +/-{Delta Coverage %}
135+
- Complex Delta
136+
- Duplication Delta
137+
138+
For the Issues List in particular, showing them in a table will not work. So follow this format:
139+
```
140+
--------------------------------
141+
142+
{Severity} | {Category} {Subcategory} | {Detected by}
143+
{Issue Message}
144+
145+
{File Path}:{Line Number}
146+
{Line content}
147+
148+
--------------------------------
149+
```
150+
151+
- [x] 2026-02-18 Implement `pull-request` command - show details for a specific pull request
152+
- [x] 2026-02-18 Write tests for `pull-request` command
153+
154+
95155
## Deployment & CI
96156

97157
- [ ] Make the project ready to deploy to npm and be executed as a CLI tool by running `npm install -g`
@@ -109,3 +169,5 @@ Important information to show:
109169
- 2026-02-17: Utility tests added for `auth` and `providers` (6 tests)
110170
- 2026-02-17: `src/commands/CLAUDE.md` created with design decisions
111171
- 2026-02-18: `repository` command implemented with tests (5 tests) — dashboard with about, setup, metrics, PRs, and issues overview
172+
- 2026-02-18: Extracted shared formatting helpers to `utils/formatting.ts` (reused by repository + pull-request)
173+
- 2026-02-18: `pull-request` command implemented with tests (9 tests) — about, analysis with gate reasons, issues cards, files list

src/commands/CLAUDE.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,41 @@ Instead of a dedicated "Visibility" column (wastes horizontal space), public rep
8282
- **Issues Overview**: three count tables — by category, severity level, and language — sorted descending by count within each group
8383
- Shows pagination warning for pull requests if more exist
8484
- JSON output bundles all three API responses into a single object
85+
86+
## Shared Formatting Utilities (`utils/formatting.ts`)
87+
88+
Several helpers are shared between `repository.ts` and `pull-request.ts` via `utils/formatting.ts`:
89+
- `printSection(title)` — bold section header
90+
- `truncate(text, max)` — truncate with "..." suffix
91+
- `colorMetric(value, threshold, mode)` — threshold-based coloring (max/min)
92+
- `colorByGate(display, passing)` — green/red based on gate status
93+
- `formatDelta(value, passing)` — +/- signed value with optional gate coloring
94+
- `buildGateStatus(pr)` — maps `resultReasons` gate names to metric columns
95+
- `formatStandards(pr)` — ✓/✗/- from quality + coverage `isUpToStandards`
96+
- `formatPrCoverage(pr, passing)` — diffCoverage% (+/-deltaCoverage%)
97+
- `formatPrIssues(pr, passing)` — +newIssues (colored by gate) / -fixedIssues (always gray)
98+
99+
## pull-request command (`pull-request.ts`)
100+
101+
- Takes `<provider>`, `<organization>`, `<repository>`, and `<prNumber>` as required arguments
102+
- Calls four API endpoints in parallel:
103+
- `getRepositoryPullRequest` — PR metadata + analysis summary
104+
- `listPullRequestIssues` (status=new, onlyPotential=false) — new confirmed issues
105+
- `listPullRequestIssues` (status=new, onlyPotential=true) — new potential issues
106+
- `listPullRequestFiles` — files with metric deltas
107+
- Displays a multi-section view:
108+
- **About**: provider/org/repo, PR number + title, status, author, branches (origin → target), updated (friendly date), head commit SHA
109+
- **Analysis**: analyzing status, up-to-standards (✓/✗ computed from quality + coverage), issues, coverage, complexity, duplication — all colored by gate status
110+
- Gate failure/pass reasons shown inline next to the metric (e.g. "Fails <= 2 warning issues", "Fails <= 0 security issues")
111+
- "To check" hints shown inline when a gate is configured but the metric has no data yet (e.g. "To check >= 50% coverage")
112+
- Security gates (`securityIssueThreshold`) are handled explicitly — not falling through to generic formatting
113+
- **Issues**: single merged list of confirmed + potential issues, card-style format (not a table), sorted by severity (Error > High > Warning > Info)
114+
- Each card shows: colored severity | category + subcategory | POTENTIAL (if potential issue)
115+
- Message, file:line, line content
116+
- Severity colors: Error=red, High=orange (#FF8C00), Warning=yellow, Info=blue
117+
- False positive detection: if `falsePositiveProbability >= falsePositiveThreshold`, shows "Potential false positive: {reason}" below line content
118+
- **Files**: table showing only files with any metric delta change
119+
- File path (truncated at 50), issues (new red, fixed green), coverage delta, complexity delta, duplication delta
120+
- Zero values shown in gray without +/- sign; N/A also gray
121+
- Shows pagination warnings for issues and files
122+
- JSON output bundles PR data, new issues, potential issues, and files

0 commit comments

Comments
 (0)