Question

Background

I'm researching the ability to add some services on top of git web hosts (ie github, gitlab, bitbucket etc, I'm not even sure what they're called, I borrowed that term from the github wiki).

An example of what I'm trying to do is integrating a spreadsheet with one such git web host so that whenever a user adds a new row in a spreadsheet, an issue with the contents of that row is automatically created.

Naturally, these webhosts have different apis that perform these things. I can wrap them up with a facade or something but I will still need to know the kind of the webhost.

Problem

If the git repository is hosted on a cloud version of a webhost (ie Gitlab cloud or github, then knowing the kind of webhost is easy straight from the repo itself, for example this repo:

https://github.com/facebook/buck.git 

is obviously from github. However some of these providers offer users the ability to install their gihtub hosting service on their own machines.. so for example I can have gitlab installed on my aws machine, and so the above version control will look like this:

https://mydomain.com/facebook/buck.git 

Question

How can I know what kind of git webhost is associated with a repo of it's installed on a user server rather than the cloud of the provider them self?

Was it helpful?

Solution

Well-designed web APIs usually have ways to discover what versions of which endpoints are currently supported. For example, if you curl https://api.github.com, you'll get a list of all the endpoint categories the API supports. This allows for customization and smoother upgrades of individual components.

For your use case, you can check if that has an entry for issues_url, then check if that endpoint responds in a github-like way, then you know it's a github server. If not, you can repeat the process for the other kinds of servers. Once you know what kind of server it is, you can store that for future use, and avoid guessing. If you make a couple wrong guesses, the worst you're going to get is some weird 404s in your logs.

OTHER TIPS

You can't, at least not in general (not until auto-discoverable APIs are actually a thing, anyway). But since you're going to have to support a limited set of APIs in any case, and since the humans actually using the interface can be expected to know the host rather well for such a system, how about giving them a simple list to select the type of web host from?

Licensed under: CC-BY-SA with attribution
scroll top