Skip to content

Commit 1922d1e

Browse files
authored
Add telemetry for when Copilot is assigned to an issue (#7463)
Fixes #7445
1 parent 42685ee commit 1922d1e

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

src/github/folderRepositoryManager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,7 +1304,7 @@ export class FolderRepositoryManager extends Disposable {
13041304
};
13051305
for (const issue of data.items) {
13061306
const githubRepository = await this.getRepoForIssue(issue);
1307-
mappedData.items.push(new IssueModel(githubRepository, githubRepository.remote, issue));
1307+
mappedData.items.push(new IssueModel(this.telemetry, githubRepository, githubRepository.remote, issue));
13081308
}
13091309
return mappedData;
13101310
} catch (e) {
@@ -1601,7 +1601,7 @@ export class FolderRepositoryManager extends Disposable {
16011601
// Create PR
16021602
const { data } = await repo.octokit.call(repo.octokit.api.issues.create, params);
16031603
const item = convertRESTIssueToRawPullRequest(data, repo);
1604-
const issueModel = new IssueModel(repo, repo.remote, item);
1604+
const issueModel = new IssueModel(this.telemetry, repo, repo.remote, item);
16051605

16061606
/* __GDPR__
16071607
"issue.create.success" : {

src/github/githubRepository.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,7 @@ export class GitHubRepository extends Disposable {
11041104
}
11051105
Logger.debug(`Fetch issue ${id} - done`, this.id);
11061106

1107-
return new IssueModel(this, remote, await parseGraphQLIssue(data.repository.issue, this));
1107+
return new IssueModel(this.telemetry, this, remote, await parseGraphQLIssue(data.repository.issue, this));
11081108
} catch (e) {
11091109
Logger.error(`Unable to fetch issue: ${e}`, this.id);
11101110
return;

src/github/issueModel.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { COPILOT_ACCOUNTS, IComment } from '../common/comment';
88
import { Disposable } from '../common/lifecycle';
99
import Logger from '../common/logger';
1010
import { Remote } from '../common/remote';
11+
import { ITelemetry } from '../common/telemetry';
1112
import { ClosedEvent, CrossReferencedEvent, EventType, TimelineEvent } from '../common/timelineEvent';
1213
import { compareIgnoreCase, formatError } from '../common/utils';
1314
import { OctokitCommon } from './common';
@@ -57,6 +58,7 @@ export class IssueModel<TItem extends Issue = Issue> extends Disposable {
5758
public updatedAt: string;
5859
public milestone?: IMilestone;
5960
public readonly githubRepository: GitHubRepository;
61+
protected readonly _telemetry: ITelemetry;
6062
public readonly remote: Remote;
6163
public item: TItem;
6264
public body: string;
@@ -67,8 +69,9 @@ export class IssueModel<TItem extends Issue = Issue> extends Disposable {
6769
protected _onDidChange = this._register(new vscode.EventEmitter<IssueChangeEvent>());
6870
public onDidChange = this._onDidChange.event;
6971

70-
constructor(githubRepository: GitHubRepository, remote: Remote, item: TItem, skipUpdate: boolean = false) {
72+
constructor(telemetry: ITelemetry, githubRepository: GitHubRepository, remote: Remote, item: TItem, skipUpdate: boolean = false) {
7173
super();
74+
this._telemetry = telemetry;
7275
this.githubRepository = githubRepository;
7376
this.remote = remote;
7477
this.item = item;
@@ -579,6 +582,15 @@ export class IssueModel<TItem extends Issue = Issue> extends Disposable {
579582

580583
try {
581584
if (schema.ReplaceActorsForAssignable) {
585+
const assignToCopilot = allAssignees.find(assignee => COPILOT_ACCOUNTS[assignee.login]);
586+
const alreadyHasCopilot = this.assignees?.find(assignee => COPILOT_ACCOUNTS[assignee.login]) !== undefined;
587+
if (assignToCopilot && !alreadyHasCopilot) {
588+
/* __GDPR__
589+
"pr.assignCopilot" : {}
590+
*/
591+
this._telemetry.sendTelemetryEvent('pr.assignCopilot');
592+
}
593+
582594
const assigneeIds = allAssignees.map(assignee => assignee.id);
583595
await mutate({
584596
mutation: schema.ReplaceActorsForAssignable,

src/github/pullRequestModel.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ export class PullRequestModel extends IssueModel<PullRequest> implements IPullRe
156156
this._isActive = isActive;
157157
}
158158

159-
_telemetry: ITelemetry;
160159

161160
constructor(
162161
private readonly credentialStore: CredentialStore,
@@ -166,9 +165,8 @@ export class PullRequestModel extends IssueModel<PullRequest> implements IPullRe
166165
item: PullRequest,
167166
isActive?: boolean,
168167
) {
169-
super(githubRepository, remote, item, true);
168+
super(telemetry, githubRepository, remote, item, true);
170169

171-
this._telemetry = telemetry;
172170
this.isActive = !!isActive;
173171

174172
this._showChangesSinceReview = false;

0 commit comments

Comments
 (0)