将拉式请求和问题添加到项目 [英] Adding Pull Requests & Issues to a Project

查看:0
本文介绍了将拉式请求和问题添加到项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Github API是否提供了向项目委员会添加拉式请求或问题的简单方法

这是用户的编程等效项going to a pull request and selecting one more "Projects" from the sidebar menu

注意:API似乎确实提供了一种向项目添加卡片的方法,但我必须指定一个特定的项目专栏。我喜欢盲目地添加项目,让自动化规则决定列,类似于通过UI点击它。

谢谢!

推荐答案

我认为,在某种缺省列中,将现有的Pull请求与项目关联的最好方法是以菊花链形式将Github API的三个独立部分:Get a Single Pull Request方法、Create a Project Card方法和List Project Columns方法。想法如下:

  1. 使用‘Get a Single Pull Request’检索ID
  2. 使用"列出项目列"获取列的列表
  3. 如果要查看某一列是否存在,请执行任何条件逻辑,或者只使用第一列,如果不存在则创建某一列
  4. 使用"创建项目卡",使用您选择的拉式请求ID和列添加该卡。

以下是一个用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

这篇关于将拉式请求和问题添加到项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