MCPcopy Index your code
hub / github.com/utterance/utterances / toggleReaction

Function toggleReaction

src/github.ts:235–255  ·  view source on GitHub ↗
(url: string, content: ReactionID)

Source from the content-addressed store, hash-verified

233}
234
235export async function toggleReaction(url: string, content: ReactionID) {
236 url = url.replace(GITHUB_API, '');
237 // We don't know if the reaction exists or not. Attempt to create it. If the GitHub
238 // API responds that the reaction already exists, delete it.
239 const body = JSON.stringify({ content });
240 const postRequest = githubRequest(url, { method: 'POST', body });
241 postRequest.headers.set('Accept', GITHUB_ENCODING__REST_V3);
242 const response = await githubFetch(postRequest);
243 const reaction: Reaction = response.ok ? await response.json() : null;
244 if (response.status === 201) { // reaction created.
245 return { reaction, deleted: false };
246 }
247 if (response.status !== 200) {
248 throw new Error('expected "201 reaction created" or "200 reaction already exists"');
249 }
250 // reaction already exists... delete.
251 const deleteRequest = githubRequest(`${url}/${reaction.id}`, { method: 'DELETE' });
252 deleteRequest.headers.set('Accept', GITHUB_ENCODING__REST_V3);
253 await githubFetch(deleteRequest);
254 return { reaction, deleted: true };
255}
256
257export function renderMarkdown(text: string) {
258 const body = JSON.stringify({ text, mode: 'gfm', context: `${owner}/${repo}` });

Callers 1

submitReactionFunction · 0.90

Calls 2

githubRequestFunction · 0.85
githubFetchFunction · 0.85

Tested by

no test coverage detected