4

Does github provide

  • hooks to setup scripts to be run on every pull request (where say, one could call a simple static code analyser script)
  • and a provision to reject the pull request, based on the results from that script run via pull request hook.

Am trying to setup a pre-screener mechanism to catch trivial bugs/mistakes so that the reviewers are not bothered about trivial mistakes and they could focus more on the logic/feature. And if the prescreening script finds that the source in question doesn't fit the norms (typically, when even the simplest of checks fail; e.g, a function with >5000 SLoC, or unsafe strcpy(), or inclusion of deprecated header files etc), it should return a failure and pull request itself should fail unless the minimum gating criteria is met.

Since the code is on github rather than a local server, this seems to be kinda tricky.

I got a couple of pointers (here, and here) but still couldn't gather the details fully. The codebase consists of multiple repositories on github. Is there a better way to achieve and accomplish this? Please share your thoughts on possible approaches. Thanks!

4

2 回答 2

4

GitHub 是否提供挂钩来设置要在每个拉取请求上运行的脚本(例如,可以调用一个简单的静态代码分析器脚本)以及拒绝拉取请求的规定,基于该脚本通过拉取请求挂钩运行的结果。

这应该可以通过 GitHub API 实现,方法是结合为pull_request类型的事件创建一个钩子,然后用结果状态装饰提交。

这是一种相当低级的方法,但是这使您可以完全控制正在执行的操作。例如,您可以自动向拉取请求添加评论,甚至在它们未通过分析过程时关闭它们。

另一种更高级别的方法是通过在存储库中添加.travis.yml文件来利用Travis CI服务。Travis 对开源项目是免费的,也为私有存储库提供付费服务。

设置 Travis 非常简单,调整构建脚本轻而易举。

下面两个示例 Travis 脚本供您参考:

  • LibGit2:一个 C 库。使用多个编译器构建、运行测试、运行 Valgrind。当代码未编译或测试失败时,构建失败(并且 PR 被这样修饰)。
  • LibGit2Sharp : LibGit2 的 AC# 绑定。针对 Mono Xbuild 编译器构建,运行测试。当代码未编译或测试失败时,构建失败(并且 PR 被这样修饰)。

GitHub Commit Status 服务的官方公告可以在这篇文中阅读。

于 2013-08-01T10:50:57.217 回答
1

您可能对此有用: https ://github.com/tomasbjerre/violation-comments-to-github-lib

它将解析文件系统以从静态代码分析器中查找报告文件,然后使用这些文件在 GitHub 中评论拉取请求。

在此处输入图像描述

于 2016-03-05T17:06:07.187 回答