Rob*_*Lin 5 github github-issues
我一直在查看GitHub 文档,但没有找到maximum
任何地方指定的数字。
我刚刚使用 GitHub API 向存储库添加标签进行了测试:我能够添加超过一万个标签,而不会出现任何错误。
由于GitHub API只允许一次添加一个标签,所以这个过程有点耗时,并且在此过程中我两次达到API 速率限制,所以我在达到第二个速率限制后结束了测试,此时有10,501 个标签已添加到存储库中,而且我还可以添加更多标签。
以下是在 Python 中重现实验的方法:
PyLinks
用于与 GitHub API 通信(免责声明:我是作者):pip install pylinks
Run Code Online (Sandbox Code Playgroud)
import pylinks
import itertools
GITHUB_USERNAME = "YOUR GITHUB USERNAME HERE"
GITHUB_REPO = "YOUR GITHUB REPOSITORY NAME HERE"
PAT = "YOUR PERSONAL ACCESS TOKEN HERE"
NUM_LABELS = 11000 # Number of labels to add to the repo
def create_unique_strings(n):
"""Generate n unique strings with the minimum possible length
by using combinations of lowercase letters.
"""
# Limiting the characters to lowercase to ensure the strings are as short as possible
characters = 'abcdefghijklmnopqrstuvwxyz'
# Start with the shortest possible strings (length 1)
length = 1
# List to store the unique strings
unique_strings = []
while len(unique_strings) < n:
# Generate all combinations of the current length
for s in itertools.product(characters, repeat=length):
unique_string = ''.join(s)
unique_strings.append(unique_string)
if len(unique_strings) == n:
break
# Increase the length for the next iteration
length += 1
return unique_strings
gh_api = pylinks.api.github(PAT).user(GITHUB_USERNAME).repo(GITHUB_REPO)
labels = create_unique_strings(NUM_LABELS)
for label in labels:
gh_api.label_create(label)
Run Code Online (Sandbox Code Playgroud)
正如我所提到的,每次大约之后您都会受到速率限制的影响。5000 个标签,因此您每次都必须等待一段时间才能继续剩余的标签。
我还测试了可以向一个问题/拉取请求添加多少个标签:有一个最大限制。100 个标签。要重现此情况,请将以下代码添加到上面的脚本中:
ISSUE_OR_PR_NUMBER = 123 # The number of an existing issue/pr in the repository
gh_api.issue_labels_set(ISSUE_OR_PR_NUMBER, unique_strings[:100]) # This will pass
gh_api.issue_labels_set(ISSUE_OR_PR_NUMBER, unique_strings[:101]) # This will fail with status code 422 and reason 'Unprocessable Entity'
Run Code Online (Sandbox Code Playgroud)