Skip to content

Commit 219f920

Browse files
committed
Support latest turnserver API
1 parent 56040d6 commit 219f920

3 files changed

Lines changed: 65 additions & 109 deletions

File tree

assets/app.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -572,12 +572,11 @@ const App = (() => {
572572
}
573573

574574
pr.turnData = {
575-
pr_state: {
576-
unblock_action: unblockAction,
577-
updated_at: pr.updated_at,
575+
analysis: {
576+
next_action: unblockAction,
578577
last_activity: {
579578
kind: "comment",
580-
author: pr.user.login,
579+
actor: pr.user.login,
581580
message: "Latest activity on this PR",
582581
timestamp: pr.updated_at,
583582
},
@@ -586,19 +585,22 @@ const App = (() => {
586585
? 3
587586
: 0,
588587
size: size,
589-
draft: pr.draft || false,
590588
ready_to_merge:
591589
labelNames.includes("ready") &&
592590
!labelNames.includes("blocked on you"),
593591
merge_conflict: labelNames.includes("merge conflict"),
594592
approved: labelNames.includes("approved"),
595593
tags: [],
596594
},
595+
pull_request: {
596+
draft: pr.draft || false,
597+
updated_at: pr.updated_at,
598+
},
597599
timestamp: new Date().toISOString(),
598600
commit: "demo-version",
599601
};
600602

601-
pr.prState = pr.turnData.pr_state;
603+
pr.prState = pr.turnData.analysis;
602604
pr.status_tags = User.getStatusTags(pr);
603605
});
604606

assets/user.js

Lines changed: 53 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -414,16 +414,16 @@ export const User = (() => {
414414
);
415415

416416
pr.turnData = turnResponse;
417-
pr.prState = turnResponse?.pr_state;
417+
pr.prState = turnResponse?.analysis; // Updated to use new structure
418418
pr.status_tags = getStatusTags(pr);
419419

420-
const lastActivity = turnResponse?.pr_state?.last_activity;
420+
const lastActivity = turnResponse?.analysis?.last_activity;
421421
if (lastActivity) {
422422
pr.last_activity = {
423423
type: lastActivity.kind,
424424
message: lastActivity.message,
425425
timestamp: lastActivity.timestamp,
426-
actor: lastActivity.author,
426+
actor: lastActivity.actor, // Updated from 'author' to 'actor'
427427
};
428428
}
429429

@@ -482,16 +482,16 @@ export const User = (() => {
482482
);
483483

484484
pr.turnData = turnResponse;
485-
pr.prState = turnResponse?.pr_state;
485+
pr.prState = turnResponse?.analysis; // Updated to use new structure
486486
pr.status_tags = getStatusTags(pr);
487487

488-
const lastActivity = turnResponse?.pr_state?.last_activity;
488+
const lastActivity = turnResponse?.analysis?.last_activity;
489489
if (lastActivity) {
490490
pr.last_activity = {
491491
type: lastActivity.kind,
492492
message: lastActivity.message,
493493
timestamp: lastActivity.timestamp,
494-
actor: lastActivity.author,
494+
actor: lastActivity.actor, // Updated from 'author' to 'actor'
495495
};
496496
}
497497

@@ -510,53 +510,59 @@ export const User = (() => {
510510

511511
const getStatusTags = (pr) => {
512512
if (pr.turnData !== undefined) {
513-
if (!pr.turnData || !pr.turnData.pr_state) {
513+
if (!pr.turnData || !pr.turnData.analysis) {
514514
return [];
515515
}
516516

517-
const prState = pr.turnData.pr_state;
517+
const analysis = pr.turnData.analysis;
518+
const prData = pr.turnData.pull_request;
518519
const tags = [];
519520

520-
if (pr.draft || prState.mergeable_state === "draft") {
521+
if (pr.draft || prData?.draft) {
521522
tags.push("draft");
522523
}
523524

524-
if (prState.labels) {
525-
prState.labels.forEach((label) => {
526-
tags.push(`label:${label}`);
525+
// Tags are now directly in analysis.tags array
526+
if (analysis.tags) {
527+
analysis.tags.forEach((tag) => {
528+
tags.push(`label:${tag}`);
527529
});
528530
}
529531

530-
const blockedOnYou = prState.blocked_on?.you || false;
531-
const blockedOnOthers = prState.blocked_on?.others || false;
532+
// Check next_action to determine if blocked
533+
const currentUser = window.App?.state?.currentUser || window.App?.state?.viewingUser;
534+
const nextAction = analysis.next_action || {};
535+
const userHasAction = currentUser && nextAction[currentUser.login];
536+
const othersHaveAction = Object.keys(nextAction).length > 0;
532537

533-
if (blockedOnYou) {
538+
if (userHasAction) {
534539
tags.push("blocked on you");
535540

536-
if (prState.needs_review && prState.requested_reviewers?.includes(pr.user?.login)) {
541+
const action = nextAction[currentUser.login];
542+
if (action.kind === "review" || action.kind === "re_review") {
537543
tags.push("needs-review");
538544
}
539-
if (prState.tests_failing) {
545+
if (action.kind === "fix_tests" || action.kind === "rerun_tests") {
540546
tags.push("needs-fixes", "tests_failing");
541547
}
542-
if (prState.has_merge_conflict) {
548+
if (action.kind === "fix_conflict") {
543549
tags.push("needs-rebase", "merge_conflict");
544550
}
545-
if (prState.changes_requested) {
551+
if (action.kind === "resolve_comments" || action.kind === "respond") {
546552
tags.push("needs-changes", "changes_requested");
547553
}
548-
} else if (blockedOnOthers) {
554+
} else if (othersHaveAction && !userHasAction) {
549555
tags.push("blocked on others");
550556
}
551557

552-
if (prState.approved && prState.all_checks_passing && !prState.has_merge_conflict) {
558+
if (analysis.ready_to_merge) {
553559
tags.push("ready-to-merge");
554560
}
555561

556-
if (prState.approved) {
562+
if (analysis.approved) {
557563
tags.push("approved");
558564
}
559-
if (prState.all_checks_passing) {
565+
if (analysis.checks?.failing === 0 && analysis.checks?.total > 0) {
560566
tags.push("all_checks_passing");
561567
}
562568

@@ -890,8 +896,8 @@ export const User = (() => {
890896
};
891897

892898
const isBlockedOnUser = (pr, user) => {
893-
if (!pr.turnData?.pr_state?.unblock_action || !user) return false;
894-
return Object.keys(pr.turnData.pr_state.unblock_action).includes(user.login);
899+
if (!pr.turnData?.analysis?.next_action || !user) return false;
900+
return Object.keys(pr.turnData.analysis.next_action).includes(user.login);
895901
};
896902

897903
const renderPRList = (container, prs, isDraft = false, section = "", state) => {
@@ -945,26 +951,26 @@ export const User = (() => {
945951
};
946952

947953
const buildWaitingOn = (pr, viewingUser, currentUser, isIncomingPR = false) => {
948-
if (!pr.turnData?.pr_state?.unblock_action) {
954+
if (!pr.turnData?.analysis?.next_action) {
949955
return '';
950956
}
951-
952-
// unblock_action is a dictionary where keys are usernames and values have critical/reason
953-
const unblockAction = pr.turnData.pr_state.unblock_action;
954-
const usernames = Object.keys(unblockAction);
955-
957+
958+
// next_action is a dictionary where keys are usernames and values have kind/critical/reason
959+
const nextAction = pr.turnData.analysis.next_action;
960+
const usernames = Object.keys(nextAction);
961+
956962
if (usernames.length === 0) {
957963
return '';
958964
}
959-
965+
960966
const waitingList = usernames.map(username => {
961-
const action = unblockAction[username];
967+
const action = nextAction[username];
962968
const isViewingUser = viewingUser && username === viewingUser.login;
963969
const isCurrentUser = currentUser && username === currentUser.login;
964-
970+
965971
let displayName = username;
966972
let className = 'pr-waiting-on-user';
967-
973+
968974
// If viewing someone else's dashboard, highlight their name
969975
if (viewingUser && currentUser && viewingUser.login !== currentUser.login) {
970976
if (isViewingUser) {
@@ -979,12 +985,12 @@ export const User = (() => {
979985
className = 'pr-waiting-on-you';
980986
}
981987
}
982-
988+
983989
const title = action.reason || 'Waiting for action';
984-
990+
985991
return `<span class="${className}" title="${escapeHtml(title)}">${escapeHtml(displayName)}</span>`;
986992
}).join(', ');
987-
993+
988994
return ` <span class="pr-waiting-on"><span class="pr-waiting-on-label">(waiting on</span> ${waitingList}<span class="pr-waiting-on-label">)</span></span>`;
989995
};
990996

@@ -1185,21 +1191,21 @@ export const User = (() => {
11851191
const badges = [];
11861192

11871193
// Add prominent badges first based on turnData
1188-
if (pr.turnData?.pr_state?.ready_to_merge) {
1194+
if (pr.turnData?.analysis?.ready_to_merge) {
11891195
badges.push('<span class="badge badge-ready">ready to merge</span>');
11901196
}
1191-
1192-
if (pr.turnData?.pr_state?.merge_conflict) {
1197+
1198+
if (pr.turnData?.analysis?.merge_conflict) {
11931199
badges.push('<span class="badge badge-merge-conflict">merge conflict</span>');
11941200
}
1195-
1196-
if (pr.turnData?.pr_state?.unresolved_comment_count > 0) {
1197-
const count = pr.turnData.pr_state.unresolved_comment_count;
1201+
1202+
if (pr.turnData?.analysis?.unresolved_comments > 0) {
1203+
const count = pr.turnData.analysis.unresolved_comments;
11981204
badges.push(`<span class="badge badge-unresolved-comments">${count} unresolved comment${count > 1 ? 's' : ''}</span>`);
11991205
}
1200-
1201-
if (pr.turnData?.pr_state?.checks?.failing > 0) {
1202-
const failing = pr.turnData.pr_state.checks.failing;
1206+
1207+
if (pr.turnData?.analysis?.checks?.failing > 0) {
1208+
const failing = pr.turnData.analysis.checks.failing;
12031209
badges.push(`<span class="badge badge-failing">${failing} failing</span>`);
12041210
}
12051211

main.go

Lines changed: 4 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -378,11 +378,11 @@ func main() {
378378
// Uses Fetch Metadata (Sec-Fetch-Site header) for reliable cross-origin detection
379379
csrfProtection = http.NewCrossOriginProtection()
380380
// Trust requests from our own domain and all subdomains
381-
csrfProtection.AddTrustedOrigin("https://" + baseDomain)
382-
csrfProtection.AddTrustedOrigin("https://*." + baseDomain)
381+
_ = csrfProtection.AddTrustedOrigin("https://" + baseDomain)
382+
_ = csrfProtection.AddTrustedOrigin("https://*." + baseDomain)
383383
// Allow localhost for development
384-
csrfProtection.AddTrustedOrigin("http://localhost")
385-
csrfProtection.AddTrustedOrigin("http://localhost:*")
384+
_ = csrfProtection.AddTrustedOrigin("http://localhost")
385+
_ = csrfProtection.AddTrustedOrigin("http://localhost:*")
386386

387387
// Set up routes
388388
mux := http.NewServeMux()
@@ -1212,58 +1212,6 @@ func trackFailedAttempt(ip string) {
12121212
}
12131213
}
12141214

1215-
func origin(r *http.Request) string {
1216-
// Check Origin header first
1217-
if origin := r.Header.Get("Origin"); origin != "" {
1218-
return origin
1219-
}
1220-
1221-
// Check Referer as fallback
1222-
if referer := r.Header.Get("Referer"); referer != "" {
1223-
if u, err := url.Parse(referer); err == nil {
1224-
return fmt.Sprintf("%s://%s", u.Scheme, u.Host)
1225-
}
1226-
}
1227-
1228-
// Default to request origin
1229-
scheme := "http"
1230-
if r.TLS != nil || r.Header.Get("X-Forwarded-Proto") == "https" {
1231-
scheme = "https"
1232-
}
1233-
return fmt.Sprintf("%s://%s", scheme, r.Host)
1234-
}
1235-
1236-
func isAllowedOrigin(origin string) bool {
1237-
// Always allow same-origin
1238-
if origin == "" {
1239-
return true
1240-
}
1241-
1242-
// Parse allowed origins from flag
1243-
if *allowedOrigins != "" {
1244-
allowed := strings.Split(*allowedOrigins, ",")
1245-
for _, ao := range allowed {
1246-
if strings.TrimSpace(ao) == origin {
1247-
return true
1248-
}
1249-
}
1250-
return false
1251-
}
1252-
1253-
// Default allowed origins
1254-
u, err := url.Parse(origin)
1255-
if err != nil {
1256-
return false
1257-
}
1258-
1259-
// Allow localhost for development and the production domain (including all subdomains)
1260-
host := u.Hostname()
1261-
return host == "localhost" ||
1262-
host == "127.0.0.1" ||
1263-
strings.HasPrefix(host, "localhost:") ||
1264-
host == baseDomain ||
1265-
strings.HasSuffix(host, "."+baseDomain) // Allow all subdomains
1266-
}
12671215

12681216
// requestSizeLimiter prevents large request bodies from exhausting server resources.
12691217
func requestSizeLimiter(next http.Handler) http.Handler {

0 commit comments

Comments
 (0)