Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/commands/linear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,16 @@ async function renderHelp(input: {
});
return;
}
await display.panel({
title: "Linear routing model",
tone: "info",
lines: [
"Profiles are global Linear auth identities.",
"Repos can bind a default Linear project route plus optional linked projects.",
"When you omit --profile, Hack prefers the repo binding first and then the global default profile.",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Correct the help text about repo-vs-global profile precedence

For repos that bind only a default project/team and do not set controlPlane.routing.overrides.linear.profile, this sentence is inaccurate. resolveLinearProfileSelection() in src/control-plane/extensions/linear/auth.ts:785-799 only prefers the repo-level profile override; otherwise it falls back to the global default profile. As written, the new help text implies any repo binding wins, which can send users debugging the wrong setting and lead them to run syncs against the wrong Linear account.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok can you put up a pr to fix this please

"Use `hack linear status` to see the active profile, default project, team, linked projects, and recovery steps.",
],
});
await display.table({
columns: ["Command", "Summary"],
rows: input.commands.map((cmd) => [`hack linear ${cmd.name}`, cmd.summary]),
Expand Down
14 changes: 13 additions & 1 deletion src/control-plane/extensions/linear/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,24 @@ export function resolveLinearAuthSettingsResult(input: {
availableProfileIds.length > 0
? availableProfileIds.join(", ")
: "(none configured)";
const fixLabel = (() => {
if (selected.selectedProfileSource === "command_flags") {
return `Use one of the available profiles with \`--profile <id>\`, or run \`hack linear connect --profile ${selected.selectedProfileId}\` to create it.`;
}
if (selected.selectedProfileSource === "project_routing") {
return `Update the repo route with \`hack linear setup --profile <id>\` or connect the missing profile with \`hack linear connect --profile ${selected.selectedProfileId}\`.`;
}
if (selected.selectedProfileSource === "global_default") {
return `Switch the global default with \`hack linear use --profile <id>\` or connect the missing profile with \`hack linear connect --profile ${selected.selectedProfileId}\`.`;
}
return `Connect a profile with \`hack linear connect --profile ${selected.selectedProfileId}\` or choose one with \`hack linear use --profile <id>\`.`;
})();
return {
ok: false,
selectedProfileId: selected.selectedProfileId,
selectedProfileSource: selected.selectedProfileSource,
availableProfileIds,
error: `Linear profile "${selected.selectedProfileId}" (${sourceLabel}) was not found. Available profiles: ${availableLabel}.`,
error: `Linear profile "${selected.selectedProfileId}" (${sourceLabel}) was not found. Available profiles: ${availableLabel}. ${fixLabel}`,
};
}

Expand Down
41 changes: 37 additions & 4 deletions src/control-plane/extensions/linear/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2187,9 +2187,16 @@ async function renderLinearStatusPayload(input: {
readonly payload: LinearStatusCommandPayload;
readonly logger: ExtensionCommandContext["logger"];
}): Promise<void> {
const bindingSummary = describeLinearBindingState({
binding: input.payload.projectBinding,
});
const lines = [
`Active profile: ${input.payload.summary.activeProfile}`,
`Connection: ${input.payload.summary.connectionLabel}`,
`Repo binding profile: ${bindingSummary.profile}`,
`Default project: ${bindingSummary.project}`,
`Default team: ${bindingSummary.team}`,
`Linked projects: ${bindingSummary.linkedProjects}`,
`Route: ${input.payload.summary.routingSummary}`,
...(input.payload.summary.linkedProjectsLabel
? [input.payload.summary.linkedProjectsLabel]
Expand Down Expand Up @@ -5230,8 +5237,7 @@ async function resolveLinearTargetForTicketSync(input: {
if (!teamId) {
return {
ok: false,
error:
"Cannot resolve Linear team for ticket sync. Pass --team-id or bind a project with `hack x linear project-bind`.",
error: `Cannot resolve Linear team for ticket sync. Active route project: ${projectId ?? "(none)"}. Pass --team-id, or bind a default project/team with \`hack linear project-bind --project-id <linear-project-id> --team-id <linear-team-id>\`.`,
};
}

Expand Down Expand Up @@ -7010,6 +7016,33 @@ function buildLinearRoutingSummary(input: {
})}.`;
}

function describeLinearBindingState(input: {
readonly binding:
| ResolvedLinearProjectBinding
| LinearStatusCommandPayload["projectBinding"];
}): {
readonly profile: string;
readonly project: string;
readonly team: string;
readonly linkedProjects: string;
} {
const defaultProject = input.binding.projectId
? formatLinearProjectTarget({
projectId: input.binding.projectId,
...(input.binding.projectName
? { projectName: input.binding.projectName }
: {}),
...(input.binding.teamId ? { teamId: input.binding.teamId } : {}),
})
: "(none)";
return {
profile: readOptionalString(input.binding.profileId) ?? "(none)",
project: defaultProject,
team: readOptionalString(input.binding.teamId) ?? "(none)",
linkedProjects: String(input.binding.additionalProjects.length),
};
}

function buildLinkedProjectsLabel(input: {
readonly binding: ResolvedLinearProjectBinding;
}): string | null {
Expand Down Expand Up @@ -7572,7 +7605,7 @@ function describeAmbiguousProjectArtifactTarget(input: {
input.projectName ? `project name "${input.projectName}"` : null,
input.teamId ? `team id "${input.teamId}"` : null,
].filter((part): part is string => Boolean(part));
return `Multiple ${input.source} Linear projects match ${parts.join(" and ")}. Pass --project-id to disambiguate.`;
return `Multiple ${input.source} Linear projects match ${parts.join(" and ")}. Pass --project-id to disambiguate, then confirm the repo route with \`hack linear status\`.`;
}

function describeMissingProjectArtifactTarget(input: {
Expand All @@ -7583,7 +7616,7 @@ function describeMissingProjectArtifactTarget(input: {
input.projectName ? `project name "${input.projectName}"` : null,
input.teamId ? `team id "${input.teamId}"` : null,
].filter((part): part is string => Boolean(part));
return `No Linear project matches ${parts.join(" and ")}. Pass --project-id or update the project binding.`;
return `No Linear project matches ${parts.join(" and ")}. Pass --project-id, run \`hack linear projects\` to inspect available projects, or update the repo binding with \`hack linear project-bind --project-id <linear-project-id>\`.`;
}

async function resolveProjectBindingDetails(input: {
Expand Down
Loading