Compare commits

..

No commits in common. "fdb8dacebc9fefaa57def08f4d8995b4abc5f9a5" and "f30f22daf48964dc9c2e1fb684e6bdfdfeeaa275" have entirely different histories.

5 changed files with 0 additions and 223 deletions

View file

@ -438,62 +438,6 @@ stoke pr merge -o heavy-duty -r stoke -n 2 --delete-branch
Calls `POST /api/v1/repos/{owner}/{repo}/pulls/{number}/merge`.
### `stoke pr show`
Show details of a pull request.
```text
Options:
-o, --owner <owner> repository owner (required)
-r, --repo <repo> repository name (required)
-n, --number <number> pull request number (required)
```
```bash
stoke pr show -o heavy-duty -r stoke -n 3
```
Calls `GET /api/v1/repos/{owner}/{repo}/pulls/{number}`.
### `stoke pr comment`
Add a comment to a pull request.
```text
Options:
-o, --owner <owner> repository owner (required)
-r, --repo <repo> repository name (required)
-n, --number <number> pull request number (required)
-b, --body <body> comment body (markdown)
--body-file <path> read the comment body from a file
```
```bash
stoke pr comment -o heavy-duty -r stoke -n 3 -b "Looks good."
```
Calls `POST /api/v1/repos/{owner}/{repo}/issues/{number}/comments`.
### `stoke pr review`
Submit a review on a pull request.
```text
Options:
-o, --owner <owner> repository owner (required)
-r, --repo <repo> repository name (required)
-n, --number <number> pull request number (required)
--event <event> review event: approve, request-changes, comment (required)
-b, --body <body> review body (markdown)
--body-file <path> read the review body from a file
```
```bash
stoke pr review -o heavy-duty -r stoke -n 3 --event approve -b "Ship it."
```
Calls `POST /api/v1/repos/{owner}/{repo}/pulls/{number}/reviews`.
### `stoke branch list`
List branches in a repository.

View file

@ -167,21 +167,6 @@ class ForgejoClient {
return this.post(`/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/pulls`, payload);
}
async getPullRequest(owner, repo, index) {
return this.get(`/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/pulls/${index}`);
}
async createPullRequestComment(owner, repo, index, body) {
return this.post(`/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/issues/${index}/comments`, { body });
}
async createPullRequestReview(owner, repo, index, event, body) {
return this.post(`/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/pulls/${index}/reviews`, {
event,
body: body || '',
});
}
async mergePullRequest(owner, repo, index, payload) {
return this.post(`/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/pulls/${index}/merge`, payload);
}

View file

@ -679,93 +679,6 @@ pr
}
});
pr
.command('show')
.description('Show details of a pull request')
.requiredOption('-o, --owner <owner>', 'repository owner')
.requiredOption('-r, --repo <repo>', 'repository name')
.requiredOption('-n, --number <number>', 'pull request number', parseId)
.action(async (options) => {
try {
const config = loadConfig();
const client = ForgejoClient.fromConfig(config);
const prData = await client.getPullRequest(options.owner, options.repo, options.number);
console.log(`!${prData.number} [${prData.state}] ${prData.title}`);
console.log(`URL: ${prData.html_url}`);
console.log(`Author: ${prData.user.login}`);
console.log(`Branch: ${prData.head.ref} -> ${prData.base.ref}`);
console.log(`Mergeable: ${prData.mergeable}`);
console.log(`Created: ${prData.created_at}`);
if (prData.body) {
console.log('\n' + prData.body);
}
} catch (err) {
console.error(`Failed to show pull request: ${err.message}`);
if (err.status) console.error(`HTTP status: ${err.status}`);
process.exit(1);
}
});
pr
.command('comment')
.description('Add a comment to a pull request')
.requiredOption('-o, --owner <owner>', 'repository owner')
.requiredOption('-r, --repo <repo>', 'repository name')
.requiredOption('-n, --number <number>', 'pull request number', parseId)
.option('-b, --body <body>', 'comment body (markdown)')
.option('--body-file <path>', 'read the comment body from a file')
.action(async (options) => {
try {
const config = loadConfig();
const client = ForgejoClient.fromConfig(config);
const body = readBodyOption(options);
if (!body) {
console.error('Comment body is required. Use -b/--body or --body-file.');
process.exit(1);
}
const result = await client.createPullRequestComment(options.owner, options.repo, options.number, body);
console.log(`Comment added to !${options.number}.`);
console.log(`URL: ${result.html_url}`);
} catch (err) {
console.error(`Failed to comment on pull request: ${err.message}`);
if (err.status) console.error(`HTTP status: ${err.status}`);
process.exit(1);
}
});
pr
.command('review')
.description('Submit a review on a pull request')
.requiredOption('-o, --owner <owner>', 'repository owner')
.requiredOption('-r, --repo <repo>', 'repository name')
.requiredOption('-n, --number <number>', 'pull request number', parseId)
.requiredOption('--event <event>', 'review event: approve, request-changes, comment')
.option('-b, --body <body>', 'review body (markdown)')
.option('--body-file <path>', 'read the review body from a file')
.action(async (options) => {
try {
const config = loadConfig();
const client = ForgejoClient.fromConfig(config);
const eventMap = {
approve: 'APPROVE',
'request-changes': 'REQUEST_CHANGES',
comment: 'COMMENT',
};
const event = eventMap[options.event.toLowerCase()];
if (!event) {
console.error(`Invalid review event: ${options.event}. Must be approve, request-changes, or comment.`);
process.exit(1);
}
const body = readBodyOption(options) || '';
await client.createPullRequestReview(options.owner, options.repo, options.number, event, body);
console.log(`Review submitted on !${options.number}: ${event}.`);
} catch (err) {
console.error(`Failed to submit review: ${err.message}`);
if (err.status) console.error(`HTTP status: ${err.status}`);
process.exit(1);
}
});
const branchCmd = program
.command('branch')
.description('Manage branches');

