Skip to content

Commit

Permalink
Add Create GitHub feature (#8653)
Browse files Browse the repository at this point in the history
Co-authored-by: Chidozie Ononiwu <[email protected]>
  • Loading branch information
WhitShake and chidozieononiwu authored Aug 1, 2024
1 parent 2e2e0a6 commit a1c9993
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<ng-container *ngIf="item.type === CodePanelRowDatatype.CommentThread">
<app-comment-thread
[codePanelRowData]="item"
[associatedCodeLine]="getAssociatedCodeLine(item)"
(cancelCommentActionEmitter)="handleCancelCommentActionEmitter($event)"
(saveCommentActionEmitter)="handleSaveCommentActionEmitter($event)"
(deleteCommentActionEmitter)="handleDeleteCommentActionEmitter($event)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ export class CodePanelComponent implements OnChanges{
}
}

getAssociatedCodeLine(item: CodePanelRowData): CodePanelRowData | undefined {
if (this.codePanelData?.nodeMetaData && this.codePanelData.nodeMetaData[item.nodeIdHashed]) {
return this.codePanelData.nodeMetaData[item.nodeIdHashed].codeLines[item.associatedRowPositionInGroup] || undefined;
}
return undefined;
}

getRowClassObject(row: CodePanelRowData) {
let classObject: { [key: string]: boolean } = {};
if (row.rowClasses) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { UserProfile } from 'src/app/_models/userProfile';
})
export class CommentThreadComponent {
@Input() codePanelRowData: CodePanelRowData | undefined = undefined;
@Input() associatedCodeLine: CodePanelRowData | undefined;
@Output() cancelCommentActionEmitter : EventEmitter<any> = new EventEmitter<any>();
@Output() saveCommentActionEmitter : EventEmitter<any> = new EventEmitter<any>();
@Output() deleteCommentActionEmitter : EventEmitter<any> = new EventEmitter<any>();
Expand Down Expand Up @@ -62,34 +63,37 @@ export class CommentThreadComponent {
items: [{
title: "csharp",
label: ".NET",
state: {
repo: "azure-sdk-for-net",
language: "C#"
}
command: (event) => this.createGitHubIssue(event),
},
{
title: "java",
label: "Java",
command: (event) => this.createGitHubIssue(event),
},
{
title: "python",
label: "Python",
command: (event) => this.createGitHubIssue(event),
},
{
title: "c",
label: "C",
command: (event) => this.createGitHubIssue(event),
},
{
title: "javascript",
label: "JavaScript",
command: (event) => this.createGitHubIssue(event),
},
{
title: "go",
label: "Go",
command: (event) => this.createGitHubIssue(event),
},
{
title: "cplusplus",
label: "C++",
command: (event) => this.createGitHubIssue(event),
},
]
});
Expand Down Expand Up @@ -137,9 +141,9 @@ export class CommentThreadComponent {
this.allowAnyOneToResolve = !this.allowAnyOneToResolve;
}

createGitHubIsuue(title : string) {
createGitHubIssue(event: MenuItemCommandEvent) {
let repo = "";
switch (title) {
switch (event.item?.title) {
case "csharp":
repo = "azure-sdk-for-net";
break;
Expand All @@ -162,6 +166,24 @@ export class CommentThreadComponent {
repo = "azure-sdk-for-cpp";
break;
}

const target = (event.originalEvent?.target as Element).closest("a") as Element;
const commentId = target.getAttribute("data-item-id");
const commentData = this.codePanelRowData?.comments?.find(comment => comment.id === commentId)?.commentText.replace(/<[^>]*>/g, '').trim();

console.log(this.associatedCodeLine);

const codeLineContent = this.associatedCodeLine
? this.associatedCodeLine.rowOfTokens
.map(token => token.value)
.join('')
: '';

const nodeId: string = this.codePanelRowData?.nodeId ?? 'defaultNodeId';
const apiViewUrl = `${window.location.href.split("#")[0]}&nId=${encodeURIComponent(nodeId)}`;
const issueBody = encodeURIComponent(`\`\`\`${event.item?.title}\n${codeLineContent}\n\`\`\`\n#\n${commentData}\n#\n[Created from ApiView comment](${apiViewUrl})`);

window.open(`https://github.com/Azure/${repo}/issues/new?body=${issueBody}`, '_blank');
}

showReplyEditor(event: Event) {
Expand Down

0 comments on commit a1c9993

Please sign in to comment.