next-issue 6.6.31 → 6.6.33

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 CHANGED
@@ -132,7 +132,17 @@ the run handles one issue. For each issue:
132
132
  during the push, so a run stopped meanwhile, or the next run after that
133
133
  hand-over, checks the base on resume and waits for the checks of the
134
134
  commit when it landed. The harness then waits for the checks of the
135
- pushed commit on the base branch. A repository
135
+ pushed commit on the base branch: its GitHub Actions workflow runs, its
136
+ commit statuses and the check runs of every other GitHub App, so checks
137
+ from another CI service count too. It leaves out the check runs of the
138
+ GitHub Actions app, since it judges GitHub Actions by its workflow runs. A
139
+ failed or errored commit status, or a check run that ends with
140
+ `failure`, `timed_out` or `action_required`, fails the checks. When any check
141
+ ends `cancelled`, for example because a later push cancelled the workflow
142
+ run, that check never finished, even when another check (such as a release
143
+ workflow) ends `success`: the harness
144
+ hands the issue to a person with the reason `main checks cancelled` and
145
+ halts, and the issue stays open. A repository
136
146
  that reports no check keeps asking for `checkGraceSeconds`. A pending state
137
147
  waits again, up to `checkTimeoutMinutes`. A read that fails is tried three
138
148
  times. When the checks pass, the harness closes the issue and sets
@@ -141,10 +151,12 @@ the run handles one issue. For each issue:
141
151
  and the state file go away. A fetch that fails or a fast-forward that is
142
152
  not safe leaves the local base branch as it is and writes a `base.behind`
143
153
  event, and the issue is still done. When the checks fail, the harness
144
- reruns the failed jobs once with `gh run rerun <id> --failed`, records a
154
+ reruns the failed GitHub Actions jobs once with
155
+ `gh run rerun <id> --failed`, records a
145
156
  `main-checks.rerun` event, saves the rerun in the state file and waits
146
157
  again once the runs restart. When the rerun cannot start, or the checks
147
- fail again, the fixer gets their logs from the check budget, and its fix
158
+ fail again, the fixer gets their logs from the check budget (for a check
159
+ from another CI service, only its name and link), and its fix
148
160
  lands the same way. When the fixer cannot fix them, its fix cannot land,
149
161
  an error stops the fix, or the budget runs out, the harness reverts every
150
162
  commit of the change on the base branch, pushes the revert and hands the
@@ -1,9 +1,11 @@
1
1
  import { setTimeout as delay } from 'node:timers/promises';
2
2
  import { pollChecks } from './check-poll.mjs';
3
3
  import { secondsToMs } from './durations.mjs';
4
- import { gh, ghJson } from './gh.mjs';
4
+ import { gh, ghApi, ghJson } from './gh.mjs';
5
5
  import { runLogs } from './run-logs.mjs';
6
6
  const RESTART_TRIES = 10;
7
+ const ACTIONS_APP = 'github-actions';
8
+ const FAILED_STATES = new Set(['failure', 'error']);
7
9
  const FAILED_CONCLUSIONS = new Set(['failure', 'timed_out', 'startup_failure']);
