github - Github rest api post label 给出数组输入错误
问题描述
我们正在托管 GitHub 企业进行开发。我能够访问重置 api 并创建 jira、创建 PR 等。
当我尝试将标签添加到我的 PR 时,它会给出数组错误。
curl -X POST -u githuser:gittoken https://api.github.mycompany.com/repos/team/repo/issues/560/labels -H "Content-type: application/json" -k -d '{"labels": ["bug"]}' -H "Accept: application/json"
{
"message": "Invalid request.\n\nFor 'links/2/schema', {\"labels\"=>[\"bug\"]} is not an array.",
"documentation_url": "https://developer.github.com/enterprise/2.13/v3/issues/labels/#add-labels-to-an-issue"
}
我检查,bug
是有效的标签。
curl -u githuser:gittoken -X GET \
https://api.github.mycompany.com/repos/team/repo/labels
[
{
"id": 163461,
"url": "https://github.mycompany.com/api/v3/repos/team/repo/labels/+1",
"name": "+1",
"color": "c2e0c6",
"default": false
},
{
"id": 382069,
"url": "https://github.mycompany.com/api/v3/repos/team/repo/labels/Blocked",
"name": "Blocked",
"color": "fbca04",
"default": false
},
{
"id": 163462,
"url": "https://github.mycompany.com/api/v3/repos/team/repo/labels/Changes%20Requested",
"name": "Changes Requested",
"color": "cc317c",
"default": false
},
{
"id": 404926,
"url": "https://github.mycompany.com/api/v3/repos/team/repo/labels/Release%20Review",
"name": "Release Review",
"color": "5319e7",
"default": false
},
{
"id": 228780,
"url": "https://github.mycompany.com/api/v3/repos/team/repo/labels/Review%20Pass",
"name": "Review Pass",
"color": "009800",
"default": false
},
{
"id": 228781,
"url": "https://github.mycompany.com/api/v3/repos/team/repo/labels/Review%20Requested",
"name": "Review Requested",
"color": "eb6420",
"default": false
},
{
"id": 426113,
"url": "https://github.mycompany.com/api/v3/repos/team/repo/labels/Staging%20Bug",
"name": "Staging Bug",
"color": "d6021a",
"default": false
},
{
"id": 163457,
"url": "https://github.mycompany.com/api/v3/repos/team/repo/labels/bug",
"name": "bug",
"color": "fc2929",
"default": true
},
{
"id": 163458,
"url": "https://github.mycompany.com/api/v3/repos/team/repo/labels/duplicate",
"name": "duplicate",
"color": "cccccc",
"default": true
},
{
"id": 163459,
"url": "https://github.mycompany.com/api/v3/repos/team/repo/labels/enhancement",
"name": "enhancement",
"color": "84b6eb",
"default": true
},
{
"id": 163460,
"url": "https://github.mycompany.com/api/v3/repos/team/repo/labels/help%20wanted",
"name": "help wanted",
"color": "159818",
"default": true
},
{
"id": 163463,
"url": "https://github.mycompany.com/api/v3/repos/team/repo/labels/wontfix",
"name": "wontfix",
"color": "ffffff",
"default": true
}
]
我尝试了其他组合,例如仅字符串,带逗号的字符串等。但它的错误相同。
解决方案
Python 工作示例
import requests
url = f'https://api.github.com/repos/your/url/issues/{issue_number/pr_number}'
data = {"labels": [your_label/list_of_labels]}
requests.patch(url, auth=auth, json=data)
推荐阅读
- python - 从excel导入后如何在python中永久保存数据
- javascript - Rollup 将我的主类名 (SDK) 替换为 default() 名称
- java - 在整个对象上同步与在对象的特定字段上同步 - 这是一种更好的方法
- javascript - 调用 setState 后,当从维基百科复制文本时,Chrome 正在取消选择文本
- haskell - 对参数强制执行参数化
- c# - 为什么格式说明符“U”会改变 DateTime 的值?
- matlab - 使用函数句柄时,MATLAB cellfun 向量化速度很慢
- c++ - 将用户价值与枚举中的价值进行比较
- machine-learning - 如何为 2D 输入和输出创建深度学习模型?
- python - xarray.Dataset.weighted(...) 的问题