Blame · Line-by-line history
issues.ts
Each line is annotated with the commit that last touched it. Click any SHA to jump to that commit and see the surrounding change.
| 9989d86 | 1 | import { fetchJSON, postJSON } from './client'; |
| 2 | ||
| 3 | export interface Label { | |
| 4 | id: number; | |
| 5 | name: string; | |
| 6 | color: string; | |
| 7 | description: string | null; | |
| 8 | } | |
| 9 | ||
| 10 | export interface Issue { | |
| 11 | id: number; | |
| 12 | number: number; | |
| 13 | title: string; | |
| 14 | body: string | null; | |
| 15 | state: 'open' | 'closed'; | |
| 16 | authorUsername: string; | |
| 17 | authorAvatarUrl: string | null; | |
| 18 | labels: Label[]; | |
| 19 | commentCount: number; | |
| 20 | createdAt: string; | |
| 21 | updatedAt: string; | |
| 22 | closedAt: string | null; | |
| 23 | } | |
| 24 | ||
| 25 | export interface IssueComment { | |
| 26 | id: number; | |
| 27 | body: string; | |
| 28 | authorUsername: string; | |
| 29 | authorAvatarUrl: string | null; | |
| 30 | createdAt: string; | |
| 31 | updatedAt: string; | |
| 32 | } | |
| 33 | ||
| 34 | export interface CreateIssueInput { | |
| 35 | title: string; | |
| 36 | body?: string; | |
| 37 | labelIds?: number[]; | |
| 38 | } | |
| 39 | ||
| 40 | export interface CreateCommentInput { | |
| 41 | body: string; | |
| 42 | } | |
| 43 | ||
| 44 | /** List issues for a repository. */ | |
| 45 | export async function listIssues( | |
| 46 | owner: string, | |
| 47 | repo: string, | |
| 48 | state: 'open' | 'closed' | 'all' = 'open', | |
| 49 | page = 1, | |
| 50 | ): Promise<Issue[]> { | |
| 51 | return fetchJSON<Issue[]>( | |
| 52 | `/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/issues?state=${state}&page=${page}&json=1`, | |
| 53 | ); | |
| 54 | } | |
| 55 | ||
| 56 | /** Get a single issue with comments. */ | |
| 57 | export async function getIssue( | |
| 58 | owner: string, | |
| 59 | repo: string, | |
| 60 | number: number, | |
| 61 | ): Promise<Issue> { | |
| 62 | return fetchJSON<Issue>( | |
| 63 | `/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/issues/${number}?json=1`, | |
| 64 | ); | |
| 65 | } | |
| 66 | ||
| 67 | /** Get comments for an issue. */ | |
| 68 | export async function getIssueComments( | |
| 69 | owner: string, | |
| 70 | repo: string, | |
| 71 | number: number, | |
| 72 | ): Promise<IssueComment[]> { | |
| 73 | return fetchJSON<IssueComment[]>( | |
| 74 | `/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/issues/${number}/comments?json=1`, | |
| 75 | ); | |
| 76 | } | |
| 77 | ||
| 78 | /** Create a new issue. */ | |
| 79 | export async function createIssue( | |
| 80 | owner: string, | |
| 81 | repo: string, | |
| 82 | input: CreateIssueInput, | |
| 83 | ): Promise<Issue> { | |
| 84 | return postJSON<Issue>( | |
| 85 | `/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/issues`, | |
| 86 | input, | |
| 87 | ); | |
| 88 | } | |
| 89 | ||
| 90 | /** Post a comment on an issue. */ | |
| 91 | export async function createIssueComment( | |
| 92 | owner: string, | |
| 93 | repo: string, | |
| 94 | number: number, | |
| 95 | input: CreateCommentInput, | |
| 96 | ): Promise<IssueComment> { | |
| 97 | return postJSON<IssueComment>( | |
| 98 | `/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/issues/${number}/comments`, | |
| 99 | input, | |
| 100 | ); | |
| 101 | } | |
| 102 | ||
| 103 | /** Close an issue. */ | |
| 104 | export async function closeIssue( | |
| 105 | owner: string, | |
| 106 | repo: string, | |
| 107 | number: number, | |
| 108 | ): Promise<Issue> { | |
| 109 | return postJSON<Issue>( | |
| 110 | `/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/issues/${number}/close`, | |
| 111 | {}, | |
| 112 | ); | |
| 113 | } | |
| 114 | ||
| 115 | /** Reopen a closed issue. */ | |
| 116 | export async function reopenIssue( | |
| 117 | owner: string, | |
| 118 | repo: string, | |
| 119 | number: number, | |
| 120 | ): Promise<Issue> { | |
| 121 | return postJSON<Issue>( | |
| 122 | `/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/issues/${number}/reopen`, | |
| 123 | {}, | |
| 124 | ); | |
| 125 | } | |
| 126 | ||
| 127 | /** List labels for a repository. */ | |
| 128 | export async function listLabels(owner: string, repo: string): Promise<Label[]> { | |
| 129 | return fetchJSON<Label[]>( | |
| 130 | `/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/labels?json=1`, | |
| 131 | ); | |
| 132 | } |