2019-07-04 14:45:46 +02:00
|
|
|
import * as vscode from 'vscode';
|
2019-04-10 13:45:47 +02:00
|
|
|
|
2019-07-04 14:45:46 +02:00
|
|
|
import { Issue } from './issue';
|
2020-08-16 20:26:14 +02:00
|
|
|
import { Config } from './config';
|
|
|
|
import { GiteaConnector } from './giteaConnector';
|
2019-04-09 14:37:58 +02:00
|
|
|
|
2020-08-16 20:26:14 +02:00
|
|
|
export class IssueProvider implements vscode.TreeDataProvider<Issue> {
|
2022-08-08 14:53:53 +02:00
|
|
|
private _onDidChangeTreeData: vscode.EventEmitter<Issue | undefined | null | void> = new vscode.EventEmitter<Issue | undefined | null | void>();
|
2019-07-04 14:45:46 +02:00
|
|
|
|
2022-08-08 14:53:53 +02:00
|
|
|
readonly onDidChangeTreeData: vscode.Event<Issue | undefined | null | void> = this._onDidChangeTreeData.event;
|
2019-07-04 14:45:46 +02:00
|
|
|
|
2020-08-16 20:26:14 +02:00
|
|
|
private state: string;
|
|
|
|
private issueList: Issue[] = [];
|
2019-07-04 14:45:46 +02:00
|
|
|
|
2020-08-16 20:26:14 +02:00
|
|
|
constructor(state: string) {
|
|
|
|
this.state = state;
|
|
|
|
}
|
2020-04-11 10:52:50 +02:00
|
|
|
|
2020-08-16 20:26:14 +02:00
|
|
|
public getTreeItem(element: Issue): vscode.TreeItem | Thenable<vscode.TreeItem> {
|
|
|
|
return element;
|
|
|
|
}
|
2020-04-11 10:52:50 +02:00
|
|
|
|
2020-08-16 20:26:14 +02:00
|
|
|
public async getIssuesAsync() {
|
|
|
|
this.issueList = [];
|
|
|
|
const config = new Config();
|
|
|
|
const giteaConnector = new GiteaConnector(config.token, config.sslVerify);
|
|
|
|
|
|
|
|
const issues = [];
|
|
|
|
let page = 0;
|
|
|
|
while (page < 11) {
|
|
|
|
const issuesOfPage = (await giteaConnector.getIssues(config.repoApiUrl, this.state, page)).data;
|
|
|
|
issues.push(...issuesOfPage);
|
|
|
|
issuesOfPage.forEach((c) => {
|
2020-08-19 08:00:27 +02:00
|
|
|
c.label = `#${c.number} - ${c.title}`;
|
2020-08-16 20:26:14 +02:00
|
|
|
c.issueId = c.number;
|
|
|
|
c.assignee = c.assignee === null ? 'Nobody' : c.assignee;
|
|
|
|
c.creator = c.user.login;
|
|
|
|
});
|
|
|
|
page++;
|
|
|
|
if (issues.length < 10) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.issueList = issues as Issue[];
|
|
|
|
this.issueList.forEach((issue: Issue) => {
|
|
|
|
issue.command = {
|
|
|
|
command: 'giteaIssues.openIssue',
|
|
|
|
title: '',
|
|
|
|
arguments: [issue],
|
|
|
|
};
|
|
|
|
issue.collapsibleState = vscode.TreeItemCollapsibleState.Collapsed;
|
2019-07-04 14:45:46 +02:00
|
|
|
});
|
2019-04-09 14:37:58 +02:00
|
|
|
}
|
2019-07-04 14:45:46 +02:00
|
|
|
|
2020-08-16 20:26:14 +02:00
|
|
|
public async refresh() {
|
|
|
|
await this.getIssuesAsync();
|
|
|
|
this._onDidChangeTreeData.fire();
|
2019-04-09 14:37:58 +02:00
|
|
|
}
|
2019-04-10 13:45:47 +02:00
|
|
|
|
2020-08-16 20:26:14 +02:00
|
|
|
public getChildren(element?: Issue): vscode.ProviderResult<any[]> {
|
|
|
|
return this.createChildNodes(element, this.issueList);
|
2019-04-12 08:09:19 +02:00
|
|
|
}
|
|
|
|
|
2020-08-16 20:26:14 +02:00
|
|
|
private createChildNodes(element: Issue | undefined, issues: Issue[]) {
|
|
|
|
for (const issue of issues) {
|
|
|
|
if (element === issue) {
|
|
|
|
let childItems: vscode.TreeItem[] = [
|
|
|
|
new vscode.TreeItem('Assignee - ' + element.assignee, vscode.TreeItemCollapsibleState.None),
|
|
|
|
new vscode.TreeItem('State - ' + element.state, vscode.TreeItemCollapsibleState.None),
|
|
|
|
new vscode.TreeItem('ID - ' + element.issueId, vscode.TreeItemCollapsibleState.None),
|
|
|
|
new vscode.TreeItem('From - ' + element.creator, vscode.TreeItemCollapsibleState.None),
|
|
|
|
];
|
|
|
|
return Promise.resolve(childItems);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return issues;
|
2019-04-12 08:09:19 +02:00
|
|
|
}
|
2019-07-04 14:45:46 +02:00
|
|
|
}
|
2020-08-16 20:26:14 +02:00
|
|
|
|