-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Added example for GitHub_issues_analyzer #923
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?
Added example for GitHub_issues_analyzer #923
Conversation
ROHANDWIVEDI2005
commented
Aug 29, 2025
- This is an updated version of I've added a new example notebook that demonstrates how you can use t… #887
- Added extra explanation for GITHUB_API_KEY
- Run the entire notebook
- nbfmt check
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
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.
Summary of Changes
Hello @ROHANDWIVEDI2005, 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, fully functional example notebook that showcases a practical application of the Gemini API's function calling feature by integrating it with the GitHub API. The example simplifies the process of querying GitHub issues programmatically, providing a clear and runnable demonstration for users.
Highlights
- New Example Notebook Added: A new Jupyter notebook,
GitHub_issues_analyzer.ipynb
, has been added to theexamples
directory. - Gemini API and GitHub API Integration: The notebook demonstrates how to use the Gemini API with function calling to interact with the GitHub API, specifically to retrieve open issues from a repository.
- Improved API Key Setup Instructions: Enhanced explanations and steps are provided for setting up the
GITHUB_API_KEY
as a Colab Secret, including guidance on generating a GitHub Personal Access Token. - Notebook Validation: The entire notebook has been run and verified, and it has passed
nbfmt
checks, ensuring its functionality and adherence to formatting standards.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
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 issue 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
-
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. ↩
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 example notebook, GitHub_issues_analyzer.ipynb
, which is a great demonstration of using the Gemini API with function calling to interact with the GitHub API. The notebook is well-structured and provides a practical use case. My review includes feedback on several points to enhance code quality, correctness, and readability. I've pointed out some violations of the project's style guide, such as non-null execution counts and minor formatting inconsistencies. I've also suggested improvements to error handling and code conciseness in the Python tool function, and corrections for typos and grammatical errors in the markdown text.
" try:\n", | ||
" repo = g.get_repo(repository_name)\n", | ||
" issues = repo.get_issues(state='open')\n", | ||
" \n", | ||
" issue_list = []\n", | ||
" for issue in issues:\n", | ||
" issue_list.append({\n", | ||
" 'title': issue.title,\n", | ||
" 'number': issue.number,\n", | ||
" 'url': issue.html_url\n", | ||
" })\n", | ||
" return issue_list\n", | ||
"\n", | ||
" except Exception as e:\n", | ||
" return {\"error\": f\"An error occurred: {e}\"}" |
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.
This function can be improved in a few ways:
- Inconsistent return types: It returns a
list
on success but adict
on failure. This can cause runtime errors and confuse the model. It's better to return an empty list on error. - Use list comprehension: The
for
loop can be replaced with a more concise list comprehension, which is more Pythonic and aligns with the style guide's preference for brevity.1 - Broad exception: The
except Exception
clause is too broad. While the suggestion below keeps it for simplicity, for a more robust implementation, you should consider catching specific exceptions from thePyGithub
library (e.g.,github.UnknownObjectException
).
I've provided a suggestion that addresses the return type and uses a list comprehension.
try:
repo = g.get_repo(repository_name)
issues = repo.get_issues(state='open')
return [{
'title': issue.title,
'number': issue.number,
'url': issue.html_url
} for issue in issues]
except Exception as e:
print(f"An error occurred: {e}")
return []
Style Guide References
Footnotes
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, |
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 execution_count
for this cell is 1
, not null
. According to the style guide, this indicates that the notebook formatting script (nbfmt
) may not have been run before submission. Please run the formatter to reset all execution counts to null
.1 I've noticed this in other cells as well, but am only commenting once per the style guide.
Style Guide References
Footnotes
"id": "02d1b126d613" | ||
}, | ||
"source": [ | ||
"### Setup up yout API key\n", |
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.
"GOOGLE_API_KEY=userdata.get('GOOGLE_API_KEY')\n", | ||
"GITHUB_API_KEY = userdata.get(\"GITHUB_API_KEY\")\n", |
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 code style here is inconsistent. Line 151 uses single quotes and no spaces around =
, while line 152 uses double quotes and spaces. For consistency and adherence to PEP 8, please use the same quote style and include spaces around the assignment operator.1
GOOGLE_API_KEY = userdata.get('GOOGLE_API_KEY')
GITHUB_API_KEY = userdata.get('GITHUB_API_KEY')
Style Guide References
Footnotes
"id": "fe59bdc48c66" | ||
}, | ||
"source": [ | ||
"You can ask the model for other types of analysis such as what are the best issues to start from as a beginner,what are the most pressing issues I should look at. " |
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.
"### Next Steps\n", | ||
"\n", | ||
"- Learn more about PyGithub from the [PyGithub Docs](https://pygithub.readthedocs.io/en/stable/).\n", | ||
"- You some of your own tools the GitHub API has a vast range of functionalities such a as create_github_issue(),List_pll_requests(),get_issues_comments. " |
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.
This sentence has several typos and grammatical errors. "You some" should be "You can add", "such a as" should be "such as", and "List_pll_requests" seems to be a typo. Also, function names should be formatted as code for better readability.1
- You can add some of your own tools. The GitHub API has a vast range of functionalities such as `create_github_issue()`, `list_pull_requests()`, and `get_issues_comments()`.
Style Guide References
Footnotes
Thanks for tagging me! I've reviewed the changes in Let me know if you have any further questions or if there's anything else I can assist with regarding this pull request! |
@gemini-code-assist review this notebook |
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 adds a new example notebook, GitHub_issues_analyzer.ipynb
, demonstrating how to use the Gemini API with function calling to interact with the GitHub API. The notebook is well-structured and provides a clear example. My feedback includes suggestions to align with the project's style guide, such as running the notebook formatter to clear execution counts and fixing a typo in a heading. I've also recommended improvements for code quality and robustness, like adding a docstring and return type hints to the function, and using more specific exception handling. These changes will enhance the notebook's clarity, maintainability, and adherence to best practices.
"def get_github_issues(repository_name: str):\n", | ||
" \n", |
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.
This function is missing a docstring and a return type hint. For function calling, a descriptive docstring is crucial for the model to understand the function's purpose and arguments.[^1] Adding a return type hint also improves code clarity.[^2]
"def get_github_issues(repository_name: str):\n", | |
" \n", | |
"def get_github_issues(repository_name: str) -> list[dict]:\n", | |
" \"\"\"Gets the open issues for a given GitHub repository.\"\"\"\n", |
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, |
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.
"id": "02d1b126d613" | ||
}, | ||
"source": [ | ||
"### Setup up your API key\n", |
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.
}, | ||
"outputs": [], | ||
"source": [ | ||
"from github import Github\n", |
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.
" } for issue in issues]\n", | ||
"\n", | ||
"\n", | ||
" except Exception as e:\n", |
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.
Added link in the readme |
…01424736a84adf2424c48ccf71/?path=a424e687&cell_index=3&sha=52fda7b5f43b33d6e3a0eef1530492a4a1f3b85ahttps://app.reviewnb.com/google-gemini/cookbook/commit/581d32209983d301424736a84adf2424c48ccf71/?path=a424e687&cell_index=3&sha=52fda7b5f43b33d6e3a0eef1530492a4a1f3b85a Merge branch 'PyGithub-Example' of https://github.com/ROHANDWIVEDI2005/cookbook into PyGithub-Example "TO resolve a conflict"