Github API是否提供一种简便的方法来向项目委员会添加拉取请求或问题?
这是用户going to a pull request and selecting one more "Projects" from the sidebar menu的编程等效项
注意:API似乎确实提供了一种向项目添加卡片的方法,但是我必须指定一个特定的项目列。我很想盲目添加项目,让自动化规则确定该列,类似于通过UI单击它。
谢谢!
答案 0 :(得分:2)
我认为在某种默认列中,将现有拉取请求与项目相关联的最佳方法是菊花链式连接Github API的三个独立部分,即Get a Single Pull Request方法,{{ 3}}方法和Create a Project Card方法。这个想法如下:
这是Python中的简化示例:
import requests, json
#get pull request
r = requests.get('https://api.github.com/repos/[myusername]/[myrepo]/pulls/2')
pull = json.loads(r.text)
#requires authentication ... create your token through Github.com
api_token = "mytoken"
#prepare dictionary of header data
h = {"Accept":"application/vnd.github.inertia-preview+json", "Authorization": "token %s" % api_token}
projects_r = requests.get('https://api.github.com/repos/[myusername]/[myrepo]/projects', headers=h)
#get projects data
projects = json.loads(projects_r.text)
#get columns url for the first project in the list projects
columns_url = projects[0]['columns_url']
columns_r = requests.get(columns_url, headers=h)
columns = json.loads(columns_r.text)
#get column url for the first column in the list of columns
column_url = columns[0]['cards_url']
#use retrieved data to build post
data = {"content_id":pull_id, "content_type":"PullRequest"}
#use post method with headers and data to create card in column
result = requests.post(column_url, headers=h, data=json.dumps(data))
#returns with status 201, created