From b4ab34377c0311ae6cddbe5b5e62668b8d97edc9 Mon Sep 17 00:00:00 2001 From: Aaron Meese Date: Mon, 10 Aug 2020 07:32:20 -0500 Subject: [PATCH 1/6] Fake stats committer I need to push this commit to test the activity on my own README to see if it works. I am using the same general principle as the activity tracker repo, I just had to figure out how to convert that to pygithub. --- main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 28e3382..de8c3f3 100644 --- a/main.py +++ b/main.py @@ -489,7 +489,9 @@ if __name__ == '__main__': new_readme = generate_new_readme(stats=waka_stats, readme=rdmd) if new_readme != rdmd: 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=g.InputGitAuthor("readme-bot", + "readme-bot@example.com")) print("Readme updated") except Exception as e: traceback.print_exc() From e2b5960e2e3c8e4033b2ca34e94bcba1feda2765 Mon Sep 17 00:00:00 2001 From: Aaron Meese Date: Mon, 10 Aug 2020 08:06:14 -0500 Subject: [PATCH 2/6] Imported function The InputGitAuthor attribute wasn't found because I forgot to import it. Still getting used to Python and importing individual modules. --- main.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index de8c3f3..d2edae1 100644 --- a/main.py +++ b/main.py @@ -7,7 +7,7 @@ import base64 from pytz import timezone import pytz import requests -from github import Github, GithubException +from github import Github, GithubException, InputGitAuthor import datetime from string import Template from loc import LinesOfCode @@ -461,7 +461,7 @@ def get_stats(github): def decode_readme(data: str): - '''Decode the contets of old readme''' + '''Decode the contents of old readme''' decoded_bytes = base64.b64decode(data) return str(decoded_bytes, 'utf-8') @@ -487,11 +487,11 @@ if __name__ == '__main__': waka_stats = get_stats(g) rdmd = decode_readme(contents.content) new_readme = generate_new_readme(stats=waka_stats, readme=rdmd) + committer = g.InputGitAuthor('readme-bot', 'readme-bot@example.com') if new_readme != rdmd: repo.update_file(path=contents.path, message='Updated with Dev Metrics', content=new_readme, sha=contents.sha, branch='master', - committer=g.InputGitAuthor("readme-bot", - "readme-bot@example.com")) + committer=committer) print("Readme updated") except Exception as e: traceback.print_exc() From 8376e637910a7922412b8597ed2dd742c70b59fc Mon Sep 17 00:00:00 2001 From: Aaron Meese Date: Mon, 10 Aug 2020 08:10:38 -0500 Subject: [PATCH 3/6] InputGitAuthor not an attrribute I think this is mean to be a separate method when imported like this. At least, that's how it is in the example project I found, so here's to hoping. --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index d2edae1..f153cbf 100644 --- a/main.py +++ b/main.py @@ -487,7 +487,7 @@ if __name__ == '__main__': waka_stats = get_stats(g) rdmd = decode_readme(contents.content) new_readme = generate_new_readme(stats=waka_stats, readme=rdmd) - committer = g.InputGitAuthor('readme-bot', 'readme-bot@example.com') + committer = InputGitAuthor('readme-bot', 'readme-bot@example.com') if new_readme != rdmd: repo.update_file(path=contents.path, message='Updated with Dev Metrics', content=new_readme, sha=contents.sha, branch='master', From 7566684749b91d8454302b395dc788b7dfa834b9 Mon Sep 17 00:00:00 2001 From: Aaron Meese Date: Mon, 10 Aug 2020 08:16:13 -0500 Subject: [PATCH 4/6] Lines of Code committer It worked for the README, so let's see if it works for the charts. --- loc.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/loc.py b/loc.py index e46151c..a40c383 100644 --- a/loc.py +++ b/loc.py @@ -81,10 +81,11 @@ class LinesOfCode: def pushChart(self): 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: data = input_file.read() try: 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) 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) From 33d73645a9730dd650e1e10b61d9a92587049daa Mon Sep 17 00:00:00 2001 From: Aaron Meese Date: Mon, 10 Aug 2020 08:21:34 -0500 Subject: [PATCH 5/6] Forgot to import function As it turns out, I am an idiot. Figures. --- loc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loc.py b/loc.py index a40c383..e99e42a 100644 --- a/loc.py +++ b/loc.py @@ -2,7 +2,7 @@ import re import os import base64 import requests -from github import Github +from github import Github, InputGitAuthor import datetime from string import Template import matplotlib.pyplot as plt From f44ea74b2007937a262bcbb0aa64692c6efa09dc Mon Sep 17 00:00:00 2001 From: Aaron Meese Date: Mon, 10 Aug 2020 08:31:30 -0500 Subject: [PATCH 6/6] Vars out of order The function was expecting a branch there, so I had to specify the committer. --- loc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/loc.py b/loc.py index e99e42a..8d37f16 100644 --- a/loc.py +++ b/loc.py @@ -86,6 +86,6 @@ class LinesOfCode: data = input_file.read() try: contents = repo.get_contents("charts/bar_graph.png") - repo.update_file(contents.path, "Charts Updated", data, contents.sha, committer) + repo.update_file(contents.path, "Charts Updated", data, contents.sha, committer=committer) except Exception as e: - repo.create_file("charts/bar_graph.png", "Charts Added", data, committer) + repo.create_file("charts/bar_graph.png", "Charts Added", data, committer=committer)