Skip to content

feat(drive): add drive.copy tool for file/template copying#277

Open
oskarcode wants to merge 3 commits intogemini-cli-extensions:mainfrom
oskarcode:feat/drive-copy-tool
Open

feat(drive): add drive.copy tool for file/template copying#277
oskarcode wants to merge 3 commits intogemini-cli-extensions:mainfrom
oskarcode:feat/drive-copy-tool

Conversation

@oskarcode
Copy link
Contributor

Summary

Adds a focused drive.copy tool to copy existing Google Drive files. This is useful for template-based workflows where users need to create a new document while preserving formatting/content from an existing file.

New Tool

  • drive.copy - Copy a Drive file by fileId, set a new name, and optionally place it in a destination folderId

Implementation

  • Added copyFile method to DriveService
  • Uses drive.files.copy API with optional destination folder support
  • Returns copied file details: id, name, mimeType, webViewLink
  • Reuses existing Drive OAuth scope (https://www.googleapis.com/auth/drive), no new scopes

Files Changed

  • workspace-server/src/services/DriveService.ts - Added copyFile method
  • workspace-server/src/index.ts - Registered drive.copy MCP tool with input schema

Notes

  • Minimal, focused implementation (single new tool)
  • Backward compatible with existing tools and behavior

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a focused capability to copy Google Drive files, significantly enhancing support for template-based document creation. By providing a dedicated drive.copy tool, users can efficiently duplicate files, rename them, and organize them into specific folders, streamlining workflows that rely on existing document structures without altering the originals.

Highlights

  • New drive.copy tool added: A new tool, drive.copy, has been introduced to facilitate copying existing Google Drive files. This tool is designed to support template-based workflows by allowing users to create new documents from existing files while preserving their original formatting and content.
  • File copying functionality: The drive.copy tool enables copying a Drive file using its fileId, assigning a new name, and optionally specifying a folderId for the destination. It returns the id, name, mimeType, and webViewLink of the newly copied file.
  • Implementation details: The core functionality is implemented in the copyFile method within DriveService, utilizing the drive.files.copy API. It supports optional destination folders and reuses the existing Drive OAuth scope, ensuring no new permissions are required.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • workspace-server/src/index.ts
    • Registered the new drive.copy tool with its description and input schema, including fileId, name, and an optional folderId.
  • workspace-server/src/services/DriveService.ts
    • Added the copyFile asynchronous method to handle the logic for copying files in Google Drive.
    • Implemented logging for the file copy operation, including success messages and error handling.
    • Constructed the request body for the Drive API to include the new file name and optional parent folder.
    • Utilized the drive.files.copy API endpoint, specifying fields to return and enabling supportsAllDrives.
    • Formatted the successful response to return the new file's ID, name, MIME type, and web view link.
Activity
  • No human activity (comments, reviews) has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new drive.copy tool, which is a great addition for template-based workflows. The implementation is clean and follows the existing structure for adding new tools. I've identified one high-severity issue where the fileId is not being processed to handle Google Drive URLs, which is inconsistent with other Drive tools and the tool's own documentation. Applying the suggested fix will make the tool more robust and user-friendly.

Comment on lines +547 to +559
const drive = await this.getDriveClient();

const requestBody: drive_v3.Schema$File = { name };
if (folderId) {
requestBody.parents = [folderId];
}

const copy = await drive.files.copy({
fileId: fileId,
requestBody: requestBody,
fields: 'id, name, mimeType, webViewLink',
supportsAllDrives: true,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

high

For consistency with other tools like drive.trashFile and drive.renameFile, and to support the functionality described in the tool's input schema ('Can be extracted from a Google Drive URL'), the fileId should be processed with extractDocumentId. This will allow users to provide either a direct file ID or a full Google Drive URL.

Suggested change
const drive = await this.getDriveClient();
const requestBody: drive_v3.Schema$File = { name };
if (folderId) {
requestBody.parents = [folderId];
}
const copy = await drive.files.copy({
fileId: fileId,
requestBody: requestBody,
fields: 'id, name, mimeType, webViewLink',
supportsAllDrives: true,
});
const drive = await this.getDriveClient();
const id = extractDocumentId(fileId);
const requestBody: drive_v3.Schema$File = { name };
if (folderId) {
requestBody.parents = [folderId];
}
const copy = await drive.files.copy({
fileId: id,
requestBody: requestBody,
fields: 'id, name, mimeType, webViewLink',
supportsAllDrives: true,
});

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