Merge pull request #12 from IJustDev/11-HTTP-error

Fixes #11
This commit is contained in:
IJustDev 2020-03-22 00:28:18 +01:00 committed by GitHub
commit b44f968747
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 47 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "gitea-vscode", "name": "gitea-vscode",
"version": "0.0.8", "version": "1.0.1",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -71,17 +71,16 @@
"default": "", "default": "",
"description": "The token for the gitea server." "description": "The token for the gitea server."
}, },
"gitea.domain": { "gitea.instanceURL": {
"scope": "resource", "scope": "resource",
"type": "string", "type": "string",
"default": "", "default": "",
"description": "The remote gitea instance's domain." "examples": [
}, "http://example.com:3000",
"gitea.port": { "https://gitea.com"
"scope": "resource", ],
"type": "number", "description": "The remote gitea instance's url. Should not end with a slash.",
"default": 80, "pattern": "^(https|http)://"
"description": "The remote gitea instance's port."
}, },
"gitea.owner": { "gitea.owner": {
"scope": "resource", "scope": "resource",
@ -94,12 +93,6 @@
"type": "string", "type": "string",
"default": "", "default": "",
"description": "The repository name." "description": "The repository name."
},
"gitea.ssl": {
"scope": "resource",
"type": "boolean",
"default": true,
"description": "If https should be used or not."
} }
} }
} }

View File

@ -2,11 +2,9 @@ import { workspace, window } from 'vscode';
interface ConfigStorage { interface ConfigStorage {
token: string; token: string;
domain: string; instanceURL: string;
port: number;
owner: string; owner: string;
repo: string; repo: string;
ssl: boolean;
} }
export interface ConfigTypes extends ConfigStorage { export interface ConfigTypes extends ConfigStorage {
@ -44,20 +42,12 @@ export class Config implements ConfigTypes {
this.storage.update('token', value); this.storage.update('token', value);
} }
public get domain() { public set instanceUrl(value: string) {
return this.loadConfigValue('domain', 'string'); this.storage.update('instanceURL', value);
} }
public set domain(value) { public get instanceURL(): any {
this.storage.update('domain', value); return this.loadConfigValue('instanceURL', 'string');
}
public get port() {
return this.loadConfigValue('port', 'number');
}
public set port(value) {
this.storage.update('port', value);
} }
public get owner() { public get owner() {
@ -76,18 +66,7 @@ export class Config implements ConfigTypes {
this.storage.update('repo', value); this.storage.update('repo', value);
} }
public get ssl() {
return this.loadConfigValue('ssl', 'boolean', true);
}
public set ssl(value) {
this.storage.update('ssl', value);
}
public get repoApiUrl() { public get repoApiUrl() {
if (this.ssl || this.port === 443) { return this.instanceURL + '/api/v1/repos/' + this.owner + '/' + this.repo + '/issues';
return 'https://' + this.domain + '/api/v1/repos/' + this.owner + '/' + this.repo + '/issues';
}
return 'http://' + this.domain + ':' + this.port + '/api/v1/repos/' + this.owner + '/' + this.repo + '/issues';
} }
} }

View File

@ -40,7 +40,6 @@ export class OpenIssuesProvider implements vscode.TreeDataProvider<Issue> {
await axios await axios
.get(repoUri + '?page=' + i, { headers: { Authorization: 'token ' + token } }) .get(repoUri + '?page=' + i, { headers: { Authorization: 'token ' + token } })
.then((res) => { .then((res) => {
console.log(res.data);
if (res.data.length === 0) { if (res.data.length === 0) {
stop = true; stop = true;
return; return;
@ -48,9 +47,8 @@ export class OpenIssuesProvider implements vscode.TreeDataProvider<Issue> {
parseToIssues(res, this.issueList); parseToIssues(res, this.issueList);
}) })
.catch((err) => { .catch((err) => {
console.log(err);
stop = true; stop = true;
vscode.window.showErrorMessage("Can't fetch issues; HTTP Error!"); vscode.window.showErrorMessage("An error occoured. Please check your repository url: " + repoUri);
return; return;
}); });
if (stop) { if (stop) {
@ -103,7 +101,7 @@ export class ClosedIssuesProvider implements vscode.TreeDataProvider<Issue> {
}) })
.catch(() => { .catch(() => {
stop = true; stop = true;
vscode.window.showErrorMessage("Can't fetch issues; HTTP Error!"); vscode.window.showErrorMessage("An error occoured. Please check your repository url: " + repoUri);
return; return;
}); });
if (stop) { if (stop) {