@warpmetrics/coder 0.2.8 → 0.2.9
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/package.json +1 -1
- package/src/warp.js +21 -0
- package/src/watch.js +15 -1
package/package.json
CHANGED
package/src/warp.js
CHANGED
|
@@ -186,6 +186,27 @@ export async function emitAct(apiKey, { outcomeId, actId, name, opts }) {
|
|
|
186
186
|
});
|
|
187
187
|
}
|
|
188
188
|
|
|
189
|
+
export async function findIssueRun(apiKey, { repo, issueNumber }) {
|
|
190
|
+
const runs = await findRuns(apiKey, 'issue');
|
|
191
|
+
const match = runs.find(r =>
|
|
192
|
+
r.opts?.repo === repo &&
|
|
193
|
+
r.opts?.issue === String(issueNumber)
|
|
194
|
+
);
|
|
195
|
+
if (!match) return null;
|
|
196
|
+
|
|
197
|
+
const res = await fetch(`${API_URL}/v1/runs/${match.id}`, {
|
|
198
|
+
headers: { Authorization: `Bearer ${apiKey}` },
|
|
199
|
+
});
|
|
200
|
+
if (!res.ok) return null;
|
|
201
|
+
const { data } = await res.json();
|
|
202
|
+
|
|
203
|
+
const outcomes = data.outcomes || [];
|
|
204
|
+
const lastOutcome = outcomes[outcomes.length - 1];
|
|
205
|
+
const blockedAt = lastOutcome?.name === 'Max Retries' ? lastOutcome.timestamp : null;
|
|
206
|
+
|
|
207
|
+
return { runId: match.id, blockedAt };
|
|
208
|
+
}
|
|
209
|
+
|
|
189
210
|
export async function countRevisions(apiKey, { prNumber, repo, since }) {
|
|
190
211
|
try {
|
|
191
212
|
const runs = await findRuns(apiKey, 'agent-pipeline');
|
package/src/watch.js
CHANGED
|
@@ -74,9 +74,23 @@ export async function watch() {
|
|
|
74
74
|
for (const item of reviewItems) {
|
|
75
75
|
if (!running) break;
|
|
76
76
|
const issueNumber = item.content?.number;
|
|
77
|
-
|
|
77
|
+
let issueCtx = issueNumber ? issueRuns.get(issueNumber) : null;
|
|
78
78
|
log(`Found review feedback: PR #${item._prNumber || item.content?.number}`);
|
|
79
79
|
|
|
80
|
+
// Recover issue run from WM if watcher was restarted
|
|
81
|
+
if (!issueCtx && issueNumber && config.warpmetricsApiKey) {
|
|
82
|
+
try {
|
|
83
|
+
const recovered = await warp.findIssueRun(config.warpmetricsApiKey, { repo: repoName, issueNumber });
|
|
84
|
+
if (recovered) {
|
|
85
|
+
issueRuns.set(issueNumber, recovered);
|
|
86
|
+
issueCtx = recovered;
|
|
87
|
+
log(` recovered issue run: ${recovered.runId}`);
|
|
88
|
+
}
|
|
89
|
+
} catch (err) {
|
|
90
|
+
log(` warning: could not recover issue run: ${err.message}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
80
94
|
// Detect resume: item was previously blocked, human moved it back to In Review
|
|
81
95
|
let since = null;
|
|
82
96
|
if (issueCtx?.blockedAt) {
|