标签: github-api

使用 GitHub V3 API (REST) 创建分支

我正在尝试通过 REST 使用 GitHub V3 API 分叉一个存储库,但是,我在按照文档发出 POST 请求时遇到问题(https://developer.github.com/v3/repos/forks/#create-一把叉子)。

基本上,到目前为止我所拥有的:

  • 具有 OAuth 令牌的登录用户
  • 对 API (URL:) 的 POST 请求设置https://api.github.com/repos/carmichaelalonso/infiniteflight/forks/- 我首先使用 hurl.it 对此进行测试。
  • 请求中的标头:一个标头的名称Authorization值为“token ...”,另一个标头的Content-Type值指定application/json
  • 具有以下 JSON 的正文:{"organization" : "shortlisthome"}(shortlisthome 是我尝试将存储库分叉到的帐户。

我不打算将其分叉给一个组织,而不是一个标准用户帐户,这就是我感到困惑的地方。当我运行请求时,我没有收到任何身份验证错误或 404 错误(我以前有过,但我错误地输入了不正确的值,导致了此类错误)。

当我运行此请求时,我得到以下结果(422 无法处理的请求):

{
    "message": "Validation Failed",
    "documentation_url": "---url-to-docs---",
    "errors": [
        {
            "resource": "Fork",
            "code": "invalid",
            "field": "organization"
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

我不确定我是否能够将其分叉给标准用户,或者这是否是我的请求的错误。如果我可以提供更多信息,请告诉我(这里是第一篇文章,所以对惯例有点不熟悉)。谢谢!

api rest github github-api

5
推荐指数
1
解决办法
5821
查看次数

如何从 node.js 将资产上传到 github 版本

我正在尝试在我以编程方式创建的 Github 版本上自动发布一些资产。

这是我的上传功能:

function uploadFile(fileName, uploadUrl, callback){

  var uploadEndPoint = url.parse(uploadUrl.substring(0,uploadUrl.indexOf('{')));

  options.host = uploadEndPoint.hostname;
  options.path = uploadEndPoint.pathname+'?name=' + fileName;
  options.method = 'POST';
  options.headers['content-type'] = 'application/zip';

  var uploadRequest = https.request(options, callback);

  uploadRequest.on('error', function(e) {
    console.log('release.js - problem with uploadRequest request: ' + e.message);
  });

  var readStream = fs.ReadStream(path.resolve(__dirname,'builds',fileName));
  readStream.pipe(uploadRequest);

  readStream.on('close', function () {
    req.end();
    console.log('release.js - ' + fileName + ' sent to the server');
  });
}
Run Code Online (Sandbox Code Playgroud)

最后我得到 404 not found

我尝试从令牌和用户/密码进行身份验证

我检查了网址

我认为这可能是因为 SNI,但我不知道如何检查。

有什么线索吗?谢谢 !

node.js github-api

5
推荐指数
1
解决办法
1121
查看次数

Github API 的错误凭证

我有以下脚本,我正在尝试在 bash 中测试它,使用curl 做几件事,一是创建一个新的存储库,第二个 - 尚未实现 - 是从 json 中获取 git_url返回,我不确定我的parse_json函数是否允许我这样做,然后最终将示例提交消息推送到该存储库。

脚本如下:

#!/usr/bin/env bash

set -eux

# Json Function: parse_json 'json string' key
function parse_json()
{
    echo $1 | sed -e 's/[{}]/''/g' | awk -F=':' -v RS=',' "\$1~/\"$2\"/ {print}" | sed -e "s/\"$2\"://" | tr -d "\n\t" | sed -e 's/\\"/"/g' | sed -e 's/\\\\/\\/g' | sed -e 's/^[ \t]*//g' | sed -e 's/^"//'  -e 's/"$//'
}

git_create_repo() {
    read -e -p  "Please enter your API Key: " …
Run Code Online (Sandbox Code Playgroud)

git bash curl github github-api

5
推荐指数
1
解决办法
1万
查看次数

通过github api获取构建状态

GitHub API提供了很多功能,但是有没有办法检索提交的构建状态?GitHub UI 提供了我们配置的 CI 系统的信息,但我看不到通过 API 公开的这些信息?

github github-api

5
推荐指数
2
解决办法
3290
查看次数

使用 github api 重命名文件?

我认为Github API 的更新文件方法可用于重命名文件(通过提供新路径作为参数),但它似乎不起作用。

重命名的唯一方法是删除该文件并使用新名称创建一个类似的文件?

rename github-api

5
推荐指数
1
解决办法
3344
查看次数

如何通过curl获取GitHub OAuth2状态代码来模拟Web应用程序流程?

我正在尝试将少数存储库的代码自动导出code.google.com到 GitHub(在它们在下个月消失之前!)。

以下是执行此操作的手动过程(例如 repo foo):

  1. https://code.google.com/export-to-github/request-export/foo

    • 这重定向到https://github.com/login
  2. https://code.google.com/export-to-github/start-export/foo

    • 该表格应包括code和state
  3. https://code.google.com/export-to-github/confirm-export/foo

所以我的方法是使用start-export给定的and将表单提交到confirm-exportvia :curlcodestate

<form method="GET" action="/export-to-github/confirm-export/foo">
  <input type="text" hidden="true" name="code" value="GITHUB_CODE">
  <input type="text" hidden="true" name="state" value="FORM_STATE">
  <input class="maia-button" id="confirm-button" type="submit" value="Confirm" tabindex="1">
</form>
Run Code Online (Sandbox Code Playgroud)

我已经知道如何获取最后的表单状态:

curl -s https://code.google.com/export-to-github/start-export/foo | grep -o 'state.\+value=.[^"]\+' | grep -o '[^"]\+$'
Run Code Online (Sandbox Code Playgroud)

但我不知道如何code从 GitHub API 获取价值。

我的 GitHub 凭证存储为~/.secrets:

$ cat ~/.secrets 
export GITHUB_API_TOKEN=xyz
export GITHUB_CLIENT_ID=xyz
Run Code Online (Sandbox Code Playgroud)

它们可以通过以下方式加载:

. …
Run Code Online (Sandbox Code Playgroud)

shell curl oauth github-api access-token

5
推荐指数
1
解决办法
1051
查看次数

即使在基本身份验证后,Github API 速率也限制为 60

我使用以下方法进行了基本身份验证:

curl -u "username:password" https://api.github.com
Run Code Online (Sandbox Code Playgroud)

我得到输出:

{
  "current_user_url": "https://api.github.com/user",
  "current_user_authorizations_html_url": "https://github.com/settings/connections/applications{/client_id}",
  "authorizations_url": "https://api.github.com/authorizations",
  "code_search_url": "https://api.github.com/search/code?q={query}{&page,per_page,sort,order}",
  "emails_url": "https://api.github.com/user/emails",
  "emojis_url": "https://api.github.com/emojis",
  "events_url": "https://api.github.com/events",
  "feeds_url": "https://api.github.com/feeds",
  "followers_url": "https://api.github.com/user/followers",
  "following_url": "https://api.github.com/user/following{/target}",
  "gists_url": "https://api.github.com/gists{/gist_id}",
  "hub_url": "https://api.github.com/hub",
  "issue_search_url": "https://api.github.com/search/issues?q={query}{&page,per_page,sort,order}",
  "issues_url": "https://api.github.com/issues",
  "keys_url": "https://api.github.com/user/keys",
  "notifications_url": "https://api.github.com/notifications",
  "organization_repositories_url": "https://api.github.com/orgs/{org}/repos{?type,page,per_page,sort}",
  "organization_url": "https://api.github.com/orgs/{org}",
  "public_gists_url": "https://api.github.com/gists/public",
  "rate_limit_url": "https://api.github.com/rate_limit",
  "repository_url": "https://api.github.com/repos/{owner}/{repo}",
  "repository_search_url": "https://api.github.com/search/repositories?q={query}{&page,per_page,sort,order}",
  "current_user_repositories_url": "https://api.github.com/user/repos{?type,page,per_page,sort}",
  "starred_url": "https://api.github.com/user/starred{/owner}{/repo}",
  "starred_gists_url": "https://api.github.com/gists/starred",
  "team_url": "https://api.github.com/teams",
  "user_url": "https://api.github.com/users/{user}",
  "user_organizations_url": "https://api.github.com/user/orgs",
  "user_repositories_url": "https://api.github.com/users/{user}/repos{?type,page,per_page,sort}",
  "user_search_url": "https://api.github.com/search/users?q={query}{&page,per_page,sort,order}"
}
Run Code Online (Sandbox Code Playgroud)

之后我使用以下方法检查了限制:

curl https://api.github.com/rate_limit
Run Code Online (Sandbox Code Playgroud)

输出:

{
  "resources": {
    "core": {
      "limit": 60,
      "remaining": …
Run Code Online (Sandbox Code Playgroud)

github github-api

5
推荐指数
1
解决办法
1634
查看次数

GitHub REST API:git 标签 --contains

我正在尝试识别包含特定提交的所有标签。使用 git 命令工具,可以通过以下方式完成此操作:

git tag --contains <commit>
Run Code Online (Sandbox Code Playgroud)

但是,我需要对多个存储库执行此操作,因此我希望依赖 REST API。有没有办法通过 GitHub 的 REST API 收集相同的信息?

github github-api

5
推荐指数
1
解决办法
1842
查看次数

GitHub API - 如何确定文件是否实际上是符号链接?

通过 GitHub API 查询符号链接时,如果符号链接指向文件而不是目录,我会得到不同的结果。后者的表现更好,因为它"type": "symlink"作为 JSON 的一部分返回,而前者返回"type": "file". 示例文件符号链接,示例目录符号链接。

当符号链接将自己宣传为文件时,这是非常令人困惑的,因为 GET-ing 其下载 URL 只会为您提供符号链接的目标,而不是文件内容。

如何判断文件实际上是符号链接,而不是真实文件?

另外,为文件符号链接返回类型“file”的行为是一个彻头彻尾的错误吗?这看起来不太对劲。

rest github github-api

5
推荐指数
1
解决办法
520
查看次数

GitHub API - 如何添加管理员协作者?

我正在使用 github api (v3) 使用我的帐户在组织中创建存储库。我是该组织的管理员。然后,我使用协作者端点添加具有管理员权限的协作者。我正在使用具有“repos”范围的 oauth 令牌进行身份验证;

PUT /repos/:owner/:repo/collaborators/:username?permission=admin
Run Code Online (Sandbox Code Playgroud)

返回 204 让我相信 PUT 已经成功。但是,当我获取存储库协作者或使用 github UI 查看协作者时,我添加的用户仅具有写入权限。

如果我通过 UI 将用户设置为管理员并获取存储库协作者,则该用户拥有管理员权限。如果我再次执行 PUT,用户将恢复为仅具有写入权限。

谁能建议我在这里可能做错了什么,或者这是 GitHub API 的问题吗?

塔。

github-api

5
推荐指数
1
解决办法
4789
查看次数

标签 统计

github-api ×10

github ×6

curl ×2

rest ×2

access-token ×1

api ×1

bash ×1

git ×1

node.js ×1

oauth ×1

rename ×1

shell ×1