This repository has been archived on 2026-11-17. You can view files and clone it, but cannot push or open issues or pull requests.
gitgram-ai/gitgram/web/services/githubService.ts
caelum0x 46bf9b83bf feat: round-5 external harvest (22 features ported from external/ into 5 products)
Harvest valuable features from external/ reference repos, adapted to each
product's stack and wired in; all products typecheck clean.

- gitgram-web (5): clickable @mention/#hashtag linkify in rendered content
  (munia), + feed/notification/accessibility patterns; install @testing-library/dom
- gitgram-backend (3): feed thread dedup + muted-thread removal (bluesky),
  GitHub star/follow write-back via OAuth (gh-social)
- gitgram-mobile (4): double-tap-to-like + heart bounce (proximity), haptics layer
  (bluesky useHaptics), + gesture/feed UX
- aitm-api (4): beads ready/dependency-DAG endpoints + atomic claim (beads)
- aitm-mcp (6): beads_ready work-queue tool, context-efficient projections,
  transport arg aliasing (context7/pal-mcp/beads)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-28 18:48:46 +03:00

118 lines
3.7 KiB
TypeScript

import api from './api'
// ---------------------------------------------------------------------------
// Write-back result envelope
// ---------------------------------------------------------------------------
/**
* Result of a GitHub write-back action proxied through the backend. The backend
* uses the user's stored OAuth token (scope `repo,read:user`, requested in
* connectGitHub) to call the GitHub REST API on their behalf.
*/
export interface GitHubActionResult {
success: boolean
/** New state after the action: true if now starred / following. */
active: boolean
message?: string
}
export interface GitHubStarStatus {
starred: boolean
}
export interface GitHubFollowStatus {
following: boolean
}
export const githubService = {
connectGitHub: () => {
const clientId = process.env.NEXT_PUBLIC_GITHUB_CLIENT_ID
const redirectUri = `${window.location.origin}/auth/github/callback`
window.location.href = `https://github.com/login/oauth/authorize?client_id=${clientId}&redirect_uri=${redirectUri}&scope=user:email,repo,read:user`
},
syncProjects: async () => {
const { data } = await api.post('/github/sync')
return data
},
getProjects: async () => {
const { data } = await api.get('/github/projects')
return data
},
getProject: async (owner: string, repo: string) => {
const { data } = await api.get(`/github/projects/${owner}/${repo}`)
return data
},
claimAccount: async (githubUsername: string) => {
const { data } = await api.post('/github/claim', { githubUsername })
return data
},
disconnectGitHub: async () => {
const { data } = await api.delete('/github/disconnect')
return data
},
searchProjects: async (query: string, page = 1, limit = 20) => {
const { data } = await api.get('/github/search', { params: { q: query, page, limit } })
return data
},
getSavedProjects: async (page = 1, limit = 20) => {
const { data } = await api.get('/github/saved', { params: { page, limit } })
return data
},
syncProject: async (repoName: string, owner: string) => {
const { data } = await api.post('/github/sync-project', { repoName, owner })
return data
},
// -------------------------------------------------------------------------
// GitHub write-back (star / follow) — proxied through the backend, which
// holds the user's OAuth token. Mirrors gh-social's starAction/followAction.
// `repoName` is the `owner/repo` full name.
// -------------------------------------------------------------------------
hasStarredRepo: async (repoName: string): Promise<boolean> => {
const { data } = await api.get<GitHubStarStatus>('/github/starred', {
params: { repo: repoName },
})
return Boolean(data?.starred)
},
starRepo: async (repoName: string): Promise<GitHubActionResult> => {
const { data } = await api.put<GitHubActionResult>('/github/star', { repo: repoName })
return data
},
unstarRepo: async (repoName: string): Promise<GitHubActionResult> => {
const { data } = await api.delete<GitHubActionResult>('/github/star', {
data: { repo: repoName },
})
return data
},
isFollowingOnGitHub: async (username: string): Promise<boolean> => {
const { data } = await api.get<GitHubFollowStatus>('/github/following', {
params: { username },
})
return Boolean(data?.following)
},
followOnGitHub: async (username: string): Promise<GitHubActionResult> => {
const { data } = await api.put<GitHubActionResult>('/github/follow', { username })
return data
},
unfollowOnGitHub: async (username: string): Promise<GitHubActionResult> => {
const { data } = await api.delete<GitHubActionResult>('/github/follow', {
data: { username },
})
return data
},
}