From fd48cf4d60f4304c650d20d8dffedbb07b39cfd7 Mon Sep 17 00:00:00 2001 From: Cedric Vidal Date: Thu, 19 Nov 2026 16:30:26 -0800 Subject: [PATCH 1/7] fix(website): count commit contributors Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .github/workflows/contribution-data.yml | 40 ++++++------ scripts/ci-workflow.test.ts | 40 ++++++++++++ website/AGENTS.md | 30 +++++---- website/README.md | 9 +-- .../contribute/ContributeTeaser.astro | 4 +- .../components/contribute/Contributors.astro | 2 +- .../src/content/docs/community/contribute.mdx | 9 +-- website/src/data/contributors.sample.jsonl | 18 +++--- website/src/scripts/contributors-element.ts | 16 ++--- website/src/scripts/contributors.test.mjs | 62 +++++++++++-------- website/src/scripts/contributors.ts | 38 +++++++----- website/src/styles/contributors.css | 4 +- 12 files changed, 168 insertions(+), 104 deletions(-) diff --git a/.github/workflows/contribution-data.yml b/.github/workflows/contribution-data.yml index d0748e6ad..6606df483 100644 --- a/.github/workflows/contribution-data.yml +++ b/.github/workflows/contribution-data.yml @@ -1,4 +1,4 @@ -# Publishes merged pull request contributors to the orphan `website-data` +# Publishes commit contributors to the orphan `website-data` # branch. The docs site fetches the deterministic JSONL at runtime. name: Publish website contribution data @@ -9,7 +9,6 @@ on: permissions: contents: write - pull-requests: read concurrency: group: website-contribution-data @@ -28,27 +27,28 @@ jobs: - name: Collect contributors run: | set -euo pipefail - gh api graphql --paginate \ - -F owner="${REPO%/*}" \ - -F name="${REPO#*/}" \ - -f query=' - query($owner: String!, $name: String!, $endCursor: String) { - repository(owner: $owner, name: $name) { - pullRequests(states: MERGED, first: 100, after: $endCursor) { - pageInfo { hasNextPage endCursor } - nodes { author { __typename login } } - } - } - }' \ - --jq '.data.repository.pullRequests.nodes[]' | + gh api --paginate \ + -H 'Accept: application/vnd.github+json' \ + -H 'X-GitHub-Api-Version: 2022-11-28' \ + "repos/${REPO}/contributors?per_page=100&anon=0" \ + --jq '.[]' | jq -cS -s ' map(select( - .author != null - and .author.__typename == "User" - and (.author.login | endswith("[bot]") | not) + .login != null + and .type == "User" + and (.login | endswith("[bot]") | not) + and (.contributions | type == "number" and . > 0 and floor == .) )) - | group_by(.author.login) - | map({login: .[0].author.login, prs: length}) + | group_by(.login | ascii_downcase) + | map( + (map(.contributions) | add) as $commits + | { + commits: $commits, + login: .[0].login, + # Compatibility alias for the currently deployed reader. + prs: $commits + } + ) | sort_by(.login | ascii_downcase) | .[]' > contributors.jsonl diff --git a/scripts/ci-workflow.test.ts b/scripts/ci-workflow.test.ts index 0da2bcedc..f330dad3d 100644 --- a/scripts/ci-workflow.test.ts +++ b/scripts/ci-workflow.test.ts @@ -48,6 +48,15 @@ const communityContributionWorkflow = parse(communityContributionWorkflowSource) permissions: Record; jobs: Record; }; +const contributionDataWorkflowSource = readFileSync(".github/workflows/contribution-data.yml", "utf8"); +const contributionDataWorkflow = parse(contributionDataWorkflowSource) as { + on: { + push: { branches: string[] }; + workflow_dispatch: null; + }; + permissions: Record; + jobs: Record; +}; const actionPinningWorkflow = parse(readFileSync(".github/workflows/pin-actions.yml", "utf8")) as { on: { push: { paths: string[] }; @@ -330,6 +339,37 @@ describe("Community contribution labeler workflow", () => { }); }); +describe("Website contribution data workflow", () => { + const publish = contributionDataWorkflow.jobs.publish; + const collect = publish.steps.find((candidate) => candidate.name === "Collect contributors")?.run ?? ""; + + it("publishes commit contributors after default-branch changes and on demand", () => { + expect(contributionDataWorkflow.on).toEqual({ + push: { branches: ["main"] }, + workflow_dispatch: null, + }); + expect(contributionDataWorkflow.permissions).toEqual({ contents: "write" }); + expect(publish.if).toBe("github.repository == 'microsoft/scope'"); + }); + + it("collects paginated human commit contributors deterministically", () => { + expect(collect).toContain("gh api --paginate"); + expect(collect).toContain('"repos/${REPO}/contributors?per_page=100&anon=0"'); + expect(collect).toContain('.type == "User"'); + expect(collect).toContain('endswith("[bot]")'); + expect(collect).toContain("group_by(.login | ascii_downcase)"); + expect(collect).toContain("commits: $commits"); + expect(collect).toContain("prs: $commits"); + expect(collect).toContain("sort_by(.login | ascii_downcase)"); + }); + + it("keeps every embedded shell step syntactically valid", () => { + for (const command of publish.steps.filter((candidate) => candidate.run)) { + expect(spawnSync("bash", ["-n"], { input: command.run }).status, command.name).toBe(0); + } + }); +}); + describe("Public CLI release workflow", () => { const release = parse(readFileSync(".github/workflows/publish-cli.yml", "utf8")) as { on: Record; diff --git a/website/AGENTS.md b/website/AGENTS.md index 4ed0ee1f6..a953085bd 100644 --- a/website/AGENTS.md +++ b/website/AGENTS.md @@ -221,25 +221,29 @@ player or its scripts. ### Contributors The landing page (an avatar wall) and the **Community → Contributors** -page (a card grid) thank every author of a merged pull request, -community and Microsoft alike: +page (a card grid) thank every commit contributor, community and +Microsoft alike: - The publisher writes `contributors.jsonl` to `website-data`. It - counts merged PRs whose author is a user, not a bot (`[bot]` suffix). - Team members count too; don't filter on `authorAssociation`. + uses GitHub's repository contributors endpoint and counts commits for + user accounts, excluding bots (`[bot]` suffix) and anonymous entries. - [`.github/workflows/contribution-data.yml`](../.github/workflows/contribution-data.yml) - runs after pushes to `main` (including merged pull requests) and on - demand. It updates the orphan data branch only when the deterministic - file changes. -- One line per person, `{"login":"…","prs":N}`, with sorted keys and - sorted by lowercase login. No avatar URLs or timestamps; avatars come - from `https://github.com/.png`, and a failed image shows the - login's initial. -- The browser sorts by merged PRs, then login. The wall shows up to + runs after pushes to `main` and on demand. It updates the orphan data + branch only when the deterministic file changes. +- One line per person, `{"commits":N,"login":"…","prs":N}`, with sorted + keys and sorted by lowercase login. `prs` is a temporary compatibility + alias for the previously deployed reader and must equal `commits`; the + browser also accepts legacy lines containing only `prs`. No avatar URLs + or timestamps are published; avatars come from + `https://github.com/.png`, and a failed image shows the login's + initial. +- The browser sorts by commits, then login. The wall shows up to `limit` items; the last slot becomes a "+N" bubble that links to the full grid. The grid shows `limit` cards (30 on the Contributors page) and a "Show all N contributors" button, unless only one card - would stay hidden. Each person links to their merged PRs. + would stay hidden. Each person still links to their merged PRs; copy + must not imply that this destination explains the displayed commit + count. - Wall tooltips get a `--tip-shift` so they stay inside the wall (a hidden tip on an edge avatar would otherwise make narrow pages scroll sideways). The intro and count are hidden in the empty and error diff --git a/website/README.md b/website/README.md index 570e9a19f..d300307ee 100644 --- a/website/README.md +++ b/website/README.md @@ -198,10 +198,11 @@ table of contents, code examples, and previous/next navigation. example, and the contributor avatars (pop-in, hover tooltips), with pause controls and reduced-motion support. The logo and documentation chrome remain still. -- **Contribution:** a landing-page wall and full grid thank merged-PR - contributors, refreshed after merges from a data branch without a - redeploy. The publisher is `.github/workflows/contribution-data.yml`; - see "Contributors" in `AGENTS.md`. +- **Contribution:** a landing-page wall and full grid thank commit + contributors, refreshed after default-branch changes from a data branch + without a redeploy. Contributor links still open merged pull requests. The + publisher is `.github/workflows/contribution-data.yml`; see "Contributors" + in `AGENTS.md`. ### Showreel diff --git a/website/src/components/contribute/ContributeTeaser.astro b/website/src/components/contribute/ContributeTeaser.astro index 5029839ff..f61d3f4ef 100644 --- a/website/src/components/contribute/ContributeTeaser.astro +++ b/website/src/components/contribute/ContributeTeaser.astro @@ -16,11 +16,11 @@ const allHref = `${import.meta.env.BASE_URL.replace(/\/$/, '')}/community/contri

- +

-

Everyone below got a pull request merged into Scope. Hover an avatar to see how many.

+

Everyone below has contributed commits to Scope. Hover an avatar to see how many; select it to view merged pull requests.

See all contributors diff --git a/website/src/components/contribute/Contributors.astro b/website/src/components/contribute/Contributors.astro index f0337a26b..d3bfb3e9c 100644 --- a/website/src/components/contribute/Contributors.astro +++ b/website/src/components/contribute/Contributors.astro @@ -46,7 +46,7 @@ const listId = `thanks-list-${variant}`; ) }

- No pull request contributors are available yet. + No commit contributors are available yet.

