eve-hub 0.16.24 → 0.16.25

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/prepare.mjs +22 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eve-hub",
3
- "version": "0.16.24",
3
+ "version": "0.16.25",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Bot-side code shared by every hub agent: registry tools, the roster hook, the eve channel, the host sandbox and browser, and model helpers.",
6
6
  "type": "module",
package/prepare.mjs CHANGED
@@ -77,17 +77,36 @@ const broker: GitHubLeaseBroker = async (sandbox, rules) => {
77
77
  // \`-R\` or \`gh repo clone|view|fork\` target differs from the declared repository, nor a \`git\`
78
78
  // remote outside it, so this does. \`authorize\` can't read the sandbox, so a remote name such as
79
79
  // \`origin\` can't be resolved: authenticated git names the declared repository's URL itself.
80
+ // \`repository\` may be null: eve's tool text tells bots to omit it for \`gh api user\`,
81
+ // \`gh repo list\` and \`gh search\`, and a user token isn't narrowed by it anyway.
80
82
  const GIT_REMOTE_COMMANDS = ["fetch", "ls-remote", "pull", "push"];
83
+ const GIT_GLOBAL_VALUE_OPTIONS = ["-C", "-c", "--git-dir", "--work-tree", "--namespace", "--config-env"];
84
+ const GIT_REMOTE_VALUE_OPTIONS = ["--depth", "--deepen", "--shallow-since", "--shallow-exclude", "--upload-pack", "--receive-pack", "--exec", "--refmap", "--negotiation-tip", "-o", "--push-option", "--server-option", "-j", "--jobs", "--filter", "--recurse-submodules-default"];
81
85
  const targets = (argv: readonly string[]) => [
82
86
  ...argv.flatMap((a, i) => (a === "--repo" || a === "-R" ? [argv[i + 1] ?? ""] : a.startsWith("--repo=") ? [a.slice(7)] : [])),
83
87
  ...(argv[0] === "gh" && argv[1] === "repo" && ["clone", "view", "fork"].includes(argv[2] ?? "") && argv[3] && !argv[3].startsWith("-") ? [argv[3]] : []),
84
88
  ];
85
89
  const GITHUB_URL = /^(?:https:\\/\\/github\\.com\\/|git@github\\.com:|ssh:\\/\\/git@github\\.com\\/)/i;
86
90
  const canonical = (repo: string) => repo.toLowerCase().replace(GITHUB_URL, "").replace(/\\/$/, "").replace(/\\.git$/, "");
91
+ const operands = (args: readonly string[], valued: readonly string[]) => {
92
+ const found: string[] = [];
93
+ for (let i = 0; i < args.length; i++) {
94
+ if (valued.includes(args[i])) i++;
95
+ else if (!args[i].startsWith("-")) found.push(args[i]);
96
+ }
97
+ return found;
98
+ };
99
+ const gitRemote = (argv: readonly string[]) => {
100
+ let i = 1;
101
+ while (argv[i]?.startsWith("-")) i += GIT_GLOBAL_VALUE_OPTIONS.includes(argv[i]) ? 2 : 1;
102
+ const remote = operands(argv.slice(i + 1), GIT_REMOTE_VALUE_OPTIONS)[0] ?? "";
103
+ return GIT_REMOTE_COMMANDS.includes(argv[i] ?? "") && GITHUB_URL.test(remote) ? [remote] : null;
104
+ };
87
105
  const commandTargets = (argv: readonly string[]) =>
88
- argv[0] === "git" ? (GIT_REMOTE_COMMANDS.includes(argv[1] ?? "") && GITHUB_URL.test(argv[2] ?? "") ? [argv[2]] : null)
106
+ argv[0] === "git" ? gitRemote(argv)
89
107
  : argv[0] === "gh-signed-commit" ? (targets(argv).length ? targets(argv) : null)
90
108
  : targets(argv);
109
+ const inOrg = (repo: string) => canonical(repo).startsWith(\`\${ORG}/\`);
91
110
 
92
111
  export default git({
93
112
  github: {
@@ -95,7 +114,8 @@ export default git({
95
114
  broker,
96
115
  authorize: ({ argv, repository }) => {
97
116
  const found = commandTargets(argv);
98
- return repository !== null && canonical(repository).startsWith(\`\${ORG}/\`) && found !== null && found.every((t) => canonical(t) === canonical(repository));
117
+ if (found === null || !found.every(inOrg)) return false;
118
+ return repository === null || (inOrg(repository) && found.every((t) => canonical(t) === canonical(repository)));
99
119
  },
100
120
  principalType: "user",
101
121
  },