forked from FoldingCommunity/Translate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommit_report.py
executable file
·33 lines (22 loc) · 921 Bytes
/
commit_report.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python3
import os
import sys
import base64
from github import Github
TRANSLATION_REPORT_FILENAME = "translation_report.md"
github_token = sys.argv[1]
g = Github(github_token)
repo = g.get_repo(os.getenv("GITHUB_REPOSITORY"))
branch = os.getenv("GITHUB_REF")
def get_previous_file(path):
return repo.get_contents(path, ref=os.getenv("GITHUB_SHA"))
def decode_contents(contents):
decoded_bytes = base64.b64decode(contents.content)
return str(decoded_bytes, "utf-8")
previous_report_obj = get_previous_file(TRANSLATION_REPORT_FILENAME)
previous_report = decode_contents(previous_report_obj)
with open(TRANSLATION_REPORT_FILENAME) as r:
current_report = r.read()
if previous_report != current_report:
repo.update_file(path=TRANSLATION_REPORT_FILENAME, message="Updated translation report", content=current_report,
sha=previous_report_obj.sha, branch=branch)