-
Notifications
You must be signed in to change notification settings - Fork 381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use GitHub/GitLab API to get a repo readme #160
Conversation
Thanks for your PR, @cristiand391! I'll try this out and review it asap! |
return nil, err | ||
} | ||
|
||
apiRepoURL := fmt.Sprintf("https://gitlab.com/api/v4/projects/%s%s%s", user, "%2F", repo) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be safe, this should probably be escaped.
Ref: url.PathEscape
apiRepoURL := fmt.Sprintf("https://gitlab.com/api/v4/projects/%s%s%s", user, "%2F", repo) | |
apiRepoURL := fmt.Sprintf("https://gitlab.com/api/v4/projects/%s", url.PathEscape(user + "/" + repo)) |
v.Path += "/raw/master/" + r | ||
repoInfo := gitLabRepo{} | ||
|
||
if err := json.Unmarshal([]byte(string(content)), &repoInfo); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is useless conversion as ioutil.ReadAll
already returns []byte
.
Ref: ioutil.ReadAll
if err := json.Unmarshal([]byte(string(content)), &repoInfo); err != nil { | |
if err := json.Unmarshal(content, &repoInfo); err != nil { |
return "", "", err | ||
} | ||
|
||
pathSplit := strings.Split(u.Path, "/") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is better to use path.Split
here as it will work on non-Unix systems as well.
Ref: #151 (comment)
This PR adds initial support for using the GitHub/GitLab public API to get a repo readme file.
TODO:Rate limiting:
The GitHub API allows up to 60 requests per hour, in the case the user exceeds the limit, how should Glow handle it?
GitLab allows up to 10 req per second so it shouldn't be a problem.