Skip to content
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

[AXON-109] Expose toggle switch to push branch to remote (Start work) #137

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## What's new in 3.4.8

### Features

- Added a new toggle switch in 'Start work' page to choose if the new branch should be automatically pushed to remote.

## What's new in 3.4.7

### Features
Expand Down
106 changes: 106 additions & 0 deletions src/analytics.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import { viewScreenEvent } from './analytics';

interface MockedData {
getFirstAAID_value?: boolean;
}

const mockedData: MockedData = {};

jest.mock('./container', () => ({
Container: { siteManager: { getFirstAAID: () => mockedData.getFirstAAID_value } },
}));

function setProcessPlatform(platform: NodeJS.Platform) {
Object.defineProperty(process, 'platform', {
value: platform,
writable: false,
});
}

describe('viewScreenEvent', () => {
const originalPlatform = process.platform;

beforeAll(() => {
setProcessPlatform('win32');
});

beforeEach(() => {
mockedData.getFirstAAID_value = true;
});

afterAll(() => {
setProcessPlatform(originalPlatform);
});

it('should create a screen event with the correct screen name', async () => {
const screenName = 'testScreen';
const event = await viewScreenEvent(screenName);
expect(event.name).toEqual(screenName);
expect(event.screenEvent.attributes).toBeUndefined();
});

it('should exclude from activity if screen name is atlascodeWelcomeScreen', async () => {
const screenName = 'atlascodeWelcomeScreen';
const event = await viewScreenEvent(screenName);
expect(event.screenEvent.attributes.excludeFromActivity).toBeTruthy();
});

it('should include site information if provided (cloud)', async () => {
const screenName = 'testScreen';
const site: any = {
id: 'siteId',
product: { name: 'Jira', key: 'jira' },
isCloud: true,
};
const event = await viewScreenEvent(screenName, site);
expect(event.screenEvent.attributes.instanceType).toEqual('cloud');
expect(event.screenEvent.attributes.hostProduct).toEqual('Jira');
});

it('should include site information if provided (server)', async () => {
const screenName = 'testScreen';
const site: any = {
id: 'siteId',
product: { name: 'Jira', key: 'jira' },
isCloud: false,
};
const event = await viewScreenEvent(screenName, site);
expect(event.screenEvent.attributes.instanceType).toEqual('server');
expect(event.screenEvent.attributes.hostProduct).toEqual('Jira');
});

it('should include product information if provided', async () => {
const screenName = 'testScreen';
const product = { name: 'Bitbucket', key: 'bitbucket' };
const event = await viewScreenEvent(screenName, undefined, product);
expect(event.screenEvent.attributes.hostProduct).toEqual('Bitbucket');
});

it('should set platform based on process.platform (win32)', async () => {
setProcessPlatform('win32');
const screenName = 'testScreen';
const event = await viewScreenEvent(screenName);
expect(event.screenEvent.platform).toEqual('windows');
});

it('should set platform based on process.platform (darwin)', async () => {
setProcessPlatform('darwin');
const screenName = 'testScreen';
const event = await viewScreenEvent(screenName);
expect(event.screenEvent.platform).toEqual('mac');
});

it('should set platform based on process.platform (linux)', async () => {
setProcessPlatform('linux');
const screenName = 'testScreen';
const event = await viewScreenEvent(screenName);
expect(event.screenEvent.platform).toEqual('linux');
});

it('should set platform based on process.platform (aix)', async () => {
setProcessPlatform('aix');
const screenName = 'testScreen';
const event = await viewScreenEvent(screenName);
expect(event.screenEvent.platform).toEqual('desktop');
});
});
49 changes: 24 additions & 25 deletions src/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const Registry = {
};

