Skip to content

Commit 125cbcd

Browse files
committed
instructions
1 parent 3840864 commit 125cbcd

2 files changed

Lines changed: 97 additions & 0 deletions

File tree

‎src/commands/settings/index.js‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { runBranchesAll, runBranchesDefault, runBranchesUpdateDefault } from './branches.js';
22
import { runFeatureFlagsGet, runFeatureFlagsUpdate } from './feature-flags.js';
33
import { runAnalysisFeatureFlagsGet, runAnalysisFeatureFlagsUpdate } from './analysis-feature-flags.js';
4+
import { runPrInstructionsGet, runPrInstructionsSave, runPrInstructionsEdit, runPrInstructionsDelete } from './pr-instructions.js';
45

56
/**
67
* Register all `codeant settings <verb>` subcommands.
@@ -75,4 +76,56 @@ export default function registerSettingsCommands(program, { runCmd }) {
7576
.requiredOption('--repo <repo>', 'Repository (owner/repo)')
7677
.requiredOption('--flags <json>', 'Feature flags as a JSON string (e.g. \'{"sast_analysis":"enabled"}\')')
7778
.action((opts) => runCmd(() => runAnalysisFeatureFlagsUpdate({ repo: opts.repo, flags: opts.flags })));
79+
80+
// ── pr-instructions get ────────────────────────────────────────────────────
81+
settings
82+
.command('pr-instructions-get')
83+
.description('Get PR review instructions')
84+
.option('--type <type>', 'Instruction type (e.g. custom)')
85+
.action((opts) => runCmd(() => runPrInstructionsGet({ instructionsType: opts.type })));
86+
87+
// ── pr-instructions save ───────────────────────────────────────────────────
88+
settings
89+
.command('pr-instructions-save')
90+
.description('Save a new PR review instruction')
91+
.option('--type <type>', 'Instruction type (e.g. custom)')
92+
.option('--file-pattern <pattern>', 'File pattern (e.g. *.py)')
93+
.option('--description <text>', 'Instruction description')
94+
.option('--description-file <path>', 'Path to a file containing the description')
95+
.option('--instruction-id <id>', 'Instruction ID (for upsert)')
96+
.action((opts) => runCmd(() => runPrInstructionsSave({
97+
instructionType: opts.type,
98+
filePattern: opts.filePattern,
99+
description: opts.description,
100+
descriptionFile: opts.descriptionFile,
101+
instructionId: opts.instructionId,
102+
})));
103+
104+
// ── pr-instructions edit ───────────────────────────────────────────────────
105+
settings
106+
.command('pr-instructions-edit')
107+
.description('Edit an existing PR review instruction')
108+
.requiredOption('--instruction-id <id>', 'Instruction ID to edit')
109+
.option('--type <type>', 'Instruction type (e.g. custom)')
110+
.option('--description <text>', 'Updated description')
111+
.option('--description-file <path>', 'Path to a file containing the description')
112+
.option('--file-pattern <pattern>', 'Updated file pattern')
113+
.action((opts) => runCmd(() => runPrInstructionsEdit({
114+
instructionType: opts.type,
115+
instructionId: opts.instructionId,
116+
description: opts.description,
117+
descriptionFile: opts.descriptionFile,
118+
filePattern: opts.filePattern,
119+
})));
120+
121+
// ── pr-instructions delete ─────────────────────────────────────────────────
122+
settings
123+
.command('pr-instructions-delete')
124+
.description('Delete a PR review instruction')
125+
.requiredOption('--instruction-id <id>', 'Instruction ID to delete')
126+
.option('--type <type>', 'Instruction type (e.g. custom)')
127+
.action((opts) => runCmd(() => runPrInstructionsDelete({
128+
instructionType: opts.type,
129+
instructionId: opts.instructionId,
130+
})));
78131
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { fetchApi } from '../../utils/fetchApi.js';
2+
3+
export async function runPrInstructionsGet({ instructionsType } = {}) {
4+
return fetchApi('/extension/config/pullrequest/instructions/get', 'POST', {
5+
instructions_type: instructionsType,
6+
});
7+
}
8+
9+
export async function runPrInstructionsSave({ instructionType, filePattern, description, descriptionFile, instructionId } = {}) {
10+
return fetchApi('/extension/config/pullrequest/instructions/save', 'POST', {
11+
instruction_type: instructionType,
12+
file_pattern: filePattern,
13+
description,
14+
description_file: descriptionFile,
15+
instruction_id: instructionId,
16+
});
17+
}
18+
19+
export async function runPrInstructionsEdit({ instructionType, instructionId, description, descriptionFile, filePattern } = {}) {
20+
if (!instructionId) {
21+
const err = new Error('--instruction-id is required');
22+
err.exitCode = 1;
23+
throw err;
24+
}
25+
return fetchApi('/extension/config/pullrequest/instructions/edit', 'POST', {
26+
instruction_type: instructionType,
27+
instruction_id: instructionId,
28+
description,
29+
description_file: descriptionFile,
30+
file_pattern: filePattern,
31+
});
32+
}
33+
34+
export async function runPrInstructionsDelete({ instructionType, instructionId } = {}) {
35+
if (!instructionId) {
36+
const err = new Error('--instruction-id is required');
37+
err.exitCode = 1;
38+
throw err;
39+
}
40+
return fetchApi('/extension/config/pullrequest/instructions/delete', 'POST', {
41+
instruction_type: instructionType,
42+
instruction_id: instructionId,
43+
});
44+
}

0 commit comments

Comments
 (0)