【问题标题】:Github API - add an issue to a project?Github API - 向项目添加问题?
【发布时间】:2022-01-15 06:07:24
【问题描述】:

是否可以使用 github API 将问题添加到项目板?

本文档: https://docs.github.com/en/rest/reference/projects#create-a-project-card 表明这是可能的,但我使用 https://github.com/fastai/ghapi 的尝试失败了。

我试过了:

api.projects.create_card(col.id, note=f'{issue.title} {issue.html_url}', content_id=issue.id)

但该卡不显示为问题卡,它显示为引用问题的卡 - 这是不同的。

我也试过了:

curl -X POST -H "Accept: application/vnd.github.v3+json" https://api.github.com/projects/columns/####/cards -d '{"column_id": colid, "content_id": cid, "content_type": "json"}' -u user:$GITHUB_TOKEN

这给出了一个错误:

{
  "message": "Validation Failed",
  "errors": [
    {
      "resource": "ProjectCard",
      "code": "unprocessable",
      "field": "data",
      "message": "Could not resolve to a node with the global id of 'XXXXXXXXXX'."
    }
  ],
  "documentation_url": "https://docs.github.com/v3/projects/cards/#create-a-project-card"
}

这表明我搞砸了 curl 请求,但我不确定在哪里。

【问题讨论】:

    标签: github-api


    【解决方案1】:

    我在https://stackoverflow.com/a/57696731/814354 之后找到了解决方案。我需要在 POST 请求中声明 content_type(这是我在 github 文档中找不到的信息)。

    CURL 版本:

    curl -X POST -H "Accept: application/vnd.github.v3+json" https://api.github.com/projects/columns/{column_id}/cards -d '{"column_id": {column_id}, "content_id": {issue_id}, "content_type": "Issue"}' -u {username}:$GITHUB_TOKEN
    

    ghapi版本不行:

    # this fails - `content_id` and  `content_type` are not included in the request
    api.projects.create_card(col.id, content_id=issue.id, content_type='Issue')
    

    但您仍然可以以更笨重的方式使用 ghapi:

    api(path=f'/projects/columns/{col.id}/cards', verb='POST',
        data={'content_id': issue.id,
              'column_id': col.id,
              'content_type': 'Issue'
             },
             headers={"Accept": "application/vnd.github.v3+json"}
          )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-16
      • 2015-10-28
      • 1970-01-01
      • 1970-01-01
      • 2021-10-17
      • 1970-01-01
      • 1970-01-01
      • 2023-02-12
      相关资源
      最近更新 更多