|
1 | 1 | import { tool } from "@opencode-ai/plugin" |
2 | | -import { getJiraClient } from "./lib/jira-client" |
| 2 | +import { getJiraClient, resolveAccountIdByEmail } from "./lib/jira-client" |
3 | 3 |
|
4 | 4 | export default tool({ |
5 | 5 | description: |
6 | | - "Assign a Jira issue to a user by their accountId. Use jira-search-users to find the accountId for a user by display name or email. Pass empty string to unassign. Requires Jira credentials — see JIRA_SETUP.md.", |
| 6 | + "Assign a Jira issue to a user. Pass 'me' to assign to yourself (uses JIRA_EMAIL), a Jira accountId to assign to someone else, or empty string to unassign. Use jira-search-users to find accountIds by name or email. Requires Jira credentials — see JIRA_SETUP.md.", |
7 | 7 | args: { |
8 | 8 | issue_key: tool.schema.string().describe("Issue key, e.g. 'PROJ-123'"), |
9 | 9 | account_id: tool.schema |
10 | 10 | .string() |
11 | 11 | .describe( |
12 | | - "The Jira accountId of the user to assign. Use jira-search-users to find this. Pass empty string to unassign." |
| 12 | + "Pass 'me' to assign to yourself, a Jira accountId to assign to a specific user, or empty string to unassign." |
13 | 13 | ), |
14 | 14 | }, |
15 | 15 | async execute(args) { |
16 | 16 | const result = getJiraClient() |
17 | 17 | if ("error" in result) return result.error |
18 | | - const { client } = result |
| 18 | + const { client, currentUserEmail } = result |
19 | 19 |
|
20 | 20 | try { |
| 21 | + let accountId: string | null = args.account_id || null |
| 22 | + |
| 23 | + // Resolve "me" to the current user's accountId |
| 24 | + if (args.account_id === "me") { |
| 25 | + if (!currentUserEmail) { |
| 26 | + return "Cannot resolve 'me' — JIRA_EMAIL is not set." |
| 27 | + } |
| 28 | + accountId = await resolveAccountIdByEmail(client, currentUserEmail) |
| 29 | + if (!accountId) { |
| 30 | + return `Could not find a Jira account for ${currentUserEmail}. Check that this email matches a Jira user.` |
| 31 | + } |
| 32 | + } |
| 33 | + |
21 | 34 | await client.issues.assignIssue({ |
22 | 35 | issueIdOrKey: args.issue_key, |
23 | | - accountId: args.account_id || null, |
| 36 | + accountId, |
24 | 37 | }) |
25 | 38 |
|
26 | | - return args.account_id |
27 | | - ? `${args.issue_key} assigned to accountId ${args.account_id}` |
28 | | - : `${args.issue_key} unassigned` |
| 39 | + if (!accountId) return `${args.issue_key} unassigned` |
| 40 | + if (args.account_id === "me") return `${args.issue_key} assigned to you (${currentUserEmail})` |
| 41 | + return `${args.issue_key} assigned to accountId ${accountId}` |
29 | 42 | } catch (error: unknown) { |
30 | 43 | const e = error as { status?: number; message?: string } |
31 | 44 | return `Failed to assign ${args.issue_key}: ${e.status ?? ""} ${e.message ?? String(error)}` |
|
0 commit comments