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