generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 8
/
client.ts
69 lines (61 loc) · 1.61 KB
/
client.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import * as github from '@actions/github'
import {GitHub} from '@actions/github/lib/utils'
interface HideResponse {
data?: {
minimizeComment: {
minimizedComment: {
isMinimized: boolean
}
}
}
errors?: {
message: string
}[]
}
export class Client {
octokit: InstanceType<typeof GitHub>
issueNumber: number
owner: string
repo: string
constructor(
githubToken: string,
issueNumber?: number,
owner?: string,
repo?: string
) {
this.octokit = github.getOctokit(githubToken)
this.issueNumber =
issueNumber !== undefined ? issueNumber : github.context.issue.number
this.owner = owner !== undefined ? owner : github.context.repo.owner
this.repo = repo !== undefined ? repo : github.context.repo.repo
}
async SelectComments(userName: string): Promise<string[]> {
const resp = await this.octokit.rest.issues.listComments({
owner: this.owner,
repo: this.repo,
issue_number: this.issueNumber
})
const ids: string[] = []
for (const r of resp.data) {
if (r.user !== null && r.user.login !== userName) {
continue
}
ids.push(r.node_id)
}
return new Promise<string[]>(resolve => resolve(ids))
}
async HideComment(nodeID: string, reason: string): Promise<void> {
const resp: HideResponse = await this.octokit.graphql(`
mutation {
minimizeComment(input: {classifier: ${reason}, subjectId: "${nodeID}"}) {
minimizedComment {
isMinimized
}
}
}
`)
if (resp.errors) {
throw new Error(`${resp.errors[0].message}`)
}
}
}