For my project, I need to know if a git repo is public or not to do some actions. I first thought to use HTTP request so I'm using postman and I tried with multiple URLs with HEAD method.
When I'm sending a request, I can't see what in the header can indicate me when it failed or not.
When I send a request to github for a private project, I'm receiving a the status 404 so it's perfect for me cause I know that is a private project.
BUT when I do this for gitlab, I'm receiving the status 200 then I'm redirected.
I would like to know if there is a solution for that.
Under your repository name, click Settings. Under "Danger Zone", to the right of to "Change repository visibility", click Change visibility. Select a visibility. To verify that you're changing the correct repository's visibility, type the name of the repository you want to change the visibility of.
Open Security for a repository You set Git repository permissions from Project Settings>Repositories. Open the web portal and choose the project where you want to add users or groups. To choose another project, see Switch project, repository, team. Open Project settings>Repositories.
You can restrict who has access to a repository by choosing a repository's visibility: public or private. When you create a repository, you can choose to make the repository public or private.
GitHub is public Git hosting site for both public, open source projects and private, proprietary codes. GitHub is not open source. Free accounts (applicable to Open Source projects) have a soft limit of 1GB per repository.
Generally, the easiest way to do this is to perform a GET
request after appending /info/refs?service=git-upload-pack
to the URL. That's the endpoint which Git uses to get reference information.
If the repo is public, you'll get a 200. You'll likely get a 401 if the repository is private or doesn't exist. Most major hosting providers don't provide information about whether a private repository exists or not until after you've authenticated, so you'll get a 401 either way.
Note that you can't use a HEAD
request; GitHub returns a 405 Method Not Allowed in that case.
Example: Open Source Repo: https://gitlab.com/gitlab-org/gitlab-ce.git
{GET}: https://gitlab.com/gitlab-org/gitlab-ce.git/info/refs?service=git-upload-pack
Example 401:
wget $URL
Connecting to gitlab.com (35.231.145.151:80)
Connecting to gitlab.com (35.231.145.151:443)
wget: server returned error: HTTP/1.1 401 Unauthorized
echo $?
1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With