Verified Commit 36debb32 authored by Enrique Alcántara's avatar Enrique Alcántara 3️⃣
Browse files

fix: Fix gitlab platform creation for code suggestions

Fixes a bug where the user is constantly asked about their
preferred GitLab account to use in code suggestions.

This commit changes the behavior by inquiring each GitLab
account and identifying which account has code suggestions enabled.

It stores in a user preference the user preferred gitlab account
parent 673c42e4
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -140,6 +140,11 @@
          "type": "boolean",
          "default": true
        },
        "gitlab.aiAssistedCodeSuggestions.preferredAccount": {
          "description": "GitLab account to use for code completion",
          "type": "string",
          "default": null
        },
        "gitlab.duoChat.enabled": {
          "description": "Enable GitLab Duo Chat assistant (Beta)",
          "type": "boolean",
+2 −2
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@ import { gqlProject, project } from '../common/test_utils/entities';
import { createGitLabPlatformManagerBrowser } from './gitlab_platform_browser';
import {
  GitLabPlatformForActiveProject,
  GitLabPlatformForActiveAccount,
  GitLabPlatformForAccount,
  GitLabPlatformManager,
} from '../common/platform/gitlab_platform';

@@ -48,7 +48,7 @@ describe('createGitLabPlatformManagerBrowser', () => {
    });

    describe('without GitLab hosted project', () => {
      let platform: GitLabPlatformForActiveAccount | undefined;
      let platform: GitLabPlatformForAccount | undefined;

      beforeEach(async () => {
        platform = await manager.getForActiveAccount();
+6 −0
Original line number Diff line number Diff line
@@ -55,5 +55,11 @@ export const createGitLabPlatformManagerBrowser: () => Promise<GitLabPlatformMan
          ...platformBase,
        }),
      getForActiveAccount: async () => ({ type: 'account', ...platformBase }),
      getForAllAccounts: async () => [
        {
          type: 'account',
          ...platformBase,
        },
      ],
    };
  };
+1 −0
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ describe('GitLabChatApi', () => {
        fetchFromApi: makeApiRequest,
        getUserAgentHeader: () => ({}),
      })),
      getForAllAccounts: jest.fn(),
    };
  };

+26 −0
Original line number Diff line number Diff line
import { gql } from 'graphql-request';
import { GraphQLRequest } from '../../platform/web_ide';

export interface GqlCurrentUser {
  ide: {
    codeSuggestionsEnabled: boolean;
  };
}

const queryGetProject = gql`
  query getCodeSuggestionsSupport {
    currentUser {
      ide {
        codeSuggestionsEnabled
      }
    }
  }
`;

export function getCodeSuggestionsSupport(): GraphQLRequest<{ currentUser: GqlCurrentUser }> {
  return {
    type: 'graphql',
    query: queryGetProject,
    variables: {},
  };
}
Loading