-
Notifications
You must be signed in to change notification settings - Fork 23
feat(gmail): add createLabel tool #164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat(gmail): add createLabel tool #164
Conversation
Add simple gmail.createLabel tool that creates a new Gmail label by name. Labels are created with default visibility settings (labelShow, show).
Summary of ChangesHello @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 Highlights
🧠 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 AssistThe 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
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 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
|
There was a problem hiding this 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.
| 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', | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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,
}
});| inputSchema: { | ||
| name: z.string().describe('The display name of the label.'), | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
allenhutchison
left a comment
There was a problem hiding this 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:
-
Validation: In
workspace-server/src/index.ts, consider adding.min(1)to thenameschema to ensure we don't try to create labels with empty names.name: z.string().min(1).describe('The display name of the label.'),
-
Tests: It would be great to add unit tests for
createLabelinworkspace-server/src/__tests__/services/GmailService.test.tsto 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' }); }); });
-
Logging: Usage of
logToFileis consistent withsrc/utils/logger.ts. Good job.
Summary
Adds a simple
gmail.createLabeltool to create new Gmail labels.New Tool
gmail.createLabel- Create a new Gmail label by nameImplementation
labelShow,show)Files Changed
workspace-server/src/services/GmailService.ts- AddedcreateLabelmethod (+37 lines)workspace-server/src/index.ts- Registeredgmail.createLabeltool (+11 lines)Notes
gmail.modifyOAuth scope which covers label management