async verifyGitLabVersion()

in src/common/code_suggestions/legacy_api_fallback_config.ts [25:72]


  async verifyGitLabVersion() {
    if (!valid(NEW_CODE_SUGGESTION_GITLAB_RELEASE)) {
      log.error(
        `Incorrect min GitLab version configured, falling back to legacy code suggestions API`,
      );
      this.flagLegacyVersion();
      return;
    }

    const platform = await this.#manager.getGitLabPlatform();

    if (!platform) {
      log.error(`Could not intialise API client, falling back to legacy code suggestions API`);
      this.flagLegacyVersion();
      return;
    }

    const versionReq: GetRequest<{ version: string }> = {
      type: 'rest',
      method: 'GET',
      path: '/version',
    };
    const { version } = await platform.fetchFromApi(versionReq);
    if (!version) {
      log.error(`Could not fetch version from API, falling back to legacy code suggestions API`);
      this.flagLegacyVersion();
      return;
    }

    const parsedVersion = coerce(version);
    if (!parsedVersion) {
      log.error(
        `Could not parse version from "${version}", falling back to legacy code suggestions API`,
      );
      this.flagLegacyVersion();
      return;
    }

    if (!gte(parsedVersion, NEW_CODE_SUGGESTION_GITLAB_RELEASE)) {
      log.warn(
        `GitLab version ${parsedVersion} is not new enough, falling back to legacy code suggestions API`,
      );
      this.flagLegacyVersion();
      return;
    }

    this.#isLegacyVersion = false;
  }