Skip to content

feat: add Gmail list messages sample#1748

Open
emrila wants to merge 1 commit intogoogleworkspace:mainfrom
emrila:feature/gmail-list-messages
Open

feat: add Gmail list messages sample#1748
emrila wants to merge 1 commit intogoogleworkspace:mainfrom
emrila:feature/gmail-list-messages

Conversation

@emrila
Copy link

@emrila emrila commented Feb 28, 2026

Description

Adds Gmail sample for listing messages and corresponding unit test. Based on the list_messages sample from Python.

Is it been tested?

  • Development testing done

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have performed a peer-reviewed with team member(s)
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules

@gemini-code-assist
Copy link

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 new Java sample for interacting with the Gmail API to retrieve a list of messages from a user's inbox. It provides a clear, runnable example for developers, complete with necessary API client setup and robust unit tests to ensure its reliability and correct behavior under various conditions.

Highlights

  • New Gmail Sample: A new Java sample has been added to demonstrate how to list messages from a user's Gmail inbox using the Gmail API.
  • Unit Testing: A comprehensive unit test class has been included to verify the functionality of the new Gmail list messages sample, covering successful retrieval, error handling, and empty results.
Changelog
  • gmail/snippets/src/main/java/ListMessages.java
    • Added a new Java class ListMessages to encapsulate the logic for listing Gmail messages.
    • Implemented the listMessages method to fetch up to 10 messages from the 'INBOX' label.
    • Included a getGmailService helper method for authenticating and building the Gmail API client.
  • gmail/snippets/src/test/java/TestListMessages.java
    • Added a new JUnit test class TestListMessages to validate the ListMessages sample.
    • Implemented testListMessagesReturnsMessages to verify successful message retrieval with mock data.
    • Added testListMessagesHandlesApiError to ensure proper handling of API errors (e.g., 404 Not Found).
    • Included testListMessagesHandlesEmptyResults to confirm correct behavior when no messages are found.
    • Utilized MockHttpTransport for isolated and efficient testing of API interactions.
Activity
  • The author has completed development testing for the changes.
  • A self-review of the code has been performed by the author.
  • Code has been commented, particularly in complex sections, to improve readability.
  • The changes introduced do not generate any new warnings.
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

@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 snippet for listing messages. The implementation has a critical performance issue due to making API calls within a loop, which should be addressed by using batch requests. Additionally, there are a couple of style guide violations related to wildcard imports in both the main code and the test file. I've provided specific suggestions to resolve these issues.

Add Gmail sample for listing messages and corresponding unit test. Based on the `list_messages` sample from Python.
@emrila emrila force-pushed the feature/gmail-list-messages branch from 3b44bff to 128f207 Compare February 28, 2026 01:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants