Skip to content

Commit 3b36a92

Browse files
authored
Merge pull request #23 from FuugaMo/auto-fix/issue-22-chatgpt-turn-fallback
fix: ChatGPT 会话回合检测增加 fallback 选择器
2 parents c1cbb42 + 4415502 commit 3b36a92

3 files changed

Lines changed: 59 additions & 12 deletions

File tree

.github/workflows/codex-trigger.yml

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Trigger Codex Review
22

33
on:
44
pull_request:
5-
types: [opened, reopened]
5+
types: [opened, reopened, labeled, synchronize]
66

77
jobs:
88
trigger:
@@ -13,9 +13,26 @@ jobs:
1313
with:
1414
github-token: ${{ secrets.FUUGAMO_PAT }}
1515
script: |
16+
const prNumber = context.payload.pull_request.number;
17+
const pingText = '@codex Please review this PR. If you find no critical issues, reply with "LGTM". If you find critical issues, describe them clearly.';
18+
19+
// 去重:如果已存在相同触发评论则跳过,避免重复@codex
20+
const { data: comments } = await github.rest.issues.listComments({
21+
owner: context.repo.owner,
22+
repo: context.repo.repo,
23+
issue_number: prNumber,
24+
per_page: 100,
25+
});
26+
27+
const alreadyPinged = comments.some(c => (c.body || '').includes(pingText));
28+
if (alreadyPinged) {
29+
core.info('Codex already pinged on this PR, skip duplicate comment.');
30+
return;
31+
}
32+
1633
await github.rest.issues.createComment({
1734
owner: context.repo.owner,
18-
repo: context.repo.repo,
19-
issue_number: context.payload.pull_request.number,
20-
body: '@codex Please review this PR. If you find no critical issues, reply with "LGTM". If you find critical issues, describe them clearly.',
35+
repo: context.repo.repo,
36+
issue_number: prNumber,
37+
body: pingText,
2138
});

content.js

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
chatgpt: {
2222
turns: [
2323
"article[data-testid^='conversation-turn-']",
24+
"[data-testid='conversation-turn']",
25+
'[data-message-author-role]',
2426
'[data-message-id]',
2527
],
2628
turnRoleAttr: 'data-turn',
@@ -556,10 +558,25 @@ function makePathEntry(turn) {
556558
}
557559

558560
function readChatGPTTurns() {
559-
const turns = [...document.querySelectorAll('article[data-testid^="conversation-turn-"]')];
561+
let turns = [...document.querySelectorAll('article[data-testid^="conversation-turn-"]')];
562+
563+
if (!turns.length) {
564+
const fallbackSelectors = [
565+
"[data-testid='conversation-turn']",
566+
'[data-message-author-role]',
567+
'main article',
568+
];
569+
const candidates = dedupeElements(fallbackSelectors.flatMap(sel => [...document.querySelectorAll(sel)]))
570+
.filter(el => isReadableTurnCandidate(el, { minText: 2 }));
571+
turns = candidates
572+
.filter(el => !candidates.some(other => other !== el && other.contains(el)))
573+
.sort((a, b) => rectTop(a) - rectTop(b));
574+
}
575+
560576
return turns.map((turn, idx) => {
561-
const role = turn.getAttribute('data-turn') === 'user' ? 'user' : 'assistant';
562-
const msgDiv = turn.querySelector('[data-message-id]');
577+
const roleAttr = turn.getAttribute('data-turn') || turn.getAttribute('data-message-author-role') || '';
578+
const role = /^user$/i.test(roleAttr) ? 'user' : 'assistant';
579+
const msgDiv = turn.matches('[data-message-id]') ? turn : turn.querySelector('[data-message-id]');
563580
const msgId = msgDiv?.getAttribute('data-message-id') || turn.getAttribute('data-turn-id') || null;
564581
const nav = findChatGPTBranchNav(turn);
565582
return {
@@ -1007,17 +1024,28 @@ function makePathEntry(turn) {
10071024
return false;
10081025
}
10091026

1027+
function isLikelyChatConversationPage() {
1028+
try {
1029+
const path = new URL(location.href).pathname || '';
1030+
return path.includes('/c/');
1031+
} catch (_) {
1032+
return (location.pathname || '').includes('/c/');
1033+
}
1034+
}
1035+
10101036
function syncStateToPanel(force = false) {
10111037
const turns = serializeTurns(readRawTurns());
10121038
if (!turns.length) {
10131039
if (pageSeemsLoading()) {
10141040
sendToPanel({ type: 'CONVERSATION_LOADING' });
10151041
return;
10161042
}
1017-
maybeReportBreakage('no_turns_detected', {
1018-
phase: 'sync',
1019-
force,
1020-
});
1043+
if (isLikelyChatConversationPage()) {
1044+
maybeReportBreakage('no_turns_detected', {
1045+
phase: 'sync',
1046+
force,
1047+
});
1048+
}
10211049
sendToPanel({ type: 'CONVERSATION_LOADING' });
10221050
return;
10231051
}

selectors.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
{
2-
"version": "0.3.0",
2+
"version": "0.3.1",
33
"lastVerified": "2026-03-11",
44
"platforms": {
55
"chatgpt": {
66
"turns": [
77
"article[data-testid^='conversation-turn-']",
8+
"[data-testid='conversation-turn']",
9+
"[data-message-author-role]",
810
"[data-message-id]"
911
],
1012
"turnRoleAttr": "data-turn",

0 commit comments

Comments
 (0)