Search code examples
gitgithubgithub-api

How to connect to local github server through api


I have a local server in my office, where i have github installed and configured to use. Currently we use tortoise svn to connect to the local repositories and manage it.

Now I need to connect to the github repositories installed on my local server using Github APIs. I know how to connect to remote github repo's using github API.

Currenlty i tried a API request to fetch a cloud github repo using GET request to https://api.github.com/orgs/:username/repos to list my organization repo's and i get correct response from the server.

[
  {
    "id": 1296269,
    "node_id": "MDEwOlJlcG9zaXRvcnkxMjk2MjY5",
    "name": "Hello-World",
    "full_name": "octocat/Hello-World",
    "owner": {
      "login": "octocat",
      "id": 1,
      "node_id": "MDQ6VXNlcjE=",
      "avatar_url": "https://github.com/images/error/octocat_happy.gif",
      "gravatar_id": "",
      "url": "https://api.github.com/users/octocat",
      "html_url": "https://github.com/octocat",      
      "type": "User",
      "site_admin": false
   },
   ...
]

Similarly i wanted to do with my local server github repos. The local server named as masterhub in my host file and i can clone the repo like git clone ssh://username@masterhub/git/sample.git and it is working.

What i want now is what is the endpoint i should make an API call to make github APIs work on local?

Note: I know the github APIs available to play based on my need but all i need to know is what is the endpoint i should hit?


Solution

  • The GitHub Enterprise Server API is under a slightly different endpoint than the cloud version. If the hostname for your server is github.example.com, then the API is available under https://github.example.com/api/v3 instead of https://api.github.com.

    So for your example above, you'd need to use https://github.example.com/api/v3/orgs/:username/repos.

    Note that whatever you have configured in your SSH config file doesn't matter here: you need to use a hostname, not an SSH alias. If you're not sure what that hostname should be, then look in ~/.ssh/config and find the hostname, then use that.