根据 github API 的文档 - https://developer.github.com/v3/repos/contents/来获取存储库或文件的内容,我应该使用GET /repos/:owner/:repo/contents/:path
基于此,如果我想获取此存储库中的 package.json 文件的内容 - https://github.com/fastly/epoch/tree/master(此存储库仅用于示例),我应该这样做"/repos/fastly/epoch/contents/package.json"。这直接获取master上的package.json文件的内容。
但是就我而言,我想从标签之一获取 package.json 文件的内容,即 -https://github.com/fastly/epoch/tree/0.6.0
我尝试了 github API 中可用的标签和树的任何内容,但这里没有任何帮助 - https://developer.github.com/v3/git/trees/和https://developer.github.com/v3/git/标签/
如何获取标记分支下的文件内容?
我试图运行一个条件来基本上查看对象是否为空,但我不断收到此错误(类似的变体):
invalid operation: release.Name == "" (mismatched types *string and string)
Run Code Online (Sandbox Code Playgroud)
这是即将消亡的代码:
import (
"github.com/google/go-github/github"
)
func TestLatestTag(user, project string) {
var client *github.Client
client = github.NewClient(nil)
releases, _, err := client.Repositories.ListTags(user, project, nil)
var release github.RepositoryTag
if err != nil {
fmt.Println("Error")
} else {
if release.Name == "" {
fmt.Println("None")
} else {
fmt.Println(releases[0])
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果我将 if 语句更改为*release.Name == ""错误所暗示的那样,我会得到一个不同的错误,我不太明白:
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 …Run Code Online (Sandbox Code Playgroud) 有没有办法通过 github api 来做到这一点?我尝试过 api.github.com/repos/name/repo/contents/path
但我对内容和路径的内容有点困惑。如果它对我试图获取的文件有帮助,则该文件存在于存储库的根目录中。所以这是我正在寻找的 ./fileName 。我将如何构建 GET url(除非我做对了,还有其他一些问题)
我查看了文档,可以看到 Github UI 可以获取链接到里程碑的 PR 列表,例如/https://github.com/NancyFx/Nancy/milestone/48但是如何从 API 中做到这一点?
您可以通过 API 访问里程碑,例如/https://api.github.com/repos/X/Y/milestones/1但它不包含其 PR 或提供获取 PR 的链接
我按照这篇文章在我的 django 应用程序中获取社交登录。它运行良好,但对于 github 用户,即使我添加,我也无法获取用户电子邮件
SOCIAL_AUTH_GITHUB_SCOPE = ['email']
Run Code Online (Sandbox Code Playgroud)
我应该在文章示例中更改哪些内容才能获取用户电子邮件?
我正在寻找获取提交的作者/贡献者的方法。我对 github-api 真的很陌生,这给我带来的麻烦比我想象的要多。
问题描述
如果我有这样的文件的 URL ,是否有 github API 可以向我显示已提交该文件的贡献者列表?
或者,我是否需要使用多个 API 调用的结果(例如)
I'm thinking of cross-referencing the outputs of those two^ if everything else fails.
这应该返回 Pratik855
我找到了这个答案,但这并不是我想要的。虽然满足了所有要求,但我不确定如何https://api.github.com/repos/csitauthority/csitauthority.github.io/commits?=README转换为https://api.github.com/repos/csitauthority/csitauthority.github.io/commits?=HUGO/content/page/vlan-101.md基于https://github.com/csitauthority/CSITauthority.github.io/blob/master/HUGO/content/post/vlan-101.md,因为 HUGO 只能生成第三种规范 URL。
我正在尝试在我公司的企业 github 服务器上下载存储库的版本。我有带有 OAuth 令牌的正确授权标头,并且能够获取发布端点的响应。这个特定的存储库包含源代码的 zip 和 tarball 以及已编译的可执行文件。我正在尝试下载构建的可执行文件。发布请求的响应如下所示,其中包含感兴趣的密钥browser_download_url中的密钥。assets
{
"url": "***/releases/1491",
"assets_url": "***/releases/1491/assets",
"upload_url": "***/releases/1491/assets{?name,label}",
"html_url": "***/releases/tag/1.0.6",
"id": 1491,
"tag_name": "1.0.6",
"target_commitish": "release-1.0.6",
"name": "1.0.6",
"draft": false,
"prerelease": true,
"created_at": "2017-10-03T15:51:25Z",
"published_at": "2017-10-10T16:54:16Z",
"assets": [
{
"url": "***/releases/assets/53",
"id": 53,
"name": "<program>.exe",
"label": null,
"content_type": "application/x-msdownload",
"state": "uploaded",
"size": 36023208,
"download_count": 10,
"created_at": "2017-10-10T17:40:32Z",
"updated_at": "2017-10-10T17:40:32Z",
"browser_download_url": "***/1.0.6/<program>.exe"
}
],
"tarball_url": "***/tarball/1.0.6",
"zipball_url": "***/zipball/1.0.6",
"body": "<description of release>"
}
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试请求时,browser_download_url我会在响应内容中获取登录页面的 html,因为它正在寻找进一步的身份验证。
response = session.get(release_endpoint_response.json()['assets'][0]['browser_download_url'], …Run Code Online (Sandbox Code Playgroud) user使用查询时,GitHub API v4 不会显示公司的结果。如果我使用repositoryOwner它,它会返回用户和公司的结果。但是,user查询可以返回更详细的信息,例如传记、网站、位置等,这些信息不包含在repositoryOwner。
是否有覆盖所有类型用户的替代选项?
我正在使用 Github 的 GraphQL (v4) API 进行一些调用。我正在尝试获取有关存储库的提交信息,但在定义对象连接的since属性时遇到问题。historyCommit
我收到以下错误:
{
"data": null,
"errors": [
{
"message": "Argument 'since' on Field 'history' has an invalid value. Expected type 'GitTimestamp'.",
"locations": [
{
"line": 38,
"column": 9
}
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
这是我的 GraphQL 中提取的导致错误的部分:
query {
search(query:"is:public", type:REPOSITORY, first:10){
edges{
node{
... on Repository{
ref(qualifiedName: "master"){
target{
... on Commit{
history(first: 10, since:"2017-07-15"){
totalCount
pageInfo{
startCursor
endCursor
}
edges{
node{
... on Commit{
committedDate
}
}
}
} …Run Code Online (Sandbox Code Playgroud) 我想让用户使用 github 登录我的网络应用程序(之后我可以使用他们的姓名/电子邮件等),就像您可以使用 Google 或 Facebook 登录 stackoverflow 一样。我知道你必须让用户登录 github,一旦他们验证了你的应用程序,你就可以从用户重定向到的页面的 url 中检索代码,并使用该代码发出 POST 请求来获取访问权限代码,您可以使用它来访问 github API。但是,当我对访问代码发出 POST 请求时,出现 CORS 错误:
无法加载https://github.com/login/oauth/access_token?client_id=7...&client_secret=b...&code=f ...:对预检请求的响应未通过访问控制检查:否' Access-Control-Allow-Origin'标头存在于所请求的资源上。因此,不允许访问来源“ http://localhost ”。
响应的 HTTP 状态代码为 404。
这是我的 POST 请求:
$.ajax (
{
url:"https://github.com/login/oauth/access_token?client_id=7...&client_secret=b...&code=" + authCode, // Extraction of authCode has no bugs
type:'POST',
dataType:'json',
success: function() {
alert('success');
},
error: function() {
alert('error');
}
});
Run Code Online (Sandbox Code Playgroud)
如何纠正此问题以便集成登录?
编辑:我无法使用像网守这样的外部应用程序。这是一个测试网站,但最终将用于公司网站。