Commit db883b81 authored by Phil Hughes's avatar Phil Hughes

Merge branch 'vrt-mr-update' into 'master'

Update Visual Review Toolbar to post to MRs

See merge request gitlab-org/gitlab-ee!13254
parents 5d49646c c8cfa325
...@@ -49,7 +49,7 @@ export default { ...@@ -49,7 +49,7 @@ export default {
required: false, required: false,
default: () => ({ default: () => ({
sourceProjectId: '', sourceProjectId: '',
issueId: '', mergeRequestId: '',
appUrl: '', appUrl: '',
}), }),
}, },
......
...@@ -48,7 +48,7 @@ export default { ...@@ -48,7 +48,7 @@ export default {
visualReviewAppMeta() { visualReviewAppMeta() {
return { return {
appUrl: this.mr.appUrl, appUrl: this.mr.appUrl,
issueId: this.mr.iid, mergeRequestId: this.mr.iid,
sourceProjectId: this.mr.sourceProjectId, sourceProjectId: this.mr.sourceProjectId,
}; };
}, },
......
...@@ -37,7 +37,7 @@ export default { ...@@ -37,7 +37,7 @@ export default {
return { return {
script: `<script defer script: `<script defer
data-project-id='${this.appMetadata.sourceProjectId}' data-project-id='${this.appMetadata.sourceProjectId}'
data-discussion-id='${this.appMetadata.issueId}' data-merge-request-id='${this.appMetadata.mergeRequestId}'
data-mr-url='${this.appMetadata.appUrl}' data-mr-url='${this.appMetadata.appUrl}'
id='review-app-toolbar-script' id='review-app-toolbar-script'
src='https://gitlab.com/public/visual-review-toolbar.js' src='https://gitlab.com/public/visual-review-toolbar.js'
......
...@@ -13,7 +13,7 @@ describe('Visual Review App Link', () => { ...@@ -13,7 +13,7 @@ describe('Visual Review App Link', () => {
propsData = { propsData = {
cssClass: 'button cool-button best-button', cssClass: 'button cool-button best-button',
appMetadata: { appMetadata: {
issueId: 1, mergeRequestId: 1,
sourceProjectId: 20, sourceProjectId: 20,
appUrl: 'http://gitlab.example.com', appUrl: 'http://gitlab.example.com',
}, },
...@@ -58,9 +58,9 @@ describe('Visual Review App Link', () => { ...@@ -58,9 +58,9 @@ describe('Visual Review App Link', () => {
); );
}); });
it('with expected discussion Id', () => { it('with expected merge request id', () => {
expect(wrapper.find(GlModal).text()).toEqual( expect(wrapper.find(GlModal).text()).toEqual(
expect.stringContaining(`data-discussion-id='${propsData.appMetadata.issueId}'`), expect.stringContaining(`data-merge-request-id='${propsData.appMetadata.mergeRequestId}'`),
); );
}); });
......
...@@ -374,12 +374,12 @@ function clearNote (inputId) { ...@@ -374,12 +374,12 @@ function clearNote (inputId) {
} }
} }
function confirmAndClear (discussionId) { function confirmAndClear (mergeRequestId) {
const commentButton = document.getElementById('gitlab-comment-button'); const commentButton = document.getElementById('gitlab-comment-button');
const note = document.getElementById('gitlab-validation-note'); const note = document.getElementById('gitlab-validation-note');
commentButton.innerText = 'Feedback sent'; commentButton.innerText = 'Feedback sent';
note.innerText = `Your comment was successfully posted to issue #${discussionId}`; note.innerText = `Your comment was successfully posted to merge request #${mergeRequestId}`;
setTimeout(resetCommentButton, 1000); setTimeout(resetCommentButton, 1000);
} }
...@@ -412,7 +412,7 @@ function getProjectDetails () { ...@@ -412,7 +412,7 @@ function getProjectDetails () {
const browser = getBrowserId(userAgent); const browser = getBrowserId(userAgent);
const scriptEl = document.getElementById('review-app-toolbar-script') const scriptEl = document.getElementById('review-app-toolbar-script')
const { projectId, discussionId, mrUrl } = scriptEl.dataset; const { projectId, mergeRequestId, mrUrl } = scriptEl.dataset;
return { return {
href, href,
...@@ -422,7 +422,7 @@ function getProjectDetails () { ...@@ -422,7 +422,7 @@ function getProjectDetails () {
innerWidth, innerWidth,
innerHeight, innerHeight,
projectId, projectId,
discussionId, mergeRequestId,
mrUrl, mrUrl,
}; };
} }
...@@ -449,7 +449,7 @@ function postComment ({ ...@@ -449,7 +449,7 @@ function postComment ({
innerWidth, innerWidth,
innerHeight, innerHeight,
projectId, projectId,
discussionId, mergeRequestId,
mrUrl, mrUrl,
}) { }) {
// Clear any old errors // Clear any old errors
...@@ -466,18 +466,20 @@ function postComment ({ ...@@ -466,18 +466,20 @@ function postComment ({
} }
const detailText = ` const detailText = `
<details> \n
<summary>Metadata</summary> <details>
Posted from ${href} | ${platform} | ${browser} | ${innerWidth} x ${innerHeight}. <summary>Metadata</summary>
<br /><br /> Posted from ${href} | ${platform} | ${browser} | ${innerWidth} x ${innerHeight}.
*User agent: ${userAgent}* <br /><br />
</details> <em>User agent: ${userAgent}</em>
</details>
`; `;
const url = ` const url = `
${mrUrl}/api/v4/projects/${projectId}/issues/${discussionId}/discussions`; ${mrUrl}/api/v4/projects/${projectId}/merge_requests/${mergeRequestId}/discussions`;
const body = `${commentText}${detailText}`;
const body = `${commentText} ${detailText}`;
fetch(url, { fetch(url, {
method: 'POST', method: 'POST',
...@@ -489,7 +491,7 @@ function postComment ({ ...@@ -489,7 +491,7 @@ function postComment ({
}) })
.then((response) => { .then((response) => {
if (response.ok) { if (response.ok) {
confirmAndClear(discussionId); confirmAndClear(mergeRequestId);
return; return;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment