From 3affb10531f9ef0a14496913aa99d8cb7a99a221 Mon Sep 17 00:00:00 2001 From: John Hampton Date: Mon, 20 Jan 2020 18:58:14 +0000 Subject: [PATCH] Add Comment in MR --- CHANGELOG.md | 4 ++++ package-lock.json | 2 +- package.json | 2 +- src/gitlab_service.js | 13 +++++-------- src/sidebar_tree_item.js | 2 +- src/webview/src/components/CommentForm.vue | 6 +++++- src/webview_controller.js | 11 ++++++----- 7 files changed, 23 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f54dc6b..1918469 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # 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 ### Fixed diff --git a/package-lock.json b/package-lock.json index 0d38cce..f177b59 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "gitlab-workflow", - "version": "2.1.0", + "version": "2.2.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 748e723..68468f7 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "gitlab-workflow", "displayName": "GitLab Workflow", "description": "GitLab VSCode integration", - "version": "2.1.1", + "version": "2.2.0", "publisher": "fatihacet", "license": "MIT", "repository": { diff --git a/src/gitlab_service.js b/src/gitlab_service.js index 8d41c0c..273cc4e 100644 --- a/src/gitlab_service.js +++ b/src/gitlab_service.js @@ -180,9 +180,7 @@ async function fetchIssuables(params = {}) { 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); } @@ -419,15 +417,14 @@ async function renderMarkdown(markdown) { return rendered.html; } -async function saveNote({ issuable, note }) { +async function saveNote({ issuable, note, noteType }) { let response = {}; try { const projectId = issuable.project_id; - const issueId = issuable.iid; - response = await fetch(`/projects/${projectId}/issues/${issueId}/notes`, 'POST', { - id: projectId, - issue_iid: issueId, + const { iid } = issuable; + const { path } = noteType; + response = await fetch(`/projects/${projectId}/${path}/${iid}/notes`, 'POST', { body: note, }); } catch (e) { diff --git a/src/sidebar_tree_item.js b/src/sidebar_tree_item.js index 71a253d..8f04ae3 100644 --- a/src/sidebar_tree_item.js +++ b/src/sidebar_tree_item.js @@ -10,7 +10,7 @@ class SidebarTreeItem extends vscode.TreeItem { let command = 'gl.showRichContent'; let arg = data; - if (data.sha || !enableExperimentalFeatures) { + if (!enableExperimentalFeatures) { command = 'vscode.open'; arg = vscode.Uri.parse(data.web_url); } diff --git a/src/webview/src/components/CommentForm.vue b/src/webview/src/components/CommentForm.vue index 281f479..d61f11a 100644 --- a/src/webview/src/components/CommentForm.vue +++ b/src/webview/src/components/CommentForm.vue @@ -20,12 +20,16 @@ export default { }, }, methods: { + getNoteType() { + return this.issuable.sha ? { type: 'merge_request', path: 'merge_requests' } : { type: 'issue', path: 'issues' }; + }, addComment() { const { issuable, note, command } = this; this.isSaving = true; this.isFailed = false; - window.vsCodeApi.postMessage({ command, issuable, note }); + const noteType = this.getNoteType(); + window.vsCodeApi.postMessage({ command, issuable, note, noteType }); }, }, mounted() { diff --git a/src/webview_controller.js b/src/webview_controller.js index 09fc33c..95b76cd 100644 --- a/src/webview_controller.js +++ b/src/webview_controller.js @@ -20,7 +20,7 @@ const getNonce = () => { return text; }; -const getResources = () => { +const getResources = panel => { const paths = { appScriptUri: 'src/webview/dist/js/app.js', vendorUri: 'src/webview/dist/js/chunk-vendors.js', @@ -31,7 +31,7 @@ const getResources = () => { Object.keys(paths).forEach(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; @@ -43,8 +43,8 @@ const getIndexPath = () => { return isDev ? 'src/webview/public/dev.html' : 'src/webview/public/index.html'; }; -const replaceResources = () => { - const { appScriptUri, vendorUri, styleUri, devScriptUri } = getResources(); +const replaceResources = panel => { + const { appScriptUri, vendorUri, styleUri, devScriptUri } = getResources(panel); return fs .readFileSync(path.join(context.extensionPath, getIndexPath()), 'UTF-8') @@ -96,6 +96,7 @@ async function handleCreate(panel, issuable) { const response = await gitLabService.saveNote({ issuable: message.issuable, note: message.note, + noteType: message.noteType, }); if (response.status !== false) { @@ -114,7 +115,7 @@ async function handleCreate(panel, issuable) { async function create(issuable) { const panel = createPanel(issuable); - const html = replaceResources(); + const html = replaceResources(panel); panel.webview.html = html; panel.onDidChangeViewState(() => { -- GitLab