Commit bb2b8a01 authored by Tomas Vik (OOO back on 2026-08-31)'s avatar Tomas Vik (OOO back on 2026-08-31) 🌴
Browse files

fix: remove the broken code related to creating user snippets

Creating snippets in user space hasn't worked in a long time. And for
the last year, when the extension supports multiple GitLab instances, we
wouldn't know which instance to use for adding the user snippet.

This commit removes the broken logic and focuses on creating project
snippets.
parent 2d4618a9
Loading
Loading
Loading
Loading
+3 −16
Original line number Diff line number Diff line
@@ -30,13 +30,9 @@ const contextOptions = [
  },
];

async function showPicker(additionalEntries = [], placeHolder = 'Select a Gitlab Project') {
async function showPicker() {
  const repositoryRootOptions = await gitLabService.getAllGitlabProjects();

  additionalEntries.forEach(additionalEntry => {
    repositoryRootOptions.push(additionalEntry);
  });

  if (repositoryRootOptions.length === 0) {
    return null;
  }
@@ -45,7 +41,7 @@ async function showPicker(additionalEntries = [], placeHolder = 'Select a Gitlab
  }

  const repositoryRoot = await vscode.window.showQuickPick(repositoryRootOptions, {
    placeHolder,
    placeHolder: "Select a Gitlab Project or use the User's Snippets",
  });

  if (repositoryRoot) {
@@ -101,17 +97,8 @@ async function createSnippet() {
      logError(e);
    }

    // FIXME: the empty `uri` representing user's snippets is not correctly handled
    if (!project) {
      repositoryRoot = await showPicker(
        [
          {
            label: "User's Snippets",
            uri: '',
          },
        ],
        "Select a Gitlab Project or use the User's Snippets",
      );
      repositoryRoot = await showPicker();
      try {
        const selectedRepository = gitExtensionWrapper.getRepository(repositoryRoot);
        project = selectedRepository && (await selectedRepository.getProject());
+3 −12
Original line number Diff line number Diff line
@@ -478,21 +478,12 @@ export async function fetchMRIssues(mrId: number, repositoryRoot: string): Promi

// TODO specify the correct interface when we convert `create_snippet.js`
export async function createSnippet(repositoryRoot: string, data: { id: string }) {
  let snippet;
  let path = '/snippets';

  if (data.id) {
    path = `/projects/${data.id}/snippets`;
  }

  try {
    const { response } = await fetch(repositoryRoot, path, 'POST', data);
    snippet = response;
    const { response } = await fetch(repositoryRoot, `/projects/${data.id}/snippets`, 'POST', data);
    return response;
  } catch (e) {
    handleError(new UserFriendlyError('Failed to create your snippet.', e));
    throw new UserFriendlyError('Failed to create your snippet.', e);
  }

  return snippet;
}

export async function validateCIConfig(repositoryRoot: string, content: string): Promise<boolean> {