-
Notifications
You must be signed in to change notification settings - Fork 0
Include anonymous human GitHub contributors and preserve hyphenated names #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
beanbean9339
wants to merge
2
commits into
main
Choose a base branch
from
fix/issue-69-anonymous-names
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| import test from 'node:test'; | ||
| import assert from 'node:assert/strict'; | ||
|
|
||
| import { buildContributorAuthorInput, extractCoAuthorNamesFromCommitMessage, fetchContributorAuthors } from '../../src/services/githubImporterContributors.js'; | ||
| import { buildGithubContributorsApiUrl } from '../../src/services/githubApi.js'; | ||
| import { importGithubMetadata } from '../../src/services/githubImporter.js'; | ||
| import { cleanString, normalizeAuthor, normalizeAuthors } from '../../src/services/githubImporterUtils.js'; | ||
|
|
||
| test('anonymous humans and hyphenated names survive, but bots and handles do not', async () => { | ||
| const contributorUrls = []; | ||
| const result = await fetchContributorAuthors({ | ||
| owner: 'test-owner', repo: 'test-repo', warnings: [], contributorFallbackLimit: 10, | ||
| cleanString, normalizeAuthor, normalizeAuthors, addWarning: () => {}, | ||
| fetchOptionalJson: async (url) => { | ||
| if (url.includes('/contributors?')) { | ||
| contributorUrls.push(url); | ||
| assert.equal(new URL(url).searchParams.get('anon'), '1'); | ||
| return [ | ||
| { name: 'Anne-Marie', type: 'Anonymous' }, | ||
| { name: 'Dana Example', type: 'Anonymous' }, | ||
| { name: 'Anne-Marie Smith', type: 'Anonymous' }, | ||
| { name: 'Jane Smith-Jones', type: 'Anonymous' }, | ||
| { name: 'copilot-agent', type: 'Anonymous' }, | ||
| { name: 'jane-doe', type: 'Anonymous' }, | ||
| { name: 'anne-marie Smith', type: 'Anonymous' }, | ||
| { name: '@janedoe', type: 'Anonymous' }, | ||
| { name: 'Automation', type: 'Bot' }, | ||
| ]; | ||
| } | ||
| throw new Error(`Unexpected URL: ${url}`); | ||
| }, | ||
| extractOrcidFromGithubProfile: () => '', | ||
| }); | ||
| assert.equal(contributorUrls.length, 1); | ||
| assert.deepEqual(result.fallbackAuthors.map((author) => [author.givenNames, author.familyNames]), [ | ||
| ['', 'Anne-Marie'], ['Dana', 'Example'], ['Anne-Marie', 'Smith'], ['Jane', 'Smith-Jones'], | ||
| ]); | ||
| }); | ||
|
|
||
| test('GitHub-specific hyphen preservation leaves shared metadata normalization unchanged', () => { | ||
| assert.equal(normalizeAuthor(buildContributorAuthorInput('Anne-Marie')).familyNames, 'Anne-Marie'); | ||
| assert.equal(normalizeAuthor({ name: 'Anne-Marie' }).familyNames, 'Marie'); | ||
| assert.equal(normalizeAuthor(buildContributorAuthorInput('jane-doe')).familyNames, 'Doe'); | ||
| assert.equal(normalizeAuthor({ name: 'Anne-Marie Smith' }).givenNames, 'Anne Marie'); | ||
| }); | ||
|
|
||
| test('contributor URL explicitly requests anonymous records and retains pagination', () => { | ||
| const url = new URL(buildGithubContributorsApiUrl('owner', 'repo', 2, 50)); | ||
| assert.equal(url.searchParams.get('anon'), '1'); | ||
| assert.equal(url.searchParams.get('page'), '2'); | ||
| assert.equal(url.searchParams.get('per_page'), '50'); | ||
| }); | ||
|
|
||
| test('GitHub name input preserves qualifying hyphenated given and family tokens and enrichment', () => { | ||
| const extra = { affiliation: 'Example Lab', orcid: 'https://orcid.org/0000-0002-1825-0097' }; | ||
| for (const [name, givenNames, familyNames] of [ | ||
| ['Anne-Marie Smith', 'Anne-Marie', 'Smith'], | ||
| ['Jane Smith-Jones', 'Jane', 'Smith-Jones'], | ||
| ['Anne-Marie Louise Smith-Jones', 'Anne-Marie Louise', 'Smith-Jones'], | ||
| ['Smith-Jones, Anne-Marie Louise', 'Anne-Marie Louise', 'Smith-Jones'], | ||
| [' Anne-Marie Smith ', 'Anne-Marie', 'Smith'], | ||
| ['Anne-Marie', '', 'Anne-Marie'], | ||
| ]) { | ||
| assert.deepEqual(normalizeAuthor(buildContributorAuthorInput(name, extra)), { | ||
| givenNames, familyNames, ...extra, | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
| test('co-author trailers preserve human hyphens while excluding handles and automated names', () => { | ||
| const names = extractCoAuthorNamesFromCommitMessage([ | ||
| 'Co-authored-by: Anne-Marie Smith <anne@example.test>', | ||
| 'Co-authored-by: Jane Smith-Jones <jane@example.test>', | ||
| 'Co-authored-by: jane-doe <handle@example.test>', | ||
| 'Co-authored-by: @janedoe <handle@example.test>', | ||
| 'Co-authored-by: bot-123 <bot@example.test>', | ||
| 'Co-authored-by: Claude Code <bot@example.test>', | ||
| 'Co-authored-by: GitHub Copilot <bot@example.test>', | ||
| ].join('\n')); | ||
| assert.deepEqual(names, ['Anne-Marie Smith', 'Jane Smith-Jones']); | ||
| assert.deepEqual(names.map((name) => normalizeAuthor(buildContributorAuthorInput(name)).givenNames), ['Anne-Marie', 'Jane']); | ||
| }); | ||
|
|
||
| test('hyphenated profile and co-author names survive the full importer pipeline', async () => { | ||
| const originalFetch = globalThis.fetch; | ||
| globalThis.fetch = async (url) => { | ||
| const value = String(url); | ||
| if (value.endsWith('/repos/owner/repo')) { | ||
| return Response.json({ name: 'repo', default_branch: 'main', html_url: 'https://github.com/owner/repo' }); | ||
| } | ||
| if (value.includes('/releases?')) return Response.json([{ tag_name: '1.0.0', published_at: '2026-01-01' }]); | ||
| if (value.includes('/commits?')) { | ||
| return Response.json([{ commit: { message: | ||
| 'Co-authored-by: Anne-Marie Smith <anne@example.test>\nCo-authored-by: jane-doe <handle@example.test>' } }]); | ||
| } | ||
| if (value.includes('/contributors?')) { | ||
| assert.equal(new URL(value).searchParams.get('anon'), '1'); | ||
| return Response.json([ | ||
| { login: 'janesmith', type: 'User' }, | ||
| { name: 'Anne-Marie Smith', type: 'Anonymous' }, | ||
| ]); | ||
| } | ||
| if (value.endsWith('/users/janesmith')) { | ||
| return Response.json({ login: 'janesmith', type: 'User', name: 'Jane Smith-Jones', company: 'Example Lab' }); | ||
| } | ||
| if (value.endsWith('/users/janesmith/social_accounts')) return Response.json([]); | ||
| throw new Error(`Unexpected URL: ${value}`); | ||
| }; | ||
| try { | ||
| const result = await importGithubMetadata('https://github.com/owner/repo', { | ||
| inspectRepositoryFiles: false, lookupExternalDoi: false, | ||
| }); | ||
| assert.equal(result.errors.length, 0); | ||
| assert.equal(result.warnings.some((warning) => warning.code === 'request-failed'), false); | ||
| assert.deepEqual(result.metadata.authors.map((author) => [author.givenNames, author.familyNames]), [ | ||
| ['Anne-Marie', 'Smith'], ['Jane', 'Smith-Jones'], | ||
| ]); | ||
| assert.equal(result.metadata.authors[1].affiliation, 'Example Lab'); | ||
| } finally { | ||
| globalThis.fetch = originalFetch; | ||
| } | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.