Skip to content

Add 'Copy Changes' feature to PR files view - #5

Open
dciborow wants to merge 1 commit into
mainfrom
add-copy-changes
Open

Add 'Copy Changes' feature to PR files view#5
dciborow wants to merge 1 commit into
mainfrom
add-copy-changes

Conversation

@dciborow

@dciborow dciborow commented Oct 14, 2024

Copy link
Copy Markdown
Owner

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.

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:

  • Introduce a 'Copy Changes' feature that allows users to create a new branch, commit changes, and create a new pull request from a file in the current PR.

Enhancements:

  • Add the 'Copy Changes' feature to the list of features initialized in the feature manager.

Build:

  • Add a devcontainer configuration file with tasks for testing, building, and launching the project.

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).
@sourcery-ai

sourcery-ai Bot commented Oct 14, 2024

Copy link
Copy Markdown

Reviewer's Guide by Sourcery

This 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' feature

journey
    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
Loading

File-Level Changes

Change Details Files
Implement 'Copy Changes' feature
  • Add new 'Copy Changes' option to the context menu
  • Implement functionality to create a new branch
  • Add logic to commit changes to the new branch
  • Create a new PR with the copied changes
  • Handle file renaming and new file scenarios
  • Implement progress tracking and error handling
source/features/copy-changes.tsx
Update feature manager to include 'Copy Changes' feature
  • Import the new 'Copy Changes' feature
  • Add the feature to the list of features to be initialized
source/feature-manager.tsx
Add devcontainer configuration
  • Define tasks for testing, building, and launching the project
.devcontainer.json

Assessment against linked issues

Issue Objective Addressed Explanation
#4 Add a 'Copy Changes' feature next to the 'Discard Changes' option in the PR file view
#4 Implement functionality to create a new branch with the changes from a specific file
#4 Create a new PR from the newly created branch with the copied changes

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
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> {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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> {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
	}
}

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.

Easily Create a new PR from a file in current PR

1 participant