Skip to content

Conversation

@oskarcode
Copy link

Summary

Adds a simple gmail.createLabel tool to create new Gmail labels.

New Tool

  • gmail.createLabel - Create a new Gmail label by name

Implementation

  • Labels are created with default visibility settings (labelShow, show)
  • Returns label details including id, name, type, and visibility settings

Files Changed

  • workspace-server/src/services/GmailService.ts - Added createLabel method (+37 lines)
  • workspace-server/src/index.ts - Registered gmail.createLabel tool (+11 lines)

Notes

  • Uses existing gmail.modify OAuth scope which covers label management
  • Minimal implementation - color and advanced visibility options can be added in follow-up PRs

Add simple gmail.createLabel tool that creates a new Gmail label by name.
Labels are created with default visibility settings (labelShow, show).
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @oskarcode, 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 new gmail.createLabel tool, significantly enhancing the system's ability to manage Gmail resources. This addition allows for the automated creation of Gmail labels, improving email organization capabilities. The implementation is focused on core functionality, providing a foundation for potential future expansions like custom color and advanced visibility options.

Highlights

  • New Tool: gmail.createLabel: A new tool, gmail.createLabel, has been added to enable the programmatic creation of new Gmail labels.
  • Label Creation Logic: The createLabel method in GmailService.ts handles the API call to Gmail, setting default visibility options (labelShow, show) for the new label.
  • Tool Registration: The new gmail.createLabel tool is registered in index.ts with a clear description and an input schema requiring only the label's name.
  • Output and Error Handling: Upon successful creation, the tool returns the new label's ID, name, type, and visibility settings. It also includes robust error handling via handleError.

🧠 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.

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 gmail.createLabel tool, allowing users to create Gmail labels by name. The implementation correctly integrates with the Gmail API and includes appropriate logging and error handling. My feedback focuses on enhancing the flexibility of the new tool by making label visibility settings configurable, and ensuring the tool's input schema is aligned with the method's capabilities.

Comment on lines 439 to 451
public createLabel = async ({ name }: { name: string }) => {
try {
logToFile(`Creating Gmail label: ${name}`);

const gmail = await this.getGmailClient();

const response = await gmail.users.labels.create({
userId: 'me',
requestBody: {
name,
labelListVisibility: 'labelShow',
messageListVisibility: 'show',
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The labelListVisibility and messageListVisibility are currently hardcoded to 'labelShow' and 'show' respectively. To make this tool more flexible and allow for different label display behaviors, consider making these optional parameters in the createLabel method. This would enable users to specify these settings if needed, while retaining the current values as defaults.

public createLabel = async ({
    name,
    labelListVisibility = 'labelShow',
    messageListVisibility = 'show',
}: {
    name: string;
    labelListVisibility?: 'labelShow' | 'labelHide' | 'labelShowIfUnread';
    messageListVisibility?: 'show' | 'hide';
}) => {
    try {
        logToFile(`Creating Gmail label: ${name}`);
        
        const gmail = await this.getGmailClient();
        
        const response = await gmail.users.labels.create({
            userId: 'me',
            requestBody: {
                name,
                labelListVisibility,
                messageListVisibility,
            }
        });

Comment on lines 679 to 681
inputSchema: {
name: z.string().describe('The display name of the label.'),
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

To align with the enhanced gmail.createLabel method in GmailService.ts (which now supports configurable visibility settings), the inputSchema for this tool should also include labelListVisibility and messageListVisibility as optional parameters. This will allow users to specify these settings when creating a label, providing more control over the label's behavior.

            inputSchema: {
                name: z.string().describe('The display name of the label.'),
                labelListVisibility: z.enum(['labelShow', 'labelHide', 'labelShowIfUnread']).optional().describe('Visibility of the label in the label list. Defaults to "labelShow".'),
                messageListVisibility: z.enum(['show', 'hide']).optional().describe('Visibility of messages with this label in the message list. Defaults to "show".'),
            }

Address review feedback by adding optional labelListVisibility and
messageListVisibility parameters with sensible defaults.
Copy link
Contributor

@allenhutchison allenhutchison left a comment

Choose a reason for hiding this comment

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

Thanks for adding this feature! The implementation looks good and follows the existing patterns.

A couple of suggestions to make it even better:

  1. Validation: In workspace-server/src/index.ts, consider adding .min(1) to the name schema to ensure we don't try to create labels with empty names.

    name: z.string().min(1).describe('The display name of the label.'),
  2. Tests: It would be great to add unit tests for createLabel in workspace-server/src/__tests__/services/GmailService.test.ts to ensure it works as expected and handles errors correctly.
    Here is a starter for the test:

    describe('createLabel', () => {
        it('should create a label with default visibility', async () => {
            const mockLabel = {
                id: 'Label_1',
                name: 'Test Label',
                type: 'user',
                labelListVisibility: 'labelShow',
                messageListVisibility: 'show',
            };
    
            mockGmailAPI.users.labels.create.mockResolvedValue({
                data: mockLabel,
            });
    
            const result = await gmailService.createLabel({
                name: 'Test Label',
            });
    
            expect(mockGmailAPI.users.labels.create).toHaveBeenCalledWith({
                userId: 'me',
                requestBody: {
                    name: 'Test Label',
                    labelListVisibility: 'labelShow',
                    messageListVisibility: 'show',
                }
            });
    
            const response = JSON.parse(result.content[0].text);
            expect(response).toEqual({
                ...mockLabel,
                status: 'created'
            });
        });
    });
  3. Logging: Usage of logToFile is consistent with src/utils/logger.ts. Good job.

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.

2 participants