View file

@ -141,32 +141,3 @@ test('createIssue and createPullRequest hit the expected endpoints', async () =>
assert.equal(calls[0].opts.method, 'POST');
assert.equal(JSON.parse(calls[1].opts.body).head, 'h');
});
test('getPullRequest fetches a single pull request', async () => {
const calls = mockFetch(() => jsonResponse({ number: 7, title: 'Fix' }));
const client = new ForgejoClient('https://forge.test', 'tok');
const pr = await client.getPullRequest('owner', 'repo', 7);
assert.equal(pr.number, 7);
assert.equal(calls[0].url, 'https://forge.test/api/v1/repos/owner/repo/pulls/7');
assert.equal(calls[0].opts.method, 'GET');
});
test('createPullRequestComment posts to the issue comments endpoint', async () => {
const calls = mockFetch(() => jsonResponse({ id: 99, html_url: 'https://forge.test/comment/99' }));
const client = new ForgejoClient('https://forge.test', 'tok');
await client.createPullRequestComment('owner', 'repo', 7, 'Looks good.');
assert.equal(calls[0].url, 'https://forge.test/api/v1/repos/owner/repo/issues/7/comments');
assert.equal(calls[0].opts.method, 'POST');
assert.equal(JSON.parse(calls[0].opts.body).body, 'Looks good.');
});
test('createPullRequestReview posts the review event and body', async () => {
const calls = mockFetch(() => jsonResponse({ id: 88 }));
const client = new ForgejoClient('https://forge.test', 'tok');
await client.createPullRequestReview('owner', 'repo', 7, 'APPROVE', 'Ship it.');
assert.equal(calls[0].url, 'https://forge.test/api/v1/repos/owner/repo/pulls/7/reviews');
assert.equal(calls[0].opts.method, 'POST');
const body = JSON.parse(calls[0].opts.body);
assert.equal(body.event, 'APPROVE');
assert.equal(body.body, 'Ship it.');
});

View file

@ -75,39 +75,3 @@ test('issue create --body-file reports unreadable files cleanly', () => {
fs.unlinkSync(cfg);
}
});
test('pr show validates --number before any network call', () => {
const cfg = path.join(os.tmpdir(), `stoke-cfg-${process.pid}.json`);
fs.writeFileSync(cfg, JSON.stringify({ url: 'https://forge.test', token: 'tok' }));
try {
const res = run(['pr', 'show', '-o', 'o', '-r', 'r', '-n', 'zero'], { STOKE_CONFIG_FILE: cfg });
assert.equal(res.status, 1);
assert.match(res.stderr, /Id must be a positive integer/);
} finally {
fs.unlinkSync(cfg);
}
});
test('pr comment rejects a missing body before any network call', () => {
const cfg = path.join(os.tmpdir(), `stoke-cfg-${process.pid}.json`);
fs.writeFileSync(cfg, JSON.stringify({ url: 'https://forge.test', token: 'tok' }));
try {
const res = run(['pr', 'comment', '-o', 'o', '-r', 'r', '-n', '1'], { STOKE_CONFIG_FILE: cfg });
assert.equal(res.status, 1);
assert.match(res.stderr, /Comment body is required/);
} finally {
fs.unlinkSync(cfg);
}
});
test('pr review rejects an invalid event before any network call', () => {
const cfg = path.join(os.tmpdir(), `stoke-cfg-${process.pid}.json`);
fs.writeFileSync(cfg, JSON.stringify({ url: 'https://forge.test', token: 'tok' }));
try {
const res = run(['pr', 'review', '-o', 'o', '-r', 'r', '-n', '1', '--event', 'nope'], { STOKE_CONFIG_FILE: cfg });
assert.equal(res.status, 1);
assert.match(res.stderr, /Invalid review event/);
} finally {
fs.unlinkSync(cfg);
}
});