| 124 | } |
| 125 | |
| 126 | async function updateSubscription(targetStatus: SubscriptionStatus, id: string): Promise<void> { |
| 127 | const response = await fetch('/_graphql', { |
| 128 | headers: githubApiBaseHeaders, |
| 129 | method: 'POST', |
| 130 | body: JSON.stringify({ |
| 131 | // `updateIssueSubscriptionMutation` |
| 132 | query: 'd0752b2e49295017f67c84f21bfe41a3', |
| 133 | variables: { |
| 134 | input: { |
| 135 | events: targetStatus === 'status' ? ['CLOSED', 'REOPENED'] : [], |
| 136 | state: targetStatus === 'status' ? 'CUSTOM' : targetStatus === 'all' ? 'SUBSCRIBED' : 'UNSUBSCRIBED', |
| 137 | subscribableId: id, |
| 138 | }, |
| 139 | }, |
| 140 | }), |
| 141 | }); |
| 142 | if (!response.ok) { |
| 143 | throw new Error('Failed to update the issue subscription status'); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | async function addButton(subscriptionButton: HTMLButtonElement): Promise<void> { |
| 148 | const previousRghButton = $optional('.rgh-status-subscription', subscriptionButton.parentElement!); |