2019-04-09 14:37:58 +02:00
|
|
|
import * as vscode from "vscode";
|
|
|
|
import axios from "axios";
|
2019-04-10 08:59:42 +02:00
|
|
|
import { RepositoryInformationManager } from "./configurationProvider";
|
2019-04-09 14:37:58 +02:00
|
|
|
|
|
|
|
export class IssueProvider implements vscode.TreeDataProvider<Issue> {
|
|
|
|
|
2019-04-09 21:22:33 +02:00
|
|
|
private _onDidChangeTreeData: vscode.EventEmitter<Issue | undefined> = new vscode.EventEmitter<Issue | undefined>();
|
|
|
|
readonly onDidChangeTreeData: vscode.Event<Issue | undefined> = this._onDidChangeTreeData.event;
|
|
|
|
|
2019-04-10 08:59:42 +02:00
|
|
|
issueList: Issue[] = [];
|
2019-04-09 21:22:33 +02:00
|
|
|
|
2019-04-10 08:59:42 +02:00
|
|
|
async refresh() {
|
|
|
|
await this.getChildrenAsync();
|
|
|
|
this._onDidChangeTreeData.fire();
|
2019-04-09 14:37:58 +02:00
|
|
|
}
|
|
|
|
|
2019-04-10 08:59:42 +02:00
|
|
|
constructor() { }
|
|
|
|
|
2019-04-09 14:37:58 +02:00
|
|
|
getTreeItem(element: Issue): vscode.TreeItem | Thenable<vscode.TreeItem> {
|
|
|
|
return element;
|
|
|
|
}
|
2019-04-09 21:22:33 +02:00
|
|
|
|
|
|
|
async getChildrenAsync() {
|
|
|
|
this.issueList = [];
|
2019-04-10 08:59:42 +02:00
|
|
|
const repoMng = new RepositoryInformationManager();
|
|
|
|
const repoUri = repoMng.repoApiUrl(vscode.workspace.rootPath);
|
|
|
|
console.log(repoUri);
|
|
|
|
const token = repoMng.token(vscode.workspace.rootPath);
|
|
|
|
let stop = false;
|
2019-04-09 21:22:33 +02:00
|
|
|
for (let i = 0; i !== 10; i++) {
|
2019-04-10 08:59:42 +02:00
|
|
|
await axios.get(repoUri + "?page=" + i, { headers: { Authorization: "token " + token } }).then(res => {
|
2019-04-09 21:22:33 +02:00
|
|
|
for (const issue of res.data) {
|
|
|
|
const id = issue["number"];
|
2019-04-10 08:59:42 +02:00
|
|
|
let isAlreadyInList = false;
|
|
|
|
this.issueList.forEach((issueOfList) => {
|
|
|
|
if (id === issueOfList.issueId) {
|
|
|
|
isAlreadyInList = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (isAlreadyInList) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const title = issue["title"];
|
2019-04-09 21:22:33 +02:00
|
|
|
const body = issue["body"];
|
|
|
|
const state = issue["state"];
|
|
|
|
const assignee = issue["assignee"] === null ? "None" : issue["assignee"]["username"];
|
2019-04-10 08:59:42 +02:00
|
|
|
const tmpIssue = new Issue("#" + id + " - " + title, id, body, state, assignee, "Frontend", vscode.TreeItemCollapsibleState.None);
|
|
|
|
const issueForList = new Issue(tmpIssue.label, tmpIssue.issueId, tmpIssue.body, tmpIssue.issueState,
|
|
|
|
tmpIssue.assignee, tmpIssue.firstlabel, tmpIssue.collapsibleState, {
|
|
|
|
command: 'giteaIssues.openIssue',
|
|
|
|
title: '',
|
|
|
|
arguments: [tmpIssue],
|
|
|
|
});
|
2019-04-09 21:22:33 +02:00
|
|
|
this.issueList.push(issueForList);
|
|
|
|
}
|
|
|
|
}).catch(err => {
|
|
|
|
console.log(err);
|
2019-04-10 08:59:42 +02:00
|
|
|
stop = true;
|
|
|
|
vscode.window.showErrorMessage("Can't fetch issues; HTTP Error!");
|
|
|
|
return;
|
2019-04-09 21:22:33 +02:00
|
|
|
});
|
2019-04-10 08:59:42 +02:00
|
|
|
if (stop) {
|
|
|
|
return;
|
|
|
|
}
|
2019-04-09 21:22:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
console.log(this.issueList);
|
|
|
|
}
|
2019-04-09 14:37:58 +02:00
|
|
|
getChildren(element?: Issue): vscode.ProviderResult<any[]> {
|
2019-04-09 21:22:33 +02:00
|
|
|
return this.issueList;
|
2019-04-09 14:37:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export class Issue extends vscode.TreeItem {
|
|
|
|
|
|
|
|
constructor(public readonly label: string,
|
|
|
|
public issueId: number,
|
|
|
|
public body: string,
|
|
|
|
public issueState: string,
|
2019-04-09 21:22:33 +02:00
|
|
|
public assignee: string,
|
|
|
|
public firstlabel: string,
|
2019-04-09 14:37:58 +02:00
|
|
|
public readonly collapsibleState: vscode.TreeItemCollapsibleState,
|
|
|
|
public readonly command?: vscode.Command) {
|
|
|
|
super(label, collapsibleState);
|
|
|
|
}
|
|
|
|
|
|
|
|
get tooltip() {
|
2019-04-09 21:22:33 +02:00
|
|
|
return this.label + " - " + this.assignee;
|
2019-04-09 14:37:58 +02:00
|
|
|
}
|
|
|
|
contextValue = 'issue';
|
|
|
|
}
|