克服公共项目中的GitHub API速率限制? [英] Overcoming GitHub API Rate-Limiting from a Public Project?

查看:205
本文介绍了克服公共项目中的GitHub API速率限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个公共存储库,它是Ansible角色.这个Ansible角色使用GitHub API,以获取给定存储库的最新版本.我使用此元数据以便随后为给定项目下载最新版本的二进制文件.

I have a public repository which is an Ansible role. This Ansible role uses the GitHub API in order to get the most recent release for a given repository. I use this metadata in order to then subsequently download the latest release binary for the given project.

不幸的是,当我在Travis中运行测试,偶尔在本地计算机上运行测试时,我遇到了GitHub的API速率限制.既然这是一个面向公众的项目,那么克服此速率限制有什么选择?

Unfortunately, I'm hitting GitHub's API rate-limit when running my tests in Travis and occasionally on my local machine. Since this is a public-facing project, what are my options for overcoming this rate limit?

可以在Ansible中使用某种秘密管理系统,还是可以通过Travis环境变量公开其值,但是是否存在处理此类公共代码场景的标准做法?

I could use some kind of secret management system in Ansible or expose the value via Travis environment variables, but is there a standard practice for dealing with these kinds of scenarios for public code?

推荐答案

未经身份验证的请求每小时仅可获取60个请求.经过身份验证的请求每小时可获得5000个请求.

Unauthenticated requests only get 60/hour. Authenticated requests get 5000/hour.

要进行身份验证,请生成供项目使用的个人API访问令牌.将其放在加密的Travis环境变量中或其他存储加密机密的方式(例如,Rails内置了加密的凭据.使用该令牌访问API.

To authenticate, generate a personal API access token for use by the project. Put it either in an encrypted Travis environment variable or some other way to store encrypted secrets (for example, Rails has built in encrypted credentials. Use that token to access the API.

为该项目创建一个单独的Github帐户,并为此使用API​​令牌.这样可以避免与其他任何人共享其速率限制.

Make a separate Github account for the project and use an API token for that. This avoids sharing its rate limit with anyone else.

在可能的情况下在本地克隆上使用Git命令.例如,如果您要查找提交而不是通过API进行提交,克隆存储库并使用普通的Git命令.定期缓存克隆和git fetch以使其保持最新状态.

Use Git commands on a local clone where possible. For example, if you want to look up a commit instead of doing it via the API, clone the repository and use normal Git commands. Cache the clones and git fetch periodically to keep them up to date.

最后,利用条件请求.这些使用HTTP标头,因此您可以安全地使用缓存的查询.这些不计入您的速率限制.好的Github身份验证库应具有用于缓存的选项.

Finally, make use of conditional requests. These use HTTP headers so you can safely use cached queries. These do not count against your rate limit. A good Github authentication library should have an option for caching.

这篇关于克服公共项目中的GitHub API速率限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