提交 452586c4 编写于 作者: T Tomas Vik

refactor: group discussion and note types into separate files

上级 e623b271
......@@ -3,7 +3,7 @@ import { PROGRAMMATIC_COMMANDS } from '../../command_names';
import { createGitLabNewService } from '../../service_factory';
import { ChangedFileItem } from './changed_file_item';
import { ItemModel } from './item_model';
import { GqlDiscussion, GqlTextDiffDiscussion } from '../../gitlab/gitlab_new_service';
import { GqlDiscussion, GqlTextDiffDiscussion } from '../../gitlab/graphql/get_discussions';
import { handleError } from '../../log';
import { UserFriendlyError } from '../../errors/user_friendly_error';
import { GitLabCommentThread } from '../../review/gitlab_comment_thread';
......
......@@ -13,26 +13,25 @@ import { GitLabProject } from './gitlab_project';
import { getRestIdFromGraphQLId } from '../utils/get_rest_id_from_graphql_id';
import { UserFriendlyError } from '../errors/user_friendly_error';
import { getMrPermissionsQuery, MrPermissionsQueryOptions } from './graphql/mr_permission';
import { fragmentProjectDetails, GqlProject, noteDetailsFragment } from './graphql/shared';
import {
fragmentProjectDetails,
GqlBasePosition,
GqlGenericNote,
GqlNote,
GqlProject,
GqlProjectResult,
Node,
noteDetailsFragment,
} from './graphql/shared';
import { GetProjectsOptions, GqlProjectsResult, queryGetProjects } from './graphql/get_projects';
import {
getIssueDiscussionsQuery,
getMrDiscussionsQuery,
GetDiscussionsQueryOptions,
GqlDiscussion,
GetDiscussionsQueryResult,
} from './graphql/get_discussions';
interface Node<T> {
pageInfo?: {
hasNextPage: boolean;
endCursor: string;
};
nodes: T[];
}
interface GqlProjectResult<T> {
project?: T;
}
interface GqlSnippetProject {
id: string;
snippets: Node<GqlSnippet>;
......@@ -58,88 +57,6 @@ export interface GqlBlob {
path: string;
}
interface GqlUser {
avatarUrl: string | null;
name: string;
username: string;
webUrl: string;
}
interface GqlBasePosition {
diffRefs: {
baseSha: string;
headSha: string;
};
filePath: string;
newPath: string;
oldPath: string;
}
interface GqlImagePosition extends GqlBasePosition {
positionType: 'image';
newLine: null;
oldLine: null;
}
interface GqlNewPosition extends GqlBasePosition {
positionType: 'text';
newLine: number;
oldLine: null;
}
interface GqlOldPosition extends GqlBasePosition {
positionType: 'text';
newLine: null;
oldLine: number;
}
export type GqlTextPosition = GqlOldPosition | GqlNewPosition;
interface GqlNotePermissions {
resolveNote: boolean;
adminNote: boolean;
createNote: boolean;
}
interface GqlGenericNote<T extends GqlBasePosition | null> {
id: string;
author: GqlUser;
createdAt: string;
system: boolean;
body: string; // TODO: remove this once the SystemNote.vue doesn't require plain text body
bodyHtml: string;
userPermissions: GqlNotePermissions;
position: T;
}
interface GqlGenericDiscussion<T extends GqlNote> {
replyId: string;
createdAt: string;
resolved: boolean;
resolvable: boolean;
notes: Node<T>;
}
export type GqlTextDiffNote = GqlGenericNote<GqlTextPosition>;
type GqlImageNote = GqlGenericNote<GqlImagePosition>;
export type GqlOverviewNote = GqlGenericNote<null>;
export type GqlNote = GqlTextDiffNote | GqlImageNote | GqlOverviewNote;
export type GqlDiscussion =
| GqlGenericDiscussion<GqlTextDiffNote>
| GqlGenericDiscussion<GqlImageNote>
| GqlGenericDiscussion<GqlOverviewNote>;
export type GqlTextDiffDiscussion = GqlGenericDiscussion<GqlTextDiffNote>;
interface GqlDiscussionsProject {
mergeRequest?: {
discussions: Node<GqlDiscussion>;
};
issue?: {
discussions: Node<GqlDiscussion>;
};
}
interface RestLabelEvent {
label: unknown;
body: string;
......@@ -375,10 +292,7 @@ export class GitLabNewService {
iid: String(issuable.iid),
endCursor,
};
const result = await this.client.request<GqlProjectResult<GqlDiscussionsProject>>(
query,
options,
);
const result = await this.client.request<GetDiscussionsQueryResult>(query, options);
assert(result.project, `Project ${projectPath} was not found.`);
const discussions =
result.project.issue?.discussions || result.project.mergeRequest?.discussions;
......
import { gql } from 'graphql-request';
import { noteDetailsFragment } from './shared';
import {
noteDetailsFragment,
Node,
GqlProjectResult,
GqlNote,
GqlTextDiffNote,
GqlOverviewNote,
GqlImageNote,
} from './shared';
const discussionsFragment = gql`
${noteDetailsFragment}
......@@ -59,3 +67,29 @@ export interface GetDiscussionsQueryOptions {
iid: string;
endCursor?: string;
}
interface GqlGenericDiscussion<T extends GqlNote> {
replyId: string;
createdAt: string;
resolved: boolean;
resolvable: boolean;
notes: Node<T>;
}
export type GqlTextDiffDiscussion = GqlGenericDiscussion<GqlTextDiffNote>;
export type GqlDiscussion =
| GqlGenericDiscussion<GqlTextDiffNote>
| GqlGenericDiscussion<GqlImageNote>
| GqlGenericDiscussion<GqlOverviewNote>;
interface GqlDiscussionsProject {
mergeRequest?: {
discussions: Node<GqlDiscussion>;
};
issue?: {
discussions: Node<GqlDiscussion>;
};
}
export type GetDiscussionsQueryResult = GqlProjectResult<GqlDiscussionsProject>;
......@@ -69,3 +69,73 @@ export interface GqlProject {
webUrl: string;
group?: GqlGroup;
}
export interface GqlProjectResult<T> {
project?: T;
}
export interface Node<T> {
pageInfo?: {
hasNextPage: boolean;
endCursor: string;
};
nodes: T[];
}
interface GqlUser {
avatarUrl: string | null;
name: string;
username: string;
webUrl: string;
}
export interface GqlBasePosition {
diffRefs: {
baseSha: string;
headSha: string;
};
filePath: string;
newPath: string;
oldPath: string;
}
interface GqlImagePosition extends GqlBasePosition {
positionType: 'image';
newLine: null;
oldLine: null;
}
interface GqlNewPosition extends GqlBasePosition {
positionType: 'text';
newLine: number;
oldLine: null;
}
interface GqlOldPosition extends GqlBasePosition {
positionType: 'text';
newLine: null;
oldLine: number;
}
export type GqlTextPosition = GqlOldPosition | GqlNewPosition;
interface GqlNotePermissions {
resolveNote: boolean;
adminNote: boolean;
createNote: boolean;
}
export interface GqlGenericNote<T extends GqlBasePosition | null> {
id: string;
author: GqlUser;
createdAt: string;
system: boolean;
body: string; // TODO: remove this once the SystemNote.vue doesn't require plain text body
bodyHtml: string;
userPermissions: GqlNotePermissions;
position: T;
}
export type GqlTextDiffNote = GqlGenericNote<GqlTextPosition>;
export type GqlImageNote = GqlGenericNote<GqlImagePosition>;
export type GqlOverviewNote = GqlGenericNote<null>;
export type GqlNote = GqlTextDiffNote | GqlImageNote | GqlOverviewNote;
import { GitLabComment } from './gitlab_comment';
import { GitLabCommentThread } from './gitlab_comment_thread';
import { noteOnDiff } from '../../test/integration/fixtures/graphql/discussions.js';
import { GqlTextDiffNote } from '../gitlab/gitlab_new_service';
import { GqlTextDiffNote } from '../gitlab/graphql/shared';
describe('GitLabComment', () => {
let comment: GitLabComment;
......
import * as vscode from 'vscode';
import { GqlTextDiffNote } from '../gitlab/gitlab_new_service';
import { GqlTextDiffNote } from '../gitlab/graphql/shared';
import { GitLabCommentThread } from './gitlab_comment_thread';
interface CommentOptions {
......
......@@ -5,12 +5,10 @@ import {
noteOnDiff,
} from '../../test/integration/fixtures/graphql/discussions.js';
import { GitLabComment } from './gitlab_comment';
import {
GitLabNewService,
GqlTextDiffDiscussion,
GqlTextDiffNote,
} from '../gitlab/gitlab_new_service';
import { GitLabNewService } from '../gitlab/gitlab_new_service';
import { mr } from '../test_utils/entities';
import { GqlTextDiffNote } from '../gitlab/graphql/shared';
import { GqlTextDiffDiscussion } from '../gitlab/graphql/get_discussions';
describe('GitLabCommentThread', () => {
let gitlabCommentThread: GitLabCommentThread;
......
import * as vscode from 'vscode';
import * as assert from 'assert';
import {
GitLabNewService,
GqlNote,
GqlTextDiffDiscussion,
GqlTextDiffNote,
GqlTextPosition,
} from '../gitlab/gitlab_new_service';
import { GitLabNewService } from '../gitlab/gitlab_new_service';
import { GitLabComment } from './gitlab_comment';
import { toReviewUri } from './review_uri';
import { GqlTextDiffDiscussion } from '../gitlab/graphql/get_discussions';
import { GqlNote, GqlTextDiffNote, GqlTextPosition } from '../gitlab/graphql/shared';
const firstNoteFrom = (discussion: GqlTextDiffDiscussion): GqlTextDiffNote => {
const note = discussion.notes.nodes[0];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册