Skip to content

Commit 81c7e58

Browse files
committed
Document submodule handling in Repo Contents API
1 parent e18ad2e commit 81c7e58

File tree

4 files changed

+67
-1
lines changed

4 files changed

+67
-1
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
kind: change
3+
title: Improved Support for Submodules in the Repository Contents API
4+
created_at: 2013-04-30
5+
author_name: jasonrudolph
6+
---
7+
8+
When you view a repository with a submodule on github.com, you get useful links and information for the submodule.
9+
10+
[![Repository Contents with Submodule](/images/posts/submodule-links.png)][screenshot]
11+
12+
Today we're making that data available in the [Repository Contents API][docs].
13+
14+
<pre class="terminal">
15+
curl https://api.github.com/repos/jquery/jquery/contents/test/qunit
16+
17+
{
18+
"name": "qunit",
19+
"path": "test/qunit",
20+
"type": "submodule",
21+
"submodule_git_url": "git://github.com/jquery/qunit.git",
22+
"sha": "6ca3721222109997540bd6d9ccd396902e0ad2f9",
23+
"size": 0,
24+
"url": "https://api.github.com/repos/jquery/jquery/contents/test/qunit?ref=master",
25+
"git_url": "https://api.github.com/repos/jquery/qunit/git/trees/6ca3721222109997540bd6d9ccd396902e0ad2f9",
26+
"html_url": "https://github.com/jquery/qunit/tree/6ca3721222109997540bd6d9ccd396902e0ad2f9",
27+
"_links": {
28+
"self": "https://api.github.com/repos/jquery/jquery/contents/test/qunit?ref=master",
29+
"git": "https://api.github.com/repos/jquery/qunit/git/trees/6ca3721222109997540bd6d9ccd396902e0ad2f9",
30+
"html": "https://github.com/jquery/qunit/tree/6ca3721222109997540bd6d9ccd396902e0ad2f9"
31+
}
32+
}
33+
</pre>
34+
35+
If you have any questions or feedback, please drop us a line at
36+
[support@github.com](mailto:support@github.com?subject=Submodules in Repository Contents API).
37+
38+
[docs]: /v3/repos/contents/#get-contents
39+
[screenshot]: /images/posts/submodule-links.png

content/v3/repos/contents.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ This method returns the contents of a file or directory in a repository.
3535
GET /repos/:owner/:repo/contents/:path
3636

3737
Files and symlinks support [a custom media type](#custom-media-types) for getting the raw content.
38-
Directories do _not_ support custom media types.
38+
Directories and submodules do _not_ support custom media types.
3939

4040
*Notes*:
4141

@@ -69,6 +69,16 @@ Otherwise, the API responds with a hash describing the symlink itself:
6969
<%= headers 200 %>
7070
<%= json :symlink_content %>
7171

72+
### Response if content is a submodule
73+
74+
<%= headers 200 %>
75+
<%= json :submodule_content %>
76+
77+
The `submodule_git_url` identifies the location of the submodule repository, and the `sha` identifies a specific commit within the submodule repository.
78+
Git uses the given URL when cloning the submodule repository, and checks out the submodule at that specific commit.
79+
80+
If the submodule repository is not hosted on github.com, the Git URLs (`git_url` and `_links["git"]`) and the github.com URLs (`html_url` and `_links["html"]`) will have null values.
81+
7282
## Get archive link
7383

7484
This method will return a `302` to a URL to download a tarball

lib/resources.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,23 @@ def text_html(response, status, head = {})
10211021
},
10221022
}
10231023

1024+
SUBMODULE_CONTENT = {
1025+
"type" => "submodule",
1026+
"submodule_git_url" => "git://github.com/jquery/qunit.git",
1027+
"size" => 0,
1028+
"name" => "qunit",
1029+
"path" => "test/qunit",
1030+
"sha" => "6ca3721222109997540bd6d9ccd396902e0ad2f9",
1031+
"url" => "https://api.github.com/repos/jquery/jquery/contents/test/qunit?ref=master",
1032+
"git_url" => "https://api.github.com/repos/jquery/qunit/git/trees/6ca3721222109997540bd6d9ccd396902e0ad2f9",
1033+
"html_url" => "https://github.com/jquery/qunit/tree/6ca3721222109997540bd6d9ccd396902e0ad2f9",
1034+
"_links" => {
1035+
"git" => "https://api.github.com/repos/jquery/qunit/git/trees/6ca3721222109997540bd6d9ccd396902e0ad2f9",
1036+
"self" => "https://api.github.com/repos/jquery/jquery/contents/test/qunit?ref=master",
1037+
"html" => "https://github.com/jquery/qunit/tree/6ca3721222109997540bd6d9ccd396902e0ad2f9"
1038+
}
1039+
}
1040+
10241041
DIRECTORY_CONTENT = [
10251042
{
10261043
"type" => "file",
87.1 KB
Loading

0 commit comments

Comments
 (0)