简体   繁体   English

使用gitpython来区分拉取请求中的更改

[英]Using gitpython to diff changes from a pull request

I'm trying to write a script that will be triggered by a pull request github webhook. 我正在尝试编写一个由pull请求github webhook触发的脚本。 When this script is triggered, it needs to find out which files were modified from master to newBranch . 触发此脚本时,需要找出哪些文件已从master修改为newBranch End of day, I'll read through those files, verify that no breaking changes were made, and then write up why it should/shouldn't be merged and send it off to a human to confirm. 一天结束,我将通读这些文件,确认没有进行任何重大更改,然后写出为什么应该/不应该合并并将其发送给人类进行确认。

I'm using gitpython (or, rather, trying to), but the documentation doesn't really go over the PR use case. 我正在使用gitpython(或者更确切地说,尝试),但文档并没有真正覆盖PR用例。

My code looks like this so far, but I'm not convinced that I'm doing things correctly: 到目前为止,我的代码看起来像这样,但我不相信我正在做的事情:

repo = git.Repo('.')
repo.config_reader()
for d in repo.index.diff(repo.remotes.origin.refs.master.commit):
  print d
  print d.diff

I guess I'm not sure what the index is in a PR, so I'm not convinced that this is diffing the right things. 我想我不确定PR中的索引是什么,所以我不相信这是正确的事情。 When I try it out in a test repo, I don't see any diffs unless I'm manually fixing merge conflicts, so I suspect I'm not doing things correctly. 当我在测试仓库中试用它时,除非我手动修复合并冲突,否则我看不到任何差异,所以我怀疑我没有正确地做事。

Can you please either help me with the code, or suggest a workflow that I could use to test this script? 你可以帮我解释一下代码,或者建议我可以用来测试这个脚本的工作流程吗? I'm getting all muddled up the more I look at this. 我看得越多,我就越搞砸了。

This is not the right approach. 这不是正确的方法。

PRs are not a git concept; PR不是一个git概念; they are a Github one. 他们是Github之一。 You can't use gitpython for this. 你不能使用gitpython。 You will have to use Github's own API, for which there are several third-party libraries . 您将不得不使用Github自己的API,其中有几个第三方库

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM