提交 d41218c9 编写于 作者: T Tomas Vik

refactor: introduce RestMr interface

Credit: [@Musisimaru](https://gitlab.com/Musisimaru) (originally
introduced in
[!229](https://gitlab.com/gitlab-org/gitlab-vscode-extension/-/merge_requests/229))
上级 d540d298
...@@ -38,6 +38,7 @@ import { ...@@ -38,6 +38,7 @@ import {
import { createDiffNoteMutation, GqlDiffPositionInput } from './graphql/create_diff_comment'; import { createDiffNoteMutation, GqlDiffPositionInput } from './graphql/create_diff_comment';
import { removeLeadingSlash } from '../utils/remove_leading_slash'; import { removeLeadingSlash } from '../utils/remove_leading_slash';
import { log, logError } from '../log'; import { log, logError } from '../log';
import { isMr } from '../utils/is_mr';
interface CreateNoteResult { interface CreateNoteResult {
createNote: { createNote: {
...@@ -109,7 +110,6 @@ const updateNoteBodyMutation = gql` ...@@ -109,7 +110,6 @@ const updateNoteBodyMutation = gql`
`; `;
const getProjectPath = (issuable: RestIssuable) => issuable.references.full.split(/[#!]/)[0]; const getProjectPath = (issuable: RestIssuable) => issuable.references.full.split(/[#!]/)[0];
const isMr = (issuable: RestIssuable) => Boolean(issuable.sha);
const getIssuableGqlId = (issuable: RestIssuable) => const getIssuableGqlId = (issuable: RestIssuable) =>
`gid://gitlab/${isMr(issuable) ? 'MergeRequest' : 'Issue'}/${issuable.id}`; `gid://gitlab/${isMr(issuable) ? 'MergeRequest' : 'Issue'}/${issuable.id}`;
const getMrGqlId = (id: number) => `gid://gitlab/MergeRequest/${id}`; const getMrGqlId = (id: number) => `gid://gitlab/MergeRequest/${id}`;
......
...@@ -14,7 +14,6 @@ interface RestIssuable { ...@@ -14,7 +14,6 @@ interface RestIssuable {
project_id: number; project_id: number;
web_url: string; web_url: string;
author: { name: string; avatar_url: string | null }; author: { name: string; avatar_url: string | null };
sha?: string; // only present in MR, legacy logic uses the presence to decide issuable type
references: { references: {
full: string; // e.g. "gitlab-org/gitlab#219925" full: string; // e.g. "gitlab-org/gitlab#219925"
}; };
...@@ -22,6 +21,10 @@ interface RestIssuable { ...@@ -22,6 +21,10 @@ interface RestIssuable {
name: string; name: string;
} }
interface RestMr extends RestIssuable {
sha: string;
}
interface RestMrVersion { interface RestMrVersion {
head_commit_sha: string; head_commit_sha: string;
base_commit_sha: string; base_commit_sha: string;
......
export const isMr = (issuable: RestIssuable): issuable is RestMr =>
Boolean((issuable as RestMr).sha);
...@@ -7,6 +7,7 @@ import * as gitLabService from './gitlab_service'; ...@@ -7,6 +7,7 @@ import * as gitLabService from './gitlab_service';
import { createGitLabNewService } from './service_factory'; import { createGitLabNewService } from './service_factory';
import { logError } from './log'; import { logError } from './log';
import { getInstanceUrl } from './utils/get_instance_url'; import { getInstanceUrl } from './utils/get_instance_url';
import { isMr } from './utils/is_mr';
const webviewResourcePaths = { const webviewResourcePaths = {
appScriptUri: 'src/webview/dist/js/app.js', appScriptUri: 'src/webview/dist/js/app.js',
...@@ -140,8 +141,7 @@ class WebviewController { ...@@ -140,8 +141,7 @@ class WebviewController {
const lightMrIcon = getIconUri('light', 'merge_requests.svg'); const lightMrIcon = getIconUri('light', 'merge_requests.svg');
const darkIssueIcon = getIconUri('dark', 'issues.svg'); const darkIssueIcon = getIconUri('dark', 'issues.svg');
const darkMrIcon = getIconUri('dark', 'merge_requests.svg'); const darkMrIcon = getIconUri('dark', 'merge_requests.svg');
const isMr = issuable.sha !== undefined; return isMr(issuable)
return isMr
? { light: lightMrIcon, dark: darkMrIcon } ? { light: lightMrIcon, dark: darkMrIcon }
: { light: lightIssueIcon, dark: darkIssueIcon }; : { light: lightIssueIcon, dark: darkIssueIcon };
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册