feat: Add Product Update Automation (Targeting product-updates branch)#1518
feat: Add Product Update Automation (Targeting product-updates branch)#1518AjinkyaM1 wants to merge 4 commits intouser-guides-pubfrom
Conversation
Summary of ChangesHello @AjinkyaM1, 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 an automated system designed to streamline the creation of monthly product updates. By integrating with GitHub and Google's Gemini AI, it automatically gathers information from recently closed pull requests and their associated issues, then uses AI to generate polished, customer-facing release notes. This significantly reduces manual effort in communicating product advancements and ensures consistent, high-quality updates. 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.
Code Review
This pull request introduces a valuable automation for generating monthly product updates by fetching data from GitHub and using Gemini AI to create marketing-friendly content. However, a medium-severity prompt injection vulnerability was identified where untrusted data from GitHub is directly concatenated into the LLM prompt, which could be exploited to manipulate the generated product updates. Recommendations for mitigation include using delimiters and refining the system prompt. Additionally, suggestions were made to improve robustness, performance, and maintainability, including a critical fix to prevent the monthly update file from being overwritten, improved error logging, parallelizing API calls, and removing an unused import. Addressing these points will make the script more resilient, efficient, and secure.
scripts/generate_updates.js
Outdated
| if (!content) throw new Error("AI servers are unavailable. Try again in 5 minutes."); | ||
|
|
||
| if (!fs.existsSync('product-updates')) fs.mkdirSync('product-updates'); | ||
| fs.writeFileSync(`product-updates/${new Date().getFullYear()}.md`, content); |
There was a problem hiding this comment.
The current filename for the product update is based only on the year. Since this script is intended to run monthly, this will cause the same file to be overwritten with each run within the same year, leading to loss of previous months' updates. The filename should be unique for each month to prevent data loss.
fs.writeFileSync(`product-updates/${new Date().toISOString().slice(0, 7)}.md`, content);
scripts/generate_updates.js
Outdated
| Output: Scannable, customer-ready Product Update suitable for release notes or announcements. | ||
| `; | ||
|
|
||
| const prompt = `${instruction}\n\nStyle Guide:\n${style}\n\nChanges:\n${prSummaries}`; |
There was a problem hiding this comment.
The script fetches pull request titles and issue descriptions from GitHub and concatenates them directly into the prompt sent to the Gemini LLM. This allows an attacker with the ability to create PRs or issues in the target repositories to perform a prompt injection attack, potentially manipulating the generated product updates. Since the output is intended to be customer-facing, this poses a risk to the brand's reputation and the integrity of the communication.
To mitigate this, use clear delimiters to separate untrusted data from instructions and update the system prompt to explicitly ignore any instructions contained within those delimiters.
| const prompt = `${instruction}\n\nStyle Guide:\n${style}\n\nChanges:\n${prSummaries}`; | |
| const prompt = instruction + "\n\nStyle Guide:\n" + style + "\n\nChanges (Untrusted Data):\n<data>\n" + prSummaries + "\n</data>"; |
scripts/generate_updates.js
Outdated
| const { Octokit } = require("@octokit/rest"); | ||
| const { GoogleGenerativeAI } = require("@google/generative-ai"); | ||
| const fs = require('fs'); | ||
| const path = require('path'); |
| const results = []; | ||
| for (const pr of merged) { | ||
| let issueContext = ""; | ||
| const issueMatch = pr.body && pr.body.match(/(?:fix|fixes|fixed|close|closes|closed|resolve|resolves|resolved)\s+#(\d+)/i); | ||
| if (issueMatch) { | ||
| const issueNumber = issueMatch[1]; | ||
| const details = await getIssueDetails(owner, repo, issueNumber); | ||
| if (details) issueContext = details; | ||
| } | ||
| results.push({ repository: `${owner}/${repo}`, title: pr.title, context: issueContext }); | ||
| } |
There was a problem hiding this comment.
The current implementation fetches issue details for each pull request sequentially within a for...of loop. This can be inefficient and slow if there are many pull requests. You can significantly speed up the process by executing these API calls in parallel using Promise.all.
const results = await Promise.all(merged.map(async (pr) => {
let issueContext = "";
const issueMatch = pr.body && pr.body.match(/(?:fix|fixes|fixed|close|closes|closed|resolve|resolves|resolved)\s+#(\d+)/i);
if (issueMatch) {
const issueNumber = issueMatch[1];
const details = await getIssueDetails(owner, repo, issueNumber);
if (details) issueContext = details;
}
return { repository: `${owner}/${repo}`, title: pr.title, context: issueContext };
}));
scripts/generate_updates.js
Outdated
| results.push({ repository: `${owner}/${repo}`, title: pr.title, context: issueContext }); | ||
| } | ||
| return results; | ||
| } catch (e) { return []; } |
There was a problem hiding this comment.
The catch block currently returns an empty array without logging the error. This practice, known as error swallowing, can make debugging very difficult if an issue occurs while fetching pull requests (e.g., invalid token, network error, rate limiting). It's better to log the error to maintain visibility into potential problems.
} catch (e) { console.error(`Failed to fetch PRs for ${owner}/${repo}: ${e.message}`); return []; }- Parallelized repo scanning for better performance - Added prompt delimiters to prevent injection - Improved error logging in catch blocks - Fixed file overwriting by using YYYY-MM naming - Removed unused 'path' import
✅ Feedback AddressedI have updated the PR to address all points from the Gemini Code Assist review:
The automation is now faster, more secure, and enterprise-ready. 🚀 |
🔄 Target Branch UpdatedAs requested, I have created the new base branch I have also updated this PR to target Workflow Revision: - uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
title: "Monthly Product Update"
branch: "docs/product-update"
base: "product-updates" # <--- Updated |
🚀 Product Update Automation
This PR introduces an automated system to generate monthly product updates using Gemini AI.
📦 Included Changes
scripts/generate_updates.js: The core script that fetches closed PRs, retrieves linked issue context, and uses Gemini to write a marketing-focused update..gemini/styleguide.mdfor style instructions.package.json: Required dependencies (@google/generative-ai,@octokit/rest).I was unable to push the
.github/workflows/generate-updates.ymlfile due to permission restrictions. Please add the following file manually to.github/workflows/:📋 Setup Checklist
GEMINI_API_KEYto Repository Secrets.