Skip to content

Commit 7b14921

Browse files
committed
add pull request command
1 parent 6b4d599 commit 7b14921

File tree

10 files changed

+178
-22
lines changed

10 files changed

+178
-22
lines changed

.github/workflows/ci.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
build-and-test:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
node-version: [18, 20, 22]
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Use Node.js ${{ matrix.node-version }}
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: ${{ matrix.node-version }}
24+
cache: npm
25+
26+
- name: Install dependencies
27+
run: npm ci
28+
29+
- name: Type check
30+
run: npx tsc --noEmit
31+
32+
- name: Build
33+
run: npm run build
34+
35+
- name: Test
36+
run: npm test

.github/workflows/publish.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Publish to npm
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
publish:
9+
runs-on: ubuntu-latest
10+
11+
permissions:
12+
contents: read
13+
id-token: write
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- name: Use Node.js 22
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: 22
22+
registry-url: https://registry.npmjs.org
23+
cache: npm
24+
25+
- name: Install dependencies
26+
run: npm ci
27+
28+
- name: Build
29+
run: npm run build
30+
31+
- name: Test
32+
run: npm test
33+
34+
- name: Publish
35+
run: npm publish --provenance --access public
36+
env:
37+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

README.md

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,26 @@
22

33
A command-line tool to interact with [Codacy Cloud](https://app.codacy.com) directly from your terminal. Built with Node.js and TypeScript.
44

5-
## Setup
5+
## Installation
6+
7+
### From npm
8+
9+
```bash
10+
npm install -g codacy-cloud-cli
11+
```
12+
13+
### From source
614

715
```bash
16+
git clone https://github.com/alerizzo/codacy-cloud-cli.git
17+
cd codacy-cloud-cli
818
npm install
19+
npm run build
20+
npm link
921
```
1022

23+
## Authentication
24+
1125
Set your Codacy API token as an environment variable:
1226

1327
```bash
@@ -19,12 +33,7 @@ You can get a token from **Codacy > My Account > Access Management > Account API
1933
## Usage
2034

2135
```bash
22-
# Run in development mode
23-
npx ts-node src/index.ts <command>
24-
25-
# Or build and run
26-
npm run build
27-
npm start -- <command>
36+
codacy-cloud-cli <command> [options]
2837
```
2938

3039
### Global Options
@@ -106,19 +115,24 @@ codacy-cloud-cli pull-request gh my-org my-repo 42 --output json
106115
Displays:
107116
- **About** -- PR title, status, author, branches, head commit
108117
- **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
118+
- **Issues** -- issues introduced by the PR, sorted by severity, with file path and line content
111119
- **Files** -- changed files with metric deltas (issues, coverage, complexity, duplication)
112120

113121
## Development
114122

115123
```bash
124+
# Run in development mode
125+
npx ts-node src/index.ts <command>
126+
116127
# Run tests
117128
npm test
118129

119130
# Type-check without emitting
120131
npx tsc --noEmit
121132

133+
# Build for production
134+
npm run build
135+
122136
# Update the auto-generated API client
123137
npm run update-api
124138
```
@@ -129,10 +143,22 @@ npm run update-api
129143
src/
130144
index.ts # CLI entry point (Commander.js)
131145
commands/ # One file per command
132-
utils/ # Shared utilities (auth, error handling, output formatting)
146+
utils/ # Shared utilities (auth, error handling, output, formatting)
133147
api/client/ # Auto-generated API client (do not edit)
134148
```
135149

150+
### CI/CD
151+
152+
- **CI**: Runs on every push to `main` and on PRs. Builds and tests across Node.js 18, 20, and 22.
153+
- **Publish**: Triggered on GitHub release creation. Builds, tests, and publishes to npm with provenance.
154+
155+
To publish a new version:
156+
1. Update the version in `package.json`
157+
2. Create a GitHub release with a tag matching the version (e.g. `v1.1.0`)
158+
3. The publish workflow will automatically build and push to npm
159+
160+
**Prerequisite**: Add an `NPM_TOKEN` secret to your GitHub repository settings.
161+
136162
## License
137163

138164
ISC

TODO.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,11 @@ For the Issues List in particular, showing them in a table will not work. So fol
154154

155155
## Deployment & CI
156156

157-
- [ ] Make the project ready to deploy to npm and be executed as a CLI tool by running `npm install -g`
158-
- [ ] Add CI pipeline for build + test (GitHub Actions)
159-
- [ ] Add CI pipeline for deploy to npm (GitHub Actions)
160-
- [ ] Add CLI help examples to each command
157+
- [x] 2026-02-18 Make the project ready to deploy to npm and be executed as a CLI tool by running `npm install -g`
158+
- [x] 2026-02-18 Make the project ready to distribute later as a separate brew formula for macOS/Linux/Windows
159+
- [x] 2026-02-18 Add CI pipeline for build + test (GitHub Actions)
160+
- [x] 2026-02-18 Add CI pipeline for deploy to npm (GitHub Actions)
161+
- [x] 2026-02-18 Add CLI help examples to each command
161162

162163
---
163164

@@ -170,4 +171,7 @@ For the Issues List in particular, showing them in a table will not work. So fol
170171
- 2026-02-17: `src/commands/CLAUDE.md` created with design decisions
171172
- 2026-02-18: `repository` command implemented with tests (5 tests) — dashboard with about, setup, metrics, PRs, and issues overview
172173
- 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
174+
- 2026-02-18: `pull-request` command implemented with tests (11 tests) — about, analysis with gate reasons, issues cards, files list
175+
- 2026-02-18: npm package ready — bin, files, prepublishOnly, tsconfig.build.json, engines
176+
- 2026-02-18: CI pipelines — build+test on push/PR (Node 18/20/22), publish to npm on release
177+
- 2026-02-18: CLI help examples added to all commands

package.json

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,35 @@
11
{
22
"name": "codacy-cloud-cli",
33
"version": "1.0.0",
4-
"main": "index.js",
4+
"description": "A command-line tool to interact with Codacy Cloud from your terminal",
5+
"main": "dist/index.js",
6+
"bin": {
7+
"codacy": "dist/index.js"
8+
},
9+
"files": [
10+
"dist/"
11+
],
512
"scripts": {
613
"test": "vitest run",
14+
"build": "tsc -p tsconfig.build.json",
15+
"prepublishOnly": "npm run build",
16+
"start": "npx ts-node src/index.ts",
17+
"start:dist": "node dist/index.js",
718
"fetch-api": "curl https://artifacts.codacy.com/api/codacy-api/50.7.17/apiv3-bundled.yaml -o ./api-v3/api-swagger.yaml --create-dirs",
819
"generate-api": "rm -rf ./src/api/client && openapi --input ./api-v3/api-swagger.yaml --output ./src/api/client --useUnionTypes --indent 2 --client fetch",
9-
"update-api": "npm run fetch-api && npm run generate-api",
10-
"start": "npx ts-node src/index.ts",
11-
"build": "npx tsc",
12-
"start:dist": "node dist/index.js"
20+
"update-api": "npm run fetch-api && npm run generate-api"
1321
},
14-
"keywords": [],
22+
"keywords": [
23+
"codacy",
24+
"cli",
25+
"code-quality",
26+
"static-analysis"
27+
],
1528
"author": "",
1629
"license": "ISC",
17-
"description": "",
30+
"engines": {
31+
"node": ">=18"
32+
},
1833
"dependencies": {
1934
"ansis": "4.0.0",
2035
"cli-table3": "^0.6.3",

src/commands/info.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ export function registerInfoCommand(program: Command) {
1616
program
1717
.command("info")
1818
.description("Show authenticated user information and organizations")
19+
.addHelpText(
20+
"after",
21+
`
22+
Examples:
23+
$ codacy-cloud-cli info
24+
$ codacy-cloud-cli info --output json`,
25+
)
1926
.action(async function (this: Command) {
2027
try {
2128
checkApiToken();

src/commands/pull-request.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,13 @@ export function registerPullRequestCommand(program: Command) {
397397
.argument("<organization>", "organization name")
398398
.argument("<repository>", "repository name")
399399
.argument("<prNumber>", "pull request number")
400+
.addHelpText(
401+
"after",
402+
`
403+
Examples:
404+
$ codacy-cloud-cli pull-request gh my-org my-repo 42
405+
$ codacy-cloud-cli pull-request gh my-org my-repo 42 --output json`,
406+
)
400407
.action(async function (
401408
this: Command,
402409
provider: string,

src/commands/repositories.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ export function registerRepositoriesCommand(program: Command) {
5252
.argument("<provider>", "git provider (gh, gl, or bb)")
5353
.argument("<organization>", "organization name")
5454
.option("-s, --search <query>", "filter repositories by name")
55+
.addHelpText(
56+
"after",
57+
`
58+
Examples:
59+
$ codacy-cloud-cli repositories gh my-org
60+
$ codacy-cloud-cli repositories gh my-org --search my-repo
61+
$ codacy-cloud-cli repositories gl my-org --output json`,
62+
)
5563
.action(async function (
5664
this: Command,
5765
provider: string,

src/commands/repository.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,13 @@ export function registerRepositoryCommand(program: Command) {
200200
.argument("<provider>", "git provider (gh, gl, or bb)")
201201
.argument("<organization>", "organization name")
202202
.argument("<repository>", "repository name")
203+
.addHelpText(
204+
"after",
205+
`
206+
Examples:
207+
$ codacy-cloud-cli repository gh my-org my-repo
208+
$ codacy-cloud-cli repository gh my-org my-repo --output json`,
209+
)
203210
.action(async function (
204211
this: Command,
205212
provider: string,

tsconfig.build.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"exclude": [
4+
"node_modules",
5+
"dist",
6+
"**/*.test.ts",
7+
"vitest.config.ts"
8+
]
9+
}

0 commit comments

Comments
 (0)