Deleting a remote repo

As part of my CI I programmatically create repos that contain the code that was used to stamp a subscription on a cloud service. However, these repos are created in dev, test, staging and production. I need to be able to delete the dev repos, which do not exist locally on my machine, also programmatically and as part of a cleanup script. So far I can only do that on the web interface itself. Is there an API or CLI call that I can use to do this?

Hi @Zork

I think you probably want the delete project API call

1 Like

Does the CLI support this functionality?

Hi @Zork

glab is an open-source tool with the goal of bringing GitLab to your command line. It’s not an official product and we don’t offer a tool with similar functionality, but we support the API it’s built on. For your use case, glab has a repo delete command that might help!

I don’t have access to the token necessary to use the API so I cannot use this. I was hoping the git CLI could do this but I guess it does not. I should be able to delete a project for which I am owner even if I don’t have anything cloned locally.

Sorry, I don’t believe it’s possible to delete a remote repository via git on the command line (on GitLab or hosted elsewhere). Is it possible for you acquire an access token to use the API?

No. This is for a standalone script that developers would run to cleanup their workspaces, and we can’t have tokens out in the wild. That would be a major security risk.

Would it be possible to make this a manual pipeline job somewhere? That way you could keep the API token as a CI variable on GitLab. You’d need to think a bit about how to tell the manual job which repos need deleting though…

Yes, that would work, but we were trying to avoid that path if possible.

Whatever you do though, you’ll need some form of authentication. If you do something outside of the pipeline, then you will need an API key.

1 Like

Yes, but if the git cli were able to do what I want, I wouldn’t have to specifically authenticate, I would leave that to the developer using their ssh keys. Deleting a remote shouldn’t be something restricted to a REST API. That just doesn’t make sense if you have what is supposed to be a comprehensive cli.