Skip to content

Commit 07a07c7

Browse files
committed
Automatically enable Rovo Dev for internal users
1 parent 984d0f4 commit 07a07c7

File tree

7 files changed

+59
-27
lines changed

7 files changed

+59
-27
lines changed

src/container.ts

Lines changed: 55 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { BitbucketCheckoutHelper } from './bitbucket/checkoutHelper';
1111
import { CheckoutHelper } from './bitbucket/interfaces';
1212
import { PullRequest, WorkspaceRepo } from './bitbucket/model';
1313
import { BitbucketCloudPullRequestLinkProvider } from './bitbucket/terminal-link/createPrLinkProvider';
14+
import { CommandContext, setCommandContext } from './commandContext';
1415
import { openPullRequest } from './commands/bitbucket/pullRequest';
1516
import { configuration, IConfig } from './config/configuration';
1617
import { Commands } from './constants';
@@ -78,6 +79,15 @@ export class Container {
7879
private static _assignedWorkItemsView: AssignedWorkItemsViewProvider;
7980

8081
static async initialize(context: ExtensionContext, version: string) {
82+
canFetchInternalUrl().then((success) => {
83+
this._isInternalUser = success;
84+
this._isRovoDevEnabled = success;
85+
86+
if (success) {
87+
this.enableRovoDev(context);
88+
}
89+
});
90+
8191
const analyticsEnv: string = this.isDebugging ? 'staging' : 'prod';
8292

8393
this._analyticsClient = analyticsClient({
@@ -211,26 +221,30 @@ export class Container {
211221
context.subscriptions.push(new CustomJQLViewProvider());
212222
context.subscriptions.push((this._assignedWorkItemsView = new AssignedWorkItemsViewProvider()));
213223

214-
if (!!process.env.ROVODEV_ENABLED) {
215-
context.subscriptions.push(new RovoDevDecorator());
216-
context.subscriptions.push(
217-
languages.registerCodeActionsProvider({ scheme: 'file' }, new RovoDevCodeActionProvider(), {
218-
providedCodeActionKinds: [vscode.CodeActionKind.QuickFix],
219-
}),
220-
);
221-
context.subscriptions.push(
222-
(this._rovodevWebviewProvider = new RovoDevWebviewProvider(
223-
context,
224-
context.extensionPath,
225-
context.globalState,
226-
)),
227-
);
228-
this.configureRovodevSettingsCommands(context);
229-
}
230-
231224
this._onboardingProvider = new OnboardingProvider();
232225
}
233226

227+
static enableRovoDev(context: ExtensionContext) {
228+
// this enables the Rovo Dev activity bar
229+
setCommandContext(CommandContext.RovoDevEnabled, true);
230+
231+
context.subscriptions.push(new RovoDevDecorator());
232+
context.subscriptions.push(
233+
languages.registerCodeActionsProvider({ scheme: 'file' }, new RovoDevCodeActionProvider(), {
234+
providedCodeActionKinds: [vscode.CodeActionKind.QuickFix],
235+
}),
236+
);
237+
context.subscriptions.push(
238+
(this._rovodevWebviewProvider = new RovoDevWebviewProvider(
239+
context,
240+
context.extensionPath,
241+
context.globalState,
242+
)),
243+
);
244+
245+
this.configureRovodevSettingsCommands(context);
246+
}
247+
234248
static configureRovodevSettingsCommands(context: ExtensionContext) {
235249
async function openConfigFile(subPath: string, friendlyName: string) {
236250
const home = process.env.HOME || process.env.USERPROFILE;
@@ -330,6 +344,16 @@ export class Container {
330344
this._context.globalState.update(ConfigTargetKey, target);
331345
}
332346

347+
private static _isInternalUser: boolean;
348+
public static get isInternalUser() {
349+
return this._isInternalUser;
350+
}
351+
352+
private static _isRovoDevEnabled: boolean;
353+
public static get isRovoDevEnabled() {
354+
return this._isRovoDevEnabled;
355+
}
356+
333357
private static _version: string;
334358
public static get version() {
335359
return this._version;
@@ -470,3 +494,17 @@ export class Container {
470494
return this._rovodevWebviewProvider;
471495
}
472496
}
497+
498+
async function canFetchInternalUrl(): Promise<boolean> {
499+
try {
500+
const result = await fetch('http://github.internal.atlassian.com/', {
501+
method: 'GET',
502+
signal: AbortSignal.timeout(5000),
503+
});
504+
505+
const statusKind = Math.floor((result.status || 0) / 100);
506+
return statusKind === 2 || statusKind === 3;
507+
} catch {
508+
return false;
509+
}
510+
}

src/extension.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ export async function activate(context: ExtensionContext) {
5151

5252
// this disables the main Atlassian activity bar when we are in BBY
5353
setCommandContext(CommandContext.BbyEnvironmentActive, !!process.env.ROVODEV_BBY);
54-
// this disables the Rovo Dev activity bar unless it's explicitely enabled
55-
setCommandContext(CommandContext.RovoDevEnabled, !!process.env.ROVODEV_ENABLED);
5654

5755
// Mark ourselves as the PID in charge of refreshing credentials and start listening for pings.
5856
context.globalState.update('rulingPid', pid);
@@ -113,7 +111,7 @@ export async function activate(context: ExtensionContext) {
113111
// icon to appear in the activity bar
114112
activateBitbucketFeatures();
115113
activateYamlFeatures(context);
116-
} else if (!!process.env.ROVODEV_ENABLED) {
114+
} else {
117115
commands.executeCommand('workbench.view.extension.atlascode-rovo-dev');
118116
}
119117

@@ -215,7 +213,7 @@ async function sendAnalytics(version: string, globalState: Memento) {
215213
// this method is called when your extension is deactivated
216214
export function deactivate() {
217215
if (!process.env.ROVODEV_BBY) {
218-
if (!!process.env.ROVODEV_ENABLED) {
216+
if (Container.isRovoDevEnabled) {
219217
deactivateRovoDevProcessManager();
220218
}
221219

src/rovo-dev/rovoDevWebviewProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export class RovoDevWebviewProvider extends Disposable implements WebviewViewPro
153153

154154
// Register the initialization of the process when the webview is ready
155155
this.onWebviewResolved(() => {
156-
if (!!process.env.ROVODEV_ENABLED && !process.env.ROVODEV_BBY) {
156+
if (!process.env.ROVODEV_BBY) {
157157
initializeRovoDevProcessManager(context);
158158
} else {
159159
this.signalProcessStarted();
@@ -292,7 +292,7 @@ export class RovoDevWebviewProvider extends Disposable implements WebviewViewPro
292292
}
293293
});
294294

295-
if (!!process.env.ROVODEV_ENABLED && !process.env.ROVODEV_BBY) {
295+
if (!process.env.ROVODEV_BBY) {
296296
workspace.onDidChangeWorkspaceFolders(() => {
297297
if (!this._disabled) {
298298
webview.postMessage({

webpack.extension.dev.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ module.exports = [
8282
process.env.ATLASCODE_EXP_OVERRIDES_STRING,
8383
),
8484
'process.env.ROVODEV_BBY': JSON.stringify(process.env.ROVODEV_BBY),
85-
'process.env.ROVODEV_ENABLED': JSON.stringify(process.env.ROVODEV_ENABLED),
8685
}),
8786
],
8887
},

webpack.extension.prod.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ module.exports = [
108108
process.env.ATLASCODE_EXP_OVERRIDES_STRING,
109109
),
110110
'process.env.ROVODEV_BBY': JSON.stringify(process.env.ROVODEV_BBY),
111-
'process.env.ROVODEV_ENABLED': JSON.stringify(process.env.ROVODEV_ENABLED),
112111
}),
113112
],
114113
externals: ['vscode'],

webpack.react.dev.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ module.exports = {
6666
'process.env.ATLASCODE_EXP_OVERRIDES_BOOL': JSON.stringify(process.env.ATLASCODE_EXP_OVERRIDES_BOOL),
6767
'process.env.ATLASCODE_EXP_OVERRIDES_STRING': JSON.stringify(process.env.ATLASCODE_EXP_OVERRIDES_STRING),
6868
'process.env.ROVODEV_BBY': JSON.stringify(process.env.ROVODEV_BBY),
69-
'process.env.ROVODEV_ENABLED': JSON.stringify(process.env.ROVODEV_ENABLED),
7069
}),
7170
],
7271
module: {

webpack.react.prod.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ module.exports = {
104104
'process.env.ATLASCODE_EXP_OVERRIDES_BOOL': JSON.stringify(process.env.ATLASCODE_EXP_OVERRIDES_BOOL),
105105
'process.env.ATLASCODE_EXP_OVERRIDES_STRING': JSON.stringify(process.env.ATLASCODE_EXP_OVERRIDES_STRING),
106106
'process.env.ROVODEV_BBY': JSON.stringify(process.env.ROVODEV_BBY),
107-
'process.env.ROVODEV_ENABLED': JSON.stringify(process.env.ROVODEV_ENABLED),
108107
}),
109108
],
110109
performance: {

0 commit comments

Comments
 (0)