提交 c33cd33d 编写于 作者: A alpcanaydin

Project reformatted with prettier except package-lock.json.

上级 f0dd4808
package-lock.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the extensions.json format
"recommendations": [
"dbaeumer.vscode-eslint"
]
}
\ No newline at end of file
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the extensions.json format
"recommendations": ["dbaeumer.vscode-eslint"]
}
// A launch configuration that launches the extension inside a new window
{
"version": "0.1.0",
"configurations": [
{
"name": "Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
"stopOnEntry": false
},
{
"name": "Extension Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/test" ],
"stopOnEntry": false
}
]
}
\ No newline at end of file
"version": "0.1.0",
"configurations": [
{
"name": "Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}"],
"stopOnEntry": false
},
{
"name": "Extension Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceRoot}",
"--extensionTestsPath=${workspaceRoot}/test"
],
"stopOnEntry": false
}
]
}
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"lib": [
"es6"
]
},
"exclude": [
"node_modules"
]
}
\ No newline at end of file
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"lib": ["es6"]
},
"exclude": ["node_modules"]
}
......@@ -11,19 +11,9 @@
"engines": {
"vscode": "^1.19.0"
},
"categories": [
"Other"
],
"keywords": [
"git",
"gitlab",
"merge request",
"pipeline",
"ci cd"
],
"activationEvents": [
"*"
],
"categories": ["Other"],
"keywords": ["git", "gitlab", "merge request", "pipeline", "ci cd"],
"activationEvents": ["*"],
"bugs": {
"url": "https://gitlab.com/fatihacet/gitlab-vscode-extension/issues",
"email": "acetfatih@gmail.com"
......@@ -121,6 +111,7 @@
"postinstall": "node ./node_modules/vscode/bin/install",
"test": "node ./node_modules/vscode/bin/test",
"eslint": "eslint --max-warnings 0 --ext .js .",
"format": "prettier --write '**/*.{js,json}'",
"publish": "vsce publish"
},
"devDependencies": {
......
......@@ -11,7 +11,7 @@ const ciConfigValidator = require('./ci_config_validator');
let context = null;
const activate = (ctx) => {
const activate = ctx => {
context = ctx;
registerCommands();
init();
......@@ -35,12 +35,10 @@ const registerCommands = () => {
'gl.compareCurrentBranch': openers.compareCurrentBranch,
'gl.createSnippet': snippetInput.show,
'gl.validateCIConfig': ciConfigValidator.validate,
}
};
Object.keys(commands).forEach((cmd) => {
context.subscriptions.push(
vscode.commands.registerCommand(cmd, commands[cmd])
);
Object.keys(commands).forEach(cmd => {
context.subscriptions.push(vscode.commands.registerCommand(cmd, commands[cmd]));
});
};
......@@ -53,31 +51,31 @@ const init = () => {
} else {
askForToken();
}
}
};
const askForToken = () => {
const gs = context.globalState;
if (!gs.get('glToken') && !gs.get('askedForToken')) {
const message = 'GitLab Workflow: Please set GitLab Personal Access Token to setup this extension.';
const message =
'GitLab Workflow: Please set GitLab Personal Access Token to setup this extension.';
const setButton = { title: 'Set Token Now', action: 'set' };
const readMore = { title: 'Read More', action: 'more' };
gs.update('askedForToken', true);
vscode.window.showInformationMessage(message, readMore, setButton)
.then((item) => {
if (item) {
const { action } = item;
vscode.window.showInformationMessage(message, readMore, setButton).then(item => {
if (item) {
const { action } = item;
if (action === 'set') {
vscode.commands.executeCommand('gl.setToken');
} else {
opn('https://gitlab.com/fatihacet/gitlab-vscode-extension#setup');
}
if (action === 'set') {
vscode.commands.executeCommand('gl.setToken');
} else {
opn('https://gitlab.com/fatihacet/gitlab-vscode-extension#setup');
}
});
}
});
}
}
};
const deactivate = () => {
statusBar.dispose();
......
......@@ -4,7 +4,7 @@ const url = require('url');
const getWorkspaceRootPath = () => {
return vscode.workspace.workspaceFolders[0].uri.fsPath;
}
};
async function fetch(cmd) {
const [git, ...args] = cmd.split(' ');
......@@ -26,7 +26,7 @@ async function fetchBranchName() {
*
* Fixes #1 where local branch name is renamed and doesn't exists on remote but
* local branch still tracks another branch on remote.
*/
*/
async function fetchTrackingBranchName() {
const branchName = await fetchBranchName();
......@@ -38,7 +38,9 @@ async function fetchTrackingBranchName() {
return ref.replace('refs/heads/', '');
}
} catch (e) {
console.log(`Couldn't find tracking branch. Extension will fallback to branch name ${branchName}`);
console.log(
`Couldn't find tracking branch. Extension will fallback to branch name ${branchName}`,
);
}
return branchName;
......@@ -57,7 +59,7 @@ async function fetchGitRemote() {
const branchName = await fetchBranchName();
const remoteName = await fetch(`git config --get branch.${branchName}.remote`);
url = await fetch(`git ls-remote --get-url ${remoteName}`);
} catch(e) {
} catch (e) {
try {
url = await fetch('git ls-remote --get-url');
} catch (e) {
......@@ -76,9 +78,11 @@ async function fetchGitRemote() {
return null;
}
const parseGitRemote = (remote) => {
const parseGitRemote = remote => {
if (remote.startsWith('git@') || remote.startsWith('git://')) {
const match = new RegExp('^git(?:@|://)([^:/]+)(?::|:/|/)(.+)/(.+?)(?:.git)?$', 'i').exec(remote);
const match = new RegExp('^git(?:@|://)([^:/]+)(?::|:/|/)(.+)/(.+?)(?:.git)?$', 'i').exec(
remote,
);
if (!match) {
return null;
......@@ -99,7 +103,7 @@ const parseGitRemote = (remote) => {
return [protocol, hostname, ...match.slice(1, 3)];
}
}
};
exports.fetchBranchName = fetchBranchName;
exports.fetchTrackingBranchName = fetchTrackingBranchName;
......
......@@ -12,7 +12,9 @@ async function fetch(path, method = 'GET', data = null) {
const apiRoot = `${instanceUrl}/api/v4`;
if (!glToken) {
return vscode.window.showInformationMessage('GitLab Workflow: Cannot make request. No token found.');
return vscode.window.showInformationMessage(
'GitLab Workflow: Cannot make request. No token found.',
);
}
const config = {
......@@ -40,11 +42,11 @@ async function fetch(path, method = 'GET', data = null) {
async function fetchUser(userName) {
try {
const path = userName ? `/user?search=${userName}`: '/user';
const path = userName ? `/user?search=${userName}` : '/user';
return await fetch(path);
} catch (e) {
let message = 'GitLab Workflow: GitLab user not found.'
let message = 'GitLab Workflow: GitLab user not found.';
if (!userName) {
message += ' Check your Personal Access Token.';
......@@ -87,7 +89,7 @@ async function fetchCurrentProject() {
if (remote) {
const { namespace, project } = remote;
const projectData = await fetch(`/projects/${namespace.replace(/\//g, "%2F")}%2F${project}`);
const projectData = await fetch(`/projects/${namespace.replace(/\//g, '%2F')}%2F${project}`);
return projectData || null;
}
......@@ -111,21 +113,25 @@ async function fetchOpenMergeRequestForCurrentBranch() {
// Recursive fetcher method to find the branch MR in MR list.
async function fetcher() {
const mrs = await fetch(`/projects/${project.id}/merge_requests?state=opened&per_page=100&page=${page}`);
const mrs = await fetch(
`/projects/${project.id}/merge_requests?state=opened&per_page=100&page=${page}`,
);
const [mr] = mrs.filter((mr) => {
const [mr] = mrs.filter(mr => {
return mr.source_branch === branchName;
});
if (mr) {
if (page > 1) { // Cache only if we need to do pagination.
if (page > 1) {
// Cache only if we need to do pagination.
branchMR = mr;
}
return mr;
}
if (page <= 5 && mrs.length === 100) { // Retry max 5 times.
if (page <= 5 && mrs.length === 100) {
// Retry max 5 times.
page = page + 1;
return await fetcher();
}
......@@ -180,7 +186,7 @@ async function fetchMRIssues(mrId) {
}
return issues;
};
}
async function createSnippet(data) {
let snippet;
......@@ -192,7 +198,7 @@ async function createSnippet(data) {
}
return snippet;
};
}
async function validateCIConfig(content) {
let response = null;
......@@ -210,9 +216,9 @@ async function validateCIConfig(content) {
* @private
* @param {string} token GL PAT
*/
const _setGLToken = (token) => {
const _setGLToken = token => {
glToken = token;
}
};
exports.fetchUser = fetchUser;
exports.fetchMyOpenMergeRequests = fetchMyOpenMergeRequests;
......
......@@ -25,12 +25,16 @@ async function openLink(link) {
if (project) {
opn(link.replace('$userId', user.id).replace('$projectUrl', project.web_url));
} else {
vscode.window.showInformationMessage('GitLab Workflow: Failed to open file on web. No GitLab project.');
vscode.window.showInformationMessage(
'GitLab Workflow: Failed to open file on web. No GitLab project.',
);
}
} else {
vscode.window.showInformationMessage('GitLab Workflow: GitLab user not found. Check your Personal Access Token.');
vscode.window.showInformationMessage(
'GitLab Workflow: GitLab user not found. Check your Personal Access Token.',
);
}
};
}
async function showIssues() {
openLink('$projectUrl/issues?assignee_id=$userId');
......@@ -38,7 +42,7 @@ async function showIssues() {
async function showMergeRequests() {
openLink('$projectUrl/merge_requests?assignee_id=$userId');
};
}
async function openActiveFile() {
const editor = vscode.window.activeTextEditor;
......@@ -64,7 +68,9 @@ async function openActiveFile() {
opn(`${fileUrl}${anchor}`);
} else {
vscode.window.showInformationMessage('GitLab Workflow: Failed to open file on web. No GitLab project.');
vscode.window.showInformationMessage(
'GitLab Workflow: Failed to open file on web. No GitLab project.',
);
}
} else {
vscode.window.showInformationMessage('GitLab Workflow: No open file.');
......@@ -81,7 +87,7 @@ async function openCurrentMergeRequest() {
async function openCreateNewIssue() {
openLink('$projectUrl/issues/new');
};
}
async function openCreateNewMr() {
const project = await gitLabService.fetchCurrentProject();
......@@ -91,9 +97,11 @@ async function openCreateNewMr() {
opn(`${project.web_url}/merge_requests/new?merge_request%5Bsource_branch%5D=${branchName}`);
} else {
vscode.window.showInformationMessage('GitLab Workflow: Failed to open file on web. No GitLab project.');
vscode.window.showInformationMessage(
'GitLab Workflow: Failed to open file on web. No GitLab project.',
);
}
};
}
async function openProjectPage() {
openLink('$projectUrl');
......@@ -118,8 +126,7 @@ async function compareCurrentBranch() {
try {
project = await gitLabService.fetchCurrentProject();
lastCommitId = await gitService.fetchLastCommitId();
}
catch(e) {
} catch (e) {
console.log('Failed to run compareCurrentBranch command', e);
}
......
......@@ -20,7 +20,7 @@ async function showPicker() {
label: 'Cancel last pipeline',
action: 'cancel',
},
]
];
const selected = await vscode.window.showQuickPick(items);
......
......@@ -28,16 +28,17 @@ async function showSearchInputFor(noteableType) {
const parseQuery = (query, noteableType) => {
const params = {};
const tokens = query.replace(/: /g, ':') // Normalize spaces after tokens.
const tokens = query
.replace(/: /g, ':') // Normalize spaces after tokens.
.replace(/\s[a-z]*:/gi, t => `\n${t}`) // Get tokens and add new line.
.split('\n') // Create array from tokens.
.map(t => t.trim().split(':')) // Return new array with token and value arrays.
.map(t => t.trim().split(':')); // Return new array with token and value arrays.
// If there is no token it's a basic text search.
if (tokens.length === 1 && tokens[0][1] === undefined) {
params.search = tokens[0][0];
} else {
tokens.forEach((t) => {
tokens.forEach(t => {
const [token, value] = t;
switch (token) {
......@@ -86,7 +87,8 @@ const parseQuery = (query, noteableType) => {
if (value === 'me') {
params.scope = 'assigned-to-me';
} else {
const key = noteableType === 'merge_requests' ? 'assignee_username' : 'assignee_username[]';
const key =
noteableType === 'merge_requests' ? 'assignee_username' : 'assignee_username[]';
params[key] = value;
}
break;
......@@ -100,12 +102,12 @@ const parseQuery = (query, noteableType) => {
}
// URL encode keys and values and return a new array to build actual query string.
const queryParams = Object.keys(params).map(k =>
params[k] ? `${encodeURIComponent(k)}=${encodeURIComponent(params[k])}` : ''
const queryParams = Object.keys(params).map(
k => (params[k] ? `${encodeURIComponent(k)}=${encodeURIComponent(params[k])}` : ''),
);
return queryParams.length ? `?${queryParams.join('&')}` : '';
}
};
exports.showIssueSearchInput = showIssueSearchInput;
exports.showMergeRequestSearchInput = showMergeRequestSearchInput;
......@@ -25,8 +25,8 @@ const contextOptions = [
{
label: 'Snippet from selection',
type: 'selection',
}
]
},
];
async function createSnippet(project, editor, visibility, context) {
let content = '';
......
......@@ -21,11 +21,11 @@ const createStatusBarItem = (text, command) => {
}
return statusBarItem;
}
};
const commandRegisterHelper = (cmdName, callback) => {
vscode.commands.registerCommand(cmdName, callback);
}
};
async function refreshPipelines() {
let project = null;
......@@ -37,7 +37,7 @@ async function refreshPipelines() {
failed: { icon: 'x' },
canceled: { icon: 'circle-slash' },
skipped: { icon: 'diff-renamed' },
}
};
try {
project = await gitLabService.fetchCurrentProject();
......@@ -51,7 +51,8 @@ async function refreshPipelines() {
if (pipeline) {
const { status } = pipeline;
pipelineStatusBarItem.text = `$(${statuses[status].icon}) GitLab: Pipeline ${statuses[status].text || status}.`;
pipelineStatusBarItem.text = `$(${statuses[status].icon}) GitLab: Pipeline ${statuses[status]
.text || status}.`;
pipelineStatusBarItem.show();
} else {
pipelineStatusBarItem.text = 'GitLab: No pipeline.';
......@@ -59,11 +60,16 @@ async function refreshPipelines() {
}
const initPipelineStatus = () => {
pipelineStatusBarItem = createStatusBarItem('$(info) GitLab: Fetching pipeline...', 'gl.pipelineActions');
setInterval(() => { refreshPipelines() }, 30000);
pipelineStatusBarItem = createStatusBarItem(
'$(info) GitLab: Fetching pipeline...',
'gl.pipelineActions',
);
setInterval(() => {
refreshPipelines();
}, 30000);
refreshPipelines();
}
};
const initMrStatus = () => {
const cmdName = `gl.mrOpener${Date.now()}`;
......@@ -76,10 +82,12 @@ const initMrStatus = () => {
});
mrStatusBarItem = createStatusBarItem('$(info) GitLab: Finding MR...', cmdName);
setInterval(() => { fetchBranchMr() }, 60000);
setInterval(() => {
fetchBranchMr();
}, 60000);
fetchBranchMr();
}
};
async function fetchBranchMr() {
let project = null;
......@@ -129,9 +137,9 @@ const initMrIssueStatus = () => {
});
mrIssueStatusBarItem = createStatusBarItem('$(info) GitLab: Fetching closing issue...', cmdName);
}
};
const init = (ctx) => {
const init = ctx => {
context = ctx;
initPipelineStatus();
......@@ -139,7 +147,7 @@ const init = (ctx) => {
if (showIssueLinkOnStatusBar) {
initMrIssueStatus();
}
}
};
const dispose = () => {
mrStatusBarItem.dispose();
......@@ -147,7 +155,7 @@ const dispose = () => {
if (showIssueLinkOnStatusBar) {
mrIssueStatusBarItem.dispose();
}
}
};
exports.init = init;
exports.dispose = dispose;
......
......@@ -14,7 +14,7 @@ async function showInput(context) {
}
}
const removeToken = (context) => {
const removeToken = context => {
context.globalState.update('glToken', null);
extension.deactivate();
};
......
......@@ -14,11 +14,10 @@ const vscode = require('vscode');
const myExtension = require('../extension');
// Defines a Mocha test suite to group tests of similar kind together
suite("Extension Tests", function() {
// Defines a Mocha unit test
test("Something 1", function() {
assert.equal(-1, [1, 2, 3].indexOf(5));
assert.equal(-1, [1, 2, 3].indexOf(0));
});
});
\ No newline at end of file
suite('Extension Tests', function() {
// Defines a Mocha unit test
test('Something 1', function() {
assert.equal(-1, [1, 2, 3].indexOf(5));
assert.equal(-1, [1, 2, 3].indexOf(0));
});
});
......@@ -15,8 +15,8 @@ const testRunner = require('vscode/lib/testrunner');
// You can directly control Mocha options by uncommenting the following lines
// See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options for more info
testRunner.configure({
ui: 'tdd', // the TDD UI is being used in extension.test.js (suite, test, etc.)
useColors: true // colored output from test results
ui: 'tdd', // the TDD UI is being used in extension.test.js (suite, test, etc.)
useColors: true, // colored output from test results
});
module.exports = testRunner;
\ No newline at end of file
module.exports = testRunner;
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册