Skip to content

Conversation

@lehors
Copy link
Member

@lehors lehors commented Jan 20, 2026

With great help from the amazing IBM Bob coding assistant I was able to implement in about a day the ability to automatically submit a PR to add or update a model after evaluation.
This closes issue #124.

This commit implements automatic PR submission functionality that allows users
to submit their evaluated models directly to the MOT GitHub repository.

Features:
- Automatic fork creation and branch management
- Seamless GitHub OAuth integration using existing social_auth_github
- User-friendly button with real-time feedback
- Comprehensive error handling and user messaging
- Login prompt for unauthenticated users

Files Added:
- web/modules/mof/js/submit_pr.js: JavaScript for PR submission handling
- web/modules/mof/src/Services/GitHubPullRequestManager.php: GitHub API service
- TESTING_PR_FEATURE.md: Comprehensive testing guide
- PR_SUBMISSION_IMPLEMENTATION.md: Implementation documentation

Files Modified:
- web/modules/mof/src/Controller/ModelController.php: Added submitPullRequest() method
- web/modules/mof/src/ModelViewBuilder.php: Added PR submission button
- web/modules/mof/mof.services.yml: Registered github_pr_manager service
- web/modules/mof/mof.routing.yml: Added PR submission route
- web/modules/mof/mof.libraries.yml: Registered JavaScript library
- README.md: Updated documentation with PR submission instructions

Technical Details:
- Uses authenticated user's OAuth token from social_auth entity
- Creates unique branch names with timestamps
- Generates PR with model details and MOF classification
- Handles fork creation for first-time contributors
- Includes comprehensive error handling and logging

Signed-off-by: Bob <AskBob@ibm.com>
Signed-off-by: Arnaud J Le Hors <lehors@us.ibm.com>
This guide provides step-by-step instructions for configuring the
social_auth_github module with OAuth credentials needed for the PR
submission feature.

Includes:
- Creating GitHub OAuth App
- Configuring required scopes (repo, user:email)
- Drupal module configuration via UI and Drush
- Testing procedures
- Troubleshooting common issues
- Security best practices
- Environment-specific configurations

Signed-off-by: Bob <AskBob@ibm.com>
Signed-off-by: Arnaud J Le Hors <lehors@us.ibm.com>
- Updated GitHubSubscriber to fetch email from GitHub API
- Added fallback to username@users.noreply.github.com
- Fixed getGitHubUsername to check multiple data locations
- Added fetchGitHubUsername to get username from API
- Injected HTTP client and logger dependencies
- Added comprehensive logging for debugging
- Created troubleshooting guide

Fixes issues where users with private emails or missing
username data couldn't use the PR submission feature.

Signed-off-by: Bob <AskBob@ibm.com>
Signed-off-by: Arnaud J Le Hors <lehors@us.ibm.com>
- Created GitHubApiHelper service for shared GitHub API operations
- Moved fetchPrimaryEmail from GitHubSubscriber to GitHubApiHelper
- Added fetchUserName method to retrieve user's name from GitHub
- Updated GitHubSubscriber to use GitHubApiHelper
- Updated GitHubPullRequestManager to:
  - Inject GitHubApiHelper service
  - Add getGitHubEmail() method
  - Add getGitHubName() method
  - Add addSignedOffBy() method to append Signed-off-by line
  - Automatically add Signed-off-by to all commits
- Updated service definitions in mof.services.yml
- Uses GitHub name and email for Signed-off-by line
- Fallback to username if name not available

This ensures all commits made via PR submission include proper
DCO sign-off using the contributor's GitHub identity.

Signed-off-by: Bob <AskBob@ibm.com>
Signed-off-by: Arnaud J Le Hors <lehors@us.ibm.com>
When users click 'Login with GitHub to Submit PR' from the evaluation
results page, they should return to the results page after authentication,
not the empty evaluation form.

The issue was that the PHP session is destroyed during the GitHub OAuth
redirect flow, so we cannot rely on session data alone.

Solution:
- Added 'show_results=1' query parameter to the destination URL
- Updated ModelEvaluateForm::buildForm() to check for this parameter
- If parameter is present and session has model_session_data, rebuild
  the evaluation results from session data
- This works because Drupal's session is re-established after OAuth login

Changes:
- ModelViewBuilder: Add show_results parameter to login destination URL
- ModelEvaluateForm: Check for show_results parameter and rebuild evaluation

This ensures users see their evaluation results after logging in with GitHub,
providing a seamless experience for PR submission.

Signed-off-by: Bob <AskBob@ibm.com>
Signed-off-by: Arnaud J Le Hors <lehors@us.ibm.com>
This troubleshooting guide is no longer needed as the email retrieval
issues have been resolved in the implementation.

Signed-off-by: Bob <AskBob@ibm.com>
Signed-off-by: Arnaud J Le Hors <lehors@us.ibm.com>
Cleaned up trailing whitespaces from all files modified in this branch
to maintain code quality standards.

Signed-off-by: Bob <AskBob@ibm.com>
Signed-off-by: Arnaud J Le Hors <lehors@us.ibm.com>
Instead of waiting a fixed 2 seconds for the fork to be ready, we now
poll the GitHub API to check if the fork is accessible.

Changes:
- Added waitForFork() method to GitHubPullRequestManager
- Polls up to 10 times with 1 second intervals (max 10 seconds)
- Returns early if fork becomes ready
- Updated submitPullRequest() to use waitForFork()
- Added timeout error handling if fork doesn't become ready

This provides a more reliable and efficient approach than fixed delays,
typically completing in 2-3 seconds instead of always waiting 2 seconds.

Signed-off-by: Bob <AskBob@ibm.com>
Signed-off-by: Arnaud J Le Hors <lehors@us.ibm.com>
@lehors lehors force-pushed the feature/github-pr-submission branch 2 times, most recently from d7a9368 to 8ca53bf Compare January 20, 2026 13:51
getEmail() is unknown and we don't want the email from the Drupal account

Signed-off-by: Arnaud J Le Hors <lehors@us.ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant