@futurelastic/colab-handbook 1.17.0-rc.1 → 1.17.0-rc.2
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/tools/colab +10 -4
- package/tools/lib/tracker-github.js +65 -4
package/package.json
CHANGED
package/tools/colab
CHANGED
|
@@ -13440,13 +13440,19 @@ function readTargetCodeowners(repoAbs, target) {
|
|
|
13440
13440
|
|
|
13441
13441
|
/**
|
|
13442
13442
|
* #483: is this repo a fork, and which org owns it? The fork test is adopt's own (#449: a remote named
|
|
13443
|
-
* `upstream` whose URL differs from origin's), so adopt and ship never disagree about the shape
|
|
13444
|
-
*
|
|
13443
|
+
* `upstream` whose URL differs from origin's), so adopt and ship never disagree about the shape — or,
|
|
13444
|
+
* with no such remote on this checkout, the committed record of that same test (#658): the descriptor's
|
|
13445
|
+
* `instruction-files: upstream` (#602), which adopt writes on a detected fork. A checkout that never
|
|
13446
|
+
* added the remote then still reads as the fork its descriptor says it is. The owner is read from
|
|
13447
|
+
* this repo's remote URL. Either unknown → `{ fork: false }`, nothing is dropped.
|
|
13445
13448
|
*/
|
|
13446
13449
|
function codeownersForkContext(repoAbs) {
|
|
13447
|
-
|
|
13450
|
+
const declared = instructionFile.parseInstructionFiles(projectDoc(repoAbs)).exempt;
|
|
13451
|
+
if (!adoptDetectFork(repoAbs) && !declared) return { fork: false, ownOrg: null };
|
|
13448
13452
|
const name = git.remoteInfo(repoAbs).name || 'origin';
|
|
13449
|
-
|
|
13453
|
+
// The configured url, as the gh pin reads it (#658): `get-url` expands `url.<x>.insteadOf`, which
|
|
13454
|
+
// changes how git reaches the remote, never which org owns it.
|
|
13455
|
+
const u = git.git(['config', '--get', `remote.${name}.url`], repoAbs);
|
|
13450
13456
|
const ownOrg = u.ok ? codeowners.remoteOwner(u.stdout) : null;
|
|
13451
13457
|
return { fork: !!ownOrg, ownOrg };
|
|
13452
13458
|
}
|
|
@@ -15,7 +15,9 @@
|
|
|
15
15
|
* `null` is "could not read", never "none").
|
|
16
16
|
*
|
|
17
17
|
* Behaviour-preserving by construction: every method spawns the exact argv and options the call
|
|
18
|
-
* site it replaced spawned (pinned by tools/lib/tracker-github.test.js's argv table).
|
|
18
|
+
* site it replaced spawned (pinned by tools/lib/tracker-github.test.js's argv table). The one
|
|
19
|
+
* addition is the environment: `exec` pins `GH_REPO` to the resolved remote's repo (#658,
|
|
20
|
+
* `pinnedOpts`), so no call depends on gh's default repo or on which other remotes exist.
|
|
19
21
|
*
|
|
20
22
|
* This module must NOT require ./tracker (tracker requires this one), and git.js must never require
|
|
21
23
|
* this module at its top level: git.js ends in `module.exports = {…}`, which REPLACES the exports
|
|
@@ -26,9 +28,68 @@
|
|
|
26
28
|
|
|
27
29
|
let _runner = null; // test seam only — see withRunner
|
|
28
30
|
|
|
29
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* #658 — `[HOST/]OWNER/REPO` for a remote URL, in the form `GH_REPO` takes, or null.
|
|
33
|
+
*
|
|
34
|
+
* Only a host gh is known to serve is pinned: `github.com`, or the `GH_HOST` the environment names.
|
|
35
|
+
* Any other host — an SSH alias, a self-hosted forge gh was never pointed at — reads as null, and
|
|
36
|
+
* the call keeps gh's own resolution exactly as before, rather than pinning a name gh cannot reach.
|
|
37
|
+
*/
|
|
38
|
+
function ghRepoFromUrl(url, env = process.env) {
|
|
39
|
+
const s = String(url || '').trim();
|
|
40
|
+
let m = /^[a-z][a-z0-9+.-]*:\/\/(?:[^@/]+@)?([^/:]+)(?::\d+)?\/([^/]+)\/([^/]+?)(?:\.git)?\/*$/i.exec(s);
|
|
41
|
+
if (!m) m = /^(?:[^@/\s]+@)?([^:/\s]+):([^/]+)\/([^/]+?)(?:\.git)?\/*$/.exec(s);
|
|
42
|
+
if (!m) return null;
|
|
43
|
+
const host = m[1].toLowerCase();
|
|
44
|
+
const ghHost = String(env.GH_HOST || '').toLowerCase();
|
|
45
|
+
if (host === 'github.com') return `${m[2]}/${m[3]}`;
|
|
46
|
+
if (ghHost && host === ghHost) return `${host}/${m[2]}/${m[3]}`;
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const _pinCache = new Map(); // resolved cwd → GH_REPO value or null; one repo's remote does not move mid-run
|
|
51
|
+
function _resetPinCache() { _pinCache.clear(); }
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* #658 — the repo every `gh` call is pinned to: the one colab's own resolved remote points at
|
|
55
|
+
* (`origin`, or `colab.remote` / the single remote — tools/lib/git.js `remoteInfo`, #301), read
|
|
56
|
+
* for the call's `cwd`. Without it a bare `gh issue|pr|run …` follows gh's own default, which on
|
|
57
|
+
* a fork checkout with an `upstream` remote and no `gh repo set-default` is the UPSTREAM — a ship
|
|
58
|
+
* then read the carried issues as CLOSED and trunk CI as "no run" from the wrong repo.
|
|
59
|
+
* null when nothing resolves (no remote, ambiguous remotes, a host gh does not serve): unpinned.
|
|
60
|
+
*/
|
|
61
|
+
function pinnedRepo(cwd) {
|
|
62
|
+
const key = require('path').resolve(cwd || process.cwd());
|
|
63
|
+
if (_pinCache.has(key)) return _pinCache.get(key);
|
|
64
|
+
let slug = null;
|
|
65
|
+
try {
|
|
66
|
+
// The CONFIGURED url, not `git remote get-url`: get-url expands `url.<x>.insteadOf`, which
|
|
67
|
+
// rewrites how git reaches the remote (a mirror, a local path), never which forge repo it is.
|
|
68
|
+
const g = require('./git');
|
|
69
|
+
const { name } = g.remoteInfo(key);
|
|
70
|
+
const u = name ? g.git(['config', '--get', `remote.${name}.url`], key) : null;
|
|
71
|
+
slug = u && u.ok ? ghRepoFromUrl(u.stdout) : null;
|
|
72
|
+
} catch (_) { slug = null; }
|
|
73
|
+
_pinCache.set(key, slug);
|
|
74
|
+
return slug;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* `opts` with `GH_REPO` set to `pinnedRepo(opts.cwd)` — unless the call already names its repo
|
|
79
|
+
* (`--repo`/`-R`), the caller passed its own `GH_REPO`, or the environment sets one (an explicit
|
|
80
|
+
* choice, honoured as gh honours it). Every other option passes through untouched.
|
|
81
|
+
*/
|
|
82
|
+
function pinnedOpts(args, opts = {}) {
|
|
83
|
+
if ((args || []).some((a) => a === '--repo' || a === '-R' || /^--repo=/.test(String(a)))) return opts;
|
|
84
|
+
const base = opts.env || process.env;
|
|
85
|
+
if (base.GH_REPO) return opts;
|
|
86
|
+
const slug = pinnedRepo(opts.cwd);
|
|
87
|
+
return slug ? { ...opts, env: { ...base, GH_REPO: slug } } : opts;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Spawn `gh <args>` with `opts` (git.run's options: cwd, timeoutMs, maxBuffer, …), pinned to origin's repo (#658). */
|
|
30
91
|
function exec(args, opts = {}) {
|
|
31
|
-
return _runner ? _runner(args, opts) : require('./git').run('gh', args, opts);
|
|
92
|
+
return _runner ? _runner(args, opts) : require('./git').run('gh', args, pinnedOpts(args, opts));
|
|
32
93
|
}
|
|
33
94
|
|
|
34
95
|
/**
|
|
@@ -103,4 +164,4 @@ function create(repoAbs) {
|
|
|
103
164
|
};
|
|
104
165
|
}
|
|
105
166
|
|
|
106
|
-
module.exports = { exec, withRunner, create };
|
|
167
|
+
module.exports = { exec, withRunner, create, ghRepoFromUrl, pinnedRepo, pinnedOpts, _resetPinCache };
|