Repository navigation
feat(cli): resolve acting org from local git remotes #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
43dff09
feat(cli): resolve acting org from local git remotes
theCodeDrift bb52b31
refactor(cli): align canonicalOwnerUrl with the shared server algorithm
theCodeDrift f6eaf56
chore(cli): regenerate API types and derive WhoamiOrg from the schema
theCodeDrift 79ba8c8
feat(cli): send the resolved org subject on write calls
theCodeDrift 453efcf
fix(cli): keep every url of a precedence remote in owner resolution
theCodeDrift File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| --- | ||
| "@taskless/cli": minor | ||
| --- | ||
|
|
||
| Send the acting organization's identity on every write request. The CLI now resolves which Taskless org owns the current repository by matching the repo's git remotes (`origin` → `upstream` → rest) against the canonical owner URLs returned by `whoami`, and sends that org's Taskless UUID as the subject on rule generation, iterate, and reconcile calls. This fixes multi-org users being routed to whichever org their token happened to pin; the server authorizes the chosen org per request. When no remote matches a known org, the CLI falls back to the token's numeric `orgId` claim, so single-org behavior is unchanged. | ||
|
|
||
| The client-side owner-URL canonicalizer is a verbatim port of the server's shared implementation, so both sides compare by exact string equality across SSH, `ssh://`/`git://`, port, and `www.` remote forms. | ||
|
|
||
| `rule create`/`rule improve` now handle two additional generation states: `classifying` (a transient pre-build phase) and `unsupported`, a terminal state emitted when the request needs a capability the organization's plan doesn't include (for example, runtime rules) — surfaced with a clear message and the new `RULE_UNSUPPORTED` error code. When the server can't act on a repository for the selected org (its GitHub App installation doesn't cover the repo, or membership changed), the CLI now explains the coverage cause rather than only suggesting re-authentication. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import type { paths } from "../generated/api"; | ||
| import { decodeOrgId } from "./jwt"; | ||
| import { fetchWhoami } from "./whoami"; | ||
| import { listRemoteOwnerUrls } from "../util/git-remote"; | ||
|
|
||
| type WhoamiData = | ||
| paths["/cli/api/whoami"]["get"]["responses"]["200"]["content"]["application/json"]; | ||
|
|
||
| /** | ||
| * One organization from `GET /cli/api/whoami`, derived from the generated | ||
| * OpenAPI schema. `orgId` is the numeric GitHub org id; `id` is the Taskless | ||
| * org UUID — the subject the CLI acts as on write calls; `url` is the canonical | ||
| * OWNER url (e.g. `https://github.com/acme`) matched against the repo's remotes. | ||
| */ | ||
| export type WhoamiOrg = WhoamiData["orgs"][number]; | ||
|
|
||
| /** | ||
| * Pick the acting org from a whoami org list given the repo's owner urls (in | ||
| * `origin` → `upstream` → rest precedence). Exact `url` equality against | ||
| * GitHub-sourced orgs; the first remote that matches an org wins. Returns | ||
| * `undefined` when nothing matches (no current-org context). | ||
| */ | ||
| export function selectOrgForOwners( | ||
| ownerUrls: string[], | ||
| orgs: WhoamiOrg[] | ||
| ): WhoamiOrg | undefined { | ||
| const byUrl = new Map( | ||
| orgs.filter((org) => org.source === "github").map((org) => [org.url, org]) | ||
| ); | ||
| for (const ownerUrl of ownerUrls) { | ||
| const org = byUrl.get(ownerUrl); | ||
| if (org) return org; | ||
| } | ||
| return undefined; | ||
| } | ||
|
|
||
| /** | ||
| * Resolve which org the CLI acts as for the repo at `cwd`: match the repo's | ||
| * local git remotes against `orgs[].url`. Returns `undefined` when there is no | ||
| * GitHub remote or no org owns it — the caller then has no current-org context | ||
| * (and any write it attempts is authorized, and may be denied, server-side). | ||
| */ | ||
| export async function resolveCurrentOrg( | ||
| cwd: string, | ||
| orgs: WhoamiOrg[] | ||
| ): Promise<WhoamiOrg | undefined> { | ||
| const ownerUrls = await listRemoteOwnerUrls(cwd); | ||
| return selectOrgForOwners(ownerUrls, orgs); | ||
| } | ||
|
|
||
| /** | ||
| * The org subject to send on write calls. Prefers the current org's Taskless | ||
| * UUID (`id`), resolved by matching the repo's remotes against `whoami`; falls | ||
| * back to the deprecated numeric `orgId` claim in the token when whoami is | ||
| * unavailable or no org owns the repo. A new client thus routes multi-org users | ||
| * correctly, while older single-org behaviour is preserved via the claim. | ||
| * | ||
| * Returns `undefined` only when there is neither a matched org nor a claim | ||
| * (a broken or pre-org token) — the caller has no subject to send. | ||
| */ | ||
| export async function resolveOrgSubject( | ||
| cwd: string, | ||
| token: string | ||
| ): Promise<string | number | undefined> { | ||
| const whoami = await fetchWhoami(token); | ||
| if (whoami && whoami.orgs.length > 0) { | ||
| const org = await resolveCurrentOrg(cwd, whoami.orgs); | ||
| if (org) return org.id; | ||
| } | ||
| return decodeOrgId(token); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.