微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Github REST API ... go-github 似乎缺少 PyGithub 中的功能?

如何解决Github REST API ... go-github 似乎缺少 PyGithub 中的功能?

我有一个可访问 Github REST API (v3) 的工作脚本,以 (a) 提交搜索查询获取结果,然后 (b) 遍历搜索结果以下载单个源代码文件以进行更多处理。>

原始脚本使用 Python + PyGithub,我正在尝试将其移植到 Go + go-github。

这是 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)

g.search_code(keywords) 等效的 go-github 运行良好,...但我找不到与 repo.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"`
}

如果 go-github 库是 Github REST API 的不完整实现,我会感到惊讶……但我找不到如何获取搜索结果关联的“下载 url”,因此我可以下载实际的源代码文件

即使经过大量谷歌搜索,我也找不到任何使用 go-github 并实际下载搜索结果文件的示例 Go 代码

我卡住了。任何指针表示赞赏。

go-githubhttps://github.com/google/go-github

PyGithubhttps://github.com/PyGithub/PyGithub

Github REST APIhttps://docs.github.com/en/rest

解决方法

GitHub API search code 应该为找到的每个项目返回一个“html_url”字段,例如:

"html_url": "https://github.com/jquery/jquery/blob/825ac3773694e0cd23ee74895fd5aeb535b27da4/src/attributes/classes.js",

仅此一项就足以下载找到的项目。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。