glab icon indicating copy to clipboard operation
glab copied to clipboard

403 when trying to create an MR

Open bodqhrohro opened this issue 4 years ago • 11 comments

Description

Expected Behavior vs Actual Behavior No 403, successfully created an MR.

Possible Fix

Steps to Reproduce

Logs

@bq:16:38:51:/media/d/temp/git/slidge$ glab mr create
? Choose a template Open a blank merge request
? Title: Return an error when trying to chat with transport
? Description <Received>
? What's next? Submit

Creating merge request for groupchat_join_keyerror into  in bodqhrohro/slidge

POST https://gitlab.com/api/v4/projects/nicocool84/slidge/merge_requests: 403 {message: 403 Forbidden}

Your Environment

  • Version used (Run glab --version): glab version DEV (installed from Nix as glab-1.18.1)
  • Operating System and version: Debian 11

bodqhrohro avatar Aug 17 '21 13:08 bodqhrohro

Hi @bodqhrohro. Have you authenticated against GitLab using glab auth login?

zemzale avatar Aug 17 '21 14:08 zemzale

AFAIR, yes; at least, there is an entry with user/token in config.yml.

I noticed though that there is !!null before the token; is it how it should be?

bodqhrohro avatar Aug 17 '21 14:08 bodqhrohro

What's the output when you run glab auth status?

profclems avatar Aug 17 '21 16:08 profclems

@bq:18:26:40:/media/d/temp/git/slidge$ glab auth status
gitlab.com
  ✓ Logged in to gitlab.com as bodqhrohro (/home/bodqhrohro/.config/glab-cli/config.yml)
  ✓ Git operations for gitlab.com configured to use https protocol.
  ✓ API calls for gitlab.com are made over https protocol
  ✓ REST API Endpoint: https://gitlab.com/api/v4/
  ✓ GraphQL Endpoint: https://gitlab.com/api/graphql/
  ✓ Token: ********************

bodqhrohro avatar Aug 17 '21 16:08 bodqhrohro

Mostly you get 403 error when

  • MRs are disabled on the repository.

    When merge requests are disabled on a repository, GitLab only returns error 403 (unauthorised) so it's difficult to print out the right error message unless we query the projects api and check if merge requests are disabled (which is another issue to work on).

  • Token does not have enough permissions to manage merge requests.

    The minimum required scopes are api and write_repository.

profclems avatar Aug 23 '21 06:08 profclems

Neither.

I found the source of the problem: glab tried to create the MR in the fork repository rather than in the parent repository.

It remembered the chosen repository once and does not ask me anymore. gh asks every time as a first stage what repository I want to create a PR/issue in, why doesn't glab do? I have to specify it explicitly via the -R key now, which is also not explicitly stated in glab --help, so I could only guess it from the previous experience with gh or from examples.

bodqhrohro avatar Aug 23 '21 10:08 bodqhrohro

glab saves the selected base repository in the local git config in the format remote.<remote-name>.glab-resolved.

You can unset it with:

git config --unset remote.<remote-name>.glab-resolved

After unsetting it, glab should prompt for the base repository when run or you can manually set it with:

git config --add remote.<remote-name>.glab-resolved base

NB: substitute <remote-name> for the name of the remote containing the base repo

profclems avatar Aug 23 '21 15:08 profclems

@bodqhrohro, just to bring to your notice, you're running a much older version of glab btw

profclems avatar Aug 27 '21 09:08 profclems

Okay, upgraded to 1.20.0.

Still does not ask for the base repository until explicitly reset.

bodqhrohro avatar Aug 27 '21 11:08 bodqhrohro

This issue has been automatically marked as stale because it has not had recent activity. We haven't had the time to address it yet, but we want to keep it open. This message is just a reminder for us to help triage issues.

clemsbot avatar Sep 27 '21 02:09 clemsbot

This issue has been automatically marked as stale because it has not had recent activity. We haven't had the time to address it yet, but we want to keep it open. This message is just a reminder for us to help triage issues.

clemsbot avatar Nov 03 '21 02:11 clemsbot