8
10
  async function baseRuns(repo, sha) {
9
11
  return ghJson(repo, [
@@ -15,6 +17,37 @@ async function baseRuns(repo, sha) {
15
17
  'databaseId,name,status,conclusion,attempt',
16
18
  ]);
17
19
  }
20
+ function jsonLines(raw) {
21
+ return raw
22
+ .split('\n')
23
+ .filter((line) => line.trim() !== '')
24
+ .map((line) => JSON.parse(line));
25
+ }
26
+ async function externalChecks(repo, sha) {
27
+ const [runs, statuses] = await Promise.all([
28
+ ghApi(repo, `commits/${sha}/check-runs?per_page=100`, '.check_runs[] | {name, status, conclusion, app: .app.slug, url: .details_url} | @json', { paginate: true }),
29
+ ghApi(repo, `commits/${sha}/status?per_page=100`, '.statuses[] | {name: .context, state, url: .target_url} | @json', { paginate: true }),
30
+ ]);
31
+ const checkRuns = jsonLines(runs)
32
+ .filter((entry) => entry.app !== ACTIONS_APP)
33
+ .map((entry) => ({
34
+ name: entry.name,
35
+ status: entry.status,
36
+ conclusion: entry.conclusion === 'action_required' ? 'failure' : (entry.conclusion ?? ''),
37
+ url: entry.url ?? '',
38
+ }));
39
+ const commitStatuses = jsonLines(statuses).map((entry) => ({
40
+ name: entry.name,
41
+ status: entry.state === 'pending' ? 'pending' : 'completed',
42
+ conclusion: FAILED_STATES.has(entry.state) ? 'failure' : entry.state,
43
+ url: entry.url ?? '',
44
+ }));
45
+ return [...checkRuns, ...commitStatuses];
46
+ }
47
+ async function baseChecks(repo, sha) {
48
+ const [runs, external] = await Promise.all([baseRuns(repo, sha), externalChecks(repo, sha)]);
49
+ return [...runs.map((entry) => ({ ...entry, url: '' })), ...external];
50
+ }
18
51
  function failedRun(entry) {
19
52
  return entry.status === 'completed' && FAILED_CONCLUSIONS.has(entry.conclusion);
20
53
  }
@@ -22,14 +55,21 @@ function baseState(runs) {
22
55
  if (runs.some(failedRun)) {
23
56
  return 'fail';
24
57
  }
25
- return runs.every((entry) => entry.status === 'completed') ? 'pass' : 'pending';
58
+ if (!runs.every((entry) => entry.status === 'completed')) {
59
+ return 'pending';
60
+ }
61
+ return runs.some((entry) => entry.conclusion === 'cancelled') ? 'cancelled' : 'pass';
26
62
  }
27
63
  export function waitForBaseChecks(repo, sha, options) {
64
+ let checks = [];
28
65
  return pollChecks({
29
66
  head: async () => sha,
30
67
  lags: async () => true,
31
- list: async () => ((await baseRuns(repo, sha)).length === 0 ? 'none' : 'some'),
32
- watch: async () => baseState(await baseRuns(repo, sha)),
68
+ list: async () => {
69
+ checks = await baseChecks(repo, sha);
70
+ return checks.length === 0 ? 'none' : 'some';
71
+ },
72
+ watch: async () => baseState(checks),
33
73
  }, options);
34
74
  }
35
75
  export async function rerunFailedBase(repo, sha) {
@@ -54,5 +94,9 @@ export async function failedBaseLogs(repo, sha, maxChars) {
54
94
  const failed = (await baseRuns(repo, sha))
55
95
  .filter(failedRun)
56
96
  .map((entry) => ({ heading: `## ${entry.name}`, runId: String(entry.databaseId) }));
57
- return runLogs(repo, failed, maxChars);
97
+ const external = (await externalChecks(repo, sha)).filter(failedRun).map((entry) => ({
98
+ heading: entry.url === '' ? `## ${entry.name}` : `## ${entry.name}\n${entry.url}`,
99
+ runId: undefined,
100
+ }));
101
+ return runLogs(repo, [...failed, ...external], maxChars);
58
102
  }
package/dist/conflict.mjs CHANGED
@@ -8,7 +8,7 @@ export async function rebase(job) {
8
8
  const { config, ports, base } = context;
9
9
  const title = state.title ?? fallbackTitle(issue);
10
10
  const before = await ports.revision(worktree);
11
- const files = await log.step('rebase', { base }, () => ports.startMerge(worktree, base, config.remote));
11
+ const { target, files } = await log.step('rebase', { base }, () => ports.startMerge(worktree, base, config.remote));
12
12
  if (files !== undefined) {
13
13
  log.event('rebase.conflicts', { files }, 'quiet');
14
14
  const merged = await mergeBase(job, before, files);
@@ -18,7 +18,7 @@ export async function rebase(job) {
18
18
  state.title = title;
19
19
  }
20
20
  const merged = await ports.revision(worktree);
21
- const squashed = await commitWork(job, merged, title, 'fixer', (cwd, message) => ports.squashOnto(cwd, base, config.remote, message));
21
+ const squashed = await commitWork(job, merged, title, 'fixer', (cwd, message) => ports.squashOnto(cwd, target, message));
22
22
  if (!squashed) {
23
23
  return escalateAndFinish(job, `The change holds nothing that ${config.remote}/${base} does not already hold.`, 'empty change');
24
24
  }
package/dist/gate.mjs CHANGED
@@ -23,6 +23,9 @@ export async function checkGate(job, sha) {
23
23
  return GATE_PASSED;
24
24
  }
25
25
  job.mainBroken = true;
26
+ if (checks === 'cancelled') {
27
+ return escalateAndFinish(job, `The checks on ${base} were cancelled before they finished.`, 'main checks cancelled');
28
+ }
26
29
  if (checks !== 'fail') {
27
30
  return escalateAndFinish(job, `The checks on ${base} did not finish in time.`, 'main checks timeout');
28
31
  }
package/dist/git-land.mjs CHANGED
@@ -1,9 +1,8 @@
1
1
  import { evenWhenStopped } from './children.mjs';
2
- import { fetchBase, git, isOnBase, oneFetchAtATime, remoteRef, revision, succeeds, } from './git.mjs';
2
+ import { fetchBase, git, isOnBase, oneFetchAtATime, revision, succeeds } from './git.mjs';
3
3
  import { commitEverything } from './git-commit.mjs';
4
4
  export const PUSH_TRIES = 3;
5
- export async function squashOnto(cwd, base, remote, message) {
6
- const target = remoteRef(remote, base);
5
+ export async function squashOnto(cwd, target, message) {
7
6
  if (await succeeds(cwd, ['diff', '--quiet', target])) {
8
7
  return false;
9
8
  }
@@ -5,17 +5,17 @@ import { commitEverything } from './git-commit.mjs';
5
5
  import { fetchBase, git, isAncestor, remoteRef, resetHard, succeeds } from './git.mjs';
6
6
  import { lines } from './text.mjs';
7
7
  export async function startMerge(cwd, base, remote) {
8
- const target = await fetchBase(cwd, base, remote);
8
+ const target = await git(cwd, ['rev-parse', await fetchBase(cwd, base, remote)]);
9
9
  const result = await run('git', ['merge', '--no-ff', '--no-commit', target], { cwd });
10
10
  if (succeeded(result)) {
11
- return (await merging(cwd)) ? [] : undefined;
11
+ return { target, files: (await merging(cwd)) ? [] : undefined };
12
12
  }
13
13
  const listed = await git(cwd, ['diff', '--name-only', '--diff-filter=U']);
14
14
  const files = lines(listed);
15
15
  if (files.length === 0) {
16
16
  throw new Error(`git merge ${target} failed: ${result.stderr.trim()}`);
17
17
  }
18
- return files;
18
+ return { target, files };
19
19
  }
20
20
  async function merging(cwd) {
21
21
  return succeeds(cwd, ['rev-parse', '--quiet', '--verify', 'MERGE_HEAD']);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-issue",
3
- "version": "6.6.31",
3
+ "version": "6.6.33",
4
4
  "description": "Autonomous issue harness driven by the pi SDK",
5
5
  "keywords": [
6
6
  "github",