Add 'Copy Changes' feature to PR files view - #5
Conversation
Fixes #4 Add a new 'Copy Changes' feature to create a new branch, commit changes, and create a new PR from a file in the current PR. * **source/features/copy-changes.tsx**: - Implement the 'Copy Changes' feature. - Add a new option to the context menu with the label 'Copy Changes'. - Implement the functionality to create a new branch, commit changes, and create a new PR. * **source/feature-manager.tsx**: - Import the new 'Copy Changes' feature. - Add the new feature to the list of features to be initialized. * **.devcontainer.json**: - Add a devcontainer configuration file with tasks for testing, building, and launching the project. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/dciborow/refined-github/issues/4?shareId=XXXX-XXXX-XXXX-XXXX).
Reviewer's Guide by SourceryThis pull request implements a new 'Copy Changes' feature for the PR files view, allowing users to create a new branch, commit changes, and create a new PR from a file in the current PR. The implementation includes adding a new context menu option, creating the necessary API calls to GitHub, and updating the feature manager to include the new feature. Additionally, a devcontainer configuration file has been added to streamline development tasks. User journey diagram for the 'Copy Changes' featurejourney
title User journey for 'Copy Changes' feature
section Accessing the feature
User -> PR Files View: Open PR files view
User -> Context Menu: Right-click to open context menu
Context Menu -> User: Display 'Copy Changes' option
section Using the feature
User -> 'Copy Changes' Option: Click 'Copy Changes'
'Copy Changes' Option -> GitHub API: Create new branch
'Copy Changes' Option -> GitHub API: Commit changes
'Copy Changes' Option -> GitHub API: Create new PR
GitHub API -> User: Display success message
section Completion
User -> PR Files View: See updated PR files view
File-Level Changes
Assessment against linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey @dciborow - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟡 General issues: 3 issues found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| return textContent; | ||
| } | ||
|
|
||
| async function copyChanges(progress: (message: string) => void, originalFileName: string, newFileName: string): Promise<void> { |
There was a problem hiding this comment.
suggestion (performance): Consider batching copy operations to reduce the number of PRs created
The current implementation creates a new branch and PR for each copy operation. This could lead to a large number of PRs if used frequently. Consider implementing a batching mechanism or warning users about this behavior.
async function copyChanges(
progress: (message: string) => void,
originalFileName: string,
newFileName: string,
batch: boolean = false
): Promise<void> {
if (!batch) {
console.warn('Single copy operation may create a new PR. Consider using batch mode for multiple operations.');
}
| doneMessage: 'Changes copied', | ||
| }); | ||
|
|
||
| menuItem.closest('.file')!.remove(); |
There was a problem hiding this comment.
suggestion: Improve error handling in handleClick function
The function removes the file element from the DOM even if an error occurs. This could lead to a confusing user experience if the operation fails but the UI suggests it succeeded. Consider moving the removal operation inside the try block or adding a check to ensure the operation was successful before removing the element.
try {
await navigator.clipboard.writeText(changes);
menuItem.closest('.file')?.remove();
} catch (error) {
features.log.error(import.meta.url, error);
// Optionally, show an error message to the user
}
| return headRefOid; | ||
| } | ||
|
|
||
| async function getFile(filePath: string): Promise<string | undefined> { |
There was a problem hiding this comment.
suggestion: Handle case where file doesn't exist in base reference
The getFile function doesn't explicitly handle the case where the file might not exist in the base reference. Consider adding a check for this scenario and handling it appropriately.
async function getFile(filePath: string): Promise<string | undefined> {
const ref = await getMergeBaseReference();
try {
const {textContent} = await api.v3(`/repos/${repoName}/contents/${filePath}`, {
ref,
});
return textContent;
} catch (error) {
if (error.status === 404) {
return undefined;
}
throw error;
}
}
Fixes #4
Add a new 'Copy Changes' feature to create a new branch, commit changes, and create a new PR from a file in the current PR.
For more details, open the Copilot Workspace session.
Summary by Sourcery
Add a 'Copy Changes' feature to the PR files view, enabling users to create a new branch, commit changes, and open a new PR from a file in the current PR. Update the feature manager to include this new feature and introduce a devcontainer configuration for development tasks.
New Features:
Enhancements:
Build: