Lists every active subscription of the caller, following pagination links.
()
| 52 | |
| 53 | /** Lists every active subscription of the caller, following pagination links. */ |
| 54 | async subscriptions(): Promise<Subscription[]> { |
| 55 | const all: Subscription[] = []; |
| 56 | let path: string | undefined = "/event-subscriptions?per_page=100"; |
| 57 | for (let pages = 0; path; pages++) { |
| 58 | // The API lists at most twice an owner's limit, so this many pages means the links are looping. |
| 59 | if (pages >= 10) throw new Error("Event subscription listing did not end"); |
| 60 | if (!/^\/event-subscriptions\?/.test(path)) throw new Error("Unexpected event subscription pagination link"); |
| 61 | const page: { body: unknown; next?: string } = await this.page<unknown>("GET", path); |
| 62 | const body = record(page.body); |
| 63 | if (!Array.isArray(body.subscriptions) || body.subscriptions.length > 100) { |
| 64 | throw new Error("Invalid event subscription listing"); |
| 65 | } |
| 66 | all.push(...body.subscriptions.map(value => { |
| 67 | const subscription = record(value); |
| 68 | if (typeof subscription.id !== "string" || !/^sub_[A-Za-z0-9]+$/.test(subscription.id) |
| 69 | || typeof subscription.resource_url !== "string" |
| 70 | || !Array.isArray(subscription.event_types) |
| 71 | || !subscription.event_types.every(type => typeof type === "string")) { |
| 72 | throw new Error("Invalid event subscription listing"); |
| 73 | } |
| 74 | return { |
| 75 | id: subscription.id, |
| 76 | resource_url: subscription.resource_url, |
| 77 | event_types: subscription.event_types, |
| 78 | }; |
| 79 | })); |
| 80 | path = page.next; |
| 81 | } |
| 82 | return all; |
| 83 | } |
| 84 | |
| 85 | greeting(repo: string, ref: string): Promise<string> { |
| 86 | return this.fileContent(repo, "greeting.txt", ref); |
no test coverage detected