We couldn't load the list. See diff --git a/website/src/content/docs/community/contribute.mdx b/website/src/content/docs/community/contribute.mdx index 3e51d5adb..fc3629a60 100644 --- a/website/src/content/docs/community/contribute.mdx +++ b/website/src/content/docs/community/contribute.mdx @@ -1,12 +1,13 @@ --- title: Contributors -description: Thanking everyone whose pull requests have been merged into Scope. +description: Thanking everyone whose commits contribute to Scope. --- import Contributors from '../../../components/contribute/Contributors.astro'; -Thank you to everyone who got a pull request merged, from the community -and the Scope team alike. Select a name to see their merged pull requests. This list also -refreshes automatically after pull requests merge. +Thank you to everyone whose commits contribute to Scope, from the community +and the Scope team alike. Counts come from GitHub's repository contributor +statistics. Select a name to see that person's merged pull requests. The list +refreshes automatically after changes land on the default branch. diff --git a/website/src/data/contributors.sample.jsonl b/website/src/data/contributors.sample.jsonl index d2fee8679..fe9f68df6 100644 --- a/website/src/data/contributors.sample.jsonl +++ b/website/src/data/contributors.sample.jsonl @@ -1,9 +1,9 @@ -{"login":"cedricvidal","prs":11} -{"login":"chanezon","prs":1} -{"login":"cmaneu","prs":2} -{"login":"duffney","prs":3} -{"login":"Gile987","prs":1} -{"login":"idhanth","prs":2} -{"login":"itsmeasadali","prs":1} -{"login":"manekinekko","prs":14} -{"login":"mnkj0021","prs":1} +{"commits":515,"login":"cedricvidal","prs":515} +{"commits":9,"login":"chanezon","prs":9} +{"commits":2,"login":"cmaneu","prs":2} +{"commits":58,"login":"duffney","prs":58} +{"commits":1,"login":"Gile987","prs":1} +{"commits":2,"login":"idhanth","prs":2} +{"commits":1,"login":"itsmeasadali","prs":1} +{"commits":46,"login":"manekinekko","prs":46} +{"commits":2,"login":"mnkj0021","prs":2} diff --git a/website/src/scripts/contributors-element.ts b/website/src/scripts/contributors-element.ts index e39795a62..e63ba8118 100644 --- a/website/src/scripts/contributors-element.ts +++ b/website/src/scripts/contributors-element.ts @@ -4,16 +4,16 @@ import { CONTRIBUTORS_DATA_URL, avatarUrl, + commitsLabel, contributorsLabel, fetchContributors, firstPage, parseContributors, - prsLabel, prsUrl, showAllLabel, sortForDisplay, tipShift, - totalPrs, + totalCommits, visible, type Contributor, type ContributorsResult, @@ -28,7 +28,7 @@ const LIFT_SCALE = 1.14; const MAX_STAGGER_STEPS = 24; /** - * Thanks contributors: authors of merged pull requests, bots aside. Renders + * Thanks commit contributors, bots aside. Renders * an avatar wall (landing) or a card grid (Contribute page). Without * JavaScript a link to the GitHub contributors graph stays visible. Motion * is skipped entirely when the visitor prefers reduced motion. @@ -119,10 +119,10 @@ class ScopeContributors extends HTMLElement { this.updateShowAll(grid ? hidden : 0); const people = this.contributors.length; - const prs = totalPrs(this.contributors); + const commits = totalCommits(this.contributors); this.querySelectorAll('[data-count-label]').forEach((label) => { label.textContent = contributorsLabel(people); }); - this.querySelectorAll('[data-prs]').forEach((element) => { element.textContent = prsLabel(prs); }); - this.querySelectorAll('[data-count-text]').forEach((text) => { text.textContent = `${people} ${contributorsLabel(people)}, ${prsLabel(prs)}`; }); + this.querySelectorAll('[data-commits]').forEach((element) => { element.textContent = commitsLabel(commits); }); + this.querySelectorAll('[data-count-text]').forEach((text) => { text.textContent = `${people} ${contributorsLabel(people)}, ${commitsLabel(commits)}`; }); this.loaded = true; this.setState(people ? 'ready' : 'empty'); this.reveal(); @@ -259,7 +259,7 @@ class ScopeContributors extends HTMLElement { link.append(this.image(contributor, 56)); const tip = this.span(link, 'thanks-tip'); this.span(tip, 'thanks-tip__login', `@${contributor.login}`); - this.span(tip, 'thanks-tip__prs', prsLabel(contributor.prs)); + this.span(tip, 'thanks-tip__commits', commitsLabel(contributor.commits)); this.span(link, 'sr-only', ' (opens in a new tab)'); return item; } @@ -270,7 +270,7 @@ class ScopeContributors extends HTMLElement { link.append(this.image(contributor, 96)); const body = this.span(link, 'thanks-card__body'); this.span(body, 'thanks-card__login', `@${contributor.login}`).title = `@${contributor.login}`; - this.span(body, 'thanks-card__prs', prsLabel(contributor.prs)); + this.span(body, 'thanks-card__commits', commitsLabel(contributor.commits)); this.span(link, 'contrib-card__arrow thanks-card__arrow', '↗').setAttribute('aria-hidden', 'true'); this.span(link, 'sr-only', ' (opens in a new tab)'); return item; diff --git a/website/src/scripts/contributors.test.mjs b/website/src/scripts/contributors.test.mjs index 5d69ff5ca..a741ff253 100644 --- a/website/src/scripts/contributors.test.mjs +++ b/website/src/scripts/contributors.test.mjs @@ -8,24 +8,24 @@ import assert from 'node:assert/strict'; import { readFileSync } from 'node:fs'; import { avatarUrl, + commitsLabel, contributorsLabel, firstPage, parseContributors, - prsLabel, prsUrl, showAllLabel, sortForDisplay, tipShift, - totalPrs, + totalCommits, visible, } from './contributors.ts'; const line = (value) => JSON.stringify(value); test('parses JSON Lines and ignores blank lines', () => { - const text = [line({ login: 'ada', prs: 2 }), '', line({ login: 'grace-h', prs: 1 }), ''].join('\n'); + const text = [line({ commits: 2, login: 'ada', prs: 2 }), '', line({ commits: 1, login: 'grace-h', prs: 1 }), ''].join('\n'); assert.deepEqual(parseContributors(text), { - contributors: [{ login: 'ada', prs: 2 }, { login: 'grace-h', prs: 1 }], + contributors: [{ login: 'ada', commits: 2 }, { login: 'grace-h', commits: 1 }], skipped: [], }); }); @@ -34,29 +34,37 @@ test('treats an empty file as no contributors', () => { assert.deepEqual(parseContributors(''), { contributors: [], skipped: [] }); }); -test('skips invalid logins, counts and duplicates without dropping the rest', () => { +test('accepts the legacy PR field as a commit count during rollout', () => { + assert.deepEqual(parseContributors(line({ login: 'ada', prs: 2 })), { + contributors: [{ login: 'ada', commits: 2 }], + skipped: [], + }); +}); + +test('skips invalid logins, counts, aliases and duplicates without dropping the rest', () => { const text = [ '{not json', - line({ login: 'dependabot[bot]', prs: 9 }), - line({ login: '-leading', prs: 1 }), - line({ login: 'double--hyphen', prs: 1 }), - line({ login: '../evil', prs: 1 }), - line({ login: 'zero', prs: 0 }), - line({ login: 'fraction', prs: 1.5 }), - line({ login: 'Kept', prs: 3 }), - line({ login: 'kept', prs: 1 }), + line({ commits: 9, login: 'dependabot[bot]', prs: 9 }), + line({ commits: 1, login: '-leading', prs: 1 }), + line({ commits: 1, login: 'double--hyphen', prs: 1 }), + line({ commits: 1, login: '../evil', prs: 1 }), + line({ commits: 0, login: 'zero', prs: 0 }), + line({ commits: 1.5, login: 'fraction', prs: 1.5 }), + line({ commits: 3, login: 'mismatch', prs: 2 }), + line({ commits: 3, login: 'Kept', prs: 3 }), + line({ commits: 1, login: 'kept', prs: 1 }), ].join('\r\n'); const { contributors, skipped } = parseContributors(text); - assert.deepEqual(contributors, [{ login: 'Kept', prs: 3 }]); - assert.deepEqual(skipped, [1, 2, 3, 4, 5, 6, 7, 9]); + assert.deepEqual(contributors, [{ login: 'Kept', commits: 3 }]); + assert.deepEqual(skipped, [1, 2, 3, 4, 5, 6, 7, 8, 10]); }); -test('sorts by merged PRs, then login case-insensitively', () => { +test('sorts by commits, then login case-insensitively', () => { const sorted = sortForDisplay([ - { login: 'zed', prs: 1 }, - { login: 'Bea', prs: 1 }, - { login: 'max', prs: 4 }, - { login: 'alex', prs: 1 }, + { login: 'zed', commits: 1 }, + { login: 'Bea', commits: 1 }, + { login: 'max', commits: 4 }, + { login: 'alex', commits: 1 }, ]); assert.deepEqual(sorted.map((c) => c.login), ['max', 'alex', 'Bea', 'zed']); }); @@ -69,13 +77,13 @@ test('builds avatar and merged PR URLs', () => { assert.equal(url.searchParams.get('q'), 'is:pr is:merged author:grace-h'); }); -test('pluralizes labels and totals PRs', () => { - assert.equal(prsLabel(1), '1 merged PR'); - assert.equal(prsLabel(3), '3 merged PRs'); +test('pluralizes labels and totals commits', () => { + assert.equal(commitsLabel(1), '1 commit'); + assert.equal(commitsLabel(3), '3 commits'); assert.equal(contributorsLabel(1), 'contributor'); assert.equal(contributorsLabel(2), 'contributors'); - assert.equal(totalPrs([{ login: 'a', prs: 2 }, { login: 'b', prs: 3 }]), 5); - assert.equal(totalPrs([]), 0); + assert.equal(totalCommits([{ login: 'a', commits: 2 }, { login: 'b', commits: 3 }]), 5); + assert.equal(totalCommits([]), 0); }); test('keeps a slot for the overflow bubble', () => { @@ -134,6 +142,8 @@ test('the dev sample file is valid and sorted like the published file', () => { const logins = contributors.map((c) => c.login.toLowerCase()); assert.deepEqual(logins, [...logins].sort()); for (const raw of text.trim().split('\n')) { - assert.deepEqual(Object.keys(JSON.parse(raw)), ['login', 'prs'], 'keys are sorted and nothing else is published'); + const value = JSON.parse(raw); + assert.deepEqual(Object.keys(value), ['commits', 'login', 'prs'], 'keys are sorted and nothing else is published'); + assert.equal(value.prs, value.commits, 'the compatibility alias matches the commit count'); } }); diff --git a/website/src/scripts/contributors.ts b/website/src/scripts/contributors.ts index aae7281c4..d4e731c23 100644 --- a/website/src/scripts/contributors.ts +++ b/website/src/scripts/contributors.ts @@ -11,9 +11,10 @@ export const CONTRIBUTORS_DATA_URL = `https://raw.githubusercontent.com/${REPOSI export const CONTRIBUTORS_GRAPH_URL = `https://github.com/${REPOSITORY}/graphs/contributors`; export interface Contributor { + /** GitHub account login. */ login: string; - /** Number of merged pull requests. */ - prs: number; + /** Number of commits attributed by GitHub's repository contributors API. */ + commits: number; } export interface ContributorsResult { @@ -25,10 +26,16 @@ export interface ContributorsResult { // GitHub logins: alphanumerics and single hyphens, up to 39 characters. const LOGIN = /^[A-Za-z0-9](?:[A-Za-z0-9]|-(?=[A-Za-z0-9])){0,38}$/; -function isContributor(value: unknown): value is Contributor { - if (typeof value !== 'object' || value === null) return false; - const { login, prs } = value as Record; - return typeof login === 'string' && LOGIN.test(login) && Number.isSafeInteger(prs) && (prs as number) > 0; +/** Normalizes current and legacy published records into the browser model. */ +function parseContributor(value: unknown): Contributor | undefined { + if (typeof value !== 'object' || value === null) return undefined; + const record = value as Record; + const { login } = record; + const commits = Object.hasOwn(record, 'commits') ? record.commits : record.prs; + if (typeof login !== 'string' || !LOGIN.test(login)) return undefined; + if (typeof commits !== 'number' || !Number.isSafeInteger(commits) || commits <= 0) return undefined; + if (Object.hasOwn(record, 'commits') && Object.hasOwn(record, 'prs') && record.prs !== commits) return undefined; + return { login, commits }; } /** @@ -48,19 +55,20 @@ export function parseContributors(text: string): ContributorsResult { skipped.push(index + 1); return; } - if (!isContributor(value) || seen.has(value.login.toLowerCase())) { + const contributor = parseContributor(value); + if (!contributor || seen.has(contributor.login.toLowerCase())) { skipped.push(index + 1); return; } - seen.add(value.login.toLowerCase()); - contributors.push({ login: value.login, prs: value.prs }); + seen.add(contributor.login.toLowerCase()); + contributors.push(contributor); }); return { contributors, skipped }; } -/** Display order: most merged PRs first, then by login. */ +/** Display order: most commits first, then by login. */ export function sortForDisplay(contributors: readonly Contributor[]): Contributor[] { - return [...contributors].sort((a, b) => b.prs - a.prs || a.login.localeCompare(b.login, 'en', { sensitivity: 'base' })); + return [...contributors].sort((a, b) => b.commits - a.commits || a.login.localeCompare(b.login, 'en', { sensitivity: 'base' })); } export function avatarUrl(login: string, size = 96): string { @@ -73,16 +81,16 @@ export function prsUrl(login: string): string { return `https://github.com/${REPOSITORY}/pulls?q=${encodeURIComponent(query)}`; } -export function prsLabel(count: number): string { - return count === 1 ? '1 merged PR' : `${count} merged PRs`; +export function commitsLabel(count: number): string { + return count === 1 ? '1 commit' : `${count} commits`; } export function contributorsLabel(count: number): string { return count === 1 ? 'contributor' : 'contributors'; } -export function totalPrs(contributors: readonly Contributor[]): number { - return contributors.reduce((sum, contributor) => sum + contributor.prs, 0); +export function totalCommits(contributors: readonly Contributor[]): number { + return contributors.reduce((sum, contributor) => sum + contributor.commits, 0); } /** Splits the list into what fits under `limit` and how many are left over. */ diff --git a/website/src/styles/contributors.css b/website/src/styles/contributors.css index 03ef9015a..1f6639fd9 100644 --- a/website/src/styles/contributors.css +++ b/website/src/styles/contributors.css @@ -88,7 +88,7 @@ } .thanks-tip::after { content: ''; position: absolute; top: 100%; left: calc(50% - var(--tip-shift, 0px)); border: 5px solid transparent; border-top-color: var(--scope-text); transform: translateX(-50%); } .thanks-tip__login { font-weight: 650; } -.thanks-tip__prs { opacity: 0.75; } +.thanks-tip__commits { opacity: 0.75; } .thanks-avatar:is(:hover, :focus-visible) .thanks-tip { opacity: 1; transform: translate(calc(-50% + var(--tip-shift, 0px)), 0) scale(1); } /* Skeletons. */ @@ -106,7 +106,7 @@ .thanks-card:is(:hover, :focus-visible) .thanks-photo { box-shadow: 0 0 0 2px var(--scope-surface), 0 0 0 4px var(--scope-brand); } .thanks-card__body { display: flex; flex-direction: column; min-width: 0; } .thanks-card__login { overflow: hidden; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; } -.thanks-card__prs { color: var(--scope-muted); font-size: 0.78rem; } +.thanks-card__commits { color: var(--scope-muted); font-size: 0.78rem; } .thanks-card__arrow { margin-left: auto; color: var(--scope-brand); } .thanks-show-all { display: flex; align-items: center; gap: 0.5rem; margin: 1.5rem auto 0 !important; padding: 0.6rem 1.25rem; border: 1px solid var(--scope-border); border-radius: 999px; background: var(--scope-surface); color: var(--scope-brand); font: 600 0.9rem var(--sl-font); cursor: pointer; transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1); } .thanks-show-all:is(:hover, :focus-visible) { border-color: var(--scope-brand); box-shadow: var(--scope-shadow); transform: translateY(-2px); } From a0776e91195d02a3132ea614315980e1e1f6c432 Mon Sep 17 00:00:00 2001 From: Cedric Vidal Date: Thu, 19 Nov 2026 16:34:51 -0800 Subject: [PATCH 2/7] fix(website): clarify main branch commit counts Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .github/workflows/contribution-data.yml | 2 +- scripts/ci-workflow.test.ts | 4 ++-- website/AGENTS.md | 11 ++++++----- website/README.md | 10 +++++----- .../src/components/contribute/ContributeTeaser.astro | 4 ++-- website/src/components/contribute/Contributors.astro | 2 +- website/src/content/docs/community/contribute.mdx | 11 ++++++----- website/src/scripts/contributors-element.ts | 2 +- website/src/scripts/contributors.test.mjs | 4 ++-- website/src/scripts/contributors.ts | 4 ++-- 10 files changed, 28 insertions(+), 26 deletions(-) diff --git a/.github/workflows/contribution-data.yml b/.github/workflows/contribution-data.yml index 6606df483..c495f3596 100644 --- a/.github/workflows/contribution-data.yml +++ b/.github/workflows/contribution-data.yml @@ -1,4 +1,4 @@ -# Publishes commit contributors to the orphan `website-data` +# Publishes default-branch commit contributors to the orphan `website-data` # branch. The docs site fetches the deterministic JSONL at runtime. name: Publish website contribution data diff --git a/scripts/ci-workflow.test.ts b/scripts/ci-workflow.test.ts index f330dad3d..ceb2bc5af 100644 --- a/scripts/ci-workflow.test.ts +++ b/scripts/ci-workflow.test.ts @@ -343,7 +343,7 @@ describe("Website contribution data workflow", () => { const publish = contributionDataWorkflow.jobs.publish; const collect = publish.steps.find((candidate) => candidate.name === "Collect contributors")?.run ?? ""; - it("publishes commit contributors after default-branch changes and on demand", () => { + it("publishes default-branch commit contributors after changes and on demand", () => { expect(contributionDataWorkflow.on).toEqual({ push: { branches: ["main"] }, workflow_dispatch: null, @@ -352,7 +352,7 @@ describe("Website contribution data workflow", () => { expect(publish.if).toBe("github.repository == 'microsoft/scope'"); }); - it("collects paginated human commit contributors deterministically", () => { + it("collects paginated human default-branch contributors deterministically", () => { expect(collect).toContain("gh api --paginate"); expect(collect).toContain('"repos/${REPO}/contributors?per_page=100&anon=0"'); expect(collect).toContain('.type == "User"'); diff --git a/website/AGENTS.md b/website/AGENTS.md index a953085bd..353883560 100644 --- a/website/AGENTS.md +++ b/website/AGENTS.md @@ -221,12 +221,13 @@ player or its scripts. ### Contributors The landing page (an avatar wall) and the **Community → Contributors** -page (a card grid) thank every commit contributor, community and -Microsoft alike: +page (a card grid) thank everyone with commits attributed on the +repository's default branch (`main`), community and Microsoft alike: - The publisher writes `contributors.jsonl` to `website-data`. It - uses GitHub's repository contributors endpoint and counts commits for - user accounts, excluding bots (`[bot]` suffix) and anonymous entries. + uses GitHub's repository contributors endpoint and counts commits + attributed on the default branch for user accounts, excluding bots + (`[bot]` suffix) and anonymous entries. - [`.github/workflows/contribution-data.yml`](../.github/workflows/contribution-data.yml) runs after pushes to `main` and on demand. It updates the orphan data branch only when the deterministic file changes. @@ -237,7 +238,7 @@ Microsoft alike: or timestamps are published; avatars come from `https://github.com/.png`, and a failed image shows the login's initial. -- The browser sorts by commits, then login. The wall shows up to +- The browser sorts by default-branch commits, then login. The wall shows up to `limit` items; the last slot becomes a "+N" bubble that links to the full grid. The grid shows `limit` cards (30 on the Contributors page) and a "Show all N contributors" button, unless only one card diff --git a/website/README.md b/website/README.md index d300307ee..8f3e804e7 100644 --- a/website/README.md +++ b/website/README.md @@ -198,11 +198,11 @@ table of contents, code examples, and previous/next navigation. example, and the contributor avatars (pop-in, hover tooltips), with pause controls and reduced-motion support. The logo and documentation chrome remain still. -- **Contribution:** a landing-page wall and full grid thank commit - contributors, refreshed after default-branch changes from a data branch - without a redeploy. Contributor links still open merged pull requests. The - publisher is `.github/workflows/contribution-data.yml`; see "Contributors" - in `AGENTS.md`. +- **Contribution:** a landing-page wall and full grid thank contributors with + commits attributed on the default branch (`main`), refreshed after + default-branch changes from a data branch without a redeploy. Contributor + links still open merged pull requests. The publisher is + `.github/workflows/contribution-data.yml`; see "Contributors" in `AGENTS.md`. ### Showreel diff --git a/website/src/components/contribute/ContributeTeaser.astro b/website/src/components/contribute/ContributeTeaser.astro index f61d3f4ef..237d4d657 100644 --- a/website/src/components/contribute/ContributeTeaser.astro +++ b/website/src/components/contribute/ContributeTeaser.astro @@ -16,11 +16,11 @@ const allHref = `${import.meta.env.BASE_URL.replace(/\/$/, '')}/community/contri

- +

-

Everyone below has contributed commits to Scope. Hover an avatar to see how many; select it to view merged pull requests.

+

Everyone below has commits attributed on Scope's main branch. Hover an avatar to see how many; select it to view merged pull requests.

See all contributors diff --git a/website/src/components/contribute/Contributors.astro b/website/src/components/contribute/Contributors.astro index d3bfb3e9c..d909372ee 100644 --- a/website/src/components/contribute/Contributors.astro +++ b/website/src/components/contribute/Contributors.astro @@ -46,7 +46,7 @@ const listId = `thanks-list-${variant}`; ) }

