4

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

LexSav
  • 444
  • 1
  • 9
  • 19
  • 1
    This 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. – fredrik Mar 13 '19 at 12:14
  • @fredrik Therefore I typed "e.g. GitHub" – LexSav Mar 13 '19 at 12:15
  • @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 – LexSav Mar 13 '19 at 12:17
  • On the contrary, each solution is unique. What I suppose you actually mean is that there is no generic solution - which I stated already. – fredrik Mar 13 '19 at 12:18
  • @fredrik maybe. My wonderful English :) – LexSav Mar 13 '19 at 12:20

1 Answers1

6

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

  • 1
    So does this mean that someone besides me or someone at Github can get information about my private repos? – Major Mar 13 '19 at 14:11
  • 3
    There 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. – Bhargav Kinnal Mar 13 '19 at 15:25