未验证 提交 20082d4f 编写于 作者: F Fatih Acet

Implement CI config validation.

Closes #22
上级 e240d490
......@@ -3,6 +3,7 @@
## [0.5.0] - 2018-02-25
### Added
- [#25](https://gitlab.com/fatihacet/gitlab-vscode-extension/issues/25) Create snippet from selection or entire file.
- [#22](https://gitlab.com/fatihacet/gitlab-vscode-extension/issues/22) Add support for .gitlab-ci.yml lint-ing
- [#20](https://gitlab.com/fatihacet/gitlab-vscode-extension/issues/20) Added Read more and Set token now buttons to token ask notification.
......
......@@ -15,6 +15,7 @@ This extension integrates GitLab to VSCode by adding GitLab specific options to
- Create public, internal or private snippet from entire file or selection. [Read more](#create-snippet).
- Compare your branch with master and view changes on GitLab. [Read more](#compare-with-master).
- View active file on GitLab with highlighting active line number and selected text block. [Read more](#open-active-file).
- Validate GitLab CI configuration file `.gitlab-ci.yml`. [Read more](#validate-gitlab-ci-configuration).
- Open MR of current branch on GitLab.
- Open issues assigned to you on GitLab.
- Open MRs assigned to you on GitLab.
......@@ -133,6 +134,12 @@ This command allows you to see active file on GitLab. Extension sends active lin
![_open_active_file.gif](https://gitlab.com/fatihacet/gitlab-vscode-extension/raw/master/src/assets/_open_active_file.gif)
### Validate GitLab CI Configuration
Using this command, you can quickly validate GitLab CI configuration.
![_validate-ci-config.gif](https://gitlab.com/fatihacet/gitlab-vscode-extension/raw/master/src/assets/_validate-ci-config.gif)
-----
......@@ -147,21 +154,22 @@ If you are using GitLab on a custom domain, you should add this to your user set
## What's next?
- Open last commit on GitLab.
- GitLab CI config file `(.gitlab-ci.yml)` validation
- MR actions picker which will allow you to
- Go to specific MR tab, Discussions, Commits, Pipelines, Changes.
- Assign MR to user.
- View last commit.
- [moonshot] GitLab Dashboard tab where you can see your issues, MRs, Todos all in one place in VSCode.
- [moonshot] MR diff discussions on VSCode gutter with user avatars like we have in GitLab Changes tab.
- `[Shipped in v0.2.2]` Pipeline link to pipeline status bar item.
- `[Shipped in v0.2.2]` View last pipeline on GitLab.
- `[Shipped in v0.3.0]` Pipeline actions menu to quickly view, retry, cancel or create a new pipeline.
- `[Shipped in v0.4.0]` Issue and MR search.
- `[Shipped in v0.4.0]` Detailed issue and MR search.
- **[moonshot]** GitLab Dashboard tab where you can see your issues, MRs, Todos all in one place in VSCode.
- **[moonshot]** MR diff discussions on VSCode gutter with user avatars like we have in GitLab Changes tab.
- **Already Shipped**
- `[v0.2.2]` Pipeline link to pipeline status bar item.
- `[v0.2.2]` View last pipeline on GitLab.
- `[v0.3.0]` Pipeline actions menu to quickly view, retry, cancel or create a new pipeline.
- `[v0.4.0]` Issue and MR search.
- `[v0.4.0]` Detailed issue and MR search.
- `title:MR discussions refactor labels:frontend, discussions assignee:fatihacet`
- `[Shipped in v0.4.0]` Compare your changes with master on GitLab.
- `[Shipped in v0.5.0]`Create snippet from selected text
- `[v0.4.0]` Compare your changes with master on GitLab.
- `[v0.5.0]` Create snippet from selected text
- `[v0.5.0]` GitLab CI config file `(.gitlab-ci.yml)` validation
## Contribution
......
......@@ -95,6 +95,10 @@
{
"command": "gl.createSnippet",
"title": "GitLab: Create snippet"
},
{
"command": "gl.validateCIConfig",
"title": "GitLab: Validate GitLab CI config"
}
],
"configuration": {
......
const vscode = require('vscode');
const gitLabService = require('./gitlab_service');
const { showInformationMessage, showErrorMessage } = vscode.window;
async function validate() {
const editor = vscode.window.activeTextEditor;
if (!editor) {
return showInformationMessage('GitLab Workflow: No open file.');
}
const content = editor.document.getText();
const response = await gitLabService.validateCIConfig(content);
if (!response) {
return showInformationMessage('GitLab Workflow: Failed to validate CI configuration.');
}
const { status, errors, error } = response;
if (status === 'valid') {
showInformationMessage('GitLab Workflow: Your CI configuration is valid.');
} else if (status === 'invalid') {
if (errors[0]) {
showErrorMessage(errors[0]);
}
showErrorMessage('GitLab Workflow: Invalid CI configuration.');
} else if (error) {
showErrorMessage(`GitLab Workflow: Failed to validate CI configuration. Reason: ${error}`);
}
}
exports.validate = validate;
......@@ -7,6 +7,7 @@ const gitLabService = require('./gitlab_service');
const pipelineActionsPicker = require('./pipeline_actions_picker');
const searchInput = require('./search_input');
const snippetInput = require('./snippet_input');
const ciConfigValidator = require('./ci_config_validator');
let context = null;
......@@ -33,6 +34,7 @@ const registerCommands = () => {
'gl.mergeRequestSearch': searchInput.showMergeRequestSearchInput,
'gl.compareCurrentBranch': openers.compareCurrentBranch,
'gl.createSnippet': snippetInput.show,
'gl.validateCIConfig': ciConfigValidator.validate,
}
Object.keys(commands).forEach((cmd) => {
......
......@@ -194,6 +194,18 @@ async function createSnippet(data) {
return snippet;
};
async function validateCIConfig(content) {
let response = null;
try {
response = await fetch('/ci/lint', 'POST', { content });
} catch (e) {
vscode.window.showInformationMessage('GitLab Workflow: Failed to validate CI configuration.');
}
return response;
}
/**
* @private
* @param {string} token GL PAT
......@@ -210,4 +222,5 @@ exports.fetchCurrentProject = fetchCurrentProject;
exports.handlePipelineAction = handlePipelineAction;
exports.fetchMRIssues = fetchMRIssues;
exports.createSnippet = createSnippet;
exports.validateCIConfig = validateCIConfig;
exports._setGLToken = _setGLToken;
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册