fix: fall back to GitHub API for commit author when Firebase token la…#2777
fix: fall back to GitHub API for commit author when Firebase token la…#2777
Conversation
…cks name/email (CLUE-427) Extract resolveCommitAuthor helper that tries the Firebase decoded token first, then falls back to the GitHub API for missing name or email. This fixes the 'Could not determine author information from token' error for users whose GitHub profiles lack a public name or email. Add unit tests covering all fallback branches. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR addresses missing commit author metadata when pushing units by introducing a helper that derives author name/email from the Firebase decoded token, falling back to the authenticated GitHub user profile when needed (CLUE-427).
Changes:
- Add
resolveCommitAuthor()helper to derive commit author from token, with GitHub API fallback. - Update
pushUnitroute to use the new helper and a clearer error message on failure. - Add Jest unit tests covering the fallback branches; add Jest-related dev dependencies.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| authoring-api/src/routes/push-unit.ts | Switches commit author resolution to resolveCommitAuthor() with improved error messaging. |
| authoring-api/src/helpers/resolve-commit-author.ts | New helper implementing token-first, GitHub API fallback logic for commit author. |
| authoring-api/src/helpers/resolve-commit-author.test.ts | New Jest tests covering token-only, partial token, GitHub fallbacks, and error path. |
| authoring-api/package.json | Adds Jest/ts-jest and Jest types to support the new unit tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "@types/cors": "^2.8.19", | ||
| "@types/jest": "^30.0.0", | ||
| "@typescript-eslint/eslint-plugin": "^8.39.1", | ||
| "@typescript-eslint/parser": "^8.39.1", | ||
| "dotenv": "16.4.5", | ||
| "eslint": "^8.57.1", | ||
| "eslint-config-google": "^0.14.0", | ||
| "eslint-plugin-import": "^2.32.0", | ||
| "firebase-tools": "^13.15.1", | ||
| "jest": "^30.2.0", | ||
| "ts-jest": "^29.4.6", | ||
| "typescript": "^5.9.2" |
There was a problem hiding this comment.
jest/ts-jest are added but there is no test script in this package’s scripts. As a result, npm test (and any CI expecting it) won’t run the new unit tests; add a test (and optionally test:watch/test:coverage) script wired to jest.
| import {resolveCommitAuthor} from "./resolve-commit-author"; | ||
|
|
||
| // Minimal mock matching the Octokit shape used by resolveCommitAuthor | ||
| function mockOctokit(userData: {name?: string | null; email?: string | null; login: string}) { | ||
| return { |
There was a problem hiding this comment.
This test file lives under src/, and authoring-api/tsconfig.json includes src in the build, so it will be compiled into lib/ and shipped with the deployed function bundle. Consider moving tests under a dedicated test/ directory (as other packages in this repo do) and/or excluding **/*.test.ts from the production tsc build to avoid deploying test artifacts.
collaborative-learning
|
||||||||||||||||||||||||||||
| Project |
collaborative-learning
|
| Branch Review |
CLUE-427-authors-cannot-commit-clue-changes
|
| Run status |
|
| Run duration | 03m 04s |
| Commit |
|
| Committer | lbondaryk |
| View all properties for this run ↗︎ | |
| Test results | |
|---|---|
|
|
0
|
|
|
0
|
|
|
0
|
|
|
0
|
|
|
4
|
| View all changes introduced in this branch ↗︎ | |
…LUE-427) Add npm test script wired to jest so tests run via npm test and CI. Exclude *.test.ts from tsconfig build to prevent test artifacts from being compiled into lib/ and deployed with the function bundle. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2777 +/- ##
==========================================
- Coverage 86.23% 85.45% -0.78%
==========================================
Files 846 846
Lines 46028 46028
Branches 11919 11919
==========================================
- Hits 39691 39332 -359
- Misses 5939 6275 +336
- Partials 398 421 +23
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
emcelroy
left a comment
There was a problem hiding this comment.
Generally looking good, but some changes are needed.
I left a couple suggestions in resolve-commit-author.test.ts that should be applied.
Also, to get the new tests in /authoring-api to work correctly in CI (they're failing right now), you'll need to do the following...
-
in the root directory
package.jsonfile, add "/authoring-api/" to thetestPathIgnorePatternsarray. -
in
.github/workflows/ci.yml, aftercms/package-lock.jsonon line 54, addauthoring-api/package-lock.json. Then after this part a few lines down from there:
- name: Install CMS Dependencies
working-directory: ./cms
run: npm ci
add this:
- name: Install Authoring API Dependencies
working-directory: ./authoring-api
run: npm ci
- name: Run Authoring API Tests
working-directory: ./authoring-api
run: npm test
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| } as any; |
There was a problem hiding this comment.
Generally if you can avoid casting to any, it's best not to. It would be pretty simple and better to cast to Octokit like so:
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | |
| } as any; | |
| } as unknown as Octokit; |
You'll also have to add import {Octokit} from "@octokit/rest"; at the top of the file for that to work.
Casting to any makes it so any type errors that might occur later in the test won't be caught.
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| } as any; |
There was a problem hiding this comment.
Same suggestion as lines 11-12 above.
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | |
| } as any; | |
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | |
| } as unknown as Octokit; |
| "jest": "^30.2.0", | ||
| "ts-jest": "^29.4.6", |
There was a problem hiding this comment.
Just a note that I've only seen jest and ts-jest with matching version numbers in our projects (as in the package,json in the root directory where both are v28). I thought the versions always went together, but apparently ts-jest v29 will work with jest v30 according to https://github.com/kulshekhar/ts-jest/blob/main/package.json where it lists "@jest/types": "^29.0.0 || ^30.0.0" and "jest": "^29.0.0 || ^30.0.0" under peerDependencies. (And there is no v30 of ts-jest yet.)
…e from root jest (CLUE-427) Replace `as any` with `as unknown as Octokit` in test mocks for type safety. Add authoring-api install and test steps to CI workflow. Add /authoring-api/ to root testPathIgnorePatterns to prevent root jest from picking up authoring-api tests. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@emcelroy I think I've addressed your comments here? Can you approve? |
…cks name/email (CLUE-427)
Extract resolveCommitAuthor helper that tries the Firebase decoded token first, then falls back to the GitHub API for missing name or email. This fixes the 'Could not determine author information from token' error for users whose GitHub profiles lack a public name or email. Add unit tests covering all fallback branches.