Gas waits for GitLab to compute mergeability instead of refusing. An unchecked (or checking/preparing/approvals_syncing) status now makes the Hub ask for a recheck as the merge account, every 30 seconds, and give up only after two minutes; lti-api !1384 was refused twice because nobody ever asked.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
23
src/hub.ts
23
src/hub.ts
@@ -47,6 +47,7 @@ export type Ports = {
|
||||
listNotes(ref: MrRef, afterId: number): Promise<Note[]>;
|
||||
postNote(ref: MrRef, body: string): Promise<number>;
|
||||
updateNote(ref: MrRef, noteId: number, body: string): Promise<void>;
|
||||
recheckMergeStatus(ref: MrRef): Promise<string | null>;
|
||||
mergeMr(ref: MrRef, sha: string): Promise<{ mergeSha: string | null; state: string }>;
|
||||
closeMr(ref: MrRef): Promise<{ state: string }>;
|
||||
pipelineFor(project: string, sha: string | null, ref: string): Promise<{ id: number; status: string; webUrl: string } | null>;
|
||||
@@ -67,6 +68,10 @@ export type Ports = {
|
||||
};
|
||||
|
||||
const MAX_ATTEMPTS = 3;
|
||||
// GitLab statuses that mean "not computed yet", not "no": Gas asks for a recheck and waits.
|
||||
const PENDING_MERGE_STATUS = new Set(['unchecked', 'checking', 'preparing', 'approvals_syncing']);
|
||||
const MERGE_STATUS_WAIT_MS = 2 * 60_000;
|
||||
const RECHECK_EVERY_MS = 30_000;
|
||||
|
||||
export class Hub {
|
||||
readonly store: Store;
|
||||
@@ -76,6 +81,8 @@ export class Hub {
|
||||
readonly workRoot: string;
|
||||
readonly log: (line: string) => void;
|
||||
private lastDeployCheck = 0;
|
||||
// When each waiting Gas last asked GitLab to recompute mergeability (in memory; a restart just asks again).
|
||||
private rechecked = new Map<number, number>();
|
||||
private notifyRetryAt = 0;
|
||||
|
||||
constructor(store: Store, config: HubConfig, reviewer: Reviewer, ports: Ports, workRoot: string, log: (line: string) => void = () => {}) {
|
||||
@@ -339,10 +346,13 @@ export class Hub {
|
||||
const a = this.store.ajuanById(ev.ajuan_id);
|
||||
try {
|
||||
const result = ev.kind === 'gas' ? await this.gas(a, ev, now) : ev.kind === 'close' ? await this.close(a, ev) : await this.announce(a, ev);
|
||||
if (result === null) continue; // still waiting on GitLab; the claimed event runs again next tick
|
||||
this.rechecked.delete(ev.id);
|
||||
this.store.finishEvent(ev.id, result);
|
||||
this.log(`${a.project} !${a.iid} ${ev.kind}: ${result}`);
|
||||
} catch (e: any) {
|
||||
// Not retried: a merge that failed is for the approver to look at and Gas again.
|
||||
this.rechecked.delete(ev.id);
|
||||
const msg = String(e?.message ?? e).slice(0, 300);
|
||||
this.store.finishEvent(ev.id, `failed: ${msg}`);
|
||||
this.log(`${a.project} !${a.iid} ${ev.kind} gagal: ${msg}`);
|
||||
@@ -361,7 +371,8 @@ export class Hub {
|
||||
}
|
||||
|
||||
// Every check runs again against GitLab at the moment of the merge; the board's view may be old.
|
||||
private async gas(a: Ajuan, ev: QueuedEvent, now: number): Promise<string> {
|
||||
// Null: GitLab has not computed mergeability yet; try again on the next tick.
|
||||
private async gas(a: Ajuan, ev: QueuedEvent, now: number): Promise<string | null> {
|
||||
const ref = this.ref(a);
|
||||
const m = await this.ports.gitlab.mrSummary(ref);
|
||||
const by = ev.payload.by as string;
|
||||
@@ -376,6 +387,16 @@ export class Hub {
|
||||
if (a.status !== 'go') return refuse(`verdict sekarang ${a.status}`);
|
||||
if (m.sha !== a.reviewed_sha || ev.payload.sha !== a.reviewed_sha) return refuse('ada commit baru setelah review');
|
||||
if (m.pipelineStatus && m.pipelineStatus !== 'success') return refuse(`pipeline MR ${m.pipelineStatus}`);
|
||||
if (m.mergeStatus && PENDING_MERGE_STATUS.has(m.mergeStatus)) {
|
||||
const waited = now - ev.payload.at - this.gasConfig.graceSeconds * 1000;
|
||||
if (waited >= MERGE_STATUS_WAIT_MS) return refuse(`GitLab masih ${m.mergeStatus} setelah ${MERGE_STATUS_WAIT_MS / 60_000} menit`);
|
||||
if (now - (this.rechecked.get(ev.id) ?? 0) >= RECHECK_EVERY_MS) {
|
||||
this.rechecked.set(ev.id, now);
|
||||
await this.ports.gitlab.recheckMergeStatus(ref);
|
||||
this.log(`${a.project} !${a.iid} gas: GitLab ${m.mergeStatus}, minta cek ulang`);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (m.mergeStatus && m.mergeStatus !== 'mergeable') return refuse(`GitLab bilang ${m.mergeStatus}`);
|
||||
if (this.gasConfig.mode !== 'live') {
|
||||
this.store.update(a.id, { deploy_state: 'dry' });
|
||||
|
||||
Reference in New Issue
Block a user