Skip to content
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

Closed
wants to merge 2 commits into from
Closed

Use GitHub/GitLab API to get a repo readme #160

wants to merge 2 commits into from

Conversation

cristiand391
Copy link
Contributor

@cristiand391 cristiand391 commented Oct 3, 2020

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.

@cristiand391 cristiand391 marked this pull request as ready for review October 8, 2020 02:01
@muesli
Copy link
Contributor

muesli commented Oct 27, 2020

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)

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

Suggested change
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 {

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

Suggested change
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, "/")

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.

@cristiand391 cristiand391 deleted the github-gitlab-api branch March 2, 2021 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants