Repository navigation
Discover human author names from bounded commit history #71
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
5
commits into
main
Choose a base branch
from
feat/issue-68-commit-authors
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
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7e35573
feat: discover human authors from bounded commit history (#68)
beanbean9339 e1e4ab7
feat: enhance commit author filtering to exclude automated contributo…
beanbean9339 d64c40e
feat: improve author discovery in commit history and enhance related …
beanbean9339 5de14fc
rebasing
beanbean9339 714e139
fix: update download button text to reflect all files in ZIP
beanbean9339 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
Some comments aren't visible on the classic Files Changed page.
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,74 @@ | ||
| import { buildGithubCommitListApiUrl, buildGithubRequestConfig } from './githubApi.js'; | ||
| import { dedupeAuthors } from './githubImporterAuthors.js'; | ||
| import { isAutomatedContributorIdentity } from './githubImporterContributors.js'; | ||
|
|
||
| const COMMIT_PAGE_SIZE = 100; | ||
| const UNAUTHENTICATED_PAGE_LIMIT = 1; | ||
| const AUTHENTICATED_PAGE_LIMIT = 10; | ||
|
|
||
| function isUsableCommitName(name, login, knownLogins, cleanString) { | ||
| const normalized = name.toLowerCase(); | ||
| if (!name || normalized === String(login ?? '').toLowerCase() || knownLogins.has(normalized)) { | ||
| return false; | ||
| } | ||
| if ( | ||
| /\d/.test(name) | ||
| || /[_@]/.test(name) | ||
| || /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(name) | ||
| || isAutomatedContributorIdentity(name, cleanString) | ||
| || isAutomatedContributorIdentity(login, cleanString) | ||
| ) { | ||
| return false; | ||
| } | ||
| if (!/\s/.test(name) && name.includes('-') && !name.split('-').every((segment) => /^[A-Z][a-z]+$/.test(segment))) { | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| export async function fetchCommitAuthors({ | ||
| owner, repo, defaultBranch, initialCommits = [], knownGithubLogins = [], | ||
| warnings, authToken = '', cleanString, normalizeAuthor, normalizeAuthors, | ||
| addWarning, fetchOptionalJson, | ||
| }) { | ||
| const knownLogins = new Set(knownGithubLogins.map((login) => cleanString(login).toLowerCase())); | ||
| const discoveredAuthors = []; | ||
| let commits = Array.isArray(initialCommits) ? initialCommits : []; | ||
| let page = 1; | ||
| const maxPages = authToken ? AUTHENTICATED_PAGE_LIMIT : UNAUTHENTICATED_PAGE_LIMIT; | ||
|
|
||
| while (true) { | ||
| for (const commit of commits) { | ||
| const name = cleanString(commit?.commit?.author?.name ?? ''); | ||
| const login = cleanString(commit?.author?.login ?? ''); | ||
| if (login) knownLogins.add(login.toLowerCase()); | ||
| if (commit?.author?.type && commit.author.type !== 'User') continue; | ||
| discoveredAuthors.push({ name, login }); | ||
| } | ||
|
|
||
| if (commits.length < COMMIT_PAGE_SIZE) break; | ||
| if (page >= maxPages) { | ||
| addWarning(warnings, 'commit-authors', 'commit-author-scan-limited', | ||
| `Scanned the first ${page * COMMIT_PAGE_SIZE} commits for contributor author names.`, | ||
| { owner, repo, scannedPages: page, scannedCommits: page * COMMIT_PAGE_SIZE }); | ||
| break; | ||
| } | ||
|
|
||
| page += 1; | ||
| commits = await fetchOptionalJson( | ||
| buildGithubCommitListApiUrl(owner, repo, defaultBranch, COMMIT_PAGE_SIZE, page), | ||
| buildGithubRequestConfig({ | ||
| authToken, | ||
| source: 'commit-authors', | ||
| label: `commit authors page ${page}`, | ||
| onWarning: (source, code, message, details = {}) => addWarning(warnings, source, code, message, details), | ||
| }), | ||
| ) || []; | ||
| if (!Array.isArray(commits) || commits.length === 0) break; | ||
| } | ||
|
|
||
| const authorNames = discoveredAuthors | ||
| .filter(({ name, login }) => isUsableCommitName(name, login, knownLogins, cleanString)) | ||
| .map(({ name }) => normalizeAuthor({ name })); | ||
| return dedupeAuthors(normalizeAuthors(authorNames)); | ||
| } | ||
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,105 @@ | ||
| import test from 'node:test'; | ||
| import assert from 'node:assert/strict'; | ||
|
|
||
| import { fetchCommitAuthors } from '../../src/services/githubImporterCommitAuthors.js'; | ||
| import { cleanString, normalizeAuthor, normalizeAuthors } from '../../src/services/githubImporterUtils.js'; | ||
|
|
||
| function commit(name, login = '') { | ||
| return { commit: { author: { name } }, author: login ? { login, type: 'User' } : null }; | ||
| } | ||
|
|
||
| test('authenticated scans continue to page two for human author names', async () => { | ||
| const urls = []; | ||
| const warnings = []; | ||
| const result = await fetchCommitAuthors({ | ||
| owner: 'test-owner', repo: 'test-repo', defaultBranch: 'feature/new', authToken: 'token', | ||
| initialCommits: Array.from({ length: 100 }, () => commit('known-login')), | ||
| knownGithubLogins: ['known-login'], warnings, | ||
| cleanString, normalizeAuthor, normalizeAuthors, | ||
| addWarning: (items, source, code) => items.push({ source, code }), | ||
| fetchOptionalJson: async (url) => { | ||
| urls.push(url); | ||
| return [commit('Ada Lovelace'), commit('bot-123'), commit('name-handle'), commit('Alice Example', 'Alice Example')]; | ||
| }, | ||
| }); | ||
| assert.equal(urls.length, 1); | ||
| assert.equal(urls[0].endsWith('commits?per_page=100&sha=feature%2Fnew&page=2'), true); | ||
| assert.deepEqual(result.map((author) => `${author.givenNames} ${author.familyNames}`), ['Ada Lovelace']); | ||
| assert.equal(warnings.length, 0); | ||
| }); | ||
|
|
||
| test('commit names matching logins on any scanned page are excluded', async () => { | ||
| const initialCommits = [ | ||
| commit('Jane-Doe'), | ||
| commit('Anna-Maria'), | ||
| commit('Mary Smith-Jones'), | ||
| ...Array.from({ length: 97 }, () => commit('Repeated Person')), | ||
| ]; | ||
| const result = await fetchCommitAuthors({ | ||
| owner: 'test-owner', | ||
| repo: 'test-repo', | ||
| defaultBranch: 'main', | ||
| authToken: 'token', | ||
| initialCommits, | ||
| knownGithubLogins: [], | ||
| warnings: [], | ||
| cleanString, | ||
| normalizeAuthor, | ||
| normalizeAuthors, | ||
| addWarning: () => {}, | ||
| fetchOptionalJson: async () => [ | ||
| commit('Real Author', 'jane-doe'), | ||
| commit('Another Contributor', 'ANNA-MARIA'), | ||
| commit('Jean-Luc'), | ||
| commit('Full Name', 'jean-luc'), | ||
| ], | ||
| }); | ||
|
|
||
| assert.deepEqual(result.map((author) => `${author.givenNames} ${author.familyNames}`), [ | ||
| 'Mary Smith Jones', | ||
| 'Repeated Person', | ||
| 'Real Author', | ||
| 'Another Contributor', | ||
| 'Full Name', | ||
| ]); | ||
| }); | ||
|
|
||
| test('unauthenticated scans stop after the first 100 commits', async () => { | ||
| const warnings = []; | ||
| const result = await fetchCommitAuthors({ | ||
| owner: 'test-owner', repo: 'test-repo', initialCommits: Array.from({ length: 100 }, () => commit('Dana Example')), | ||
| warnings, cleanString, normalizeAuthor, normalizeAuthors, | ||
| addWarning: (items, source, code) => items.push({ source, code }), | ||
| fetchOptionalJson: async () => { throw new Error('Should not request another page'); }, | ||
| }); | ||
| assert.equal(result.length, 1); | ||
| assert.equal(warnings.some((warning) => warning.code === 'commit-author-scan-limited'), true); | ||
| }); | ||
|
|
||
| test('commit history excludes automated identities and aliases but accepts full hyphenated names', async () => { | ||
| const result = await fetchCommitAuthors({ | ||
| owner: 'test-owner', | ||
| repo: 'test-repo', | ||
| initialCommits: [ | ||
| commit('Jean-Pierre Dupont'), | ||
| commit('Mary Smith-Jones'), | ||
| commit('Claude Code'), | ||
| commit('GitHub Actions'), | ||
| commit('GitHub Actions', 'actions-bot'), | ||
| commit('Claude Fable'), | ||
| commit('alice_dev'), | ||
| commit('dev@example.com'), | ||
| ], | ||
| warnings: [], | ||
| cleanString, | ||
| normalizeAuthor, | ||
| normalizeAuthors, | ||
| addWarning: () => {}, | ||
| fetchOptionalJson: async () => [], | ||
| }); | ||
|
|
||
| assert.deepEqual(result.map((author) => `${author.givenNames} ${author.familyNames}`), [ | ||
| 'Jean Pierre Dupont', | ||
| 'Mary Smith Jones', | ||
| ]); | ||
| }); |
Oops, something went wrong.
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.