Check if Git repository is private or public (e.g. for GitHub) using Java
Specifically GitHub provides REST API to list user repositories. As per the Developer documentation you could use a GET to get all repos of a user and "Visibility" is a parameter
GET /user/repos
Parameter: visibility
Type: string
Value: all
, public
, private
The response also has a parameter "private": false
that can be easily parsed from the response.
More here:https://developer.github.com/v3/repos/#list-user-repositories
Related videos on Youtube
LexSav
Updated on June 04, 2022Comments
-
LexSav almost 2 years
Before we begin: I'm a newbie, so my apologies
Quick description:
I have a Jira plugin that can track current state of the specified repository in the selected git provider, e.g. GitHub (tracking commits, branches etc.) and display it in JIRA issue view
I need to check if the repository I'm adding to the plugin is private or public. If private, I need to request credentials for it.
Is there a way to check this condition in Java (e.g. via JGit) ?
P.S. I'm adding repo to my plugin through it's HTTPS link
-
fredrik about 5 yearsThis would vary depending on if it's GitHub, GitLab, BitBucket or some other hosting service. Git in itself does not have a concept of "public" or "private". Though I'd guess that if you try and access it and get a 403 response - it's private.
-
LexSav about 5 years@fredrik Therefore I typed "e.g. GitHub"
-
LexSav about 5 years@fredrik I found some GitHub API. Maybe there is an answer :) I assume I should look for such APIs for exactly the provider I need ... Seems there is no general solution
-
fredrik about 5 yearsOn the contrary, each solution is unique. What I suppose you actually mean is that there is no generic solution - which I stated already.
-
LexSav about 5 years@fredrik maybe. My wonderful English :)
-
-
Major about 5 yearsSo does this mean that someone besides me or someone at Github can get information about my private repos?
-
Bhargav Kinnal about 5 yearsThere are two different APIs. One to list your own repos, which allows to list even private repos. One to list anyone's repos which does not list private repos (That would be ironic and opposite to what private means!). I believe @LexSav is listing his own repositories.