@in-the-loop-labs/pair-review 5.3.7 → 5.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -0
- package/package.json +3 -3
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin-code-critic/.claude-plugin/plugin.json +1 -1
- package/plugin-pair-loop/.claude-plugin/plugin.json +1 -1
- package/public/css/pr.css +389 -13
- package/public/js/components/AIPanel.js +317 -99
- package/public/js/components/ReviewHistoryModal.js +294 -0
- package/public/js/components/ReviewModal.js +96 -7
- package/public/js/components/SplitButton.js +14 -0
- package/public/js/local.js +4 -8
- package/public/js/modules/comment-manager.js +2 -1
- package/public/js/modules/file-comment-manager.js +6 -2
- package/public/js/modules/pierre-bridge.js +35 -1
- package/public/js/modules/suggestion-manager.js +4 -1
- package/public/js/pr.js +174 -66
- package/public/js/utils/posted-comment.js +259 -14
- package/public/js/vendor/pierre-diffs-worker.js +41 -13485
- package/public/js/vendor/pierre-diffs.js +131 -1364
- package/public/pr.html +1 -0
- package/src/chat/api-reference.js +22 -2
- package/src/config.js +28 -4
- package/src/database.js +177 -56
- package/src/github/client.js +70 -15
- package/src/github/impl/graphql/pending-review-comments.js +50 -11
- package/src/github/impl/graphql/pending-review.js +8 -2
- package/src/github/impl/graphql/review-comment-edit.js +89 -0
- package/src/github/impl/host/pending-review-comments.js +41 -10
- package/src/github/impl/host/review-comment-edit.js +36 -0
- package/src/github/impl/rest/pending-review.js +6 -2
- package/src/github/impl/rest/review-comment-edit.js +44 -0
- package/src/github/impl/review-comment-edit-utils.js +45 -0
- package/src/github/operations/pending-review.js +4 -3
- package/src/github/operations/review-comment-edit.js +35 -0
- package/src/github/record-submission.js +78 -0
- package/src/github/update-posted-comment.js +115 -0
- package/src/main.js +24 -44
- package/src/routes/mcp.js +1 -0
- package/src/routes/pr.js +147 -106
package/public/pr.html
CHANGED
|
@@ -429,6 +429,7 @@
|
|
|
429
429
|
<script src="/js/components/StatusIndicator.js"></script>
|
|
430
430
|
<script src="/js/components/SuggestionNavigator.js"></script>
|
|
431
431
|
<script src="/js/components/ReviewModal.js"></script>
|
|
432
|
+
<script src="/js/components/ReviewHistoryModal.js"></script>
|
|
432
433
|
<script src="/js/components/PreviewModal.js"></script>
|
|
433
434
|
<script src="/js/components/SplitButton.js"></script>
|
|
434
435
|
<script src="/js/components/AISummaryModal.js"></script>
|
|
@@ -69,6 +69,8 @@ curl -s http://localhost:{{PORT}}/api/reviews/{{REVIEW_ID}}/comments
|
|
|
69
69
|
|
|
70
70
|
Optional query param: \`includeDismissed=true\` to include soft-deleted (inactive) comments.
|
|
71
71
|
|
|
72
|
+
User comment \`status\` is lifecycle only: \`active\` or \`inactive\`. Each comment has \`publication: null\` (never posted) or \`{ state: "draft"|"posted", posted_at, review_url, comment_url, github_review_row_id, posting_count, changed }\`. Restoring a posted comment does not post it again. Local-mode comments have no publication.
|
|
73
|
+
|
|
72
74
|
**Response:** \`{ "success": true, "comments": [...] }\`
|
|
73
75
|
|
|
74
76
|
### Create a comment
|
|
@@ -123,6 +125,24 @@ curl -s -X PUT http://localhost:{{PORT}}/api/reviews/{{REVIEW_ID}}/comments/COMM
|
|
|
123
125
|
|
|
124
126
|
**Response:** \`{ "success": true, "message": "Comment updated successfully" }\`
|
|
125
127
|
|
|
128
|
+
### Update a posted comment on GitHub (PR mode only)
|
|
129
|
+
|
|
130
|
+
Editing a comment locally does not create another GitHub comment. If \`publication.changed\` is true, an explicit update sends the edited text to the existing host comment, including a comment in a pending draft review:
|
|
131
|
+
|
|
132
|
+
\`\`\`bash
|
|
133
|
+
curl -s -X POST http://localhost:{{PORT}}/api/reviews/{{REVIEW_ID}}/comments/COMMENT_ID/update-on-github
|
|
134
|
+
\`\`\`
|
|
135
|
+
|
|
136
|
+
**Response:** \`{ "success": true, "comment": {...} }\`. Failed updates return \`{ error, code, review_url? }\` (\`not_found_on_github\`, \`forbidden\`, or \`unresolved_identity\`) and never create a replacement. Missing identities are recovered only from exactly one strict match of the original sent text, author, and anchor. Dismissal remains local-only.
|
|
137
|
+
|
|
138
|
+
### Review history (PR mode only)
|
|
139
|
+
|
|
140
|
+
\`\`\`bash
|
|
141
|
+
curl -s http://localhost:{{PORT}}/api/reviews/{{REVIEW_ID}}/submissions
|
|
142
|
+
\`\`\`
|
|
143
|
+
|
|
144
|
+
**Response:** \`{ "submissions": [{ ...review, "postings": [...] }] }\`, newest review first. Each posting retains the sent body, anchor, host link, current \`comment_status\`, and \`kind\` (\`post\` or \`update\`). Legacy duplicate review identities are grouped; backfilled snapshots are approximate.
|
|
145
|
+
|
|
126
146
|
### Delete a comment
|
|
127
147
|
|
|
128
148
|
> **Terminology note:** The UI refers to this operation as "dismiss." When a user asks to "dismiss a comment," use this DELETE endpoint.
|
|
@@ -143,9 +163,9 @@ curl -s -X PUT http://localhost:{{PORT}}/api/reviews/{{REVIEW_ID}}/comments/COMM
|
|
|
143
163
|
|
|
144
164
|
**Response:** \`{ "success": true, "message": "Comment restored successfully", "comment": {...} }\`
|
|
145
165
|
|
|
146
|
-
### Bulk delete
|
|
166
|
+
### Bulk delete pending comments
|
|
147
167
|
|
|
148
|
-
|
|
168
|
+
Dismisses all user comments not yet posted for a review. Posted comments are kept. Also dismisses any parent AI suggestions of the affected comments.
|
|
149
169
|
|
|
150
170
|
\`\`\`bash
|
|
151
171
|
curl -s -X DELETE http://localhost:{{PORT}}/api/reviews/{{REVIEW_ID}}/comments
|
package/src/config.js
CHANGED
|
@@ -12,11 +12,13 @@ const _stackWalkerOps = require('./github/operations/stack-walker');
|
|
|
12
12
|
const _pendingReviewOps = require('./github/operations/pending-review');
|
|
13
13
|
const _reviewLifecycleOps = require('./github/operations/review-lifecycle');
|
|
14
14
|
const _pendingReviewCommentsOps = require('./github/operations/pending-review-comments');
|
|
15
|
+
const _reviewCommentEditOps = require('./github/operations/review-comment-edit');
|
|
15
16
|
const IMPLEMENTATION_MATRIX = {
|
|
16
17
|
stack_walker: _stackWalkerOps.IMPLEMENTED_MODES,
|
|
17
18
|
pending_review_check: _pendingReviewOps.IMPLEMENTED_MODES,
|
|
18
19
|
review_lifecycle: _reviewLifecycleOps.IMPLEMENTED_MODES,
|
|
19
|
-
pending_review_comments: _pendingReviewCommentsOps.IMPLEMENTED_MODES
|
|
20
|
+
pending_review_comments: _pendingReviewCommentsOps.IMPLEMENTED_MODES,
|
|
21
|
+
review_comment_edit: _reviewCommentEditOps.IMPLEMENTED_MODES
|
|
20
22
|
};
|
|
21
23
|
|
|
22
24
|
// Recognised sub-keys that configure an implementation without selecting a
|
|
@@ -24,7 +26,9 @@ const IMPLEMENTATION_MATRIX = {
|
|
|
24
26
|
// explicitly keeps typos from being silently ignored.
|
|
25
27
|
const KNOWN_FEATURE_SUBKEYS = new Set([
|
|
26
28
|
'pending_review_comments_endpoint',
|
|
27
|
-
'pending_review_comments_batch'
|
|
29
|
+
'pending_review_comments_batch',
|
|
30
|
+
'review_comment_edit_endpoint',
|
|
31
|
+
'review_comment_edit_list_endpoint'
|
|
28
32
|
]);
|
|
29
33
|
|
|
30
34
|
let _cachedCommandToken = null;
|
|
@@ -41,13 +45,15 @@ const FEATURE_AREAS = [
|
|
|
41
45
|
'pending_review_check',
|
|
42
46
|
'stack_walker',
|
|
43
47
|
'review_lifecycle',
|
|
44
|
-
'pending_review_comments'
|
|
48
|
+
'pending_review_comments',
|
|
49
|
+
'review_comment_edit'
|
|
45
50
|
];
|
|
46
51
|
const GRAPHQL_DEFAULT_AREAS = new Set([
|
|
47
52
|
'pending_review_check',
|
|
48
53
|
'stack_walker',
|
|
49
54
|
'review_lifecycle',
|
|
50
|
-
'pending_review_comments'
|
|
55
|
+
'pending_review_comments',
|
|
56
|
+
'review_comment_edit'
|
|
51
57
|
]);
|
|
52
58
|
const ALLOWED_FEATURE_VALUES = new Set(['graphql', 'rest', 'host']);
|
|
53
59
|
|
|
@@ -1062,6 +1068,24 @@ function validateRepoConfig(config) {
|
|
|
1062
1068
|
}
|
|
1063
1069
|
}
|
|
1064
1070
|
|
|
1071
|
+
for (const [key, required] of [
|
|
1072
|
+
['review_comment_edit_endpoint', ['{owner}', '{repo}', '{comment_id}']],
|
|
1073
|
+
['review_comment_edit_list_endpoint', ['{owner}', '{repo}', '{pull_number}', '{review_id}']]
|
|
1074
|
+
]) {
|
|
1075
|
+
const value = features[key];
|
|
1076
|
+
if (value === undefined || value === null) continue;
|
|
1077
|
+
const prefix = `Invalid pair-review config: repos["${repoKey}"].features.${key}`;
|
|
1078
|
+
if (typeof value !== 'string' || !value) throw new Error(`${prefix} must be a non-empty string.`);
|
|
1079
|
+
if (resolvedFeatures.review_comment_edit !== 'host') throw new Error(`${prefix} is only valid when review_comment_edit = "host".`);
|
|
1080
|
+
if (!value.startsWith('/') || value.startsWith('//') || /[\\\\\r\n]/.test(value)) {
|
|
1081
|
+
throw new Error(`${prefix} must be a relative path starting with a single slash.`);
|
|
1082
|
+
}
|
|
1083
|
+
const missing = required.filter(placeholder => !value.includes(placeholder));
|
|
1084
|
+
if (missing.length) throw new Error(`${prefix} is missing required placeholder(s): ${missing.join(', ')}.`);
|
|
1085
|
+
const unknown = value.match(/\{[^}]+\}/g)?.filter(placeholder => !required.includes(placeholder)) || [];
|
|
1086
|
+
if (unknown.length) throw new Error(`${prefix} has unknown placeholder(s): ${unknown.join(', ')}.`);
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1065
1089
|
// Some hosts expose the pending-review endpoint but accept one comment
|
|
1066
1090
|
// per POST instead of the generic batch envelope. Batch mode remains the
|
|
1067
1091
|
// default to preserve the documented host-extension contract.
|
package/src/database.js
CHANGED
|
@@ -21,7 +21,7 @@ function getDbPath() {
|
|
|
21
21
|
/**
|
|
22
22
|
* Current schema version - increment this when adding new migrations
|
|
23
23
|
*/
|
|
24
|
-
const CURRENT_SCHEMA_VERSION =
|
|
24
|
+
const CURRENT_SCHEMA_VERSION = 58;
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* Database schema SQL statements
|
|
@@ -52,6 +52,27 @@ const SCHEMA_SQL = {
|
|
|
52
52
|
)
|
|
53
53
|
`,
|
|
54
54
|
|
|
55
|
+
comment_postings: `
|
|
56
|
+
CREATE TABLE IF NOT EXISTS comment_postings (
|
|
57
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
58
|
+
comment_id INTEGER NOT NULL REFERENCES comments(id) ON DELETE CASCADE,
|
|
59
|
+
github_review_row_id INTEGER REFERENCES github_reviews(id) ON DELETE SET NULL,
|
|
60
|
+
comment_body TEXT,
|
|
61
|
+
body TEXT NOT NULL,
|
|
62
|
+
file TEXT,
|
|
63
|
+
line_start INTEGER,
|
|
64
|
+
line_end INTEGER,
|
|
65
|
+
side TEXT,
|
|
66
|
+
is_file_level INTEGER NOT NULL DEFAULT 0,
|
|
67
|
+
github_comment_id TEXT,
|
|
68
|
+
github_comment_node_id TEXT,
|
|
69
|
+
github_comment_url TEXT,
|
|
70
|
+
backfilled INTEGER NOT NULL DEFAULT 0,
|
|
71
|
+
kind TEXT NOT NULL DEFAULT 'post' CHECK (kind IN ('post', 'update')),
|
|
72
|
+
posted_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
73
|
+
)
|
|
74
|
+
`,
|
|
75
|
+
|
|
55
76
|
comments_old: `
|
|
56
77
|
CREATE TABLE IF NOT EXISTS comments_old (
|
|
57
78
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
@@ -395,6 +416,8 @@ const SCHEMA_SQL = {
|
|
|
395
416
|
* Index SQL statements for performance
|
|
396
417
|
*/
|
|
397
418
|
const INDEX_SQL = [
|
|
419
|
+
'CREATE INDEX IF NOT EXISTS idx_comment_postings_comment ON comment_postings(comment_id, id)',
|
|
420
|
+
'CREATE INDEX IF NOT EXISTS idx_comment_postings_github_review ON comment_postings(github_review_row_id)',
|
|
398
421
|
'CREATE INDEX IF NOT EXISTS idx_reviews_pr ON reviews(pr_number, repository)',
|
|
399
422
|
'CREATE INDEX IF NOT EXISTS idx_comments_review_file ON comments(review_id, file, line_start)',
|
|
400
423
|
'CREATE INDEX IF NOT EXISTS idx_comments_ai_run ON comments(ai_run_id)',
|
|
@@ -490,6 +513,27 @@ function tableExists(db, tableName) {
|
|
|
490
513
|
return !!row;
|
|
491
514
|
}
|
|
492
515
|
|
|
516
|
+
// Bind each legacy comment's values rather than referencing outer columns in
|
|
517
|
+
// ORDER BY (unsupported by SQLite). Guarding by posting makes crash retry safe.
|
|
518
|
+
function backfillLegacyPostings(db) {
|
|
519
|
+
const comments = db.prepare(`SELECT * FROM comments c
|
|
520
|
+
WHERE status IN ('submitted', 'draft')
|
|
521
|
+
AND NOT EXISTS (SELECT 1 FROM comment_postings p WHERE p.comment_id = c.id)`).all();
|
|
522
|
+
const findReview = db.prepare(`SELECT id FROM github_reviews WHERE review_id = ?
|
|
523
|
+
ORDER BY (state = 'pending') = ? DESC,
|
|
524
|
+
julianday(created_at) <= julianday(?) + 5.0/86400 DESC,
|
|
525
|
+
created_at DESC, id DESC LIMIT 1`);
|
|
526
|
+
const insert = db.prepare(`INSERT INTO comment_postings
|
|
527
|
+
(comment_id, github_review_row_id, comment_body, body, file, line_start, line_end,
|
|
528
|
+
side, is_file_level, backfilled, posted_at)
|
|
529
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 1, COALESCE(?, CURRENT_TIMESTAMP))`);
|
|
530
|
+
for (const c of comments) {
|
|
531
|
+
const review = findReview.get(c.review_id, c.status === 'draft' ? 1 : 0, c.updated_at);
|
|
532
|
+
insert.run(c.id, review?.id ?? null, c.body, c.body ?? '', c.file,
|
|
533
|
+
c.line_start, c.line_end, c.side, c.is_file_level || 0, c.updated_at);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
|
|
493
537
|
const MIGRATIONS = {
|
|
494
538
|
// Migration to version 1: handles all legacy column additions
|
|
495
539
|
1: (db) => {
|
|
@@ -2363,6 +2407,42 @@ const MIGRATIONS = {
|
|
|
2363
2407
|
console.log(' pool_fetch_owner column already present; nothing to do');
|
|
2364
2408
|
}
|
|
2365
2409
|
console.log('Migration to schema version 55 complete');
|
|
2410
|
+
},
|
|
2411
|
+
|
|
2412
|
+
56: (db) => {
|
|
2413
|
+
db.transaction(() => {
|
|
2414
|
+
db.exec(SCHEMA_SQL.comment_postings);
|
|
2415
|
+
db.exec('CREATE INDEX IF NOT EXISTS idx_comment_postings_comment ON comment_postings(comment_id, id)');
|
|
2416
|
+
db.exec('CREATE INDEX IF NOT EXISTS idx_comment_postings_github_review ON comment_postings(github_review_row_id)');
|
|
2417
|
+
backfillLegacyPostings(db);
|
|
2418
|
+
})();
|
|
2419
|
+
},
|
|
2420
|
+
|
|
2421
|
+
57: (db) => {
|
|
2422
|
+
db.transaction(() => {
|
|
2423
|
+
backfillLegacyPostings(db);
|
|
2424
|
+
// Fix obsolete pending duplicates without deleting history. Subsequent
|
|
2425
|
+
// upserts propagate state to all rows of the same GitHub identity.
|
|
2426
|
+
const pending = db.prepare("SELECT * FROM github_reviews WHERE state = 'pending'").all();
|
|
2427
|
+
const newer = db.prepare(`SELECT * FROM github_reviews WHERE review_id = ? AND id > ?
|
|
2428
|
+
AND state != 'pending' AND
|
|
2429
|
+
((? IS NOT NULL AND github_node_id = ?) OR (? IS NOT NULL AND github_review_id = ?))
|
|
2430
|
+
ORDER BY id DESC LIMIT 1`);
|
|
2431
|
+
for (const row of pending) {
|
|
2432
|
+
const match = newer.get(row.review_id, row.id, row.github_node_id, row.github_node_id,
|
|
2433
|
+
row.github_review_id, row.github_review_id);
|
|
2434
|
+
if (match) db.prepare('UPDATE github_reviews SET state = ?, submitted_at = ?, event = ? WHERE id = ?')
|
|
2435
|
+
.run(match.state, match.submitted_at, match.event, row.id);
|
|
2436
|
+
}
|
|
2437
|
+
db.exec("UPDATE comments SET status = 'active' WHERE source = 'user' AND status IN ('submitted', 'draft')");
|
|
2438
|
+
db.exec("UPDATE comments SET status = 'submitted' WHERE source = 'ai' AND status = 'draft'");
|
|
2439
|
+
})();
|
|
2440
|
+
},
|
|
2441
|
+
|
|
2442
|
+
58: (db) => {
|
|
2443
|
+
if (!columnExists(db, 'comment_postings', 'kind')) {
|
|
2444
|
+
db.exec("ALTER TABLE comment_postings ADD COLUMN kind TEXT NOT NULL DEFAULT 'post' CHECK (kind IN ('post', 'update'))");
|
|
2445
|
+
}
|
|
2366
2446
|
}
|
|
2367
2447
|
};
|
|
2368
2448
|
|
|
@@ -3623,7 +3703,32 @@ class RepoSettingsRepository {
|
|
|
3623
3703
|
/**
|
|
3624
3704
|
* CommentRepository class for managing comment database records
|
|
3625
3705
|
*/
|
|
3706
|
+
// Shared joins for list/single/restore responses. Publication is independent
|
|
3707
|
+
// of lifecycle: dismissed comments retain their posting history.
|
|
3708
|
+
const PUBLICATION_JOIN = `LEFT JOIN comment_postings lp ON lp.id =
|
|
3709
|
+
(SELECT MAX(id) FROM comment_postings WHERE comment_id = c.id)
|
|
3710
|
+
LEFT JOIN github_reviews lgr ON lgr.id = lp.github_review_row_id`;
|
|
3711
|
+
const PUBLICATION_COLUMNS = `lp.id AS posting_id, lp.posted_at AS publication_posted_at,
|
|
3712
|
+
lp.github_review_row_id, lp.github_comment_url, lgr.github_url AS review_url,
|
|
3713
|
+
lgr.state AS publication_review_state, lp.comment_body IS NOT c.body AS publication_changed,
|
|
3714
|
+
(SELECT COUNT(*) FROM comment_postings WHERE comment_id = c.id) AS posting_count`;
|
|
3715
|
+
|
|
3716
|
+
function shapePublication(row) {
|
|
3717
|
+
if (!row) return row;
|
|
3718
|
+
const { posting_id, publication_posted_at, github_review_row_id,
|
|
3719
|
+
github_comment_url, review_url, publication_review_state, publication_changed, posting_count, ...comment } = row;
|
|
3720
|
+
return { ...comment, publication: posting_id == null ? null : {
|
|
3721
|
+
state: publication_review_state === 'pending' ? 'draft' : 'posted',
|
|
3722
|
+
posted_at: publication_posted_at, review_url, comment_url: github_comment_url,
|
|
3723
|
+
github_review_row_id, posting_count, changed: Boolean(publication_changed)
|
|
3724
|
+
} };
|
|
3725
|
+
}
|
|
3726
|
+
|
|
3626
3727
|
class CommentRepository {
|
|
3728
|
+
// Mirrored by isPendingComment in posted-comment.js; pinned by parity tests.
|
|
3729
|
+
static pendingCommentSql(alias = 'c') {
|
|
3730
|
+
return `${alias}.status = 'active' AND NOT EXISTS (SELECT 1 FROM comment_postings p WHERE p.comment_id = ${alias}.id)`;
|
|
3731
|
+
}
|
|
3627
3732
|
/**
|
|
3628
3733
|
* Create a new CommentRepository instance
|
|
3629
3734
|
* @param {Database} db - Database instance
|
|
@@ -3855,7 +3960,7 @@ class CommentRepository {
|
|
|
3855
3960
|
* @returns {Promise<Object|null>} Comment record or null if not found
|
|
3856
3961
|
*/
|
|
3857
3962
|
async getComment(id, source = null) {
|
|
3858
|
-
let sql =
|
|
3963
|
+
let sql = `SELECT c.*, ${PUBLICATION_COLUMNS} FROM comments c ${PUBLICATION_JOIN} WHERE c.id = ?`;
|
|
3859
3964
|
const params = [id];
|
|
3860
3965
|
|
|
3861
3966
|
if (source) {
|
|
@@ -3863,7 +3968,7 @@ class CommentRepository {
|
|
|
3863
3968
|
params.push(source);
|
|
3864
3969
|
}
|
|
3865
3970
|
|
|
3866
|
-
return await queryOne(this.db, sql, params);
|
|
3971
|
+
return shapePublication(await queryOne(this.db, sql, params));
|
|
3867
3972
|
}
|
|
3868
3973
|
|
|
3869
3974
|
/**
|
|
@@ -3925,7 +4030,7 @@ class CommentRepository {
|
|
|
3925
4030
|
}
|
|
3926
4031
|
|
|
3927
4032
|
/**
|
|
3928
|
-
* Bulk
|
|
4033
|
+
* Bulk dismiss only user comments not yet posted for a review
|
|
3929
4034
|
* Also dismisses any AI suggestions that were parents of the deleted comments.
|
|
3930
4035
|
* @param {number} reviewId - Review ID (from reviews table)
|
|
3931
4036
|
* @returns {Promise<{deletedCount: number, dismissedSuggestionIds: number[]}>} Number of comments deleted and list of dismissed suggestion IDs
|
|
@@ -3943,16 +4048,16 @@ class CommentRepository {
|
|
|
3943
4048
|
|
|
3944
4049
|
// First, find all user comments with parent_id (adopted from AI suggestions)
|
|
3945
4050
|
const adoptedComments = await query(this.db, `
|
|
3946
|
-
SELECT parent_id FROM comments
|
|
4051
|
+
SELECT parent_id FROM comments c
|
|
3947
4052
|
WHERE review_id = ? AND source = 'user' AND parent_id IS NOT NULL
|
|
3948
|
-
AND
|
|
4053
|
+
AND ${CommentRepository.pendingCommentSql()}
|
|
3949
4054
|
`, [reviewId]);
|
|
3950
4055
|
|
|
3951
4056
|
// Soft delete all user comments
|
|
3952
4057
|
const result = await run(this.db, `
|
|
3953
|
-
UPDATE comments
|
|
4058
|
+
UPDATE comments AS c
|
|
3954
4059
|
SET status = 'inactive', updated_at = CURRENT_TIMESTAMP
|
|
3955
|
-
WHERE review_id = ? AND source = 'user' AND
|
|
4060
|
+
WHERE review_id = ? AND source = 'user' AND ${CommentRepository.pendingCommentSql()}
|
|
3956
4061
|
`, [reviewId]);
|
|
3957
4062
|
|
|
3958
4063
|
// Dismiss all parent AI suggestions with a single UPDATE statement
|
|
@@ -3975,27 +4080,6 @@ class CommentRepository {
|
|
|
3975
4080
|
return { deletedCount: result.changes, dismissedSuggestionIds };
|
|
3976
4081
|
}
|
|
3977
4082
|
|
|
3978
|
-
/**
|
|
3979
|
-
* Mark every comment held in the review's pending GitHub draft as submitted.
|
|
3980
|
-
*
|
|
3981
|
-
* A comment gets status 'draft' only when it is added to a pending review on
|
|
3982
|
-
* GitHub (Save as Draft, or headless --ai-draft). Submitting that pending
|
|
3983
|
-
* review publishes all of its comments, so callers run this after a non-draft
|
|
3984
|
-
* submit that reused an existing pending review, inside the same transaction
|
|
3985
|
-
* as the rest of the submission bookkeeping.
|
|
3986
|
-
* @param {number} reviewId - Review ID (from reviews table)
|
|
3987
|
-
* @param {string} [updatedAt] - Timestamp to record (default: now)
|
|
3988
|
-
* @returns {Promise<number>} Number of comments marked submitted
|
|
3989
|
-
*/
|
|
3990
|
-
async markDraftCommentsSubmitted(reviewId, updatedAt = new Date().toISOString()) {
|
|
3991
|
-
const result = await run(this.db, `
|
|
3992
|
-
UPDATE comments
|
|
3993
|
-
SET status = 'submitted', updated_at = ?
|
|
3994
|
-
WHERE review_id = ? AND status = 'draft'
|
|
3995
|
-
`, [updatedAt, reviewId]);
|
|
3996
|
-
return result.changes;
|
|
3997
|
-
}
|
|
3998
|
-
|
|
3999
4083
|
/**
|
|
4000
4084
|
* Get all user comments for a review
|
|
4001
4085
|
* @param {number} reviewId - Review ID (from reviews table)
|
|
@@ -4005,33 +4089,14 @@ class CommentRepository {
|
|
|
4005
4089
|
*/
|
|
4006
4090
|
async getUserComments(reviewId, options = {}) {
|
|
4007
4091
|
const { includeDismissed = false } = options;
|
|
4008
|
-
const statusFilter = includeDismissed
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
id,
|
|
4015
|
-
source,
|
|
4016
|
-
author,
|
|
4017
|
-
file,
|
|
4018
|
-
line_start,
|
|
4019
|
-
line_end,
|
|
4020
|
-
side,
|
|
4021
|
-
diff_position,
|
|
4022
|
-
type,
|
|
4023
|
-
title,
|
|
4024
|
-
body,
|
|
4025
|
-
status,
|
|
4026
|
-
parent_id,
|
|
4027
|
-
is_file_level,
|
|
4028
|
-
severity,
|
|
4029
|
-
created_at,
|
|
4030
|
-
updated_at
|
|
4031
|
-
FROM comments
|
|
4032
|
-
WHERE review_id = ? AND source = 'user' AND ${statusFilter}
|
|
4033
|
-
ORDER BY file, line_start, created_at
|
|
4092
|
+
const statusFilter = includeDismissed ? "c.status IN ('active', 'inactive')" : "c.status = 'active'";
|
|
4093
|
+
const rows = await query(this.db, `
|
|
4094
|
+
SELECT c.*, ${PUBLICATION_COLUMNS}
|
|
4095
|
+
FROM comments c ${PUBLICATION_JOIN}
|
|
4096
|
+
WHERE c.review_id = ? AND c.source = 'user' AND ${statusFilter}
|
|
4097
|
+
ORDER BY c.file, c.line_start, c.created_at
|
|
4034
4098
|
`, [reviewId]);
|
|
4099
|
+
return rows.map(shapePublication);
|
|
4035
4100
|
}
|
|
4036
4101
|
|
|
4037
4102
|
/**
|
|
@@ -4087,7 +4152,8 @@ class CommentRepository {
|
|
|
4087
4152
|
}
|
|
4088
4153
|
|
|
4089
4154
|
/**
|
|
4090
|
-
* Restore a soft-deleted user comment
|
|
4155
|
+
* Restore a soft-deleted user comment. Postings survive dismissal, so
|
|
4156
|
+
* restoring a posted comment does not queue it for another submission.
|
|
4091
4157
|
* @param {number} id - Comment ID
|
|
4092
4158
|
* @returns {Promise<boolean>} True if restored successfully
|
|
4093
4159
|
*/
|
|
@@ -5675,6 +5741,33 @@ class AnalysisRunRepository {
|
|
|
5675
5741
|
/**
|
|
5676
5742
|
* GitHubReviewRepository class for managing GitHub review submission records
|
|
5677
5743
|
*/
|
|
5744
|
+
class CommentPostingRepository {
|
|
5745
|
+
constructor(db) { this.db = db; }
|
|
5746
|
+
|
|
5747
|
+
async insertMany(postings) {
|
|
5748
|
+
for (const p of postings) {
|
|
5749
|
+
await run(this.db, `INSERT INTO comment_postings
|
|
5750
|
+
(comment_id, github_review_row_id, comment_body, body, file, line_start,
|
|
5751
|
+
line_end, side, is_file_level, github_comment_id, github_comment_node_id,
|
|
5752
|
+
github_comment_url, backfilled, kind, posted_at)
|
|
5753
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, COALESCE(?, CURRENT_TIMESTAMP))`,
|
|
5754
|
+
[p.comment_id, p.github_review_row_id ?? null, p.comment_body ?? null, p.body,
|
|
5755
|
+
p.file ?? null, p.line_start ?? null, p.line_end ?? null, p.side ?? null,
|
|
5756
|
+
p.is_file_level ? 1 : 0, p.github_comment_id == null ? null : String(p.github_comment_id),
|
|
5757
|
+
p.github_comment_node_id ?? null, p.github_comment_url ?? null,
|
|
5758
|
+
p.backfilled ? 1 : 0, p.kind ?? 'post', p.posted_at ?? null]);
|
|
5759
|
+
}
|
|
5760
|
+
}
|
|
5761
|
+
|
|
5762
|
+
async listByComment(commentId) {
|
|
5763
|
+
return query(this.db, 'SELECT * FROM comment_postings WHERE comment_id = ? ORDER BY id', [commentId]);
|
|
5764
|
+
}
|
|
5765
|
+
|
|
5766
|
+
async listByGitHubReviewRow(rowId) {
|
|
5767
|
+
return query(this.db, 'SELECT * FROM comment_postings WHERE github_review_row_id = ? ORDER BY id', [rowId]);
|
|
5768
|
+
}
|
|
5769
|
+
}
|
|
5770
|
+
|
|
5678
5771
|
class GitHubReviewRepository {
|
|
5679
5772
|
/**
|
|
5680
5773
|
* Create a new GitHubReviewRepository instance
|
|
@@ -5697,6 +5790,30 @@ class GitHubReviewRepository {
|
|
|
5697
5790
|
* @param {string} [data.github_url] - GitHub URL for the review
|
|
5698
5791
|
* @returns {Promise<Object>} Created github_review record
|
|
5699
5792
|
*/
|
|
5793
|
+
async findByGitHubIdentity(reviewId, { nodeId = null, databaseId = null } = {}) {
|
|
5794
|
+
return queryOne(this.db, `SELECT * FROM github_reviews WHERE review_id = ?
|
|
5795
|
+
AND ((? IS NOT NULL AND github_node_id = ?) OR (? IS NOT NULL AND github_review_id = ?))
|
|
5796
|
+
ORDER BY id DESC LIMIT 1`, [reviewId, nodeId, nodeId, databaseId, databaseId]);
|
|
5797
|
+
}
|
|
5798
|
+
|
|
5799
|
+
async upsertForSubmission(reviewId, data) {
|
|
5800
|
+
const identity = { nodeId: data.github_node_id, databaseId: data.github_review_id };
|
|
5801
|
+
const existing = await this.findByGitHubIdentity(reviewId, identity);
|
|
5802
|
+
if (!existing) return this.create(reviewId, data);
|
|
5803
|
+
const update = { ...data };
|
|
5804
|
+
if (!update.github_url) delete update.github_url;
|
|
5805
|
+
if (data.state === 'pending') delete update.body; // GitHub ignores a replacement draft body.
|
|
5806
|
+
await this.update(existing.id, update);
|
|
5807
|
+
// Preserve legacy duplicate rows, but never leave their linked postings in
|
|
5808
|
+
// an obsolete pending state after the identity has been submitted.
|
|
5809
|
+
await run(this.db, `UPDATE github_reviews SET state = ?, submitted_at = ?, event = ?
|
|
5810
|
+
WHERE review_id = ? AND id != ? AND
|
|
5811
|
+
((? IS NOT NULL AND github_node_id = ?) OR (? IS NOT NULL AND github_review_id = ?))`,
|
|
5812
|
+
[data.state, data.submitted_at ?? null, data.event ?? null, reviewId, existing.id,
|
|
5813
|
+
identity.nodeId ?? null, identity.nodeId ?? null, identity.databaseId ?? null, identity.databaseId ?? null]);
|
|
5814
|
+
return this.getById(existing.id);
|
|
5815
|
+
}
|
|
5816
|
+
|
|
5700
5817
|
async create(reviewId, data = {}) {
|
|
5701
5818
|
const {
|
|
5702
5819
|
github_review_id = null,
|
|
@@ -6430,6 +6547,7 @@ module.exports = {
|
|
|
6430
6547
|
getDatabaseStatus,
|
|
6431
6548
|
getSchemaVersion,
|
|
6432
6549
|
CURRENT_SCHEMA_VERSION,
|
|
6550
|
+
runVersionedMigrations,
|
|
6433
6551
|
getDbPath,
|
|
6434
6552
|
WorktreeRepository,
|
|
6435
6553
|
WorktreePoolRepository,
|
|
@@ -6448,7 +6566,10 @@ module.exports = {
|
|
|
6448
6566
|
TourRepository,
|
|
6449
6567
|
generateWorktreeId,
|
|
6450
6568
|
migrateExistingWorktrees,
|
|
6569
|
+
shapePublication,
|
|
6570
|
+
CommentPostingRepository,
|
|
6451
6571
|
// Exported for testing only
|
|
6572
|
+
_setupSchema: setupSchema,
|
|
6452
6573
|
_MIGRATIONS: MIGRATIONS,
|
|
6453
6574
|
MIGRATIONS
|
|
6454
6575
|
};
|