- No commit contributors are available yet. + No contributors with commits on main are available yet.

We couldn't load the list. See diff --git a/website/src/content/docs/community/contribute.mdx b/website/src/content/docs/community/contribute.mdx index fc3629a60..7cac9359f 100644 --- a/website/src/content/docs/community/contribute.mdx +++ b/website/src/content/docs/community/contribute.mdx @@ -1,13 +1,14 @@ --- title: Contributors -description: Thanking everyone whose commits contribute to Scope. +description: Thanking everyone with commits attributed on Scope's main branch. --- import Contributors from '../../../components/contribute/Contributors.astro'; -Thank you to everyone whose commits contribute to Scope, from the community -and the Scope team alike. Counts come from GitHub's repository contributor -statistics. Select a name to see that person's merged pull requests. The list -refreshes automatically after changes land on the default branch. +Thank you to everyone with commits attributed on Scope's main branch, from the +community and the Scope team alike. Counts come from GitHub's repository +contributor statistics for the default branch. Select a name to see that +person's merged pull requests. The list refreshes automatically after changes +land on main. diff --git a/website/src/scripts/contributors-element.ts b/website/src/scripts/contributors-element.ts index e63ba8118..340ff32a3 100644 --- a/website/src/scripts/contributors-element.ts +++ b/website/src/scripts/contributors-element.ts @@ -28,7 +28,7 @@ const LIFT_SCALE = 1.14; const MAX_STAGGER_STEPS = 24; /** - * Thanks commit contributors, bots aside. Renders + * Thanks default-branch commit contributors, bots aside. Renders * an avatar wall (landing) or a card grid (Contribute page). Without * JavaScript a link to the GitHub contributors graph stays visible. Motion * is skipped entirely when the visitor prefers reduced motion. diff --git a/website/src/scripts/contributors.test.mjs b/website/src/scripts/contributors.test.mjs index a741ff253..73c192a48 100644 --- a/website/src/scripts/contributors.test.mjs +++ b/website/src/scripts/contributors.test.mjs @@ -78,8 +78,8 @@ test('builds avatar and merged PR URLs', () => { }); test('pluralizes labels and totals commits', () => { - assert.equal(commitsLabel(1), '1 commit'); - assert.equal(commitsLabel(3), '3 commits'); + assert.equal(commitsLabel(1), '1 commit on main'); + assert.equal(commitsLabel(3), '3 commits on main'); assert.equal(contributorsLabel(1), 'contributor'); assert.equal(contributorsLabel(2), 'contributors'); assert.equal(totalCommits([{ login: 'a', commits: 2 }, { login: 'b', commits: 3 }]), 5); diff --git a/website/src/scripts/contributors.ts b/website/src/scripts/contributors.ts index d4e731c23..f7abb5597 100644 --- a/website/src/scripts/contributors.ts +++ b/website/src/scripts/contributors.ts @@ -13,7 +13,7 @@ export const CONTRIBUTORS_GRAPH_URL = `https://github.com/${REPOSITORY}/graphs/c export interface Contributor { /** GitHub account login. */ login: string; - /** Number of commits attributed by GitHub's repository contributors API. */ + /** Number of commits attributed on the repository's default branch. */ commits: number; } @@ -82,7 +82,7 @@ export function prsUrl(login: string): string { } export function commitsLabel(count: number): string { - return count === 1 ? '1 commit' : `${count} commits`; + return count === 1 ? '1 commit on main' : `${count} commits on main`; } export function contributorsLabel(count: number): string { From ecd4d54262d6521dd50f10ce459e2477407fefba Mon Sep 17 00:00:00 2001 From: Cedric Vidal Date: Thu, 19 Nov 2026 16:59:18 -0800 Subject: [PATCH 3/7] fix(ci): exempt untagged Rust toolchain action Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .github/pinact.yaml | 7 +++++++ .github/workflows/ci.yml | 4 ++-- scripts/ci-workflow.test.ts | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/pinact.yaml b/.github/pinact.yaml index 37898a900..ab27e6252 100644 --- a/.github/pinact.yaml +++ b/.github/pinact.yaml @@ -5,6 +5,13 @@ files: - pattern: workflows/*.yaml rules: + # dtolnay publishes toolchain-specific commits without matching Git tags, + # so pinact cannot verify the toolchain version as an action release tag. + # The Vitest invariant still requires a full SHA and explanatory comment. + - ignore: true + conditions: + - expr: ActionName == "dtolnay/rust-toolchain" + # gh-aw owns generated lockfile annotations. Preserve its major-version # comments while the Vitest invariant still enforces a full SHA and comment. - ignore: true diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 621537e18..061963858 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -605,7 +605,7 @@ jobs: uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 - name: Install Rust toolchain - uses: dtolnay/rust-toolchain@ee868d7805ade43a1b47dd054727ab76c9108b4f # 1.94.1 + uses: dtolnay/rust-toolchain@ee868d7805ade43a1b47dd054727ab76c9108b4f # toolchain: 1.94.1 with: toolchain: 1.94.1 components: rustfmt, clippy @@ -703,7 +703,7 @@ jobs: run: pnpm install --frozen-lockfile --ignore-scripts - name: Install Rust toolchain - uses: dtolnay/rust-toolchain@ee868d7805ade43a1b47dd054727ab76c9108b4f # 1.94.1 + uses: dtolnay/rust-toolchain@ee868d7805ade43a1b47dd054727ab76c9108b4f # toolchain: 1.94.1 with: toolchain: 1.94.1 diff --git a/scripts/ci-workflow.test.ts b/scripts/ci-workflow.test.ts index ceb2bc5af..2b8fb66ae 100644 --- a/scripts/ci-workflow.test.ts +++ b/scripts/ci-workflow.test.ts @@ -127,7 +127,7 @@ describe("GitHub Action pinning", () => { it.each([ `uses: actions/checkout@${sha} # v4.4.0`, `uses: "actions/checkout@${sha}" # v4.4.0`, - `uses: dtolnay/rust-toolchain@${sha} # 1.94.1`, + `uses: dtolnay/rust-toolchain@${sha} # toolchain: 1.94.1`, "uses: ./path/to/local-action", "uses: docker://alpine:3.22", ])("accepts immutable, local or container reference: %s", (line) => { From f7f01e7738d72f56da2146e8d2e62e46cdce384f Mon Sep 17 00:00:00 2001 From: Cedric Vidal Date: Fri, 20 Nov 2026 08:54:15 -0800 Subject: [PATCH 4/7] fix(website): address contributor review feedback Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .github/workflows/contribution-data.yml | 4 +-- .mailmap | 1 + scripts/ci-workflow.test.ts | 2 +- website/AGENTS.md | 13 +++++---- website/src/data/contributors.sample.jsonl | 18 ++++++------ website/src/scripts/contributors.test.mjs | 32 ++++++++++------------ website/src/scripts/contributors.ts | 6 ++-- 7 files changed, 36 insertions(+), 40 deletions(-) create mode 100644 .mailmap diff --git a/.github/workflows/contribution-data.yml b/.github/workflows/contribution-data.yml index c495f3596..62cf0ca21 100644 --- a/.github/workflows/contribution-data.yml +++ b/.github/workflows/contribution-data.yml @@ -44,9 +44,7 @@ jobs: (map(.contributions) | add) as $commits | { commits: $commits, - login: .[0].login, - # Compatibility alias for the currently deployed reader. - prs: $commits + login: .[0].login } ) | sort_by(.login | ascii_downcase) diff --git a/.mailmap b/.mailmap new file mode 100644 index 000000000..1beab5ba4 --- /dev/null +++ b/.mailmap @@ -0,0 +1 @@ +Todd Anglin <647319+toddanglin@users.noreply.github.com> Todd Anglin diff --git a/scripts/ci-workflow.test.ts b/scripts/ci-workflow.test.ts index 2b8fb66ae..32c3911a0 100644 --- a/scripts/ci-workflow.test.ts +++ b/scripts/ci-workflow.test.ts @@ -359,7 +359,7 @@ describe("Website contribution data workflow", () => { expect(collect).toContain('endswith("[bot]")'); expect(collect).toContain("group_by(.login | ascii_downcase)"); expect(collect).toContain("commits: $commits"); - expect(collect).toContain("prs: $commits"); + expect(collect).not.toContain("prs:"); expect(collect).toContain("sort_by(.login | ascii_downcase)"); }); diff --git a/website/AGENTS.md b/website/AGENTS.md index 353883560..e04335ad1 100644 --- a/website/AGENTS.md +++ b/website/AGENTS.md @@ -227,15 +227,16 @@ repository's default branch (`main`), community and Microsoft alike: - The publisher writes `contributors.jsonl` to `website-data`. It uses GitHub's repository contributors endpoint and counts commits attributed on the default branch for user accounts, excluding bots - (`[bot]` suffix) and anonymous entries. + (`[bot]` suffix) and anonymous entries. The repository `.mailmap` + canonicalizes verified historical commit identities when an imported + author email is not associated with the corresponding GitHub account. - [`.github/workflows/contribution-data.yml`](../.github/workflows/contribution-data.yml) runs after pushes to `main` and on demand. It updates the orphan data branch only when the deterministic file changes. -- One line per person, `{"commits":N,"login":"…","prs":N}`, with sorted - keys and sorted by lowercase login. `prs` is a temporary compatibility - alias for the previously deployed reader and must equal `commits`; the - browser also accepts legacy lines containing only `prs`. No avatar URLs - or timestamps are published; avatars come from +- One line per person, `{"commits":N,"login":"…"}`, with sorted keys and + sorted by lowercase login. Legacy `prs`-only records are rejected rather + than relabeled as commits. No avatar URLs or timestamps are published; + avatars come from `https://github.com/.png`, and a failed image shows the login's initial. - The browser sorts by default-branch commits, then login. The wall shows up to diff --git a/website/src/data/contributors.sample.jsonl b/website/src/data/contributors.sample.jsonl index fe9f68df6..ae4b13a0a 100644 --- a/website/src/data/contributors.sample.jsonl +++ b/website/src/data/contributors.sample.jsonl @@ -1,9 +1,9 @@ -{"commits":515,"login":"cedricvidal","prs":515} -{"commits":9,"login":"chanezon","prs":9} -{"commits":2,"login":"cmaneu","prs":2} -{"commits":58,"login":"duffney","prs":58} -{"commits":1,"login":"Gile987","prs":1} -{"commits":2,"login":"idhanth","prs":2} -{"commits":1,"login":"itsmeasadali","prs":1} -{"commits":46,"login":"manekinekko","prs":46} -{"commits":2,"login":"mnkj0021","prs":2} +{"commits":515,"login":"cedricvidal"} +{"commits":9,"login":"chanezon"} +{"commits":2,"login":"cmaneu"} +{"commits":58,"login":"duffney"} +{"commits":1,"login":"Gile987"} +{"commits":2,"login":"idhanth"} +{"commits":1,"login":"itsmeasadali"} +{"commits":46,"login":"manekinekko"} +{"commits":2,"login":"mnkj0021"} diff --git a/website/src/scripts/contributors.test.mjs b/website/src/scripts/contributors.test.mjs index 73c192a48..01ec709c5 100644 --- a/website/src/scripts/contributors.test.mjs +++ b/website/src/scripts/contributors.test.mjs @@ -23,7 +23,7 @@ import { const line = (value) => JSON.stringify(value); test('parses JSON Lines and ignores blank lines', () => { - const text = [line({ commits: 2, login: 'ada', prs: 2 }), '', line({ commits: 1, login: 'grace-h', prs: 1 }), ''].join('\n'); + const text = [line({ commits: 2, login: 'ada' }), '', line({ commits: 1, login: 'grace-h' }), ''].join('\n'); assert.deepEqual(parseContributors(text), { contributors: [{ login: 'ada', commits: 2 }, { login: 'grace-h', commits: 1 }], skipped: [], @@ -34,29 +34,28 @@ test('treats an empty file as no contributors', () => { assert.deepEqual(parseContributors(''), { contributors: [], skipped: [] }); }); -test('accepts the legacy PR field as a commit count during rollout', () => { +test('rejects the legacy PR-count payload instead of relabeling it as commits', () => { assert.deepEqual(parseContributors(line({ login: 'ada', prs: 2 })), { - contributors: [{ login: 'ada', commits: 2 }], - skipped: [], + contributors: [], + skipped: [1], }); }); -test('skips invalid logins, counts, aliases and duplicates without dropping the rest', () => { +test('skips invalid logins, counts and duplicates without dropping the rest', () => { const text = [ '{not json', - line({ commits: 9, login: 'dependabot[bot]', prs: 9 }), - line({ commits: 1, login: '-leading', prs: 1 }), - line({ commits: 1, login: 'double--hyphen', prs: 1 }), - line({ commits: 1, login: '../evil', prs: 1 }), - line({ commits: 0, login: 'zero', prs: 0 }), - line({ commits: 1.5, login: 'fraction', prs: 1.5 }), - line({ commits: 3, login: 'mismatch', prs: 2 }), - line({ commits: 3, login: 'Kept', prs: 3 }), - line({ commits: 1, login: 'kept', prs: 1 }), + line({ commits: 9, login: 'dependabot[bot]' }), + line({ commits: 1, login: '-leading' }), + line({ commits: 1, login: 'double--hyphen' }), + line({ commits: 1, login: '../evil' }), + line({ commits: 0, login: 'zero' }), + line({ commits: 1.5, login: 'fraction' }), + line({ commits: 3, login: 'Kept' }), + line({ commits: 1, login: 'kept' }), ].join('\r\n'); const { contributors, skipped } = parseContributors(text); assert.deepEqual(contributors, [{ login: 'Kept', commits: 3 }]); - assert.deepEqual(skipped, [1, 2, 3, 4, 5, 6, 7, 8, 10]); + assert.deepEqual(skipped, [1, 2, 3, 4, 5, 6, 7, 9]); }); test('sorts by commits, then login case-insensitively', () => { @@ -143,7 +142,6 @@ test('the dev sample file is valid and sorted like the published file', () => { assert.deepEqual(logins, [...logins].sort()); for (const raw of text.trim().split('\n')) { const value = JSON.parse(raw); - assert.deepEqual(Object.keys(value), ['commits', 'login', 'prs'], 'keys are sorted and nothing else is published'); - assert.equal(value.prs, value.commits, 'the compatibility alias matches the commit count'); + assert.deepEqual(Object.keys(value), ['commits', 'login'], 'keys are sorted and nothing else is published'); } }); diff --git a/website/src/scripts/contributors.ts b/website/src/scripts/contributors.ts index f7abb5597..a6e45eb66 100644 --- a/website/src/scripts/contributors.ts +++ b/website/src/scripts/contributors.ts @@ -26,15 +26,13 @@ export interface ContributorsResult { // GitHub logins: alphanumerics and single hyphens, up to 39 characters. const LOGIN = /^[A-Za-z0-9](?:[A-Za-z0-9]|-(?=[A-Za-z0-9])){0,38}$/; -/** Normalizes current and legacy published records into the browser model. */ +/** Validates a published record before it enters the browser model. */ function parseContributor(value: unknown): Contributor | undefined { if (typeof value !== 'object' || value === null) return undefined; const record = value as Record; - const { login } = record; - const commits = Object.hasOwn(record, 'commits') ? record.commits : record.prs; + const { commits, login } = record; if (typeof login !== 'string' || !LOGIN.test(login)) return undefined; if (typeof commits !== 'number' || !Number.isSafeInteger(commits) || commits <= 0) return undefined; - if (Object.hasOwn(record, 'commits') && Object.hasOwn(record, 'prs') && record.prs !== commits) return undefined; return { login, commits }; } From d7b221189d787c92106096d5d56b64c163de210a Mon Sep 17 00:00:00 2001 From: Cedric Vidal Date: Fri, 20 Nov 2026 08:57:58 -0800 Subject: [PATCH 5/7] fix(website): aggregate default branch commits directly Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .github/workflows/contribution-data.yml | 17 ++++++++--------- scripts/ci-workflow.test.ts | 12 ++++++------ website/AGENTS.md | 12 +++++++----- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/.github/workflows/contribution-data.yml b/.github/workflows/contribution-data.yml index 62cf0ca21..2713a3b3b 100644 --- a/.github/workflows/contribution-data.yml +++ b/.github/workflows/contribution-data.yml @@ -22,6 +22,7 @@ jobs: env: GH_TOKEN: ${{ github.token }} REPO: ${{ github.repository }} + DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} DATA_BRANCH: website-data steps: - name: Collect contributors @@ -30,21 +31,19 @@ jobs: gh api --paginate \ -H 'Accept: application/vnd.github+json' \ -H 'X-GitHub-Api-Version: 2022-11-28' \ - "repos/${REPO}/contributors?per_page=100&anon=0" \ + "repos/${REPO}/commits?sha=${DEFAULT_BRANCH}&per_page=100" \ --jq '.[]' | jq -cS -s ' map(select( - .login != null - and .type == "User" - and (.login | endswith("[bot]") | not) - and (.contributions | type == "number" and . > 0 and floor == .) + .author != null + and .author.type == "User" + and (.author.login | endswith("[bot]") | not) )) - | group_by(.login | ascii_downcase) + | group_by(.author.login | ascii_downcase) | map( - (map(.contributions) | add) as $commits | { - commits: $commits, - login: .[0].login + commits: length, + login: .[0].author.login } ) | sort_by(.login | ascii_downcase) diff --git a/scripts/ci-workflow.test.ts b/scripts/ci-workflow.test.ts index 32c3911a0..793c29e2d 100644 --- a/scripts/ci-workflow.test.ts +++ b/scripts/ci-workflow.test.ts @@ -352,13 +352,13 @@ describe("Website contribution data workflow", () => { expect(publish.if).toBe("github.repository == 'microsoft/scope'"); }); - it("collects paginated human default-branch contributors deterministically", () => { + it("aggregates paginated default-branch commits by human GitHub author deterministically", () => { expect(collect).toContain("gh api --paginate"); - expect(collect).toContain('"repos/${REPO}/contributors?per_page=100&anon=0"'); - expect(collect).toContain('.type == "User"'); - expect(collect).toContain('endswith("[bot]")'); - expect(collect).toContain("group_by(.login | ascii_downcase)"); - expect(collect).toContain("commits: $commits"); + expect(collect).toContain('"repos/${REPO}/commits?sha=${DEFAULT_BRANCH}&per_page=100"'); + expect(collect).toContain('.author.type == "User"'); + expect(collect).toContain('.author.login | endswith("[bot]")'); + expect(collect).toContain("group_by(.author.login | ascii_downcase)"); + expect(collect).toContain("commits: length"); expect(collect).not.toContain("prs:"); expect(collect).toContain("sort_by(.login | ascii_downcase)"); }); diff --git a/website/AGENTS.md b/website/AGENTS.md index e04335ad1..47d87fb2e 100644 --- a/website/AGENTS.md +++ b/website/AGENTS.md @@ -225,11 +225,13 @@ page (a card grid) thank everyone with commits attributed on the repository's default branch (`main`), community and Microsoft alike: - The publisher writes `contributors.jsonl` to `website-data`. It - uses GitHub's repository contributors endpoint and counts commits - attributed on the default branch for user accounts, excluding bots - (`[bot]` suffix) and anonymous entries. The repository `.mailmap` - canonicalizes verified historical commit identities when an imported - author email is not associated with the corresponding GitHub account. + paginates GitHub's repository commits endpoint for the default branch, + groups commits by their associated GitHub user account, and excludes bots + (`[bot]` suffix) and anonymous entries. This avoids the delayed statistics + cache used by the aggregate contributors endpoint. The repository + `.mailmap` canonicalizes verified historical commit identities when an + imported author email is not associated with the corresponding GitHub + account. - [`.github/workflows/contribution-data.yml`](../.github/workflows/contribution-data.yml) runs after pushes to `main` and on demand. It updates the orphan data branch only when the deterministic file changes. From 77e0991a6e5022a310b559bcd7ac113e254a8ed0 Mon Sep 17 00:00:00 2001 From: Cedric Vidal Date: Fri, 20 Nov 2026 09:03:48 -0800 Subject: [PATCH 6/7] fix(website): load contributor stats directly Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .github/workflows/contribution-data.yml | 72 ----------------- CONTRIBUTING.md | 4 +- scripts/ci-workflow.test.ts | 40 ---------- website/AGENTS.md | 30 +++----- website/README.md | 7 +- .../components/contribute/Contributors.astro | 3 +- website/src/data/contributors.sample.json | 11 +++ website/src/data/contributors.sample.jsonl | 9 --- website/src/scripts/contributors-element.ts | 8 +- website/src/scripts/contributors.test.mjs | 77 ++++++++++++------- website/src/scripts/contributors.ts | 73 +++++++++++------- website/tests/accessibility.spec.ts | 2 +- website/tests/analytics.spec.ts | 2 +- 13 files changed, 130 insertions(+), 208 deletions(-) delete mode 100644 .github/workflows/contribution-data.yml create mode 100644 website/src/data/contributors.sample.json delete mode 100644 website/src/data/contributors.sample.jsonl diff --git a/.github/workflows/contribution-data.yml b/.github/workflows/contribution-data.yml deleted file mode 100644 index 2713a3b3b..000000000 --- a/.github/workflows/contribution-data.yml +++ /dev/null @@ -1,72 +0,0 @@ -# Publishes default-branch commit contributors to the orphan `website-data` -# branch. The docs site fetches the deterministic JSONL at runtime. -name: Publish website contribution data - -on: - push: - branches: [main] - workflow_dispatch: - -permissions: - contents: write - -concurrency: - group: website-contribution-data - cancel-in-progress: false - -jobs: - publish: - if: github.repository == 'microsoft/scope' - runs-on: ubuntu-latest - timeout-minutes: 10 - env: - GH_TOKEN: ${{ github.token }} - REPO: ${{ github.repository }} - DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} - DATA_BRANCH: website-data - steps: - - name: Collect contributors - run: | - set -euo pipefail - gh api --paginate \ - -H 'Accept: application/vnd.github+json' \ - -H 'X-GitHub-Api-Version: 2022-11-28' \ - "repos/${REPO}/commits?sha=${DEFAULT_BRANCH}&per_page=100" \ - --jq '.[]' | - jq -cS -s ' - map(select( - .author != null - and .author.type == "User" - and (.author.login | endswith("[bot]") | not) - )) - | group_by(.author.login | ascii_downcase) - | map( - | { - commits: length, - login: .[0].author.login - } - ) - | sort_by(.login | ascii_downcase) - | .[]' > contributors.jsonl - - - name: Publish website data - run: | - set -euo pipefail - git init -q data - cd data - git config user.name 'github-actions[bot]' - git config user.email '41898282+github-actions[bot]@users.noreply.github.com' - git remote add origin "https://x-access-token:${GH_TOKEN}@github.com/${REPO}.git" - if git fetch -q --depth 1 origin "$DATA_BRANCH" 2>/dev/null; then - git checkout -q -B "$DATA_BRANCH" FETCH_HEAD - else - git checkout -q --orphan "$DATA_BRANCH" - fi - cp ../contributors.jsonl . - git add contributors.jsonl - if git diff --cached --quiet; then - echo 'No website data changes.' - exit 0 - fi - git commit -q -m 'Update website contribution data' - git push -q origin "HEAD:$DATA_BRANCH" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ce13c577d..b55e85bea 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -453,8 +453,8 @@ unblock a PR. Thank the contributor and link any follow-up work. Once merged, the author appears in the "Thank you" section of the [Contribute page](https://microsoft.github.io/scope/community/contribute/#thank-you) -and on the landing page after the merge-triggered contribution-data workflow completes. The PR -owner checks the post-merge result and coordinates a fix or revert if needed. +and on the landing page after GitHub refreshes the repository contributor statistics. The PR owner +checks the post-merge result and coordinates a fix or revert if needed. If a contribution is not a fit, explain why and close it promptly. When a PR is waiting on the contributor after a clear request for information or changes, send a reminder after **two weeks diff --git a/scripts/ci-workflow.test.ts b/scripts/ci-workflow.test.ts index 793c29e2d..6d387174c 100644 --- a/scripts/ci-workflow.test.ts +++ b/scripts/ci-workflow.test.ts @@ -48,15 +48,6 @@ const communityContributionWorkflow = parse(communityContributionWorkflowSource) permissions: Record; jobs: Record; }; -const contributionDataWorkflowSource = readFileSync(".github/workflows/contribution-data.yml", "utf8"); -const contributionDataWorkflow = parse(contributionDataWorkflowSource) as { - on: { - push: { branches: string[] }; - workflow_dispatch: null; - }; - permissions: Record; - jobs: Record; -}; const actionPinningWorkflow = parse(readFileSync(".github/workflows/pin-actions.yml", "utf8")) as { on: { push: { paths: string[] }; @@ -339,37 +330,6 @@ describe("Community contribution labeler workflow", () => { }); }); -describe("Website contribution data workflow", () => { - const publish = contributionDataWorkflow.jobs.publish; - const collect = publish.steps.find((candidate) => candidate.name === "Collect contributors")?.run ?? ""; - - it("publishes default-branch commit contributors after changes and on demand", () => { - expect(contributionDataWorkflow.on).toEqual({ - push: { branches: ["main"] }, - workflow_dispatch: null, - }); - expect(contributionDataWorkflow.permissions).toEqual({ contents: "write" }); - expect(publish.if).toBe("github.repository == 'microsoft/scope'"); - }); - - it("aggregates paginated default-branch commits by human GitHub author deterministically", () => { - expect(collect).toContain("gh api --paginate"); - expect(collect).toContain('"repos/${REPO}/commits?sha=${DEFAULT_BRANCH}&per_page=100"'); - expect(collect).toContain('.author.type == "User"'); - expect(collect).toContain('.author.login | endswith("[bot]")'); - expect(collect).toContain("group_by(.author.login | ascii_downcase)"); - expect(collect).toContain("commits: length"); - expect(collect).not.toContain("prs:"); - expect(collect).toContain("sort_by(.login | ascii_downcase)"); - }); - - it("keeps every embedded shell step syntactically valid", () => { - for (const command of publish.steps.filter((candidate) => candidate.run)) { - expect(spawnSync("bash", ["-n"], { input: command.run }).status, command.name).toBe(0); - } - }); -}); - describe("Public CLI release workflow", () => { const release = parse(readFileSync(".github/workflows/publish-cli.yml", "utf8")) as { on: Record; diff --git a/website/AGENTS.md b/website/AGENTS.md index 47d87fb2e..a952941c1 100644 --- a/website/AGENTS.md +++ b/website/AGENTS.md @@ -224,21 +224,15 @@ The landing page (an avatar wall) and the **Community → Contributors** page (a card grid) thank everyone with commits attributed on the repository's default branch (`main`), community and Microsoft alike: -- The publisher writes `contributors.jsonl` to `website-data`. It - paginates GitHub's repository commits endpoint for the default branch, - groups commits by their associated GitHub user account, and excludes bots - (`[bot]` suffix) and anonymous entries. This avoids the delayed statistics - cache used by the aggregate contributors endpoint. The repository - `.mailmap` canonicalizes verified historical commit identities when an - imported author email is not associated with the corresponding GitHub - account. -- [`.github/workflows/contribution-data.yml`](../.github/workflows/contribution-data.yml) - runs after pushes to `main` and on demand. It updates the orphan data - branch only when the deterministic file changes. -- One line per person, `{"commits":N,"login":"…"}`, with sorted keys and - sorted by lowercase login. Legacy `prs`-only records are rejected rather - than relabeled as commits. No avatar URLs or timestamps are published; - avatars come from +- The browser calls GitHub's repository contributors endpoint directly, + follows its pagination links, and uses `contributions` as the number of + commits attributed on the default branch. It excludes bots and anonymous + entries. GitHub may cache these statistics for a few hours. +- No token is shipped to the browser. The public endpoint's unauthenticated + rate limit applies; an error keeps the fallback link to GitHub's contributor + graph visible. In local development only, a failed request uses + [`contributors.sample.json`](src/data/contributors.sample.json). +- No avatar URLs or timestamps are stored; avatars come from `https://github.com/.png`, and a failed image shows the login's initial. - The browser sorts by default-branch commits, then login. The wall shows up to @@ -254,10 +248,8 @@ repository's default branch (`main`), community and Microsoft alike: states. Check 0, 1, a few, and more contributors than fit the width, on desktop and mobile, when changing the layout. - Set `PUBLIC_CONTRIBUTORS_URL` to point at another file - ([`contributors.ts`](src/scripts/contributors.ts)). In - `pnpm run dev` a failed fetch falls back to - [`contributors.sample.jsonl`](src/data/contributors.sample.jsonl), - which lists real contributors only. + ([`contributors.ts`](src/scripts/contributors.ts)) that returns GitHub's + contributor-array shape. - Logins are user data: render them with `textContent` or attributes only. ### Style diff --git a/website/README.md b/website/README.md index 8f3e804e7..3f5b193c8 100644 --- a/website/README.md +++ b/website/README.md @@ -199,10 +199,9 @@ table of contents, code examples, and previous/next navigation. pause controls and reduced-motion support. The logo and documentation chrome remain still. - **Contribution:** a landing-page wall and full grid thank contributors with - commits attributed on the default branch (`main`), refreshed after - default-branch changes from a data branch without a redeploy. Contributor - links still open merged pull requests. The publisher is - `.github/workflows/contribution-data.yml`; see "Contributors" in `AGENTS.md`. + commits attributed on the default branch (`main`), loaded from GitHub's + repository contributor statistics. Contributor links still open merged + pull requests; see "Contributors" in `AGENTS.md`. ### Showreel diff --git a/website/src/components/contribute/Contributors.astro b/website/src/components/contribute/Contributors.astro index d909372ee..16425fd2b 100644 --- a/website/src/components/contribute/Contributors.astro +++ b/website/src/components/contribute/Contributors.astro @@ -3,8 +3,7 @@ // Licensed under the MIT License. // Thanks contributors: everyone (bots aside) who got a pull request merged. -// The contribution-data workflow publishes the list to the website-data -// branch, and the browser fetches it. See website/AGENTS.md. +// The browser fetches GitHub's contributor statistics. See website/AGENTS.md. import '../../styles/contributions.css'; import '../../styles/contributors.css'; import { CONTRIBUTORS_DATA_URL, CONTRIBUTORS_GRAPH_URL } from '../../scripts/contributors'; diff --git a/website/src/data/contributors.sample.json b/website/src/data/contributors.sample.json new file mode 100644 index 000000000..3639e3aae --- /dev/null +++ b/website/src/data/contributors.sample.json @@ -0,0 +1,11 @@ +[ + {"contributions":515,"login":"cedricvidal","type":"User"}, + {"contributions":9,"login":"chanezon","type":"User"}, + {"contributions":2,"login":"cmaneu","type":"User"}, + {"contributions":58,"login":"duffney","type":"User"}, + {"contributions":1,"login":"Gile987","type":"User"}, + {"contributions":2,"login":"idhanth","type":"User"}, + {"contributions":1,"login":"itsmeasadali","type":"User"}, + {"contributions":46,"login":"manekinekko","type":"User"}, + {"contributions":2,"login":"mnkj0021","type":"User"} +] diff --git a/website/src/data/contributors.sample.jsonl b/website/src/data/contributors.sample.jsonl deleted file mode 100644 index ae4b13a0a..000000000 --- a/website/src/data/contributors.sample.jsonl +++ /dev/null @@ -1,9 +0,0 @@ -{"commits":515,"login":"cedricvidal"} -{"commits":9,"login":"chanezon"} -{"commits":2,"login":"cmaneu"} -{"commits":58,"login":"duffney"} -{"commits":1,"login":"Gile987"} -{"commits":2,"login":"idhanth"} -{"commits":1,"login":"itsmeasadali"} -{"commits":46,"login":"manekinekko"} -{"commits":2,"login":"mnkj0021"} diff --git a/website/src/scripts/contributors-element.ts b/website/src/scripts/contributors-element.ts index 340ff32a3..12c245f8d 100644 --- a/website/src/scripts/contributors-element.ts +++ b/website/src/scripts/contributors-element.ts @@ -85,8 +85,8 @@ class ScopeContributors extends HTMLElement { // Development fallback only; production builds omit the sample. if (import.meta.env.DEV) { console.info('[contributors] Live list unavailable; using the dev sample.', error); - const { default: text } = await import('../data/contributors.sample.jsonl?raw'); - result = parseContributors(text); + const { default: text } = await import('../data/contributors.sample.json?raw'); + result = parseContributors(JSON.parse(text)); sample = true; } else { console.warn('[contributors] Could not load the live list.', error); @@ -94,7 +94,7 @@ class ScopeContributors extends HTMLElement { return; } } - if (result.skipped.length) console.warn(`[contributors] Skipped invalid lines: ${result.skipped.join(', ')}`); + if (result.skipped.length) console.warn(`[contributors] Skipped invalid entries: ${result.skipped.join(', ')}`); this.querySelectorAll('[data-sample-tag]').forEach((tag) => { tag.hidden = !sample; }); await this.render(result.contributors); } @@ -252,7 +252,7 @@ class ScopeContributors extends HTMLElement { }, { signal, passive: true }); } - // Logins come from published data, so every value is set as text or attribute. + // Logins come from GitHub data, so every value is set as text or attribute. private avatar(contributor: Contributor): HTMLLIElement { const item = this.item(); const link = this.link(item, 'thanks-avatar', prsUrl(contributor.login)); diff --git a/website/src/scripts/contributors.test.mjs b/website/src/scripts/contributors.test.mjs index 01ec709c5..0bd6c7ad5 100644 --- a/website/src/scripts/contributors.test.mjs +++ b/website/src/scripts/contributors.test.mjs @@ -10,6 +10,7 @@ import { avatarUrl, commitsLabel, contributorsLabel, + fetchContributors, firstPage, parseContributors, prsUrl, @@ -20,44 +21,65 @@ import { visible, } from './contributors.ts'; -const line = (value) => JSON.stringify(value); - -test('parses JSON Lines and ignores blank lines', () => { - const text = [line({ commits: 2, login: 'ada' }), '', line({ commits: 1, login: 'grace-h' }), ''].join('\n'); - assert.deepEqual(parseContributors(text), { +test('parses GitHub contributor records', () => { + const records = [ + { contributions: 2, login: 'ada', type: 'User' }, + { contributions: 1, login: 'grace-h', type: 'User' }, + ]; + assert.deepEqual(parseContributors(records), { contributors: [{ login: 'ada', commits: 2 }, { login: 'grace-h', commits: 1 }], skipped: [], }); }); -test('treats an empty file as no contributors', () => { - assert.deepEqual(parseContributors(''), { contributors: [], skipped: [] }); +test('treats an empty array as no contributors', () => { + assert.deepEqual(parseContributors([]), { contributors: [], skipped: [] }); }); -test('rejects the legacy PR-count payload instead of relabeling it as commits', () => { - assert.deepEqual(parseContributors(line({ login: 'ada', prs: 2 })), { +test('rejects a non-array response', () => { + assert.deepEqual(parseContributors({ message: 'rate limited' }), { contributors: [], skipped: [1], }); }); -test('skips invalid logins, counts and duplicates without dropping the rest', () => { - const text = [ - '{not json', - line({ commits: 9, login: 'dependabot[bot]' }), - line({ commits: 1, login: '-leading' }), - line({ commits: 1, login: 'double--hyphen' }), - line({ commits: 1, login: '../evil' }), - line({ commits: 0, login: 'zero' }), - line({ commits: 1.5, login: 'fraction' }), - line({ commits: 3, login: 'Kept' }), - line({ commits: 1, login: 'kept' }), - ].join('\r\n'); - const { contributors, skipped } = parseContributors(text); +test('skips bots, anonymous records, invalid values and duplicates', () => { + const records = [ + { contributions: 9, login: 'dependabot[bot]', type: 'Bot' }, + { contributions: 1, email: 'anonymous@example.com', type: 'Anonymous' }, + { contributions: 1, login: '-leading', type: 'User' }, + { contributions: 1, login: 'double--hyphen', type: 'User' }, + { contributions: 1, login: '../evil', type: 'User' }, + { contributions: 0, login: 'zero', type: 'User' }, + { contributions: 1.5, login: 'fraction', type: 'User' }, + { contributions: 3, login: 'Kept', type: 'User' }, + { contributions: 1, login: 'kept', type: 'User' }, + ]; + const { contributors, skipped } = parseContributors(records); assert.deepEqual(contributors, [{ login: 'Kept', commits: 3 }]); assert.deepEqual(skipped, [1, 2, 3, 4, 5, 6, 7, 9]); }); +test('follows GitHub pagination links', async (context) => { + const originalFetch = globalThis.fetch; + context.after(() => { globalThis.fetch = originalFetch; }); + const pages = new Map([ + ['https://api.example.test/contributors', new Response( + JSON.stringify([{ contributions: 2, login: 'ada', type: 'User' }]), + { headers: { link: '; rel="next", ; rel="last"' } }, + )], + ['https://api.example.test/contributors?page=2', new Response( + JSON.stringify([{ contributions: 1, login: 'grace-h', type: 'User' }]), + )], + ]); + globalThis.fetch = async (url) => pages.get(String(url)) ?? new Response('', { status: 404 }); + + assert.deepEqual(await fetchContributors('https://api.example.test/contributors'), { + contributors: [{ login: 'ada', commits: 2 }, { login: 'grace-h', commits: 1 }], + skipped: [], + }); +}); + test('sorts by commits, then login case-insensitively', () => { const sorted = sortForDisplay([ { login: 'zed', commits: 1 }, @@ -133,15 +155,14 @@ test('aligns a tooltip wider than the bounds to the left edge', () => { assert.equal(50 + shift - 80, 0); }); -test('the dev sample file is valid and sorted like the published file', () => { - const text = readFileSync(new URL('../data/contributors.sample.jsonl', import.meta.url), 'utf8'); - const { contributors, skipped } = parseContributors(text); +test('the dev sample file matches GitHub and is sorted by login', () => { + const value = JSON.parse(readFileSync(new URL('../data/contributors.sample.json', import.meta.url), 'utf8')); + const { contributors, skipped } = parseContributors(value); assert.deepEqual(skipped, []); assert.ok(contributors.length >= 1); const logins = contributors.map((c) => c.login.toLowerCase()); assert.deepEqual(logins, [...logins].sort()); - for (const raw of text.trim().split('\n')) { - const value = JSON.parse(raw); - assert.deepEqual(Object.keys(value), ['commits', 'login'], 'keys are sorted and nothing else is published'); + for (const record of value) { + assert.deepEqual(Object.keys(record), ['contributions', 'login', 'type']); } }); diff --git a/website/src/scripts/contributors.ts b/website/src/scripts/contributors.ts index a6e45eb66..ce7d8479e 100644 --- a/website/src/scripts/contributors.ts +++ b/website/src/scripts/contributors.ts @@ -1,13 +1,12 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -// Data helpers for the contributors thank-you section. The list is -// published as JSON Lines on the `website-data` branch by -// .github/workflows/contribution-data.yml and fetched in the browser. -// This module has no DOM dependencies so it can be unit-tested in Node. +// Data helpers for the contributors thank-you section. The browser reads +// GitHub's repository contributor statistics directly. This module has no +// DOM dependencies so it can be unit-tested in Node. const REPOSITORY = 'microsoft/scope'; -export const CONTRIBUTORS_DATA_URL = `https://raw.githubusercontent.com/${REPOSITORY}/website-data/contributors.jsonl`; +export const CONTRIBUTORS_DATA_URL = `https://api.github.com/repos/${REPOSITORY}/contributors?anon=0&per_page=100`; export const CONTRIBUTORS_GRAPH_URL = `https://github.com/${REPOSITORY}/graphs/contributors`; export interface Contributor { @@ -26,34 +25,28 @@ export interface ContributorsResult { // GitHub logins: alphanumerics and single hyphens, up to 39 characters. const LOGIN = /^[A-Za-z0-9](?:[A-Za-z0-9]|-(?=[A-Za-z0-9])){0,38}$/; -/** Validates a published record before it enters the browser model. */ +/** Validates a GitHub contributor record before it enters the browser model. */ function parseContributor(value: unknown): Contributor | undefined { if (typeof value !== 'object' || value === null) return undefined; const record = value as Record; - const { commits, login } = record; + const { contributions, login, type } = record; if (typeof login !== 'string' || !LOGIN.test(login)) return undefined; - if (typeof commits !== 'number' || !Number.isSafeInteger(commits) || commits <= 0) return undefined; - return { login, commits }; + if (type !== 'User' || login.endsWith('[bot]')) return undefined; + if (typeof contributions !== 'number' || !Number.isSafeInteger(contributions) || contributions <= 0) return undefined; + return { login, commits: contributions }; } /** - * Parses the JSON Lines payload. Invalid lines, bot accounts and duplicate - * logins are skipped so one bad line can't hide the list. + * Parses GitHub's contributor array. Invalid entries, bot accounts and + * duplicate logins are skipped so one bad entry can't hide the list. */ -export function parseContributors(text: string): ContributorsResult { +export function parseContributors(value: unknown): ContributorsResult { const contributors: Contributor[] = []; const skipped: number[] = []; const seen = new Set(); - text.split(/\r?\n/).forEach((line, index) => { - if (line.trim() === '') return; - let value: unknown; - try { - value = JSON.parse(line); - } catch { - skipped.push(index + 1); - return; - } - const contributor = parseContributor(value); + if (!Array.isArray(value)) return { contributors, skipped: [1] }; + value.forEach((entry, index) => { + const contributor = parseContributor(entry); if (!contributor || seen.has(contributor.login.toLowerCase())) { skipped.push(index + 1); return; @@ -64,6 +57,16 @@ export function parseContributors(text: string): ContributorsResult { return { contributors, skipped }; } +/** Returns the URL GitHub identifies as the next page, when present. */ +function nextPageUrl(link: string | null): string | undefined { + if (!link) return undefined; + for (const part of link.split(',')) { + const match = part.match(/^\s*<([^>]+)>;\s*rel="([^"]+)"\s*$/); + if (match?.[2].split(/\s+/).includes('next')) return match[1]; + } + return undefined; +} + /** Display order: most commits first, then by login. */ export function sortForDisplay(contributors: readonly Contributor[]): Contributor[] { return [...contributors].sort((a, b) => b.commits - a.commits || a.login.localeCompare(b.login, 'en', { sensitivity: 'base' })); @@ -123,9 +126,27 @@ export function tipShift(center: number, halfWidth: number, left: number, right: return min > 0 ? min : max < 0 ? max : 0; } -/** Fetches and parses the published list. Throws on network or HTTP errors. */ +/** Fetches and parses every GitHub contributor page. */ export async function fetchContributors(url: string, timeoutMs = 8000): Promise { - const response = await fetch(url, { signal: AbortSignal.timeout(timeoutMs) }); - if (!response.ok) throw new Error(`Contributors request failed: HTTP ${response.status}`); - return parseContributors(await response.text()); + const records: unknown[] = []; + const visited = new Set(); + let pageUrl: string | undefined = url; + + while (pageUrl) { + if (visited.has(pageUrl)) throw new Error('Contributors pagination loop detected'); + visited.add(pageUrl); + + const response = await fetch(pageUrl, { + headers: { Accept: 'application/vnd.github+json' }, + signal: AbortSignal.timeout(timeoutMs), + }); + if (!response.ok) throw new Error(`Contributors request failed: HTTP ${response.status}`); + + const page: unknown = await response.json(); + if (!Array.isArray(page)) throw new Error('Contributors response was not an array'); + records.push(...page); + pageUrl = nextPageUrl(response.headers.get('link')); + } + + return parseContributors(records); } diff --git a/website/tests/accessibility.spec.ts b/website/tests/accessibility.spec.ts index b945b93c3..6050079e4 100644 --- a/website/tests/accessibility.spec.ts +++ b/website/tests/accessibility.spec.ts @@ -5,7 +5,7 @@ import { AxeBuilder } from '@axe-core/playwright'; import { expect, test, type Page } from '@playwright/test'; const PUBLISHED_DATA_URLS = new Set([ - 'https://raw.githubusercontent.com/microsoft/scope/website-data/contributors.jsonl', + 'https://api.github.com/repos/microsoft/scope/contributors?anon=0&per_page=100', ]); const GITHUB_LOGIN = /^[A-Za-z0-9](?:[A-Za-z0-9]|-(?=[A-Za-z0-9])){0,38}$/; diff --git a/website/tests/analytics.spec.ts b/website/tests/analytics.spec.ts index 699336f49..e14a870c6 100644 --- a/website/tests/analytics.spec.ts +++ b/website/tests/analytics.spec.ts @@ -4,7 +4,7 @@ import { expect, test, type Page } from '@playwright/test'; const PUBLISHED_DATA_URLS = new Set([ - 'https://raw.githubusercontent.com/microsoft/scope/website-data/contributors.jsonl', + 'https://api.github.com/repos/microsoft/scope/contributors?anon=0&per_page=100', ]); interface AnalyticsTestState { From b0aff0fcdbeb6029ee40977fe9b94103f4b91d80 Mon Sep 17 00:00:00 2001 From: Cedric Vidal Date: Fri, 20 Nov 2026 09:22:01 -0800 Subject: [PATCH 7/7] test(website): isolate contributor API requests Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- website/tests/accessibility.spec.ts | 13 ++++++++++--- website/tests/analytics.spec.ts | 24 +++++++++++++++++++----- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/website/tests/accessibility.spec.ts b/website/tests/accessibility.spec.ts index 6050079e4..9011e080a 100644 --- a/website/tests/accessibility.spec.ts +++ b/website/tests/accessibility.spec.ts @@ -4,9 +4,9 @@ import { AxeBuilder } from '@axe-core/playwright'; import { expect, test, type Page } from '@playwright/test'; -const PUBLISHED_DATA_URLS = new Set([ - 'https://api.github.com/repos/microsoft/scope/contributors?anon=0&per_page=100', -]); +const CONTRIBUTORS_DATA_URL = 'https://api.github.com/repos/microsoft/scope/contributors?anon=0&per_page=100'; +const PUBLISHED_DATA_URLS = new Set([CONTRIBUTORS_DATA_URL]); +const CONTRIBUTORS_RESPONSE = [{ contributions: 1, login: 'octocat', type: 'User' }]; const GITHUB_LOGIN = /^[A-Za-z0-9](?:[A-Za-z0-9]|-(?=[A-Za-z0-9])){0,38}$/; @@ -41,6 +41,13 @@ async function expectAccessible(page: Page) { )).toBe(true); } +test.beforeEach(async ({ page }) => { + await page.route(CONTRIBUTORS_DATA_URL, (route) => route.fulfill({ + contentType: 'application/json', + body: JSON.stringify(CONTRIBUTORS_RESPONSE), + })); +}); + test('landing page and interactive example are accessible', async ({ page }) => { await page.goto('/scope/'); const kubernetesSection = page.locator('.scope-kubernetes'); diff --git a/website/tests/analytics.spec.ts b/website/tests/analytics.spec.ts index e14a870c6..9ef128762 100644 --- a/website/tests/analytics.spec.ts +++ b/website/tests/analytics.spec.ts @@ -3,9 +3,9 @@ import { expect, test, type Page } from '@playwright/test'; -const PUBLISHED_DATA_URLS = new Set([ - 'https://api.github.com/repos/microsoft/scope/contributors?anon=0&per_page=100', -]); +const CONTRIBUTORS_DATA_URL = 'https://api.github.com/repos/microsoft/scope/contributors?anon=0&per_page=100'; +const PUBLISHED_DATA_URLS = new Set([CONTRIBUTORS_DATA_URL]); +const CONTRIBUTORS_RESPONSE = [{ contributions: 1, login: 'octocat', type: 'User' }]; interface AnalyticsTestState { granted: boolean; @@ -100,8 +100,15 @@ async function mockPublishedSite(page: Page, options: { }, options); await page.route('https://microsoft.github.io/**', async (route) => { const url = new URL(route.request().url()); - const response = await page.request.get(`http://127.0.0.1:14321${url.pathname}${url.search}`); - await route.fulfill({ response }); + const response = await fetch(`http://127.0.0.1:14321${url.pathname}${url.search}`); + const headers = Object.fromEntries(response.headers); + delete headers['content-encoding']; + delete headers['content-length']; + await route.fulfill({ + body: Buffer.from(await response.arrayBuffer()), + headers, + status: response.status, + }); }); await page.route('https://wcpstatic.microsoft.com/**', async (route) => { await route.fulfill({ contentType: 'text/javascript', body: `(${consentStub.toString()})();` }); @@ -112,6 +119,13 @@ async function mockPublishedSite(page: Page, options: { await page.route('https://*.events.data.microsoft.com/**', (route) => route.abort()); } +test.beforeEach(async ({ page }) => { + await page.route(CONTRIBUTORS_DATA_URL, (route) => route.fulfill({ + contentType: 'application/json', + body: JSON.stringify(CONTRIBUTORS_RESPONSE), + })); +}); + test('analytics waits for consent and uses the Scope configuration', async ({ page }) => { await mockPublishedSite(page); const sdkRequests: string[] = [];