Skip to content
Open
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
8 changes: 8 additions & 0 deletions .changeset/forge-set-assignee.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@bradygaster/squad-sdk": minor
"@bradygaster/squad-cli": patch
---

feat(platform): add `setAssignee()` to PlatformAdapter so assignee changes route through the platform abstraction (GitHub + ADO) instead of inline `gh`/`az` calls

`GitHubAdapter.setAssignee` uses `gh issue edit --add/--remove-assignee`; `AzureDevOpsAdapter.setAssignee` sets `System.AssignedTo`. The watch command's `editWorkItem` now delegates assignee operations to the adapter, removing the hardcoded GitHub-vs-ADO branch.
1 change: 1 addition & 0 deletions packages/squad-cli/src/cli/commands/loop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ function createNoopAdapter(): ReturnType<typeof createPlatformAdapter> {
addTag: async () => {},
removeTag: async () => {},
addComment: async () => {},
setAssignee: async () => {},
listPullRequests: async () => [],
createPullRequest: async () => { throw new Error(msg); },
mergePullRequest: async () => {},
Expand Down
28 changes: 10 additions & 18 deletions packages/squad-cli/src/cli/commands/watch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,28 +136,20 @@ async function listWatchPullRequests(
async function editWorkItem(
adapter: PlatformAdapter,
id: number,
options: { addLabel?: string; removeLabel?: string; addAssignee?: string; removeAssignee?: string },
options: { addLabel?: string; removeLabel?: string; addAssignee?: string; removeAssignee?: boolean },
): Promise<void> {
if (options.addLabel) await adapter.addTag(id, options.addLabel);
if (options.removeLabel) await adapter.removeTag(id, options.removeLabel);
if (options.addAssignee) {
if (adapter.type === 'github') {
try {
await execFileAsync('gh', ['issue', 'edit', String(id), '--add-assignee', options.addAssignee]);
} catch { /* best-effort */ }
} else if (adapter.type === 'azure-devops') {
const assignee = options.addAssignee === '@me' ? '' : options.addAssignee;
if (assignee) {
try {
execFileSync(azCmd, [
'boards', 'work-item', 'update',
'--id', String(id),
'--fields', `System.AssignedTo=${assignee}`,
'--output', 'json',
], { encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'], ...azExecOpts });
} catch { /* best-effort */ }
}
}
try {
await adapter.setAssignee(id, options.addAssignee);
} catch { /* best-effort */ }
}
if (options.removeAssignee) {
try {
// setAssignee(undefined) unassigns the current assignee on both platforms.
await adapter.setAssignee(id, undefined);
} catch { /* best-effort */ }
}
}

Expand Down
11 changes: 11 additions & 0 deletions packages/squad-sdk/src/platform/azure-devops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,17 @@ export class AzureDevOpsAdapter implements PlatformAdapter {
]);
}

async setAssignee(workItemId: number, assignee: string | undefined): Promise<void> {
// ADO has no '@me' token; the az CLI can't resolve current user, so skip it
// (matches prior behavior). undefined/empty unassigns; a name assigns.
if (assignee === '@me') return;
const value = assignee ?? '';
this.az([
'boards', 'work-item', 'update', '--id', String(workItemId),
'--fields', `System.AssignedTo=${value}`, ...this.workItemArgs, '--output', 'json',
]);
}

async listPullRequests(options: { status?: string; limit?: number }): Promise<PullRequest[]> {
const args = [
'repos', 'pr', 'list',
Expand Down
13 changes: 13 additions & 0 deletions packages/squad-sdk/src/platform/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,19 @@ export class GitHubAdapter implements PlatformAdapter {
this.gh(['issue', 'comment', String(workItemId), '--repo', this.repoFlag, '--body', comment]);
}

async setAssignee(workItemId: number, assignee: string | undefined): Promise<void> {
const args = ['issue', 'edit', String(workItemId), '--repo', this.repoFlag];
if (assignee) {
args.push('--add-assignee', assignee);
} else {
// Unassign: remove the current assignee (if any).
const wi = await this.getWorkItem(workItemId);
if (!wi.assignedTo) return;
args.push('--remove-assignee', wi.assignedTo);
}
this.gh(args);
}

async listPullRequests(options: { status?: string; limit?: number }): Promise<PullRequest[]> {
const args = ['pr', 'list', '--repo', this.repoFlag, '--json', 'number,title,headRefName,baseRefName,state,isDraft,reviewDecision,author,url'];
if (options.status) args.push('--state', mapStatusToGhState(options.status));
Expand Down
5 changes: 5 additions & 0 deletions packages/squad-sdk/src/platform/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ export interface PlatformAdapter {
addTag(workItemId: number, tag: string): Promise<void>;
removeTag(workItemId: number, tag: string): Promise<void>;
addComment(workItemId: number, comment: string): Promise<void>;
/**
* Assign a work item to a user. Pass undefined/empty to unassign the current assignee.
* '@me' assigns the current user on GitHub; the ADO adapter cannot resolve '@me' and skips it (no-op).
*/
setAssignee(workItemId: number, assignee: string | undefined): Promise<void>;

/** Ensure a tag/label exists (creates it if missing). No-op on platforms with auto-created tags. */
ensureTag?(tag: string, options?: { color?: string; description?: string }): Promise<void>;
Expand Down
Loading