gosrc: use default branch for GitHub presentations

At present, gosrc assumes that GitHub presentations always store their
files in master branch. If a GitHub repo has a non-master default
branch, then although the presentation file itself is fetched from that
branch, all the files will be retrieved from master, which is a
confusing behaviour.

This change looks up which branch is selected as the default branch, at
the cost of an extra API call against GitHub when a presentation is
fetched.

Related to #482, although this change merely makes talksapp respect the
default branch, without allowing specification of a particular branch in
the URL.

Change-Id: Ic78f9e86e68696463cb15175d7b133252abf9917
Reviewed-on: https://go-review.googlesource.com/42653
Reviewed-by: Francesc Campoy Flores <campoy@golang.org>
diff --git a/gosrc/github.go b/gosrc/github.go
index e107496..6445327 100644
--- a/gosrc/github.go
+++ b/gosrc/github.go
@@ -203,6 +203,14 @@
 func getGitHubPresentation(client *http.Client, match map[string]string) (*Presentation, error) {
 	c := &httpClient{client: client, header: gitHubRawHeader}
 
+	var repo struct {
+		DefaultBranch string `json:"default_branch"`
+	}
+	if _, err := c.getJSON(expand("https://api.github.com/repos/{owner}/{repo}", match), &repo); err != nil {
+		return nil, err
+	}
+	branch := repo.DefaultBranch
+
 	p, err := c.getBytes(expand("https://api.github.com/repos/{owner}/{repo}/contents{dir}/{file}", match))
 	if err != nil {
 		return nil, err
@@ -212,7 +220,7 @@
 	if err != nil {
 		return nil, err
 	}
-	rawBase, err := url.Parse(expand("https://raw.github.com/{owner}/{repo}/master{dir}/", match))
+	rawBase, err := url.Parse(expand("https://raw.githubusercontent.com/{owner}/{repo}/{0}{dir}/", match, branch))
 	if err != nil {
 		return nil, err
 	}