From 7378f58665401d9b75a56213565c048e90057d28 Mon Sep 17 00:00:00 2001 From: IJustDev Date: Sat, 21 Mar 2020 20:59:42 +0100 Subject: [PATCH] Fixes #11 Advanced logging of the url if the request fails. Removed SSL option. --- package-lock.json | 2 +- package.json | 21 +++++++-------------- src/Config.ts | 35 +++++++---------------------------- src/issueProvider.ts | 6 ++---- 4 files changed, 17 insertions(+), 47 deletions(-) diff --git a/package-lock.json b/package-lock.json index 70b798f..1f53125 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "gitea-vscode", - "version": "0.0.8", + "version": "1.0.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 4233bcd..235f23d 100644 --- a/package.json +++ b/package.json @@ -71,17 +71,16 @@ "default": "", "description": "The token for the gitea server." }, - "gitea.domain": { + "gitea.instanceURL": { "scope": "resource", "type": "string", "default": "", - "description": "The remote gitea instance's domain." - }, - "gitea.port": { - "scope": "resource", - "type": "number", - "default": 80, - "description": "The remote gitea instance's port." + "examples": [ + "http://example.com:3000", + "https://gitea.com" + ], + "description": "The remote gitea instance's url. Should not end with a slash.", + "pattern": "^(https|http)://" }, "gitea.owner": { "scope": "resource", @@ -94,12 +93,6 @@ "type": "string", "default": "", "description": "The repository name." - }, - "gitea.ssl": { - "scope": "resource", - "type": "boolean", - "default": true, - "description": "If https should be used or not." } } } diff --git a/src/Config.ts b/src/Config.ts index 8bac953..683df3c 100644 --- a/src/Config.ts +++ b/src/Config.ts @@ -2,11 +2,9 @@ import { workspace, window } from 'vscode'; interface ConfigStorage { token: string; - domain: string; - port: number; + instanceURL: string; owner: string; repo: string; - ssl: boolean; } export interface ConfigTypes extends ConfigStorage { @@ -44,20 +42,12 @@ export class Config implements ConfigTypes { this.storage.update('token', value); } - public get domain() { - return this.loadConfigValue('domain', 'string'); + public set instanceUrl(value: string) { + this.storage.update('instanceURL', value); } - public set domain(value) { - this.storage.update('domain', value); - } - - public get port() { - return this.loadConfigValue('port', 'number'); - } - - public set port(value) { - this.storage.update('port', value); + public get instanceURL(): any { + return this.loadConfigValue('instanceURL', 'string'); } public get owner() { @@ -75,19 +65,8 @@ export class Config implements ConfigTypes { public set 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() { - if (this.ssl || this.port === 443) { - 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'; + return this.instanceURL + '/api/v1/repos/' + this.owner + '/' + this.repo + '/issues'; } } diff --git a/src/issueProvider.ts b/src/issueProvider.ts index e249035..b78510b 100644 --- a/src/issueProvider.ts +++ b/src/issueProvider.ts @@ -40,7 +40,6 @@ export class OpenIssuesProvider implements vscode.TreeDataProvider { await axios .get(repoUri + '?page=' + i, { headers: { Authorization: 'token ' + token } }) .then((res) => { - console.log(res.data); if (res.data.length === 0) { stop = true; return; @@ -48,9 +47,8 @@ export class OpenIssuesProvider implements vscode.TreeDataProvider { parseToIssues(res, this.issueList); }) .catch((err) => { - console.log(err); stop = true; - vscode.window.showErrorMessage("Can't fetch issues; HTTP Error!"); + vscode.window.showErrorMessage("An error occoured. Please check your repository url: " + repoUri); return; }); if (stop) { @@ -103,7 +101,7 @@ export class ClosedIssuesProvider implements vscode.TreeDataProvider { }) .catch(() => { stop = true; - vscode.window.showErrorMessage("Can't fetch issues; HTTP Error!"); + vscode.window.showErrorMessage("An error occoured. Please check your repository url: " + repoUri); return; }); if (stop) {