class AnalyticsPlatform {
private static nodeJsPlatformMapping = {
private static nodeJsPlatformMapping: Record<string, any> = {
aix: 'desktop',
android: 'android',
darwin: 'mac',
Expand Down Expand Up @@ -107,8 +107,13 @@ export async function issueCommentEvent(site: DetailedSiteInfo): Promise<TrackEv
return instanceTrackEvent(site, 'created', 'issueComment');
}

export async function issueWorkStartedEvent(site: DetailedSiteInfo): Promise<TrackEvent> {
return instanceTrackEvent(site, 'workStarted', 'issue');
export async function issueWorkStartedEvent(
site: DetailedSiteInfo,
pushBranchToRemoteChecked: boolean,
): Promise<TrackEvent> {
const attributesObject = instanceType({}, site);
attributesObject.attributes.pushBranchToRemoteChecked = pushBranchToRemoteChecked;
return instanceTrackEvent(site, 'workStarted', 'issue', attributesObject);
}

export async function issueUpdatedEvent(
Expand Down Expand Up @@ -164,7 +169,7 @@ export async function prCommentEvent(site: DetailedSiteInfo): Promise<TrackEvent
}

export async function prTaskEvent(site: DetailedSiteInfo, source: string): Promise<TrackEvent> {
const attributesObject: any = instanceType({}, site);
const attributesObject = instanceType({}, site);
attributesObject.attributes.source = source;
return trackEvent('created', 'pullRequestComment', attributesObject);
}
Expand Down Expand Up @@ -657,33 +662,27 @@ function tenantOrNull<T>(e: Object, tenantId?: string): T {
return newObj as T;
}

function instanceType(eventProps: Object, site?: DetailedSiteInfo, product?: Product): Object {
let attrs: Object | undefined = undefined;
const newObj = eventProps;

function instanceType(
eventProps: Record<string, any>,
site?: DetailedSiteInfo,
product?: Product,
): Record<string, any> {
if (product) {
attrs = { hostProduct: product.name };
eventProps.attributes = eventProps.attributes || {};
eventProps.attributes.hostProduct = product.name;
}

if (site && !isEmptySiteInfo(site)) {
const instanceType: string = site.isCloud ? 'cloud' : 'server';
attrs = { instanceType: instanceType, hostProduct: site.product.name };
eventProps.attributes = eventProps.attributes || {};
eventProps.attributes.instanceType = site.isCloud ? 'cloud' : 'server';
eventProps.attributes.hostProduct = site.product.name;
}

if (attrs) {
newObj['attributes'] = { ...newObj['attributes'], ...attrs };
}

return newObj;
return eventProps;
}

function excludeFromActivity(eventProps: Object): Object {
const newObj = eventProps;

if (newObj['attributes']) {
newObj['attributes'] = { ...newObj['attributes'], ...{ excludeFromActivity: true } };
} else {
Object.assign(newObj, { attributes: { excludeFromActivity: true } });
}
return newObj;
function excludeFromActivity(eventProps: Record<string, any>): Record<string, any> {
eventProps.attributes = eventProps.attributes || {};
eventProps.attributes.excludeFromActivity = true;
return eventProps;
}
2 changes: 1 addition & 1 deletion src/lib/analyticsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface AnalyticsApi {
fireIssueTransitionedEvent(site: DetailedSiteInfo, issueKey: string): Promise<void>;
fireIssueUrlCopiedEvent(): Promise<void>;
fireIssueCommentEvent(site: DetailedSiteInfo): Promise<void>;
fireIssueWorkStartedEvent(site: DetailedSiteInfo): Promise<void>;
fireIssueWorkStartedEvent(site: DetailedSiteInfo, pushBranchToRemoteChecked: boolean): Promise<void>;
fireIssueUpdatedEvent(site: DetailedSiteInfo, issueKey: string, fieldName: string, fieldKey: string): Promise<void>;
fireStartIssueCreationEvent(source: string, product: Product): Promise<void>;
fireBBIssueCreatedEvent(site: DetailedSiteInfo): Promise<void>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export class StartWorkWebviewController implements WebviewController<StartWorkIs
branch: msg.branchSetupEnabled ? msg.targetBranch : undefined,
upstream: msg.branchSetupEnabled ? msg.upstream : undefined,
});
this.analytics.fireIssueWorkStartedEvent(this.initData.issue.siteDetails);
this.analytics.fireIssueWorkStartedEvent(this.initData.issue.siteDetails, msg.pushBranchToRemote);
} catch (e) {
this.logger.error(new Error(`error executing start work action: ${e}`));
this.postMessage({
Expand Down
2 changes: 1 addition & 1 deletion src/react/atlascode/startwork/StartWorkPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const StartWorkPage: React.FunctionComponent = () => {

const [transitionIssueEnabled, setTransitionIssueEnabled] = useState(true);
const [branchSetupEnabled, setbranchSetupEnabled] = useState(true);
const [pushBranchEnabled, setPushBranchEnabled] = useState(false);
const [pushBranchEnabled, setPushBranchEnabled] = useState(true);
const [transition, setTransition] = useState<Transition>(emptyTransition);
const [repository, setRepository] = useState<RepoData>(emptyRepoData);
const [branchType, setBranchType] = useState<BranchType>(emptyPrefix);
Expand Down
4 changes: 2 additions & 2 deletions src/vscAnalyticsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ export class VSCAnalyticsApi implements AnalyticsApi {
});
}

public async fireIssueWorkStartedEvent(site: DetailedSiteInfo): Promise<void> {
return issueWorkStartedEvent(site).then((e) => {
public async fireIssueWorkStartedEvent(site: DetailedSiteInfo, pushBranchToRemoteChecked: boolean): Promise<void> {
return issueWorkStartedEvent(site, pushBranchToRemoteChecked).then((e) => {
this._analyticsClient.sendTrackEvent(e);
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/webviews/startWorkOnIssueWebview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export class StartWorkOnIssueWebview
: ''
}</ul>`,
});
issueWorkStartedEvent(issue.siteDetails).then((e) => {
issueWorkStartedEvent(issue.siteDetails, e.pushBranchToRemote).then((e) => {
Container.analyticsClient.sendTrackEvent(e);
});
} catch (e) {
Expand Down