提交 c1134c7d 编写于 作者: F Fatih Acet

Merge branch 'master' into 'master'

upgrade packages, fix node 8.5 / 8.6 bug & format code

Closes #23

See merge request fatihacet/gitlab-vscode-extension!32
此差异已折叠。
......@@ -232,21 +232,21 @@
"webview": "cd src/webview && yarn build --watch"
},
"devDependencies": {
"@types/mocha": "^2.2.42",
"@types/mocha": "^5.2.5",
"@types/node": "^10.12.21",
"eslint": "^4.18.1",
"eslint-config-airbnb-base": "^12.1.0",
"eslint-config-prettier": "^2.9.0",
"eslint-plugin-import": "^2.9.0",
"eslint-plugin-prettier": "^2.6.0",
"prettier": "^1.11.0",
"typescript": "^2.6.1"
"typescript": "^3.3.1",
"vscode": "^1.1.26"
},
"dependencies": {
"@types/node": "^7.0.43",
"execa": "^0.9.0",
"moment": "^2.22.2",
"execa": "^1.0.0",
"moment": "^2.24.0",
"request-promise": "^4.2.2",
"url": "^0.11.0",
"vscode": "^1.1.26"
"url": "^0.11.0"
}
}
......@@ -77,8 +77,10 @@ class DataProvider {
const issues = await gitLabService.fetchMRIssues(this.mr.iid);
if (issues.length) {
issues.forEach((issue) => {
this.children.push(new SidebarTreeItem(`Issue: #${issue.iid} · ${issue.title}`, issue.web_url));
issues.forEach(issue => {
this.children.push(
new SidebarTreeItem(`Issue: #${issue.iid} · ${issue.title}`, issue.web_url),
);
});
} else {
this.children.push(new SidebarTreeItem('No closing issue found.'));
......
......@@ -17,7 +17,7 @@ class DataProvider {
const issues = await gitLabService[this.fetcher]();
if (issues.length) {
issues.forEach((issue) => {
issues.forEach(issue => {
const title = `${this.issuableSign}${issue.iid} · ${issue.title}`;
items.push(new SidebarTreeItem(title, issue.web_url));
......
......@@ -15,34 +15,6 @@ vscode.gitLabWorkflow = {
sidebarDataProviders: [],
};
const registerCommands = () => {
const commands = {
'gl.showIssuesAssignedToMe': openers.showIssues,
'gl.showMergeRequestsAssignedToMe': openers.showMergeRequests,
'gl.setToken': tokenInput.showInput,
'gl.removeToken': tokenInput.removeTokenPicker,
'gl.openActiveFile': openers.openActiveFile,
'gl.openCurrentMergeRequest': openers.openCurrentMergeRequest,
'gl.openCreateNewIssue': openers.openCreateNewIssue,
'gl.openCreateNewMR': openers.openCreateNewMr,
'gl.openProjectPage': openers.openProjectPage,
'gl.openCurrentPipeline': openers.openCurrentPipeline,
'gl.pipelineActions': pipelineActionsPicker.showPicker,
'gl.issueSearch': searchInput.showIssueSearchInput,
'gl.mergeRequestSearch': searchInput.showMergeRequestSearchInput,
'gl.compareCurrentBranch': openers.compareCurrentBranch,
'gl.createSnippet': snippetInput.show,
'gl.validateCIConfig': ciConfigValidator.validate,
'gl.refreshSidebar': sidebar.refresh,
};
Object.keys(commands).forEach(cmd => {
context.subscriptions.push(vscode.commands.registerCommand(cmd, commands[cmd]));
});
registerSidebarTreeDataProviders();
};
const registerSidebarTreeDataProviders = () => {
const assignedIssuesDataProvider = new IssuableDataProvider({
fetcher: 'fetchIssuesAssignedToMe',
......@@ -77,7 +49,7 @@ const registerSidebarTreeDataProviders = () => {
const register = (name, provider) => {
vscode.window.registerTreeDataProvider(name, provider);
vscode.gitLabWorkflow.sidebarDataProviders.push(provider);
}
};
register('issuesAssignedToMe', assignedIssuesDataProvider);
register('issuesCreatedByMe', createdIssuesDataProvider);
......@@ -85,7 +57,35 @@ const registerSidebarTreeDataProviders = () => {
register('mrsCreatedByMe', createdMrsDataProvider);
register('allProjectMrs', allProjectMrsDataProvider);
register('currentBranchInfo', currentBranchDataProvider);
}
};
const registerCommands = () => {
const commands = {
'gl.showIssuesAssignedToMe': openers.showIssues,
'gl.showMergeRequestsAssignedToMe': openers.showMergeRequests,
'gl.setToken': tokenInput.showInput,
'gl.removeToken': tokenInput.removeTokenPicker,
'gl.openActiveFile': openers.openActiveFile,
'gl.openCurrentMergeRequest': openers.openCurrentMergeRequest,
'gl.openCreateNewIssue': openers.openCreateNewIssue,
'gl.openCreateNewMR': openers.openCreateNewMr,
'gl.openProjectPage': openers.openProjectPage,
'gl.openCurrentPipeline': openers.openCurrentPipeline,
'gl.pipelineActions': pipelineActionsPicker.showPicker,
'gl.issueSearch': searchInput.showIssueSearchInput,
'gl.mergeRequestSearch': searchInput.showMergeRequestSearchInput,
'gl.compareCurrentBranch': openers.compareCurrentBranch,
'gl.createSnippet': snippetInput.show,
'gl.validateCIConfig': ciConfigValidator.validate,
'gl.refreshSidebar': sidebar.refresh,
};
Object.keys(commands).forEach(cmd => {
context.subscriptions.push(vscode.commands.registerCommand(cmd, commands[cmd]));
});
registerSidebarTreeDataProviders();
};
const init = () => {
tokenService.init(context);
......
......@@ -56,18 +56,18 @@ async function fetchLastCommitId() {
const getInstancePath = () => {
const pathname = url.parse(currentInstanceUrl()).pathname;
if (pathname != "/") {
if (pathname !== '/') {
// Remove trailing slash if exists
return pathname.replace(/\/$/, "");
} else {
// Do not return extra slash if no extra path in instance url
return "";
return pathname.replace(/\/$/, '');
}
}
// Do not return extra slash if no extra path in instance url
return '';
};
const escapeForRegExp = str => {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
}
};
const parseGitRemote = remote => {
const pathRegExp = escapeForRegExp(getInstancePath());
......
......@@ -2,7 +2,6 @@ const vscode = require('vscode');
const request = require('request-promise');
const fs = require('fs');
const gitService = require('./git_service');
const openers = require('./openers');
const tokenService = require('./token_service');
const statusBar = require('./status_bar');
......@@ -10,7 +9,13 @@ let version = null;
let branchMR = null;
async function fetch(path, method = 'GET', data = null) {
const { instanceUrl, ignoreCertificateErrors, ca, cert, certKey } = vscode.workspace.getConfiguration('gitlab');
const {
instanceUrl,
ignoreCertificateErrors,
ca,
cert,
certKey,
} = vscode.workspace.getConfiguration('gitlab');
const { proxy } = vscode.workspace.getConfiguration('http');
const apiRoot = `${instanceUrl}/api/v4`;
const glToken = tokenService.getToken(instanceUrl);
......@@ -27,6 +32,7 @@ async function fetch(path, method = 'GET', data = null) {
headers: {
'PRIVATE-TOKEN': glToken,
},
ecdhCurve: 'auto',
rejectUnauthorized: !ignoreCertificateErrors,
};
......@@ -128,6 +134,15 @@ async function fetchUser(userName) {
return user;
}
async function fetchVersion() {
try {
const v = await fetch('/version');
version = v.version;
} catch (e) {}
return version;
}
async function fetchIssuables(params = {}) {
let project = null;
let issuables = [];
......@@ -137,7 +152,7 @@ async function fetchIssuables(params = {}) {
type: type || 'merge_requests',
scope: scope || 'created_by_me',
state: state || 'opened',
}
};
try {
project = await fetchCurrentProject();
......@@ -151,12 +166,14 @@ async function fetchIssuables(params = {}) {
if (project) {
// Normalize scope parameter for version < 11 instances.
const [ major ] = version.split('.');
const [major] = version.split('.');
if (parseInt(major, 10) < 11) {
config.scope = config.scope.replace(/_/g, '-');
}
const path = `/projects/${project.id}/${config.type}?scope=${config.scope}&state=${config.state}`;
const path = `/projects/${project.id}/${config.type}?scope=${config.scope}&state=${
config.state
}`;
issuables = await fetch(path);
}
......@@ -348,15 +365,6 @@ async function validateCIConfig(content) {
return response;
}
async function fetchVersion() {
try {
const v = await fetch('/version');
version = v.version;
} catch (e) {}
return version;
}
exports.fetchUser = fetchUser;
exports.fetchIssuesAssignedToMe = fetchIssuesAssignedToMe;
exports.fetchIssuesCreatedByMe = fetchIssuesCreatedByMe;
......
......@@ -2,9 +2,9 @@ const vscode = require('vscode');
const gitService = require('./git_service');
const gitLabService = require('./gitlab_service');
const openUrl = (url) => {
const openUrl = url => {
vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(url));
}
};
/**
* Fetches user and project before opening a link.
......
const vscode = require('vscode');
const refresh = () => {
vscode.gitLabWorkflow.sidebarDataProviders.forEach((provider) => {
vscode.gitLabWorkflow.sidebarDataProviders.forEach(provider => {
provider.refresh();
});
}
};
exports.refresh = refresh;
......@@ -8,7 +8,7 @@ class SidebarTreeItem extends vscode.TreeItem {
this.command = {
command: 'vscode.open',
arguments: [vscode.Uri.parse(url)],
}
};
}
}
}
......
......@@ -83,13 +83,13 @@ async function refreshPipeline() {
const msg = `$(${statuses[status].icon}) GitLab: Pipeline ${statusText}`;
if (showPipelineUpdateNotifications && pipelineStatusBarItem.text != msg && !firstRun) {
if (showPipelineUpdateNotifications && pipelineStatusBarItem.text !== msg && !firstRun) {
const message = `Pipeline ${statusText}.`;
vscode.window
.showInformationMessage(message, { modal: false }, 'View in Gitlab')
.then(selection => {
if (selection == 'View in Gitlab') {
if (selection === 'View in Gitlab') {
openers.openCurrentPipeline();
}
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册