MCPcopy Create free account
hub / github.com/SIMARSINGHRAYAT/Gitzo / createDiscussion

Function createDiscussion

src/utils/github.ts:685–729  ·  view source on GitHub ↗
(
  token: string,
  repoNodeId: string,
  categoryId: string,
  title: string,
  body: string
)

Source from the content-addressed store, hash-verified

683 repo: string,
684 branchName: string
685): Promise<boolean> {
686 try {
687 const res = await ghFetch(
688 `/repos/${owner}/${repo}/git/refs/heads/${encodeURIComponent(branchName)}`,
689 token,
690 { method: 'DELETE' }
691 );
692 return res.ok || res.status === 422;
693 } catch {
694 return false;
695 }
696}
697
698// ══════════════════════════════════════════════════════════════════════
699// ── Galaxy Brain (GitHub Discussions via GraphQL API) ──
700// ══════════════════════════════════════════════════════════════════════
701
702/**
703 * Execute a GitHub GraphQL query/mutation.
704 */
705export async function ghGraphQL(
706 token: string,
707 query: string,
708 variables?: Record<string, unknown>
709): Promise<{ data?: Record<string, unknown>; errors?: Array<{ message: string; type?: string }> }> {
710 try {
711 const res = await fetch('https://api.github.com/graphql', {
712 method: 'POST',
713 headers: {
714 Authorization: `bearer ${token}`,
715 'Content-Type': 'application/json',
716 'X-GitHub-Api-Version': API_VERSION,
717 },
718 body: JSON.stringify({ query, variables }),
719 });
720 if (!res.ok) {
721 const errBody = await res.text().catch(() => res.statusText);
722 if (res.status === 401)
723 throw new Error('PERMISSION_DENIED: Token expired or invalid (401 Unauthorized)');
724 if (res.status === 403)
725 throw new Error(`PERMISSION_DENIED: ${errBody}`);
726 throw new Error(`GraphQL request failed (HTTP ${res.status}): ${errBody}`);
727 }
728 return res.json();
729 } catch (err) {
730 if (err instanceof Error && (err.message.includes('PERMISSION_DENIED') || err.message.includes('RATE_LIMITED'))) throw err;
731 const message = err instanceof Error ? err.message : 'Network request failed';
732 throw new Error(`NETWORK_ERROR: ${message}`);

Callers

nothing calls this directly

Calls 1

ghGraphQLFunction · 0.85

Tested by

no test coverage detected