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 328f2061f..84d72840a 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@2d81d658c8c4093152107cdb91c1e9545a9f992c # 1.94.1 + uses: dtolnay/rust-toolchain@2d81d658c8c4093152107cdb91c1e9545a9f992c # 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@2d81d658c8c4093152107cdb91c1e9545a9f992c # 1.94.1 + uses: dtolnay/rust-toolchain@2d81d658c8c4093152107cdb91c1e9545a9f992c # toolchain: 1.94.1 with: toolchain: 1.94.1 diff --git a/.github/workflows/contribution-data.yml b/.github/workflows/contribution-data.yml deleted file mode 100644 index d0748e6ad..000000000 --- a/.github/workflows/contribution-data.yml +++ /dev/null @@ -1,75 +0,0 @@ -# Publishes merged pull request 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 - pull-requests: read - -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 }} - DATA_BRANCH: website-data - steps: - - 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[]' | - jq -cS -s ' - map(select( - .author != null - and .author.__typename == "User" - and (.author.login | endswith("[bot]") | not) - )) - | group_by(.author.login) - | map({login: .[0].author.login, prs: length}) - | 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/.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/CONTRIBUTING.md b/CONTRIBUTING.md index d965ae089..3c89cebd2 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 0da2bcedc..6d387174c 100644 --- a/scripts/ci-workflow.test.ts +++ b/scripts/ci-workflow.test.ts @@ -118,7 +118,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) => { diff --git a/website/AGENTS.md b/website/AGENTS.md index 4ed0ee1f6..a952941c1 100644 --- a/website/AGENTS.md +++ b/website/AGENTS.md @@ -221,35 +221,35 @@ 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: - -- 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`. -- [`.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 +page (a card grid) thank everyone with commits attributed on the +repository's default branch (`main`), community and Microsoft alike: + +- 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 `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 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 570e9a19f..3f5b193c8 100644 --- a/website/README.md +++ b/website/README.md @@ -198,10 +198,10 @@ 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 contributors with + 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/ContributeTeaser.astro b/website/src/components/contribute/ContributeTeaser.astro index 5029839ff..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 got a pull request merged into Scope. Hover an avatar to see how many.

+

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 f0337a26b..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'; @@ -46,7 +45,7 @@ const listId = `thanks-list-${variant}`; ) }

- No pull request 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 3e51d5adb..7cac9359f 100644 --- a/website/src/content/docs/community/contribute.mdx +++ b/website/src/content/docs/community/contribute.mdx @@ -1,12 +1,14 @@ --- title: Contributors -description: Thanking everyone whose pull requests have been merged into Scope. +description: Thanking everyone with commits attributed on Scope's main branch. --- 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 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/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 d2fee8679..000000000 --- a/website/src/data/contributors.sample.jsonl +++ /dev/null @@ -1,9 +0,0 @@ -{"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} diff --git a/website/src/scripts/contributors-element.ts b/website/src/scripts/contributors-element.ts index e39795a62..12c245f8d 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 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. @@ -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); } @@ -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(); @@ -252,14 +252,14 @@ 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)); 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..0bd6c7ad5 100644 --- a/website/src/scripts/contributors.test.mjs +++ b/website/src/scripts/contributors.test.mjs @@ -8,55 +8,84 @@ import assert from 'node:assert/strict'; import { readFileSync } from 'node:fs'; import { avatarUrl, + commitsLabel, contributorsLabel, + fetchContributors, 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'); - assert.deepEqual(parseContributors(text), { - contributors: [{ login: 'ada', prs: 2 }, { login: 'grace-h', prs: 1 }], +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('skips invalid logins, counts 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 }), - ].join('\r\n'); - const { contributors, skipped } = parseContributors(text); - assert.deepEqual(contributors, [{ login: 'Kept', prs: 3 }]); +test('rejects a non-array response', () => { + assert.deepEqual(parseContributors({ message: 'rate limited' }), { + contributors: [], + skipped: [1], + }); +}); + +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('sorts by merged PRs, then login case-insensitively', () => { +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', 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 +98,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 on main'); + assert.equal(commitsLabel(3), '3 commits on main'); 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', () => { @@ -126,14 +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')) { - assert.deepEqual(Object.keys(JSON.parse(raw)), ['login', 'prs'], '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 aae7281c4..ce7d8479e 100644 --- a/website/src/scripts/contributors.ts +++ b/website/src/scripts/contributors.ts @@ -1,19 +1,19 @@ // 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 { + /** GitHub account login. */ login: string; - /** Number of merged pull requests. */ - prs: number; + /** Number of commits attributed on the repository's default branch. */ + commits: number; } export interface ContributorsResult { @@ -25,42 +25,51 @@ 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; +/** 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 { contributions, login, type } = record; + if (typeof login !== 'string' || !LOGIN.test(login)) return undefined; + 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 { + 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; } - if (!isContributor(value) || seen.has(value.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. */ +/** 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.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 +82,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 on main' : `${count} commits on main`; } 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. */ @@ -117,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/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); } diff --git a/website/tests/accessibility.spec.ts b/website/tests/accessibility.spec.ts index b945b93c3..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://raw.githubusercontent.com/microsoft/scope/website-data/contributors.jsonl', -]); +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 699336f49..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://raw.githubusercontent.com/microsoft/scope/website-data/contributors.jsonl', -]); +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[] = [];