@link-assistant/hive-mind 1.69.14 → 1.69.15
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/CHANGELOG.md +6 -0
- package/package.json +1 -1
- package/src/solve.fork-detection.lib.mjs +81 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @link-assistant/hive-mind
|
|
2
2
|
|
|
3
|
+
## 1.69.15
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- fbda6de: Fix `--auto-fork` failing on private repositories with read-only access when forking is allowed. `handleAutoForkOption` now probes the `allow_forking` repository attribute before bailing out: when it is `true`, fork mode is enabled (the same behaviour already used for public repos without write access); when it is explicitly `false`, the fatal exit explains that direct branch mode needs push/write access, fork mode is disabled, and the maintainer must either grant Write access or enable private forking; when it cannot be determined, we fall through with a verbose warning so `gh repo fork` can produce a precise downstream error. Resolves #1795.
|
|
8
|
+
|
|
3
9
|
## 1.69.14
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -24,9 +24,41 @@ const { log, ghCmdRetry } = lib;
|
|
|
24
24
|
const githubLib = await import('./github.lib.mjs');
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
27
|
+
* Probe whether the repository allows forking via the GitHub API
|
|
28
|
+
* (`allow_forking` is true for repos that can be forked by users with read
|
|
29
|
+
* access — including private repositories). Returns `null` when the
|
|
30
|
+
* attribute could not be determined so callers can decide a safe default.
|
|
31
|
+
*
|
|
32
|
+
* Kept here (instead of github.lib.mjs) because it's only used by the
|
|
33
|
+
* auto-fork branch and the existing `detectRepositoryVisibility` already
|
|
34
|
+
* makes a separate API call; this avoids reshuffling shared helpers.
|
|
35
|
+
*
|
|
36
|
+
* Issue #1795: a private repository with read-only access can still be
|
|
37
|
+
* forked when `allow_forking` is true, so failing early was overly
|
|
38
|
+
* conservative.
|
|
39
|
+
*/
|
|
40
|
+
async function detectAllowForking(owner, repo) {
|
|
41
|
+
const result = await ghCmdRetry(() => $`gh api repos/${owner}/${repo} --jq .allow_forking`, { label: `allow_forking ${owner}/${repo}` });
|
|
42
|
+
if (result.code !== 0) return null;
|
|
43
|
+
const raw = result.stdout.toString().trim();
|
|
44
|
+
if (raw === 'true') return true;
|
|
45
|
+
if (raw === 'false') return false;
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function describeRepoPermissionLevel(permissions) {
|
|
50
|
+
if (permissions.admin === true) return 'Admin';
|
|
51
|
+
if (permissions.maintain === true) return 'Maintain';
|
|
52
|
+
if (permissions.push === true) return 'Write';
|
|
53
|
+
if (permissions.triage === true) return 'Triage';
|
|
54
|
+
if (permissions.pull === true) return 'Read';
|
|
55
|
+
return 'No confirmed repository access';
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Handle the --auto-fork option: when the user lacks write access, attempt
|
|
60
|
+
* to enable fork mode (including for private repositories where
|
|
61
|
+
* `allow_forking` is true). Only fail when forking is also unavailable.
|
|
30
62
|
*
|
|
31
63
|
* Mutates argv.fork in place when fork mode is enabled.
|
|
32
64
|
*
|
|
@@ -51,19 +83,52 @@ export async function handleAutoForkOption({ owner, repo, argv, safeExit }) {
|
|
|
51
83
|
const { isPublic } = await detectRepositoryVisibility(owner, repo);
|
|
52
84
|
|
|
53
85
|
if (!isPublic) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
await
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
86
|
+
// Issue #1795: read access to a private repo is enough to fork it
|
|
87
|
+
// when the upstream allows forking. Probe `allow_forking` before
|
|
88
|
+
// bailing out so users with limited (read-only) access can still
|
|
89
|
+
// proceed via their own fork.
|
|
90
|
+
const allowForking = await detectAllowForking(owner, repo);
|
|
91
|
+
if (allowForking === false) {
|
|
92
|
+
const permissionLevel = describeRepoPermissionLevel(permissions);
|
|
93
|
+
|
|
94
|
+
await log('');
|
|
95
|
+
await log("❌ --auto-fork failed: Repository is private, you don't have write access, and forking is disabled", { level: 'error' });
|
|
96
|
+
await log('');
|
|
97
|
+
await log(' 🔍 What happened:', { level: 'error' });
|
|
98
|
+
await log(` Repository ${owner}/${repo} is private`, { level: 'error' });
|
|
99
|
+
await log(` Your detected GitHub repository access level is ${permissionLevel}`, { level: 'error' });
|
|
100
|
+
await log(` API permissions: ${JSON.stringify(permissions)}`, { level: 'error' });
|
|
101
|
+
await log(' Direct branch mode requires push/write access, but permissions.push is false', { level: 'error' });
|
|
102
|
+
await log(" Fork mode is also unavailable because the repository owner disabled private forking ('allow_forking' is false)", {
|
|
103
|
+
level: 'error',
|
|
104
|
+
});
|
|
105
|
+
await log('');
|
|
106
|
+
await log(' 💡 Solution:', { level: 'error' });
|
|
107
|
+
await log(' • To let Hive Mind work directly in this repository:', { level: 'error' });
|
|
108
|
+
await log(` Ask an owner/admin to open https://github.com/${owner}/${repo}/settings/access`, { level: 'error' });
|
|
109
|
+
await log(' Then add this GitHub account or its team with the Write role (Maintain/Admin also works)', { level: 'error' });
|
|
110
|
+
await log(' • To let Hive Mind work through a fork instead:', { level: 'error' });
|
|
111
|
+
await log(` Ask an owner/admin to open https://github.com/${owner}/${repo}/settings`, { level: 'error' });
|
|
112
|
+
await log(' Then enable Settings -> General -> Features -> Allow forking', { level: 'error' });
|
|
113
|
+
await log(' For organization-owned private repositories, the organization must also allow private repository forks', {
|
|
114
|
+
level: 'error',
|
|
115
|
+
});
|
|
116
|
+
await log('');
|
|
117
|
+
await safeExit(1, 'Auto-fork failed - private repository without access and forking is disabled');
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (allowForking === true) {
|
|
122
|
+
await log('✅ Auto-fork: Read-only access to private repository, enabling fork mode (allow_forking=true)');
|
|
123
|
+
} else {
|
|
124
|
+
await log("✅ Auto-fork: Read-only access to private repository, attempting fork mode (allow_forking couldn't be confirmed)");
|
|
125
|
+
await log(" ⚠️ Could not determine 'allow_forking' for the private repository; letting gh repo fork report the exact result", {
|
|
126
|
+
verbose: true,
|
|
127
|
+
level: 'warning',
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
argv.fork = true;
|
|
67
132
|
return;
|
|
68
133
|
}
|
|
69
134
|
|