From ccf5eed685c36846304fe51786140d59df241f18 Mon Sep 17 00:00:00 2001 From: Arnav Jindal <60603110+Daggy1234@users.noreply.github.com> Date: Sat, 8 Aug 2020 23:51:39 +0530 Subject: [PATCH 01/12] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bc645dd..8f147da 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,7 @@ jobs: ![Lines of code](https://img.shields.io/badge/From%20Hello%20World%20I've%20written-1.3%20million%20Lines%20of%20code-blue) -`SHOW_PROFILE_VIEWS` flag can be set to `True` to show the Profile views +`SHOW_PROFILE_VIEWS` flag can be set to `False` to hide the Profile views ![Profile Views](http://img.shields.io/badge/Profile%20Views-2189-blue) From e050a43360968cb697fcf5f15cb77a62a9f9c805 Mon Sep 17 00:00:00 2001 From: Anmol Pratap Singh Date: Sun, 9 Aug 2020 14:41:00 +0530 Subject: [PATCH 02/12] Create python-app.yml --- .github/workflows/python-app.yml | 37 ++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/python-app.yml diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml new file mode 100644 index 0000000..3199058 --- /dev/null +++ b/.github/workflows/python-app.yml @@ -0,0 +1,37 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions + +name: Python application + +on: + workflow_dispatch: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up Python 3.8 + uses: actions/setup-python@v2 + with: + python-version: 3.8 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install flake8 pytest + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + pytest From 2ccd2bd4d6372fb79cdd9535bbebfd2ae9cbfbf3 Mon Sep 17 00:00:00 2001 From: Anmol Pratap Singh Date: Sun, 9 Aug 2020 14:46:43 +0530 Subject: [PATCH 03/12] Delete python-app.yml --- .github/workflows/python-app.yml | 37 -------------------------------- 1 file changed, 37 deletions(-) delete mode 100644 .github/workflows/python-app.yml diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml deleted file mode 100644 index 3199058..0000000 --- a/.github/workflows/python-app.yml +++ /dev/null @@ -1,37 +0,0 @@ -# This workflow will install Python dependencies, run tests and lint with a single version of Python -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions - -name: Python application - -on: - workflow_dispatch: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Set up Python 3.8 - uses: actions/setup-python@v2 - with: - python-version: 3.8 - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install flake8 pytest - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - name: Lint with flake8 - run: | - # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - - name: Test with pytest - run: | - pytest From b4ab34377c0311ae6cddbe5b5e62668b8d97edc9 Mon Sep 17 00:00:00 2001 From: Aaron Meese Date: Mon, 10 Aug 2020 07:32:20 -0500 Subject: [PATCH 04/12] 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 05/12] 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 06/12] 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 07/12] 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 08/12] 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 09/12] 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) From e03c6d5baacd4cdcc13b8321230d85744c2009d0 Mon Sep 17 00:00:00 2001 From: Aaron Meese Date: Mon, 10 Aug 2020 09:02:37 -0500 Subject: [PATCH 10/12] Removed duplicated code No sense in having the same array of truthy values a dozen times when there can be a variable to store it once. Also got rid of a function that isn't called anywhere, thanks to the implementation of the humanize library. --- main.py | 49 ++++++++++++++++++++----------------------------- 1 file changed, 20 insertions(+), 29 deletions(-) diff --git a/main.py b/main.py index f153cbf..4190648 100644 --- a/main.py +++ b/main.py @@ -85,15 +85,7 @@ query { get_loc_url = Template("""/repos/$owner/$repo/stats/code_frequency""") get_profile_view = Template("""/repos/$owner/$repo/traffic/views?per=week""") get_profile_traffic = Template("""/repos/$owner/$repo/traffic/popular/referrers""") - - -def human_format(num): - magnitude = 0 - while abs(num) >= 1000: - magnitude += 1 - num /= 1000.0 - # add more suffixes if you need them - return '%.2f%s' % (num, ['', 'K', 'M', 'G', 'T', 'P'][magnitude]) +truthy = ['true', '1', 't', 'y', 'yes'] def run_v3_api(query): @@ -272,7 +264,7 @@ def generate_commit_list(tz): string = string + '**' + title + '** \n\n' + '```text\n' + make_commit_list(one_day) + '\n\n```\n' - if show_days_of_week.lower() in ['true', '1', 't', 'y', 'yes']: + if show_days_of_week.lower() in truthy: max_element = { 'percent': 0 } @@ -290,52 +282,52 @@ def get_waka_time_stats(): stats = '' request = requests.get( f"https://wakatime.com/api/v1/users/current/stats/last_7_days?api_key={waka_key}") + no_activity = "No Activity tracked this Week" if request.status_code == 401: print("Error With WAKA time API returned " + str(request.status_code) + " Response " + str(request.json())) - else: empty = True data = request.json() - if showCommit.lower() in ['true', '1', 't', 'y', 'yes']: + if showCommit.lower() in truthy: empty = False stats = stats + generate_commit_list(tz=data['data']['timezone']) + '\n\n' stats += '📊 **This week I spent my time on** \n\n' stats += '```text\n' - if showTimeZone.lower() in ['true', '1', 't', 'y', 'yes']: + if showTimeZone.lower() in truthy: empty = False tzone = data['data']['timezone'] stats = stats + '⌚︎ Timezone: ' + tzone + '\n\n' - if showLanguage.lower() in ['true', '1', 't', 'y', 'yes']: + if showLanguage.lower() in truthy: empty = False if len(data['data']['languages']) == 0: - lang_list = "No Activity tracked this Week" + lang_list = no_activity else: lang_list = make_list(data['data']['languages']) stats = stats + '💬 Languages: \n' + lang_list + '\n\n' - if showEditors.lower() in ['true', '1', 't', 'y', 'yes']: + if showEditors.lower() in truthy: empty = False if len(data['data']['editors']) == 0: - edit_list = "No Activity tracked this Week" + edit_list = no_activity else: edit_list = make_list(data['data']['editors']) stats = stats + '🔥 Editors: \n' + edit_list + '\n\n' - if showProjects.lower() in ['true', '1', 't', 'y', 'yes']: + if showProjects.lower() in truthy: empty = False if len(data['data']['projects']) == 0: - project_list = "No Activity tracked this Week" + project_list = no_activity else: project_list = make_list(data['data']['projects']) stats = stats + '🐱‍💻 Projects: \n' + project_list + '\n\n' - if showOs.lower() in ['true', '1', 't', 'y', 'yes']: + if showOs.lower() in truthy: empty = False if len(data['data']['operating_systems']) == 0: - os_list = "No Activity tracked this Week" + os_list = no_activity else: os_list = make_list(data['data']['operating_systems']) stats = stats + '💻 Operating Systems: \n' + os_list + '\n\n' @@ -394,8 +386,7 @@ def get_line_of_code(): def get_short_info(github): - string = '' - string += '**🐱 My GitHub Data** \n\n' + string = '**🐱 My GitHub Data** \n\n' user_info = github.get_user() if user_info.disk_usage is None: disk_usage = humanize.naturalsize(0) @@ -434,24 +425,24 @@ def get_stats(github): stats = '' repositoryList = run_query(repositoryListQuery.substitute(username=username, id=id)) - if show_profile_view.lower() in ['true', '1', 't', 'y', 'yes']: + if show_profile_view.lower() in truthy: data = run_v3_api(get_profile_view.substitute(owner=username, repo=username)) stats += '![Profile Views](http://img.shields.io/badge/Profile%20Views-' + str(data['count']) + '-blue)\n\n' - if show_loc.lower() in ['true', '1', 't', 'y', 'yes']: + if show_loc.lower() in truthy: stats += '![Lines of code](https://img.shields.io/badge/From%20Hello%20World%20I\'ve%20written-' + quote( str(get_line_of_code())) + '%20Lines%20of%20code-blue)\n\n' - if show_short_info.lower() in ['true', '1', 't', 'y', 'yes']: + if show_short_info.lower() in truthy: stats += get_short_info(github) - if show_waka_stats.lower() in ['true', '1', 't', 'y', 'yes']: + if show_waka_stats.lower() in truthy: stats += get_waka_time_stats() - if showLanguagePerRepo.lower() in ['true', '1', 't', 'y', 'yes']: + if showLanguagePerRepo.lower() in truthy: stats = stats + generate_language_per_repo(repositoryList) + '\n\n' - if showLocChart.lower() in ['true', '1', 't', 'y', 'yes']: + if showLocChart.lower() in truthy: loc = LinesOfCode(id, username, ghtoken, repositoryList) loc.calculateLoc() stats += '**Timeline**\n\n' From f20a82a3e24c55e110b9b8b92569b63a44215664 Mon Sep 17 00:00:00 2001 From: Daniel Rowe <47305015+DanRowe1@users.noreply.github.com> Date: Sun, 16 Aug 2020 01:37:06 -0400 Subject: [PATCH 11/12] Corrected grammar and title casing --- main.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index 4190648..5681697 100644 --- a/main.py +++ b/main.py @@ -243,9 +243,9 @@ def generate_commit_list(tz): sumAll = morning + daytime + evening + night sum_week = Sunday + Monday + Tuesday + Friday + Saturday + Wednesday + Thursday if morning + daytime >= evening + night: - title = "I'm an early 🐤" + title = "I'm an Early 🐤" else: - title = "I'm a night 🦉" + title = "I'm a Night 🦉" one_day = [ {"name": "🌞 Morning", "text": str(morning) + " commits", "percent": round((morning / sumAll) * 100, 2)}, {"name": "🌆 Daytime", "text": str(daytime) + " commits", "percent": round((daytime / sumAll) * 100, 2)}, @@ -293,7 +293,7 @@ def get_waka_time_stats(): empty = False stats = stats + generate_commit_list(tz=data['data']['timezone']) + '\n\n' - stats += '📊 **This week I spent my time on** \n\n' + stats += '📊 **This Week I Spent My Time on** \n\n' stats += '```text\n' if showTimeZone.lower() in truthy: empty = False @@ -365,7 +365,7 @@ def generate_language_per_repo(result): "percent": percent }) - title = 'I mostly code in ' + most_language_repo + title = 'I Mostly Code in ' + most_language_repo return '**' + title + '** \n\n' + '```text\n' + make_list(data) + '\n\n```\n' @@ -398,7 +398,7 @@ def get_short_info(github): data = request.json() total = data['years'][0]['total'] year = data['years'][0]['year'] - string += '> 🏆 ' + humanize.intcomma(total) + ' Contributions in year ' + year + '\n > \n' + string += '> 🏆 ' + humanize.intcomma(total) + ' Contributions in ' + year + '\n > \n' string += '> 📦 Used ' + disk_usage + ' in GitHub\'s Storage \n > \n' is_hireable = user_info.hireable @@ -409,7 +409,7 @@ def get_short_info(github): if is_hireable: string += "> 💼 Opted to Hire\n > \n" else: - string += "> 🚫 Not opted to Hire\n > \n" + string += "> 🚫 Not Opted to Hire\n > \n" string += '> 📜 ' + str(public_repo) + " Public Repositor" string += 'ies \n > \n' if public_repo > 1 else 'y \n > \n' From 81c9e3db461a2f1b35b8943cb61c6bf3b41259d0 Mon Sep 17 00:00:00 2001 From: Daniel Rowe <47305015+DanRowe1@users.noreply.github.com> Date: Sun, 16 Aug 2020 01:49:23 -0400 Subject: [PATCH 12/12] Title casing --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 5681697..1628cbc 100644 --- a/main.py +++ b/main.py @@ -282,7 +282,7 @@ def get_waka_time_stats(): stats = '' request = requests.get( f"https://wakatime.com/api/v1/users/current/stats/last_7_days?api_key={waka_key}") - no_activity = "No Activity tracked this Week" + no_activity = "No Activity Tracked This Week" if request.status_code == 401: print("Error With WAKA time API returned " + str(request.status_code) + " Response " + str(request.json())) @@ -293,7 +293,7 @@ def get_waka_time_stats(): empty = False stats = stats + generate_commit_list(tz=data['data']['timezone']) + '\n\n' - stats += '📊 **This Week I Spent My Time on** \n\n' + stats += '📊 **This Week I Spent My Time On** \n\n' stats += '```text\n' if showTimeZone.lower() in truthy: empty = False