decaporg / decap-cms

A Git-based CMS for Static Site Generators
https://decapcms.org
MIT License
17.65k stars 3.02k forks source link

Backend for self-hosted Gitlab still queries gitlab.com #7168

Open JbIPS opened 2 months ago

JbIPS commented 2 months ago

Describe the bug I configured a backend for my hosted version of Gitlab

  name: gitlab
  repo: web/landing
  auth_type: pkce # Required for pkce
  app_id: *******
  api_root: https://gitlab.****/api/v4
  base_url: https://gitlab.*****
  auth_endpoint: oauth/authorize

On login:

Of course the 3rd call gives a 404 and login workflow stops.

I looked at the sources but couldn't find a static ref to gitlab.com.

To Reproduce

  1. Configure a backend for a hosted gitlab
  2. Try to login

Expected behavior No call should be made to gitlab.com

Screenshots Screenshot from 2024-04-09 17-50-08

Applicable Versions:

CMS configuration

collections:
  - name: 'posts'
    label: "Posts de blog"
    folder: "blog/posts"
    create: true
    fields:
      - { label: "Layout", name: "layout", widget: "hidden", default: "post"}
      - { label: "Titre", name: "title", widget: "string"}
      - { label: "Image", name: "image", widget: "image"}
      - { label: "Miniature", name: "thumbnail", widget: "image"}
      - { label: "Categorie", name: "categoriy", widget: "string"}
      - { label: "Résumé", name: "excerpt", widget: "markdown"}
      - { label: "Contenu", name: "body", widget: "markdown"}

locale: fr

media_folder: "assets/posts"
backend:
  name: gitlab
  repo: web/landing
  auth_type: pkce # Required for pkce
  app_id: *******
  api_root: https://gitlab.****/api/v4
  base_url: https://gitlab.*****
  auth_endpoint: oauth/authorize
yuchi commented 1 month ago

Probably the issue happens when calling getDefaultBranchName without passing all backend configuration options.

Indeed if you add branch: master (or whatever you need) to the backend configuration it will work.

JbIPS commented 1 month ago

You're right, it looks like the API roots are hard-wired into decap-cms-lib-util.

And setting the branch in my YAML do the trick, thanks a lot! :partying_face:

Should I create a PR to pass an optional api_root to getDefaultBranch and apiRequest ? If present, this line will use it as-is instead.

martinjagodic commented 1 month ago

@JbIPS a PR would be helpful, thanks!