[英]Github REST API … go-github seems to lack features in PyGithub?
I have a working script that accesses the Github REST API (v3) to (a) submit a search query and get results, and then (b) iterate through search results to download individual source code files for more processing.我有一个工作脚本,它访问 Github REST API (v3) 以 (a) 提交搜索查询并获取结果,然后 (b) 遍历搜索结果以下载单个源代码文件以进行更多处理。
The original script uses Python + PyGithub, and I am trying to port it to Go + go-github.原始脚本使用 Python + PyGithub,我正在尝试将其移植到 Go + go-github。
Here is a snippet of the Python:这是 Python 的一个片段:
g = Github(base_url=GITHUB_ENTERPRISE_URL, login_or_token=token)
def search_github(keywords):
result = g.search_code(keywords)
for repo in result:
response = requests.get(repo.download_url)
matched = re.findall(regular_expression, response.text)
for match in matched:
print(match)
The go-github equivalent of g.search_code(keywords)
works well, ... but I cannot find anything equivalent to repo.download_url
.与g.search_code(keywords)
等效的 go-github 运行良好,...但我找不到与repo.download_url
等效的任何repo.download_url
。 Here is what go-github provides for a Code Search Result, ... no "download url".这是 go-github 为代码搜索结果提供的内容,...没有“下载 url”。
// CodeResult represents a single search result.
type CodeResult struct {
Name *string `json:"name,omitempty"`
Path *string `json:"path,omitempty"`
SHA *string `json:"sha,omitempty"`
HTMLURL *string `json:"html_url,omitempty"`
Repository *Repository `json:"repository,omitempty"`
TextMatches []*TextMatch `json:"text_matches,omitempty"`
}
I would be surprised if the go-github library is an incomplete implementation of the Github REST API, ... but I cannot find how to get the "download url" associated with a search result, so I can download the actual source code file?如果 go-github 库是 Github REST API 的不完整实现,我会感到惊讶……但我找不到如何获取与搜索结果关联的“下载 url”,因此我可以下载实际的源代码文件?
Even after lots of googling, I was not able to find any example Go code that uses go-github and actually downloads search results files.即使经过大量的谷歌搜索,我也找不到任何使用 go-github 并实际下载搜索结果文件的示例 Go 代码。
I am stuck.我被困住了。 Any pointers appreciated.任何指针表示赞赏。
go-github : https://github.com/google/go-github去-github : https : //github.com/google/go-github
PyGithub : https://github.com/PyGithub/PyGithub PyGithub : https : //github.com/PyGithub/PyGithub
Github REST API : https://docs.github.com/en/rest Github REST API : https : //docs.github.com/en/rest
A GitHub API search code is supposed to return an " html_url
" field for each item found, like:GitHub API 搜索代码应该为找到的每个项目返回一个“ html_url
”字段,例如:
"html_url": "https://github.com/jquery/jquery/blob/825ac3773694e0cd23ee74895fd5aeb535b27da4/src/attributes/classes.js",
That alone should be enough to download a found item.仅此一项就足以下载找到的项目。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.