How to set an issue pipeline with ZenHub API

半腔热情 提交于 2019-12-11 02:39:46

问题


We use ZenHub with our enterprise GitHub installation. I'm writing a script to move issues from one GitHub repo to another, including the ZenHub info. I've gotten the issues copied, labels and milestones set. I then use the ZenHub API to set estimates and create epics. All that works fine. My final step is to assign the issues to ZenHub pipelines. The following works fine (to get info about an issue):

zenhub_headers = {"X-Authentication-Token": "%s" % zenhub_token}
url = '%s/p1/repositories/%d/issues/15' % (zenhub_endpoint, repo)
response = requests.get(url, headers=zenhub_headers, verify=False)

However, when I attempt to move the same issue to a pipeline with the following:

params = json.dumps({"pipeline_id": "5a36d8584b9b9e57bc9729f9"} )
zenhub_headers = {"X-Authentication-Token": "%s" % zenhub_token}
url = '%s/p1/repositories/%d/issues/15/moves' % (zenhub_endpoint, repo)
response = requests.post(url, headers=zenhub_headers, data=params, verify=False)

I get a 400 with: b'{"message":"Invalid Field for pipeline_id: undefined"}'. I've verified that pipeline 5a36d8584b9b9e57bc9729f9 does exist in the target repo.

The API is still in a beta state. I'm wondering if this is a bug in the API or something I'm doing wrong.


回答1:


Pablo from ZenHub here. The problem here is that the request is not well-formed. The position parameter is missing, and you don’t need to encode the request body as a string, you can just send the dictionary directly:

import requests

# No need to stringify
params = {
    "pipeline_id": "5a36d8584b9b9e57bc9729f9",
    "position": "top"
}

# some code omitted here...

response = requests.post(url, headers=zenhub_headers, data=params, verify=False)

The documentation of the move issues endpoint is available here. Cheers,



来源:https://stackoverflow.com/questions/47860744/how-to-set-an-issue-pipeline-with-zenhub-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!