in src/desktop/gitlab/gitlab_service.ts [122:210]
avatar_url: ensureAbsoluteAvatarUrl(instanceUrl, author.avatar_url),
},
};
};
// TODO: extract the mutation into a separate file like src/gitlab/graphql/get_project.ts
const discussionSetResolved = gql`
mutation DiscussionToggleResolve($replyId: DiscussionID!, $resolved: Boolean!) {
discussionToggleResolve(input: { id: $replyId, resolve: $resolved }) {
errors
}
}
`;
// TODO: extract the mutation into a separate file like src/gitlab/graphql/get_project.ts
const deleteNoteMutation = gql`
mutation DeleteNote($noteId: NoteID!) {
destroyNote(input: { id: $noteId }) {
errors
}
}
`;
// TODO: extract the mutation into a separate file like src/gitlab/graphql/get_project.ts
const updateNoteBodyMutation = gql`
mutation UpdateNoteBody($noteId: NoteID!, $body: String) {
updateNote(input: { id: $noteId, body: $body }) {
errors
}
}
`;
const getNamespaceWithPath = (issuable: RestIssuable) => issuable.references.full.split(/[#!]/)[0];
const getIssuableGqlId = (issuable: RestIssuable) =>
`gid://gitlab/${isMr(issuable) ? 'MergeRequest' : 'Issue'}/${issuable.id}`;
const getMrGqlId = (id: number) => `gid://gitlab/MergeRequest/${id}`;
const getTotalPages = (response: Response): number =>
parseInt(response.headers.get('x-total-pages') || '1', 10);
const getCurrentPage = (query: Record<string, QueryValue>): number =>
query.page && typeof query.page === 'number' ? query.page : 1;
interface VersionResponse {
version: string;
enterprise?: boolean;
}
export interface ValidationResponse {
valid?: boolean;
merged_yaml?: string;
errors: string[];
}
// This has to be type, because interface isn't compatible with Record<string,unknown> https://github.com/microsoft/TypeScript/issues/15300#issuecomment-332366024
type CreateSnippetOptions = {
title: string;
description?: string;
file_name: string;
visibility: SnippetVisibility;
content: string;
};
const getHttpAgent = (instanceUrl: string) => {
const agentOptions = getHttpAgentOptions();
if (agentOptions.proxy) {
return new HttpsProxyAgent(agentOptions.proxy);
}
if (instanceUrl.startsWith('https://')) {
return new https.Agent(agentOptions);
}
return undefined;
};
const getDefaultApiClientOptions = (instanceUrl: string): DefaultApiClientOptions => ({
instanceUrl,
agent: getHttpAgent(instanceUrl),
headers: getUserAgentHeader(),
});
export class GitLabService {
#credentials: Credentials;
#apiClient: DefaultApiClient;
constructor(credentials: Credentials) {
this.#credentials = credentials;
this.#apiClient = new DefaultApiClient({