我是工作中的几个大型存储库的成员,并且希望能够设置每日检查(可能是电子邮件/ slackbot)发送给我以及我已打开的未完成拉取请求以及他们的原因仍然是开放的。我们在PR合并之前进行了3次检查,Linter检查,代码审查和CI。我想看看3个检查中哪一个失败(或者在代码审查的情况下尚未完成)。
这可能吗?
答案 0 :(得分:3)
是的,这是可能的。
看看GitHub API。
获取存储库的开放PR列表:
https://developer.github.com/v3/pulls/#list-pull-requests
GET /repos/:owner/:repo/pulls
您对开放的PR感兴趣,因此请使用state
参数设置为Open
和head
来过滤您的用户参考。
CI检查被称为"状态"
https://developer.github.com/v3/repos/statuses/
GET /repos/:owner/:repo/commits/:ref/statuses
其中:ref
是最新提交的哈希值(分支中的最新提交)。
[
{
"created_at": "2012-07-20T01:19:13Z",
"updated_at": "2012-07-20T01:19:13Z",
"state": "success",
"description": "Build has completed successfully",
"id": 1,
}
}
]
最新提交SHA值可以在/pulls
响应中找到:
[
{
"head": {
"label": "new-topic",
"ref": "new-topic",
"sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e"
}
]
结合这些,您可以在早上轮询您的回购并构建一个相当简单的Slack / Email bot。
答案 1 :(得分:0)
GitHub GraphQL API v4应该适用于此用例。
这是一个单一查询,可以一次性检索存储库字段,PR字段和合并状态,按上下文分组:
query { repository(owner: "github", name:"fetch")
{
name
pullRequests(first: 3, states: OPEN, orderBy: {field: UPDATED_AT, direction: DESC}) {
nodes {
url
author {
... on User {
login name
}
}
mergeable
baseRefName
headRefName
title
milestone { title }
labels(first: 100) { nodes{name} }
... on PullRequest {
pullRequestcommits: commits(last: 1) {
totalCount
nodes {
commit {
#url
status { state contexts { context description createdAt targetUrl } }
}
}
}
}
}
}
}
}
上面的示例查询返回三个最近更新的拉取请求,并对https://github.com/github/fetch存储库进行状态检查:
{
"data": {
"repository": {
"name": "fetch",
"pullRequests": {
"nodes": [
{
"url": "https://github.com/github/fetch/pull/616",
"author": {
"login": "jayphelps",
"name": "Jay Phelps"
},
"mergeable": "MERGEABLE",
"baseRefName": "master",
"headRefName": "umd",
"title": "build/distribute as UMD",
"milestone": null,
"labels": {
"nodes": []
},
"pullRequestcommits": {
"totalCount": 1,
"nodes": [
{
"commit": {
"status": {
"state": "SUCCESS",
"contexts": [
{
"context": "continuous-integration/travis-ci/pr",
"description": "The Travis CI build passed",
"createdAt": "2018-04-09T17:39:00Z",
"targetUrl": "https://travis-ci.org/github/fetch/builds/364229647?utm_source=github_status&utm_medium=notification"
}
]
}
}
}
]
}
},
{
"url": "https://github.com/github/fetch/pull/592",
"author": {
"login": "jamesplease",
"name": "James"
},
"mergeable": "MERGEABLE",
"baseRefName": "master",
"headRefName": "abort-polyfill",
"title": "Support abort API",
"milestone": null,
"labels": {
"nodes": []
},
"pullRequestcommits": {
"totalCount": 23,
"nodes": [
{
"commit": {
"status": {
"state": "SUCCESS",
"contexts": [
{
"context": "GitHub CLA",
"description": "@jmeas has accepted the GitHub Contributor License Agreement.",
"createdAt": "2018-02-04T18:41:33Z",
"targetUrl": "https://cla.github.com/github/fetch/accept/jmeas"
},
{
"context": "continuous-integration/travis-ci/pr",
"description": "The Travis CI build passed",
"createdAt": "2018-02-04T18:42:51Z",
"targetUrl": "https://travis-ci.org/github/fetch/builds/337277553?utm_source=github_status&utm_medium=notification"
}
]
}
}
}
]
}
},
{
"url": "https://github.com/github/fetch/pull/575",
"author": {
"login": "CrOrc",
"name": "Roman Yakubuk"
},
"mergeable": "MERGEABLE",
"baseRefName": "master",
"headRefName": "CrOrc-fix-resolve-IE-11",
"title": "Fix issue #533",
"milestone": null,
"labels": {
"nodes": []
},
"pullRequestcommits": {
"totalCount": 1,
"nodes": [
{
"commit": {
"status": {
"state": "SUCCESS",
"contexts": [
{
"context": "GitHub CLA",
"description": "@CrOrc has accepted the GitHub Contributor License Agreement.",
"createdAt": "2017-10-27T16:29:56Z",
"targetUrl": "https://cla.github.com/github/fetch/accept/CrOrc"
},
{
"context": "continuous-integration/travis-ci/pr",
"description": "The Travis CI build passed",
"createdAt": "2017-10-23T14:07:55Z",
"targetUrl": "https://travis-ci.org/github/fetch/builds/291563522?utm_source=github_status&utm_medium=notification"
}
]
}
}
}
]
}
}
]
}
}
}
}
然后可以将graphql json展平为CSV报告:
您可以扩展上述查询以从多个存储库中获取拉取请求,例如,从属于您组织的所有存储库中获取拉取请求。
query { organization(login: "github") {
repositories(first: 5) {
nodes {
# serialize repo and PR fields as displayed above
}
}