0

I'm working on a prototype of a game that will use the information of a Git repository, its branch, merges, etc, as a source for the game's levels.

Is there a way to get a Git repository 'history' and save it in JSON format? Even better, is it possible to get a JSON representation of a GitHub repo?

I would love to let the Linux repo be the last stage from the game and also for people to use their own local repos.

Community
  • 1
  • 1
Draconar
  • 1,147
  • 1
  • 17
  • 36

3 Answers3

3

You can use the Github API to get all this information

http://developer.github.com/

Repo Collaborators: http://developer.github.com/v3/repos/collaborators/

Repo Commits : http://developer.github.com/v3/repos/commits/

Repo Content : http://developer.github.com/v3/repos/contents/

Repo Forks : http://developer.github.com/v3/repos/forks/

Sample URL to get the commits of github.com/holman/play

https://api.github.com/repos/holman/play/commits
Kartik
  • 9,463
  • 9
  • 48
  • 52
2

Have you looked at the developer API documentation?

The exact information that you need will depend on what, exactly, you mean by "JSON representation of a GitHub repo," as it relates to how GitHub exposes it, but the details can be found in their Repositories section.

Overall, the GitHub API is a RESTful interface, so it follows the typical REST rules. Given that they're a Ruby shop, it will likely also follow Ruby's practices for REST APIs, which may help you in experimenting.

Shauna
  • 9,495
  • 2
  • 37
  • 54
1

Other people have pointed out ways to approach this with the github API. Your question also leaves open the possibility of doing this with just git, not github. The great thing about JSON is that it's just text, so you can generate it with just git log.

$ echo "[" && git log -n5 --pretty=format:\"%H\", && echo "]"
[
"216e8824cfac3d3a46eac23fb177566829f2f236",
"8b0357b71fa824114f9db96954b364a8f815fd50",
"bd394fd40184df8b22e45fb6aaa1fc1c3c6dc31a",
"c35af70eaedcdd05b56496e555f33c65286e85ba",
"9e65dfd39de1732bc114bee184f595a6f091680c",
]

I know you will eventually need more detail than that, but it's a starting point.

OK, here's another example. This is fun.

$ echo "[" && git log -n5 --pretty=format:'{ "author": "%an", "subject":"%s" }', && echo "]"
[
{ "author": "Saul Torrell", "subject":"June 21 release - operator systems" },
{ "author": "Saul Torrell", "subject":"Missing topic for june 11 release." },
{ "author": "Saul Torrell", "subject":"June 11 release." },
{ "author": "Saul Torrell", "subject":"new topic." },
{ "author": "Saul Torrell", "subject":"Added extra sauce to the frobnicator." },
]
gcbenison
  • 11,723
  • 4
  • 44
  • 82