提交 3affb105 编写于 作者: J John Hampton 提交者: Fatih Acet

Add Comment in MR

上级 d35e2d23
# CHANGELOG # CHANGELOG
## v2.2.0 - 2019-11-06
- [Experimental Feature](https://gitlab.com/fatihacet/gitlab-vscode-extension#experimental-features): View Merge Request details and comments in VSCode. Click a Merge Request link from the sidebar and VSCode will open a new tab to show the Merge Request details. You can also directly comment on the Merge Request.
## v2.1.1 - 2019-07-10 ## v2.1.1 - 2019-07-10
### Fixed ### Fixed
......
{ {
"name": "gitlab-workflow", "name": "gitlab-workflow",
"version": "2.1.0", "version": "2.2.0",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
"name": "gitlab-workflow", "name": "gitlab-workflow",
"displayName": "GitLab Workflow", "displayName": "GitLab Workflow",
"description": "GitLab VSCode integration", "description": "GitLab VSCode integration",
"version": "2.1.1", "version": "2.2.0",
"publisher": "fatihacet", "publisher": "fatihacet",
"license": "MIT", "license": "MIT",
"repository": { "repository": {
......
...@@ -180,9 +180,7 @@ async function fetchIssuables(params = {}) { ...@@ -180,9 +180,7 @@ async function fetchIssuables(params = {}) {
config.scope = config.scope.replace(/_/g, '-'); config.scope = config.scope.replace(/_/g, '-');
} }
const path = `/projects/${project.id}/${config.type}?scope=${config.scope}&state=${ const path = `/projects/${project.id}/${config.type}?scope=${config.scope}&state=${config.state}`;
config.state
}`;
issuables = await fetch(path); issuables = await fetch(path);
} }
...@@ -419,15 +417,14 @@ async function renderMarkdown(markdown) { ...@@ -419,15 +417,14 @@ async function renderMarkdown(markdown) {
return rendered.html; return rendered.html;
} }
async function saveNote({ issuable, note }) { async function saveNote({ issuable, note, noteType }) {
let response = {}; let response = {};
try { try {
const projectId = issuable.project_id; const projectId = issuable.project_id;
const issueId = issuable.iid; const { iid } = issuable;
response = await fetch(`/projects/${projectId}/issues/${issueId}/notes`, 'POST', { const { path } = noteType;
id: projectId, response = await fetch(`/projects/${projectId}/${path}/${iid}/notes`, 'POST', {
issue_iid: issueId,
body: note, body: note,
}); });
} catch (e) { } catch (e) {
......
...@@ -10,7 +10,7 @@ class SidebarTreeItem extends vscode.TreeItem { ...@@ -10,7 +10,7 @@ class SidebarTreeItem extends vscode.TreeItem {
let command = 'gl.showRichContent'; let command = 'gl.showRichContent';
let arg = data; let arg = data;
if (data.sha || !enableExperimentalFeatures) { if (!enableExperimentalFeatures) {
command = 'vscode.open'; command = 'vscode.open';
arg = vscode.Uri.parse(data.web_url); arg = vscode.Uri.parse(data.web_url);
} }
......
...@@ -20,12 +20,16 @@ export default { ...@@ -20,12 +20,16 @@ export default {
}, },
}, },
methods: { methods: {
getNoteType() {
return this.issuable.sha ? { type: 'merge_request', path: 'merge_requests' } : { type: 'issue', path: 'issues' };
},
addComment() { addComment() {
const { issuable, note, command } = this; const { issuable, note, command } = this;
this.isSaving = true; this.isSaving = true;
this.isFailed = false; this.isFailed = false;
window.vsCodeApi.postMessage({ command, issuable, note }); const noteType = this.getNoteType();
window.vsCodeApi.postMessage({ command, issuable, note, noteType });
}, },
}, },
mounted() { mounted() {
......
...@@ -20,7 +20,7 @@ const getNonce = () => { ...@@ -20,7 +20,7 @@ const getNonce = () => {
return text; return text;
}; };
const getResources = () => { const getResources = panel => {
const paths = { const paths = {
appScriptUri: 'src/webview/dist/js/app.js', appScriptUri: 'src/webview/dist/js/app.js',
vendorUri: 'src/webview/dist/js/chunk-vendors.js', vendorUri: 'src/webview/dist/js/chunk-vendors.js',
...@@ -31,7 +31,7 @@ const getResources = () => { ...@@ -31,7 +31,7 @@ const getResources = () => {
Object.keys(paths).forEach(key => { Object.keys(paths).forEach(key => {
const uri = vscode.Uri.file(path.join(context.extensionPath, paths[key])); const uri = vscode.Uri.file(path.join(context.extensionPath, paths[key]));
paths[key] = uri.with({ scheme: 'vscode-resource' }); paths[key] = panel.webview.asWebviewUri(uri);
}); });
return paths; return paths;
...@@ -43,8 +43,8 @@ const getIndexPath = () => { ...@@ -43,8 +43,8 @@ const getIndexPath = () => {
return isDev ? 'src/webview/public/dev.html' : 'src/webview/public/index.html'; return isDev ? 'src/webview/public/dev.html' : 'src/webview/public/index.html';
}; };
const replaceResources = () => { const replaceResources = panel => {
const { appScriptUri, vendorUri, styleUri, devScriptUri } = getResources(); const { appScriptUri, vendorUri, styleUri, devScriptUri } = getResources(panel);
return fs return fs
.readFileSync(path.join(context.extensionPath, getIndexPath()), 'UTF-8') .readFileSync(path.join(context.extensionPath, getIndexPath()), 'UTF-8')
...@@ -96,6 +96,7 @@ async function handleCreate(panel, issuable) { ...@@ -96,6 +96,7 @@ async function handleCreate(panel, issuable) {
const response = await gitLabService.saveNote({ const response = await gitLabService.saveNote({
issuable: message.issuable, issuable: message.issuable,
note: message.note, note: message.note,
noteType: message.noteType,
}); });
if (response.status !== false) { if (response.status !== false) {
...@@ -114,7 +115,7 @@ async function handleCreate(panel, issuable) { ...@@ -114,7 +115,7 @@ async function handleCreate(panel, issuable) {
async function create(issuable) { async function create(issuable) {
const panel = createPanel(issuable); const panel = createPanel(issuable);
const html = replaceResources(); const html = replaceResources(panel);
panel.webview.html = html; panel.webview.html = html;
panel.onDidChangeViewState(() => { panel.onDidChangeViewState(() => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册