feat: report ai review commit status

This commit is contained in:
2026-05-15 14:39:15 +00:00
parent 93c3d0ca66
commit 4fd9a22aa0
4 changed files with 63 additions and 4 deletions
+20 -1
View File
@@ -1,7 +1,7 @@
import { describe, it, afterEach, mock } from 'node:test';
import assert from 'node:assert/strict';
import axios from 'axios';
import { getPRDiff, filterDiff, postComment, getCommitMessageBySha, getBranchHeadCommitMessage, shouldSkipBotCommit } from './gitea.js';
import { getPRDiff, filterDiff, postComment, getCommitMessageBySha, getBranchHeadCommitMessage, shouldSkipBotCommit, setCommitStatus } from './gitea.js';
afterEach(() => mock.restoreAll());
@@ -95,6 +95,25 @@ describe('gitea', () => {
});
await assert.equal(await shouldSkipBotCommit({ sha: 'sha-bot', branch: 'feat/test' }), true);
});
it('setCommitStatus posts commit status to Gitea API', async () => {
let capturedUrl, capturedBody, capturedOpts;
mock.method(axios, 'post', async (url, body, opts) => {
capturedUrl = url;
capturedBody = body;
capturedOpts = opts;
return { data: { state: body.state } };
});
const result = await setCommitStatus('sha-123', 'failure', 'found 2 critical issues', 'ai-review/critical', 'https://example.com/pr/1');
assert.equal(result.state, 'failure');
assert.ok(capturedUrl.includes('/statuses/sha-123'));
assert.equal(capturedBody.state, 'failure');
assert.equal(capturedBody.context, 'ai-review/critical');
assert.equal(capturedBody.description, 'found 2 critical issues');
assert.equal(capturedBody.target_url, 'https://example.com/pr/1');
assert.ok(capturedOpts.headers['Authorization'].startsWith('token '));
});
});
describe('filterDiff', () => {