From be67fe27a271fb790217e5b6a284427f8de6c14c Mon Sep 17 00:00:00 2001 From: "haixin.yang" Date: Mon, 13 Jul 2026 14:05:03 +0800 Subject: [PATCH] docs: automate repository star history --- .github/workflows/star-history.yml | 38 +++++++++ docs/star-history.svg | 60 +++----------- scripts/update-star-history.mjs | 124 +++++++++++++++++++++++++++++ 3 files changed, 174 insertions(+), 48 deletions(-) create mode 100644 .github/workflows/star-history.yml create mode 100644 scripts/update-star-history.mjs diff --git a/.github/workflows/star-history.yml b/.github/workflows/star-history.yml new file mode 100644 index 0000000..029c5a7 --- /dev/null +++ b/.github/workflows/star-history.yml @@ -0,0 +1,38 @@ +name: Update Star History + +on: + schedule: + - cron: '17 2 * * *' + workflow_dispatch: + +permissions: + contents: write + +concurrency: + group: update-star-history + cancel-in-progress: true + +jobs: + update: + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + - name: Generate chart from GitHub stargazer data + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: node scripts/update-star-history.mjs + - name: Commit updated chart + run: | + if git diff --quiet -- docs/star-history.svg; then + echo "Star history is already current." + exit 0 + fi + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git add docs/star-history.svg + git commit -m "docs: update star history [skip ci]" + git push diff --git a/docs/star-history.svg b/docs/star-history.svg index 1a2403f..a0061d6 100644 --- a/docs/star-history.svg +++ b/docs/star-history.svg @@ -1,57 +1,21 @@ Timeline Studio GitHub Star History - Timeline Studio grew from zero to fourteen GitHub stars between July 9 and July 13, 2026. + A chart generated from GitHub's live stargazer history. The repository currently has 15 stars. - - - - - - - - + + GitHub Stars over time - 14 stars - - - - - - - - - 0 - 4 - 8 - 12 - 16 - Jul 9 - Jul 10 - Jul 11 - Jul 12 - Jul 13 - - - - + 15 stars + Updated Jul 13, 2026 + + 0481216Jul 9Jul 10Jul 11Jul 12Jul 13 + + + diff --git a/scripts/update-star-history.mjs b/scripts/update-star-history.mjs new file mode 100644 index 0000000..d015d5a --- /dev/null +++ b/scripts/update-star-history.mjs @@ -0,0 +1,124 @@ +import { mkdir, writeFile } from 'node:fs/promises' +import path from 'node:path' + +const token = process.env.GITHUB_TOKEN +const repository = process.env.GITHUB_REPOSITORY || 'MartinDelophy/ai-video-editor' +const outputPath = process.env.STAR_HISTORY_OUTPUT || 'docs/star-history.svg' + +if (!token) { + throw new Error('GITHUB_TOKEN is required to read timestamped stargazer data.') +} + +const headers = { + Accept: 'application/vnd.github.star+json', + Authorization: `Bearer ${token}`, + 'User-Agent': 'timeline-studio-star-history', + 'X-GitHub-Api-Version': '2022-11-28', +} + +async function requestJson(url) { + const response = await fetch(url, { headers }) + if (!response.ok) { + throw new Error(`GitHub API ${response.status}: ${await response.text()}`) + } + return response.json() +} + +async function getStargazers() { + const stars = [] + for (let page = 1; ; page += 1) { + const batch = await requestJson( + `https://api.github.com/repos/${repository}/stargazers?per_page=100&page=${page}`, + ) + stars.push(...batch) + if (batch.length < 100) return stars + } +} + +const repositoryInfo = await requestJson(`https://api.github.com/repos/${repository}`) +const stargazers = await getStargazers() +const starDates = stargazers + .map(({ starred_at: starredAt }) => new Date(starredAt)) + .filter((date) => !Number.isNaN(date.getTime())) + .sort((a, b) => a - b) + +const now = new Date() +const createdAt = new Date(repositoryInfo.created_at) +const firstEvent = starDates[0] || createdAt +const start = new Date(Math.min(createdAt.getTime(), firstEvent.getTime())) +const end = new Date(Math.max(now.getTime(), start.getTime() + 86_400_000)) +const maxStars = Math.max(4, Math.ceil(starDates.length / 4) * 4) + +const chart = { left: 70, right: 830, top: 60, bottom: 260 } +const x = (date) => + chart.left + + ((date.getTime() - start.getTime()) / (end.getTime() - start.getTime())) * + (chart.right - chart.left) +const y = (count) => + chart.bottom - (count / maxStars) * (chart.bottom - chart.top) +const number = (value) => Number(value.toFixed(1)) + +const points = [{ date: start, count: 0 }] +starDates.forEach((date, index) => points.push({ date, count: index + 1 })) +points.push({ date: end, count: starDates.length }) + +const linePath = points + .map(({ date, count }, index) => `${index ? 'L' : 'M'}${number(x(date))} ${number(y(count))}`) + .join(' ') +const areaPath = `${linePath} L${chart.right} ${chart.bottom} L${chart.left} ${chart.bottom} Z` + +const dateFormatter = new Intl.DateTimeFormat('en', { + month: 'short', + day: 'numeric', + timeZone: 'UTC', +}) +const tickDates = Array.from({ length: 5 }, (_, index) => + new Date(start.getTime() + ((end.getTime() - start.getTime()) * index) / 4), +) +const yTicks = Array.from({ length: 5 }, (_, index) => (maxStars * index) / 4) +const updatedAt = new Intl.DateTimeFormat('en', { + year: 'numeric', + month: 'short', + day: 'numeric', + timeZone: 'UTC', +}).format(now) + +const grid = yTicks + .map((tick) => ``) + .join('') +const yLabels = yTicks + .map((tick) => `${tick}`) + .join('') +const xLabels = tickDates + .map((date, index) => { + const anchor = index === 0 ? 'start' : index === 4 ? 'end' : 'middle' + return `${dateFormatter.format(date)}` + }) + .join('') + +const svg = ` + Timeline Studio GitHub Star History + A chart generated from GitHub's live stargazer history. The repository currently has ${starDates.length} stars. + + + + + + + GitHub Stars over time + ${starDates.length} stars + Updated ${updatedAt} + ${grid} + ${yLabels}${xLabels} + + + + +` + +await mkdir(path.dirname(outputPath), { recursive: true }) +await writeFile(outputPath, svg) +console.log(`Updated ${outputPath} with ${starDates.length} stars.`)