fix(vscode): suppress update and install messages in managed IDEs (#10431)

This commit is contained in:
Shreya Keshive
2025-10-02 14:00:51 -04:00
committed by GitHub
parent 460ec60212
commit 4a70d6f22f
3 changed files with 75 additions and 42 deletions
@@ -42,44 +42,54 @@ function checkRelease() {
} }
const lastReleaseVersion = match[1]; const lastReleaseVersion = match[1];
const lastReleaseCommit = match[2]; const lastReleaseCommit = match[2];
console.log(`Last release version: ${lastReleaseVersion}`);
console.log(`Last release commit hash: ${lastReleaseCommit}`);
// Step 2: Check for new commits // Step 2: Check for new commits
execSync('git fetch origin main'); execSync('git fetch origin main', { stdio: 'pipe' });
const gitLog = execSync( const gitLog = execSync(
`git log ${lastReleaseCommit}..origin/main -- packages/vscode-ide-companion`, `git log ${lastReleaseCommit}..origin/main --invert-grep --grep="chore(release): bump version to" -- packages/vscode-ide-companion`,
{ encoding: 'utf-8' }, { encoding: 'utf-8' },
).trim(); ).trim();
if (gitLog) {
console.log(
'\nNew commits found since last release. A new release is needed.',
);
console.log('---');
console.log(gitLog);
console.log('---');
} else {
console.log(
'\nNo new commits found since last release. No release is necessary.',
);
}
// Step 3: Check for dependency changes // Step 3: Check for dependency changes
const noticesDiff = execSync( const noticesDiff = execSync(
`git diff ${lastReleaseCommit}..origin/main -- packages/vscode-ide-companion/NOTICES.txt`, `git diff ${lastReleaseCommit}..origin/main -- packages/vscode-ide-companion/NOTICES.txt`,
{ encoding: 'utf-8' }, { encoding: 'utf-8' },
).trim(); ).trim();
if (gitLog) {
console.log('\n--- New Commits ---');
console.log(gitLog);
console.log('-------------------');
}
if (noticesDiff) {
console.log('\n--- Dependency Changes ---');
console.log(noticesDiff);
console.log('------------------------');
}
console.log('\n--- Summary ---');
if (gitLog) {
console.log(
'New commits found for `packages/vscode-ide-companion` since last release. A new release is needed.',
);
} else {
console.log(
'No new commits found since last release. No release is necessary.',
);
}
if (noticesDiff) { if (noticesDiff) {
console.log( console.log(
'\nDependencies have changed. The license review form will require extra details.', 'Dependencies have changed. The license review form will require extra details.',
); );
console.log('---');
console.log(noticesDiff);
console.log('---');
} else { } else {
console.log('\nNo dependency changes found.'); console.log('No dependency changes found.');
} }
console.log(`Last release version: ${lastReleaseVersion}`);
console.log(`Last release commit hash: ${lastReleaseCommit}`);
console.log('---------------');
} catch (error) { } catch (error) {
console.error('Error checking for release:', error.message); console.error('Error checking for release:', error.message);
process.exit(1); process.exit(1);
@@ -209,17 +209,34 @@ describe('activate', () => {
ide: IDE_DEFINITIONS.cloudshell, ide: IDE_DEFINITIONS.cloudshell,
}, },
{ ide: IDE_DEFINITIONS.firebasestudio }, { ide: IDE_DEFINITIONS.firebasestudio },
])('does not show the notification for $ide.name', async ({ ide }) => { ])(
vi.mocked(detectIdeFromEnv).mockReturnValue(ide); 'does not show install or update messages for $ide.name',
vi.mocked(context.globalState.get).mockReturnValue(undefined); async ({ ide }) => {
const showInformationMessageMock = vi.mocked( vi.mocked(detectIdeFromEnv).mockReturnValue(ide);
vscode.window.showInformationMessage, vi.mocked(context.globalState.get).mockReturnValue(undefined);
); vi.spyOn(global, 'fetch').mockResolvedValue({
ok: true,
json: async () => ({
results: [
{
extensions: [
{
versions: [{ version: '1.2.0' }],
},
],
},
],
}),
} as Response);
const showInformationMessageMock = vi.mocked(
vscode.window.showInformationMessage,
);
await activate(context); await activate(context);
expect(showInformationMessageMock).not.toHaveBeenCalled(); expect(showInformationMessageMock).not.toHaveBeenCalled();
}); },
);
it('should not show an update notification if the version is older', async () => { it('should not show an update notification if the version is older', async () => {
vi.spyOn(global, 'fetch').mockResolvedValue({ vi.spyOn(global, 'fetch').mockResolvedValue({
+17 -11
View File
@@ -20,11 +20,9 @@ const INFO_MESSAGE_SHOWN_KEY = 'geminiCliInfoMessageShown';
export const DIFF_SCHEME = 'gemini-diff'; export const DIFF_SCHEME = 'gemini-diff';
/** /**
* IDE environments where the installation greeting is hidden. In these * In these environments the companion extension is installed and managed by the IDE instead of the user.
* environments we either are pre-installed and the installation message is
* confusing or we just want to be quiet.
*/ */
const HIDE_INSTALLATION_GREETING_IDES: ReadonlySet<IdeInfo['name']> = new Set([ const MANAGED_EXTENSION_SURFACES: ReadonlySet<IdeInfo['name']> = new Set([
IDE_DEFINITIONS.firebasestudio.name, IDE_DEFINITIONS.firebasestudio.name,
IDE_DEFINITIONS.cloudshell.name, IDE_DEFINITIONS.cloudshell.name,
]); ]);
@@ -37,6 +35,7 @@ let log: (message: string) => void = () => {};
async function checkForUpdates( async function checkForUpdates(
context: vscode.ExtensionContext, context: vscode.ExtensionContext,
log: (message: string) => void, log: (message: string) => void,
isManagedExtensionSurface: boolean,
) { ) {
try { try {
const currentVersion = context.extension.packageJSON.version; const currentVersion = context.extension.packageJSON.version;
@@ -81,7 +80,11 @@ async function checkForUpdates(
// The versions are sorted by date, so the first one is the latest. // The versions are sorted by date, so the first one is the latest.
const latestVersion = extension?.versions?.[0]?.version; const latestVersion = extension?.versions?.[0]?.version;
if (latestVersion && semver.gt(latestVersion, currentVersion)) { if (
!isManagedExtensionSurface &&
latestVersion &&
semver.gt(latestVersion, currentVersion)
) {
const selection = await vscode.window.showInformationMessage( const selection = await vscode.window.showInformationMessage(
`A new version (${latestVersion}) of the Gemini CLI Companion extension is available.`, `A new version (${latestVersion}) of the Gemini CLI Companion extension is available.`,
'Update to latest version', 'Update to latest version',
@@ -105,7 +108,11 @@ export async function activate(context: vscode.ExtensionContext) {
log = createLogger(context, logger); log = createLogger(context, logger);
log('Extension activated'); log('Extension activated');
checkForUpdates(context, log); const isManagedExtensionSurface = MANAGED_EXTENSION_SURFACES.has(
detectIdeFromEnv().name,
);
checkForUpdates(context, log, isManagedExtensionSurface);
const diffContentProvider = new DiffContentProvider(); const diffContentProvider = new DiffContentProvider();
const diffManager = new DiffManager(log, diffContentProvider); const diffManager = new DiffManager(log, diffContentProvider);
@@ -148,11 +155,10 @@ export async function activate(context: vscode.ExtensionContext) {
log(`Failed to start IDE server: ${message}`); log(`Failed to start IDE server: ${message}`);
} }
const infoMessageEnabled = !HIDE_INSTALLATION_GREETING_IDES.has( if (
detectIdeFromEnv().name, !context.globalState.get(INFO_MESSAGE_SHOWN_KEY) &&
); !isManagedExtensionSurface
) {
if (!context.globalState.get(INFO_MESSAGE_SHOWN_KEY) && infoMessageEnabled) {
void vscode.window.showInformationMessage( void vscode.window.showInformationMessage(
'Gemini CLI Companion extension successfully installed.', 'Gemini CLI Companion extension successfully installed.',
); );