From 96f79dc767d346848c62fdcf897fd471654fa591 Mon Sep 17 00:00:00 2001 From: Aadit Kamat Date: Sun, 27 Dec 2020 16:55:38 +0800 Subject: [PATCH 1/2] Detect main branch Signed-off-by: Aadit Kamat --- main.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 15893bf..ca2b336 100644 --- a/main.py +++ b/main.py @@ -454,7 +454,12 @@ def get_stats(github): yearly_data = loc.calculateLoc() loc.plotLoc(yearly_data) stats += '**' + translate['Timeline'] + '**\n\n' - stats = stats + '![Chart not found](https://raw.githubusercontent.com/' + username + '/' + username + '/master/charts/bar_graph.png) \n\n' + try: + github.get_repo(f'{username}/{username}').get_branch('main') + branch_name = 'main' + except GithubException: + branch_name = 'master' + stats = stats + '![Chart not found](https://raw.githubusercontent.com/' + username + '/' + username + '/' + branch_name + '/charts/bar_graph.png) \n\n' return stats From 6e68caad61508a9b4e696fe0ce73cff82970673a Mon Sep 17 00:00:00 2001 From: Aadit Rahul Kamat Date: Tue, 29 Dec 2020 14:23:08 +0800 Subject: [PATCH 2/2] Simplify logic to check default branch --- main.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/main.py b/main.py index ca2b336..c282549 100644 --- a/main.py +++ b/main.py @@ -454,11 +454,7 @@ def get_stats(github): yearly_data = loc.calculateLoc() loc.plotLoc(yearly_data) stats += '**' + translate['Timeline'] + '**\n\n' - try: - github.get_repo(f'{username}/{username}').get_branch('main') - branch_name = 'main' - except GithubException: - branch_name = 'master' + branch_name = github.get_repo(f'{username}/{username}').default_branch stats = stats + '![Chart not found](https://raw.githubusercontent.com/' + username + '/' + username + '/' + branch_name + '/charts/bar_graph.png) \n\n' return stats