This document summarizes the implementation of the GitHub Pull Request submission feature for the Model Openness Tool.
Users can now submit their evaluated models directly to the MOT GitHub repository via an automated Pull Request workflow. The feature integrates with the existing GitHub OAuth authentication system.
- JavaScript file handling PR submission button clicks
- Makes AJAX requests to the PR submission endpoint
- Displays success/error messages to users
- Handles loading states and user feedback
Changes:
- Complete rewrite to use authenticated user's OAuth token
- Retrieves token from
social_authentity storage - Implements methods:
getAccessToken(): Retrieves GitHub OAuth tokengetGitHubUsername(): Gets authenticated user's GitHub usernameisAuthenticated(): Checks if user has valid GitHub authenticationrequest(): Makes authenticated GitHub API requestsensureFork(): Creates fork if it doesn't existcreateBranch(): Creates a new branch in the forkcommitFile(): Commits YAML file to the branchcreatePullRequest(): Creates PR from fork to upstream
Changes:
- Added
github_pr_managerservice registration - Dependencies:
@http_client,@entity_type.manager,@current_user,@logger.channel.mot
Changes:
- Fixed typo:
RendererInterfce→RendererInterface - Added imports for
ModelSerializerInterface,GitHubPullRequestManager,JsonResponse - Added properties:
$modelSerializer,$githubPrManager - Updated
create()method to inject new services - Fixed bugs in
yaml()andjson()methods (missing$responseinitialization) - Added
submitPullRequest()method:- Checks GitHub authentication
- Validates session data
- Generates YAML content
- Creates fork, branch, commits file, and creates PR
- Returns JSON response with success/error status
- Added
generatePrBody()helper method:- Generates PR description with model details
- Includes MOF classification status
Changes:
- Added
mof.model.evaluate_form.submit_prroute - Path:
/model/evaluate/submit-pr - Controller:
ModelController::submitPullRequest - Access: Public (authentication checked in controller)
- No cache option enabled
Changes:
- Added PR submission button to evaluation results
- For authenticated users: Shows "Submit Pull Request" button with JavaScript handler
- For unauthenticated users: Shows "Login with GitHub to Submit PR" link
- Button includes data attribute with PR submission URL
Changes:
- Added JavaScript file to
model-evaluationlibrary - Added dependencies:
core/drupal,core/drupalSettings
Changes:
- Updated "Evaluating a Model" section
- Added information about PR submission feature
- Added new "Submitting Your Model via Pull Request" section
- Documented both automatic and manual submission workflows
- Explained GitHub authentication requirement
- Comprehensive testing guide
- Test scenarios for different user states
- Verification checklist
- Common issues and solutions
- Database verification queries
- Log monitoring instructions
- Implementation summary
- Files created and modified
- Architecture overview
- Workflow description
User → Evaluate Model → Results Page
↓
Not Authenticated? → Login with GitHub → Return to Evaluation
↓
Authenticated → Submit PR Button → AJAX Request
↓
Controller checks auth → Retrieves OAuth token → GitHub API calls
↓
Success → Display PR link | Error → Display error message
1. Check authentication (OAuth token from social_auth entity)
2. Get GitHub username from social_auth additional_data
3. Ensure fork exists (create if needed)
4. Create unique branch (model-{name}-{timestamp})
5. Commit YAML file to models/ directory
6. Create pull request from fork to lfai/model_openness_tool
7. Return PR URL to user
- Seamless Integration: Uses existing GitHub OAuth authentication
- User-Friendly: Single-click PR submission for authenticated users
- Automatic Fork Management: Creates fork if user doesn't have one
- Unique Branch Names: Timestamp-based to avoid conflicts
- Comprehensive Error Handling: Clear error messages for all failure scenarios
- Security: OAuth tokens encrypted in database, used only for GitHub API
- Feedback: Real-time status updates via JavaScript
- Fallback: Manual download option still available
- Token Storage: OAuth tokens encrypted in
social_authentity table - Token Access: Only accessible to authenticated user who owns it
- API Scope: Requires
reposcope for PR creation - Rate Limiting: GitHub API rate limits apply (5000 req/hour for authenticated users)
- CSRF Protection: Drupal's built-in CSRF protection on routes
- Input Validation: Model data validated before YAML generation
- Drupal Core: 10.x
- social_auth_github: ^4.0 (already installed)
- GuzzleHTTP: For GitHub API requests
- Drupal Session: For storing model evaluation data
- GitHub OAuth App: Must be configured in
social_auth_githubsettings - OAuth Scopes: Must include
reposcope for PR creation - Repository: Targets
lfai/model_openness_toolrepository
Before deploying to production:
- Test with unauthenticated users
- Test with authenticated users (first-time and existing fork)
- Test error scenarios (invalid token, API failures)
- Verify PR content and formatting
- Check rate limiting behavior
- Test on different browsers
- Verify mobile responsiveness
Potential improvements for future versions:
- PR Status Tracking: Track PR status and notify users of updates
- Draft PRs: Option to create draft PRs for review
- Batch Submissions: Submit multiple models at once
- PR Templates: Customizable PR body templates
- Conflict Resolution: Handle cases where model file already exists
- Retry Logic: Automatic retry for transient GitHub API failures
- Progress Indicator: Show detailed progress during fork/branch/commit steps
- Monitor GitHub API rate limits in production
- Keep
social_auth_githubmodule updated - Review GitHub API changes for compatibility
- Monitor error logs for common failure patterns
- Consider implementing caching for fork existence checks
For issues or questions:
- Check
TESTING_PR_FEATURE.mdfor common problems - Review Drupal watchdog logs:
drush watchdog:show --type=mof - Check browser console for JavaScript errors
- Verify GitHub OAuth configuration in Drupal admin