Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete a GitLab repository using curl?

I am able to achieve this with GitHub. But I am unable to do the same with GitLab. Currently, what I have is:

curl -u "$user:$token" -H "Content-Type:application/json" -H "PRIVATE-TOKEN:$token" \
-X DELETE https://git.lab.com/api/v4/projects/$repo_name

And then I get this error:

curl: (35) error:14077438:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert internal error

I already have a working script using curl to create a GitLab repository on the command line so my curl is working fine. I just needed the delete part.

like image 327
eigenfield Avatar asked Sep 01 '18 16:09

eigenfield


People also ask

How do I delete a GitLab repository?

On the top bar, select Menu > Projects and find your project. On the left sidebar, select Settings > General. Expand Advanced. In the "Permanently delete project" section, select Delete project.

How do I delete files from GitLab project?

Browse to the directory in your repository that you want to delete. In the top-right corner, click , then click Delete directory. Review the files you will delete. At the bottom of the page, type a short, meaningful commit message that describes the change you made to the file.


1 Answers

Removing a project by project path

curl -H 'Content-Type: application/json' -H 'Private-Token: $privatetoken' \
-X DELETE https://gitlab.com/api/v4/projects/$namespace%2F$projectname
  • https://docs.gitlab.com/ee/api/projects.html#delete-project
  • https://docs.gitlab.com/ee/api/README.html#namespaced-path-encoding

Possible causes for the SSL error

Namespaced path encoding

The URI is split by the forward slashes on the server side and then the resulting path elements are categorized.

Since the forward slash is treated as a special character, we need to URL encode it if we want to include it as a URI path element, so the server does not try to split it.

How this could cause a problem is more evident if you are executing a request with additional parameters behind the ID.

In the following examples $namespace is foo and $projectname is bar.

Good

Request: GET /projects/foo%2Fbar/users

URI path elements:

  • projects - the resources the call will be executed on
  • foo%2Fbar - the specific resource (project) name is foo/bar (after URL decoding it)
  • users - the resources to return

Bad

Request: GET /projects/foo/bar/users

URI path elements:

  • projects - the resources the call will be executed on
  • foo - the specific resource (project) name is foo (no such project, namespace is missing)
  • bar - the resource to query or action to execute (no such resource or action)
  • users - additional query parameter (parent resource or action does not exist in the first place)

API endpoint

If you are using the public GitLab hosted at https://gitlab.com/, you should use the gitlab.com domain name instead of git.lab.com, the latter is not owned by GitLab Inc.

like image 155
zsltg Avatar answered Sep 24 '22 18:09

zsltg