Merge pull request #51 from ajmeese7/fake-author

Fake author for commits
This commit is contained in:
Anmol Pratap Singh
2020-08-10 19:17:12 +05:30
committed by GitHub
2 changed files with 9 additions and 6 deletions

7
loc.py
View File

@@ -2,7 +2,7 @@ import re
import os import os
import base64 import base64
import requests import requests
from github import Github from github import Github, InputGitAuthor
import datetime import datetime
from string import Template from string import Template
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
@@ -81,10 +81,11 @@ class LinesOfCode:
def pushChart(self): def pushChart(self):
repo = self.g.get_repo(f"{self.username}/{self.username}") repo = self.g.get_repo(f"{self.username}/{self.username}")
committer = InputGitAuthor('readme-bot', 'readme-bot@example.com')
with open('bar_graph.png', 'rb') as input_file: with open('bar_graph.png', 'rb') as input_file:
data = input_file.read() data = input_file.read()
try: try:
contents = repo.get_contents("charts/bar_graph.png") contents = repo.get_contents("charts/bar_graph.png")
repo.update_file(contents.path, "Charts Added", data, contents.sha) repo.update_file(contents.path, "Charts Updated", data, contents.sha, committer=committer)
except Exception as e: except Exception as e:
repo.create_file("charts/bar_graph.png", "Initial Commit", data) repo.create_file("charts/bar_graph.png", "Charts Added", data, committer=committer)

View File

@@ -7,7 +7,7 @@ import base64
from pytz import timezone from pytz import timezone
import pytz import pytz
import requests import requests
from github import Github, GithubException from github import Github, GithubException, InputGitAuthor
import datetime import datetime
from string import Template from string import Template
from loc import LinesOfCode from loc import LinesOfCode
@@ -461,7 +461,7 @@ def get_stats(github):
def decode_readme(data: str): def decode_readme(data: str):
'''Decode the contets of old readme''' '''Decode the contents of old readme'''
decoded_bytes = base64.b64decode(data) decoded_bytes = base64.b64decode(data)
return str(decoded_bytes, 'utf-8') return str(decoded_bytes, 'utf-8')
@@ -487,9 +487,11 @@ if __name__ == '__main__':
waka_stats = get_stats(g) waka_stats = get_stats(g)
rdmd = decode_readme(contents.content) rdmd = decode_readme(contents.content)
new_readme = generate_new_readme(stats=waka_stats, readme=rdmd) new_readme = generate_new_readme(stats=waka_stats, readme=rdmd)
committer = InputGitAuthor('readme-bot', 'readme-bot@example.com')
if new_readme != rdmd: if new_readme != rdmd:
repo.update_file(path=contents.path, message='Updated with Dev Metrics', repo.update_file(path=contents.path, message='Updated with Dev Metrics',
content=new_readme, sha=contents.sha, branch='master') content=new_readme, sha=contents.sha, branch='master',
committer=committer)
print("Readme updated") print("Readme updated")
except Exception as e: except Exception as e:
traceback.print_exc() traceback.print_exc()