-
Notifications
You must be signed in to change notification settings - Fork 0
feat: view Support tickets and tighten submissions #11
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
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
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,103 @@ | ||
| import { defineCommand } from "citty"; | ||
| import { loadAuth } from "../../lib/auth.ts"; | ||
| import { | ||
| SupportSession, | ||
| type SupportTicketDetails, | ||
| } from "../../lib/support.ts"; | ||
| import { | ||
| getOutputFormat, | ||
| printOutput, | ||
| type OutputFormat, | ||
| } from "../../lib/output.ts"; | ||
|
|
||
| function ticketOutput(ticket: SupportTicketDetails, account: string | undefined) { | ||
| return { | ||
| ticket: ticket.ticketId, | ||
| subject: ticket.subject, | ||
| status: ticket.status, | ||
| account: account ?? ticket.author, | ||
| scope: ticket.scope, | ||
| created_at: ticket.createdAt, | ||
| author: ticket.author, | ||
| body: ticket.body, | ||
| comments: ticket.comments.map((comment) => ({ | ||
| id: comment.id, | ||
| author: comment.author, | ||
| created_at: comment.createdAt, | ||
| body: comment.body, | ||
| })), | ||
| }; | ||
| } | ||
|
|
||
| function printTicket( | ||
| ticket: SupportTicketDetails, | ||
| account: string | undefined, | ||
| format: OutputFormat, | ||
| ): void { | ||
| const output = ticketOutput(ticket, account); | ||
| if (format === "json") { | ||
| printOutput(output, format); | ||
| return; | ||
| } | ||
|
|
||
| printOutput( | ||
| { | ||
| ticket: output.ticket, | ||
| subject: output.subject, | ||
| status: output.status, | ||
| account: output.account, | ||
| scope: output.scope, | ||
| created_at: output.created_at, | ||
| comments: output.comments.length, | ||
| }, | ||
| format, | ||
| ); | ||
| console.log(`\nBody — ${output.author}\n\n${output.body}`); | ||
| if (output.comments.length === 0) return; | ||
|
|
||
| console.log("\nComments"); | ||
| for (const [index, comment] of output.comments.entries()) { | ||
| console.log( | ||
| `\n${index + 1}. ${comment.author} · ${comment.created_at} · ${comment.id}\n\n${comment.body}`, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| export const supportViewCommand = defineCommand({ | ||
| meta: { | ||
| name: "view", | ||
| description: "Show a GitHub Support ticket and its comments", | ||
| }, | ||
| args: { | ||
| ticket: { | ||
| type: "positional", | ||
| description: "Ticket number, for example 1234567", | ||
| required: true, | ||
| }, | ||
| scope: { | ||
| type: "string", | ||
| description: | ||
| "Ticket scope such as 'personal/0'; defaults to searching every accessible scope", | ||
| }, | ||
| output: { | ||
| type: "string", | ||
| description: "Output format: json | table (default: table)", | ||
| default: "table", | ||
| }, | ||
| }, | ||
| async run({ args }) { | ||
| const ticket = String(args.ticket).replace(/^#/, ""); | ||
| if (!/^\d+$/.test(ticket)) { | ||
| throw new Error(`"${args.ticket}" is not a ticket number.`); | ||
| } | ||
|
|
||
| const auth = await loadAuth(); | ||
| const session = new SupportSession(auth); | ||
| await session.login(); | ||
| const scopes = args.scope | ||
| ? [args.scope.replace(/^\/?(tickets\/)?/, "")] | ||
| : ["personal/0", ...(await session.ticketScopes())]; | ||
| const details = await session.viewTicket(ticket, [...new Set(scopes)]); | ||
| printTicket(details, auth.account, getOutputFormat(args.output)); | ||
| }, | ||
| }); | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: The JSON and table
accountfield is populated from the authenticated GitHub login, which is not necessarily the Support account represented by the ticket. Organization tickets will consequently report the viewer's login instead of the ticket account; derive this value from the parsed scope or expose the authenticated identity under a separate field. [api mismatch]Severity Level: Major⚠️
(Use Cmd/Ctrl + Click for best experience)
Prompt for AI Agent 🤖