Skip to content

Commit 2e74cf2

Browse files
Add Create GitHub feature
1 parent c9853b6 commit 2e74cf2

3 files changed

Lines changed: 36 additions & 6 deletions

File tree

src/dotnet/APIView/ClientSPA/src/app/_components/code-panel/code-panel.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<ng-container *ngIf="item.type === CodePanelRowDatatype.CommentThread">
2727
<app-comment-thread
2828
[codePanelRowData]="item"
29+
[associatedCodeLine]="getAssociatedCodeLine(item)"
2930
(cancelCommentActionEmitter)="handleCancelCommentActionEmitter($event)"
3031
(saveCommentActionEmitter)="handleSaveCommentActionEmitter($event)"
3132
(deleteCommentActionEmitter)="handleDeleteCommentActionEmitter($event)"

src/dotnet/APIView/ClientSPA/src/app/_components/code-panel/code-panel.component.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ export class CodePanelComponent implements OnChanges{
8888
}
8989
}
9090

91+
getAssociatedCodeLine(item: CodePanelRowData): CodePanelRowData | undefined {
92+
if (this.codePanelData?.nodeMetaData && this.codePanelData.nodeMetaData[item.nodeIdHashed]) {
93+
return this.codePanelData.nodeMetaData[item.nodeIdHashed].codeLines[item.associatedRowPositionInGroup] || undefined;
94+
}
95+
return undefined;
96+
}
97+
9198
getRowClassObject(row: CodePanelRowData) {
9299
let classObject: { [key: string]: boolean } = {};
93100
if (row.rowClasses) {

src/dotnet/APIView/ClientSPA/src/app/_components/shared/comment-thread/comment-thread.component.ts

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { UserProfile } from 'src/app/_models/userProfile';
1717
})
1818
export class CommentThreadComponent {
1919
@Input() codePanelRowData: CodePanelRowData | undefined = undefined;
20+
@Input() associatedCodeLine: CodePanelRowData | undefined;
2021
@Output() cancelCommentActionEmitter : EventEmitter<any> = new EventEmitter<any>();
2122
@Output() saveCommentActionEmitter : EventEmitter<any> = new EventEmitter<any>();
2223
@Output() deleteCommentActionEmitter : EventEmitter<any> = new EventEmitter<any>();
@@ -62,34 +63,37 @@ export class CommentThreadComponent {
6263
items: [{
6364
title: "csharp",
6465
label: ".NET",
65-
state: {
66-
repo: "azure-sdk-for-net",
67-
language: "C#"
68-
}
66+
command: (event) => this.createGitHubIssue(event),
6967
},
7068
{
7169
title: "java",
7270
label: "Java",
71+
command: (event) => this.createGitHubIssue(event),
7372
},
7473
{
7574
title: "python",
7675
label: "Python",
76+
command: (event) => this.createGitHubIssue(event),
7777
},
7878
{
7979
title: "c",
8080
label: "C",
81+
command: (event) => this.createGitHubIssue(event),
8182
},
8283
{
8384
title: "javascript",
8485
label: "JavaScript",
86+
command: (event) => this.createGitHubIssue(event),
8587
},
8688
{
8789
title: "go",
8890
label: "Go",
91+
command: (event) => this.createGitHubIssue(event),
8992
},
9093
{
9194
title: "cplusplus",
9295
label: "C++",
96+
command: (event) => this.createGitHubIssue(event),
9397
},
9498
]
9599
});
@@ -137,9 +141,9 @@ export class CommentThreadComponent {
137141
this.allowAnyOneToResolve = !this.allowAnyOneToResolve;
138142
}
139143

140-
createGitHubIsuue(title : string) {
144+
createGitHubIssue(event: MenuItemCommandEvent) {
141145
let repo = "";
142-
switch (title) {
146+
switch (event.item?.title) {
143147
case "csharp":
144148
repo = "azure-sdk-for-net";
145149
break;
@@ -162,6 +166,24 @@ export class CommentThreadComponent {
162166
repo = "azure-sdk-for-cpp";
163167
break;
164168
}
169+
170+
const target = (event.originalEvent?.target as Element).closest("a") as Element;
171+
const commentId = target.getAttribute("data-item-id");
172+
const commentData = this.codePanelRowData?.comments?.find(comment => comment.id === commentId)?.commentText.replace(/<[^>]*>/g, '').trim();
173+
174+
console.log(this.associatedCodeLine);
175+
176+
const codeLineContent = this.associatedCodeLine
177+
? this.associatedCodeLine.rowOfTokens
178+
.map(token => token.value)
179+
.join('')
180+
: '';
181+
182+
const nodeId: string = this.codePanelRowData?.nodeId ?? 'defaultNodeId';
183+
const apiViewUrl = `${window.location.href.split("#")[0]}&nId=${encodeURIComponent(nodeId)}`;
184+
const issueBody = encodeURIComponent(`\`\`\`${event.item?.title}\n${codeLineContent}\n\`\`\`\n#\n${commentData}\n#\n[Created from ApiView comment](${apiViewUrl})`);
185+
186+
window.open(`https://github.com/Azure/${repo}/issues/new?body=${issueBody}`, '_blank');
165187
}
166188

167189
showReplyEditor(event: Event) {

0 commit comments

Comments
 (0)