我正在尝试通过 REST 使用 GitHub V3 API 分叉一个存储库,但是,我在按照文档发出 POST 请求时遇到问题(https://developer.github.com/v3/repos/forks/#create-一把叉子)。
基本上,到目前为止我所拥有的:
https://api.github.com/repos/carmichaelalonso/infiniteflight/forks/- 我首先使用 hurl.it 对此进行测试。Authorization值为“token ...”,另一个标头的Content-Type值指定application/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)
我不确定我是否能够将其分叉给标准用户,或者这是否是我的请求的错误。如果我可以提供更多信息,请告诉我(这里是第一篇文章,所以对惯例有点不熟悉)。谢谢!
我正在尝试在我以编程方式创建的 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,但我不知道如何检查。
有什么线索吗?谢谢 !
我有以下脚本,我正在尝试在 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) GitHub API提供了很多功能,但是有没有办法检索提交的构建状态?GitHub UI 提供了我们配置的 CI 系统的信息,但我看不到通过 API 公开的这些信息?
我认为Github API 的更新文件方法可用于重命名文件(通过提供新路径作为参数),但它似乎不起作用。
重命名的唯一方法是删除该文件并使用新名称创建一个类似的文件?
我正在尝试将少数存储库的代码自动导出code.google.com到 GitHub(在它们在下个月消失之前!)。
以下是执行此操作的手动过程(例如 repo foo):
https://code.google.com/export-to-github/request-export/foo
https://github.com/loginhttps://code.google.com/export-to-github/start-export/foo
code和statehttps://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) 我使用以下方法进行了基本身份验证:
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) 我正在尝试识别包含特定提交的所有标签。使用 git 命令工具,可以通过以下方式完成此操作:
git tag --contains <commit>
Run Code Online (Sandbox Code Playgroud)
但是,我需要对多个存储库执行此操作,因此我希望依赖 REST API。有没有办法通过 GitHub 的 REST 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 的问题吗?
塔。