For example, I have a file t.json, the content is:
{
"a": "abcdefg"
}
And file t.json is pushed to to master branch. Then I add some content to the file, so the file looks like this now:
{
"a": "abcdefg",
"b": "mkjuujj"
}
Now I can compare two commits by using PyGithub. Codes are like this:
last_head = repo.get_branch(WORKING_BRANCH)
fc = repo.get_file_contents("/t.json", ref=WORKING_BRANCH)
file = 't.json'
commit_message = "create a new branch with changes"
input_file = open(file, 'rb')
data = input_file.read()
result = repo.update_file("/t.json",
commit_message,
data,#need solve this problem, how to use a file pass in
fc.sha, branch=WORKING_BRANCH)
diff_url = repo.compare(last_head.commit.sha,
result['commit'].sha)
print diff_url.diff_url
this is what I got:
diff --git a/t.json b/t.json
index ef03bf5..b775e51 100644
--- a/t.json
+++ b/t.json
@@ -1,3 +1,4 @@
{
- "a": "abcdefg"
+ "a": "abcdefg",
+ "b": "mkjuujj"
}
What I want is
{
"a": "abcdefg"
+ "b": "mkjuujj"
}
What should I do to compare the diff by passing entire file into repo.update_file(). Thank you very much. Really appreciate it.