Skip to content

Commit

Permalink
change switch default to true, and add switch status to telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomura committed Feb 21, 2025
1 parent 2cc0178 commit d2469fa
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 30 deletions.
47 changes: 23 additions & 24 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> {
eventProps.attributes = eventProps.attributes || {};

if (product) {
attrs = { hostProduct: product.name };
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.instanceType = instanceType;
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

0 comments on commit d2469fa

Please sign in to comment.