Skip to content

Commit 33b75c1

Browse files
committed
ISSUE-9 Add support for branch "main"
1 parent 62efb23 commit 33b75c1

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

internal/package/fetcher/fetcher.go

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,20 @@ import (
1212
"time"
1313
)
1414

15-
const AWESOMEREPOURL = "https://github.com/sindresorhus/awesome/"
15+
const AWESOMEREPOURL = "https://github.com/sindresorhus/awesome"
1616
const AWESOMECACHEFOLDER = ".awesomecache"
1717
const RAWGITHUBUSERCONTENT = "https://raw.githubusercontent.com"
1818

19+
var BRANCHES = []string{"/master/", "/main/"}
20+
var README_PATTERNS = []string{
21+
"README",
22+
"README.MD",
23+
"README.md",
24+
"readme",
25+
"readme.md",
26+
"readme.MD",
27+
}
28+
1929
func FetchAwsomeRootRepo() (string, error) {
2030
return FetchAwsomeRepo(AWESOMEREPOURL)
2131
}
@@ -53,9 +63,8 @@ func FetchAwsomeRepo(repourl string) (string, error) {
5363
continue
5464
}
5565

56-
defer response.Body.Close()
57-
5866
responseData, err := ioutil.ReadAll(response.Body)
67+
response.Body.Close()
5968

6069
if err != nil {
6170
log.Println(err)
@@ -81,16 +90,17 @@ func GetPossibleReadmeFileURLs(repourl string) []string {
8190
return []string{}
8291
}
8392

84-
prefix := RAWGITHUBUSERCONTENT + u.Path + "/master/"
93+
prefix := RAWGITHUBUSERCONTENT + u.Path
8594

86-
return []string{
87-
prefix + "README",
88-
prefix + "README.MD",
89-
prefix + "README.md",
90-
prefix + "readme",
91-
prefix + "readme.md",
92-
prefix + "readme.MD",
95+
var ret []string
96+
97+
for _, br := range BRANCHES {
98+
for _, readme := range README_PATTERNS {
99+
ret = append(ret, prefix+br+readme)
100+
}
93101
}
102+
103+
return ret
94104
}
95105

96106
func GetCachePath(url string) string {

0 commit comments

Comments
 (0)