[READ-ONLY] Mirror of https://github.com/probablykasper/starchart. GitHub star history graph starchart.kasper.space
chart github github-api github-star graph history star star-history stargazers stars
0

Configure Feed

Select the types of activity you want to include in your feed.

Remove rest api stuff

Kasper (May 14, 2025, 9:05 AM +0200) b663c1b0 b04c7342

+6 -147
+6 -63
src/routes/+page.svelte
··· 1 1 <script lang="ts"> 2 2 import { fly, slide } from 'svelte/transition' 3 - import { errors, fetch_stargazers_rest, RepoStars } from './github' 3 + import { errors, RepoStars } from './github' 4 4 import { onMount, tick } from 'svelte' 5 5 import '../app.sass' 6 6 import Nav from './Nav.svelte' ··· 13 13 let [owner, repo] = ['', ''] 14 14 15 15 let chart: Chart | undefined 16 - 17 - // async function get_stargazers(owner: string, repo: string) { 18 - // if (!chart || !$chart) { 19 - // errors.push('Chart not initialized') 20 - // return 21 - // } 22 - // for (const line of $chart.lines) { 23 - // if (line.name === `${owner}/${repo}`) { 24 - // return // already added 25 - // } 26 - // } 27 - // let count = 0 28 - // let next_page: number | null = 1 29 - // const line = chart.addLine({ 30 - // name: `${owner}/${repo}`, 31 - // color: get_next_color_index(), 32 - // data: [], 33 - // }) 34 - // let total_count = 0 35 - // do { 36 - // if (line.deleted) { 37 - // return // abort 38 - // } 39 - // // const { error, stargazers } = await fetch_stargazers_page(owner, repo, 'forward', end_cursor) 40 - // const { error, stargazers } = await fetch_stargazers_rest(owner, repo, next_page) 41 - // if (!stargazers) { 42 - // errors.push(error) 43 - // chart.deleteLine(line) 44 - // return 45 - // } 46 - 47 - // if (stargazers.pageInfo.hasNextPage) { 48 - // next_page += 1 49 - // } else { 50 - // next_page = null 51 - // } 52 - // total_count = 0 53 - 54 - // const new_data = stargazers.starTimes.map((star_time) => { 55 - // count++ 56 - // if (!star_time) { 57 - // errors.push('star_time is undefined') 58 - // throw new Error('star_time is undefined') 59 - // } 60 - // return { 61 - // t: Math.floor(new Date(star_time).getTime() / 1000) as UTCTimestamp, 62 - // v: count, 63 - // } 64 - // }) 65 - // chart.appendStargazers(line, new_data) 66 - // } while (next_page !== null) 67 - // chart.addFinal(line, { 68 - // t: Math.floor(new Date().getTime() / 1000) as UTCTimestamp, 69 - // v: Math.max(total_count, count), 70 - // }) 71 - // chart.save() 72 - // } 73 16 async function get_stargazers(owner: string, repo: string) { 74 17 if (!chart || !$chart) { 75 18 errors.push('Chart not initialized') ··· 100 43 101 44 line.data = repo_stars.data_points 102 45 // console.log(line.data.map((d) => `${d.t} ${d.v}`).join('\n')) 103 - const from = new Date(stargazers.star_times_data[0].t * 1000).toLocaleDateString('sv') 104 - const to = new Date( 105 - stargazers.star_times_data[stargazers.star_times_data.length - 1].t * 1000, 106 - ).toLocaleDateString('sv') 107 - console.log(from, stargazers.star_times_data[0].v, to, stargazers.star_times_data[0].v) 46 + // const from = new Date(stargazers.star_times_data[0].t * 1000).toLocaleDateString('sv') 47 + // const to = new Date( 48 + // stargazers.star_times_data[stargazers.star_times_data.length - 1].t * 1000, 49 + // ).toLocaleDateString('sv') 50 + // console.log(from, stargazers.star_times_data[0].v, to, stargazers.star_times_data[0].v) 108 51 chart.appendStargazers(line) 109 52 } while (repo_stars.request_queue.length > 0) 110 53 line.data.push({
-84
src/routes/github.ts
··· 5 5 import { browser } from '$app/environment' 6 6 import { throttling, type ThrottlingOptions } from '@octokit/plugin-throttling' 7 7 import { retry } from '@octokit/plugin-retry' 8 - // import parse_link_header from '@renyuneyun/parse-link-header-ts' 9 8 // @ts-expect-error import missing from bottleneck's package.json 10 9 import BottleneckLight from 'bottleneck/light.js' 11 10 import type { UTCTimestamp } from 'lightweight-charts' ··· 129 128 starredAt: string 130 129 }[] 131 130 } 132 - // const response_promise = octokit.graphql<{ 133 - // repository: { 134 - // stargazers_forwards: Stargazers 135 - // stargazers_backwards: Stargazers 136 - // } 137 - // }>( 138 - // `query($owner: String!, $repo: String!, $after: String, $before: String) { 139 - // repository(owner: $owner, name: $repo) { 140 - // stargazers_forwards: stargazers(first: 100, after: $after, orderBy: {field: STARRED_AT, direction: ASC}) { 141 - // totalCount 142 - // pageInfo { 143 - // startCursor 144 - // endCursor 145 - // hasNextPage 146 - // hasPreviousPage 147 - // } 148 - // edges { 149 - // starredAt 150 - // user: node { id } 151 - // } 152 - // } 153 - // stargazers_backwards: stargazers(last: 100, before: $before, orderBy: {field: STARRED_AT, direction: ASC}) { 154 - // totalCount 155 - // pageInfo { 156 - // startCursor 157 - // endCursor 158 - // hasNextPage 159 - // hasPreviousPage 160 - // } 161 - // edges { 162 - // starredAt 163 - // user: node { id } 164 - // } 165 - // } 166 - // } 167 - // }`, 168 - // { 169 - // owner: this.owner, 170 - // repo: this.repo, 171 - // after: this.next_cursor.forwards, 172 - // before: this.next_cursor.backwards, 173 - // }, 174 - // ) 175 131 const response_promise = octokit.graphql<{ 176 132 repository: { 177 133 stargazers: Stargazers ··· 321 277 } 322 278 } 323 279 } 324 - 325 - export async function fetch_stargazers_rest(owner: string, repo: string, page: number) { 326 - const start_time = Date.now() 327 - const response_promise = octokit.request('GET /repos/{owner}/{repo}/stargazers', { 328 - owner, 329 - repo, 330 - per_page: 100, 331 - page, 332 - headers: { 333 - accept: 'application/vnd.github.v3.star+json', 334 - }, 335 - }) 336 - 337 - const response = await response_promise.catch((error) => { 338 - if (error instanceof GraphqlResponseError && error.errors) { 339 - return { 340 - error: error.errors.map((error) => error.message).join('/n'), 341 - } 342 - } else if (error instanceof Error) { 343 - return { error: `${error.name}: ${error.message}` } 344 - } else { 345 - return { error: "Couldn't fetch stargazers" } 346 - } 347 - }) 348 - 349 - console.log('response took', Date.now() - start_time, response) 350 - if ('error' in response) { 351 - return { error: response.error, stargazers: undefined } 352 - } else { 353 - return { 354 - error: undefined, 355 - stargazers: { 356 - pageInfo: { 357 - hasNextPage: response.headers.link?.includes('rel="next"'), 358 - }, 359 - starTimes: response.data.map((stargazer) => stargazer.starred_at), 360 - }, 361 - } 362 - } 363 - }