我将给出一个 GitHub GraphQL API 的具体示例(这是我想要解决的特定问题),但这个问题似乎可以概括为 GraphQL。
假设我想为存储库 pytorch/pytorch 上的问题 #1234 添加“高优先级”标签。根据API文档,我应该使用突变https://developer.github.com/v4/mutation/addlabelstolabelable/输入要求:
labelIds ([ID!]!)
The ids of the labels to add.
labelableId (ID!)
The id of the labelable object to add labels to.
Run Code Online (Sandbox Code Playgroud)
好的,请问如何获取 ID?在我的代码中,我知道我想要标签“高优先级”,但为了实际将其传达给此突变,我必须首先将“高优先级”解析为 ID,但首先执行另一个 GraphQL 调用。我想要标记的内容也是如此:我有一个 pytorch/pytorch#1234 形式的唯一标识符,但我没有 ID,我必须查找它。)
因此,在一天结束时,我必须执行3 个API 调用来标记某些内容,而我本可以在 REST 中完成,而不是通过一次调用来完成。一般来说,我看到很多 GraphQL 突变 API 只在 ID 中进行交互(即使系统有其他可用的规范标识符),我最终不得不进行额外的往返。我做错了吗?或者这确实是 GraphQL 的设计方式吗?
我正在尝试使用个人访问令牌来访问存储库的内容。
如果存储库是公共的,我可以使用 v3 和 v4 api 来实现这一点。以下两个请求都返回内容:
v3:
curl https://api.github.com/repos/w3c/webappsec/contents/
Run Code Online (Sandbox Code Playgroud)
v4:
query {
repository(owner: "w3c", name: "webappsec") {
object(expression: "master:") {
... on Tree {
entries{
name
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在我已经生成了一个个人访问令牌,用于在我的一个私人存储库中执行此操作,但它永远不会返回任何内容:
v3(带有授权令牌):
curl -H "Authorization: bearer myauthorizationtoken" https://api.github.com/repos/myusername/myrepo/contents/
Run Code Online (Sandbox Code Playgroud)
结果:
{
"message": "Not Found",
"documentation_url": "https://developer.github.com/v3/repos/contents/#get-contents"
}
Run Code Online (Sandbox Code Playgroud)
v4(带有授权令牌):
query {
repository(owner: "myusername", name: "myrepo") {
object(expression: "master:") {
... on Tree {
entries{
name
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
结果:
{
"data": {
"repository": {
"object": …Run Code Online (Sandbox Code Playgroud) 我们希望通过 REST API 获取两个 GitLab/GitHub 分支之间的差异。我们看到 Git 支持执行此操作的命令,但似乎它们不支持 REST API。有API支持吗?
git diff --name-status firstbranch..yourBranchName
git diff --name-status origin/develop..origin/master
Run Code Online (Sandbox Code Playgroud)
我可以获得该项目,但它没有检索该Social Preview项目的:
我正在使用的链接是这个:
https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD
返回以下内容:
{
"id": 215636067,
"node_id": "MDEwOlJlcG9zaXRvcnkyMTU2MzYwNjc=",
"name": "BCMIC-PHD",
"full_name": "AngelRibeiro10/BCMIC-PHD",
"private": false,
"owner": {
"login": "AngelRibeiro10",
"id": 13433634,
"node_id": "MDQ6VXNlcjEzNDMzNjM0",
"avatar_url": "https://avatars2.githubusercontent.com/u/13433634?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/AngelRibeiro10",
"html_url": "https://github.com/AngelRibeiro10",
"followers_url": "https://api.github.com/users/AngelRibeiro10/followers",
"following_url": "https://api.github.com/users/AngelRibeiro10/following{/other_user}",
"gists_url": "https://api.github.com/users/AngelRibeiro10/gists{/gist_id}",
"starred_url": "https://api.github.com/users/AngelRibeiro10/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/AngelRibeiro10/subscriptions",
"organizations_url": "https://api.github.com/users/AngelRibeiro10/orgs",
"repos_url": "https://api.github.com/users/AngelRibeiro10/repos",
"events_url": "https://api.github.com/users/AngelRibeiro10/events{/privacy}",
"received_events_url": "https://api.github.com/users/AngelRibeiro10/received_events",
"type": "User",
"site_admin": false
},
"html_url": "https://github.com/AngelRibeiro10/BCMIC-PHD",
"description": "This is a Brain-Computer Music Interfacing Project",
"fork": false,
"url": "https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD",
"forks_url": "https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD/forks",
"keys_url": "https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD/teams",
"hooks_url": …Run Code Online (Sandbox Code Playgroud) 我想使用 GraphQL 突变删除 github 分支,但我还没有找到有关该deleteRef命令的足够信息。使用GraphQL 浏览器我想出了这个废话:
mutation {
deleteRef(input: {refId: "my-branch"}) {
__typename
}
}
Run Code Online (Sandbox Code Playgroud)
我还不知道如何添加存储库信息以使突变具有任何意义,我添加的唯一原因__typename是该deleteRef块不能留空。我该如何修复这个突变?
我正在寻找一种使用 GitHub API 从特定提交哈希读取文件内容的方法。官方文档中\xe2\x80\x99s写道,refs是commits/branch/tags,用于从特定提交中获取特定文件的内容。\n https://developer.github.com/v3/存储库/内容/#get-contents
\n\n但端点返回 404。我有存储库的访问令牌和授权。提交哈希也是正确的,我用 git log 验证了它。
\n\n对此有不同的解决方案吗?
\n今天,我在使用 GitHub API 时遇到了每小时 60 次调用的障碍,如此处所述 - https://developer.github.com/v3/rate_limit/
对于命令行测试,解决方案是使用 PAT - https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token
我是新学习者,但 GitHub 文档有点令人困惑,所以我跑了很多地方。Github 推荐以下 CURL 用法
curl -u GitHubUserName:personalaccesstoken https://api.github.com/users/GitHubUserName
Run Code Online (Sandbox Code Playgroud)
但是,在获取请求中使用它是一个挑战,因为在如何使用事物的管道中存在许多折旧。
那么,问题是,如何最好地在 Node JS 和 React JS 中的简单 fetch 调用中使其工作?
Github APIv4 GraphQL 有一些很好的功能,但我找不到使用分页来搜索问题的方法,例如
https://api.github.com/search/issues?q=repo:user/somerepo+is:open&page=10&per_page=100
Run Code Online (Sandbox Code Playgroud)
有办法解决吗?谢谢!
如何从curl 或github cli 创建webhook?
这个文档。没有多大帮助: https://docs.github.com/en/rest/reference/repos#create-a-repository-webhook--code-samples
尝试过这个:
curl -u <user>:<token>\
-X POST \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/<org>/<repo>/hooks \
-d '{"name":"name"}'
Run Code Online (Sandbox Code Playgroud)
给我留下了疑问:
-d '{"name":"name"}'错误:
{
"message": "Validation Failed",
"errors": [
{
"resource": "Hook",
"code": "custom",
"message": "Config must contain URL for webhooks"
}
],
"documentation_url": "https://docs.github.com/rest/reference/repos#create-a-repository-webhook"
}
Run Code Online (Sandbox Code Playgroud) 我正在使用该github-script操作来使用一些 javascript 来完成工作流程中的某些任务。
workflow_dispatch例如,如果我使用带有触发器的工作流程,我可以通过 获取其输入context.payload.inputs。
我正在利用可重用的工作流程,因此我有一个带有workflow_call触发器的工作流程,然后是另一个通过 调用该工作流程的工作流程jobs.<job>.uses。
在工作流文件中使用模板时,workflow_dispatch输入的引用方式与 a 类似${{ github.event.inputs.<input_name> }},但要将输入引用到 a workflow_call,我们只需使用${{ inputs.<input_name> }}. 在对值进行模板化时一切都很好,没有问题,但我想知道如何inputs从 JS 中直接获取该上下文。我似乎找不到它,也找不到任何例子。
以下是一些要演示的片段:
workflow_dispatch例子---
name: scripty
on:
workflow_dispatch:
inputs:
dummy:
required: false
description: dummy
jobs:
scripty:
runs-on: ubuntu-latest
steps:
- name: script
id: script
uses: actions/github-script@v5
with:
script: |
var dummy = context.payload.inputs.dummy
return {
context: context,
github: …Run Code Online (Sandbox Code Playgroud) github-api ×10
github ×5
graphql ×2
curl ×1
fetch ×1
git ×1
github-cli ×1
gitlab-api ×1
node.js ×1
rest ×1