From d8c4716262c2bdc384df842227aae9111a8d493a Mon Sep 17 00:00:00 2001 From: Aravind Nair <22199259+aravindvnair99@users.noreply.github.com> Date: Sun, 26 Feb 2023 14:24:55 +0530 Subject: [PATCH 01/28] Create .github/workflows/codeql.yml --- .github/workflows/codeql.yml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/codeql.yml diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..7a95b05 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,34 @@ +name: "CodeQL" + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + schedule: + - cron: '30 13 * * 6' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + strategy: + fail-fast: false + matrix: + language: [ 'python' ] + steps: + - name: Checkout repository + uses: actions/checkout@main + - name: Initialize CodeQL + uses: github/codeql-action/init@main + with: + languages: ${{ matrix.language }} + queries: security-and-quality + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@main + with: + category: "/language:${{matrix.language}}" From 9fd3d22686b2fcebaca3aa018e125ff51851ba56 Mon Sep 17 00:00:00 2001 From: Aravind Nair <22199259+aravindvnair99@users.noreply.github.com> Date: Sun, 26 Feb 2023 15:39:39 +0530 Subject: [PATCH 02/28] Create .github/workflows/dependency-review.yml Fixes #390 --- .github/workflows/dependency-review.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .github/workflows/dependency-review.yml diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml new file mode 100644 index 0000000..4883f1e --- /dev/null +++ b/.github/workflows/dependency-review.yml @@ -0,0 +1,17 @@ +name: 'Dependency Review' +on: [pull_request] + +permissions: + contents: read + pull-requests: write + +jobs: + dependency-review: + runs-on: ubuntu-latest + steps: + - name: 'Checkout Repository' + uses: actions/checkout@main + - name: 'Dependency Review' + uses: actions/dependency-review-action@main + with: + comment-summary-in-pr: true From d84d6e9541a191bf813ca7c7e09493850bd1fa44 Mon Sep 17 00:00:00 2001 From: Aravind Nair <22199259+aravindvnair99@users.noreply.github.com> Date: Sun, 26 Feb 2023 16:36:30 +0530 Subject: [PATCH 03/28] Set CodeQL to start on any push and enable workflow_dispatch --- .github/workflows/codeql.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 7a95b05..0d35a18 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -2,9 +2,7 @@ name: "CodeQL" on: push: - branches: [ "master" ] - pull_request: - branches: [ "master" ] + workflow_dispatch: schedule: - cron: '30 13 * * 6' From 0fdf0c384d69125f9f6fed34c075f19f7c0726f1 Mon Sep 17 00:00:00 2001 From: Aravind Nair <22199259+aravindvnair99@users.noreply.github.com> Date: Sun, 26 Feb 2023 17:22:22 +0530 Subject: [PATCH 04/28] Update codeql.yml --- .github/workflows/codeql.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 0d35a18..f2e2890 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -2,6 +2,9 @@ name: "CodeQL" on: push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] workflow_dispatch: schedule: - cron: '30 13 * * 6' From 336c1799c91a0729ca7b3a9b390f3994a823dc77 Mon Sep 17 00:00:00 2001 From: Aravind Nair <22199259+aravindvnair99@users.noreply.github.com> Date: Sun, 26 Feb 2023 17:56:24 +0530 Subject: [PATCH 05/28] Update codeql.yml --- .github/workflows/codeql.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index f2e2890..f51bc11 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -4,7 +4,7 @@ on: push: branches: [ "master" ] pull_request: - branches: [ "master" ] + branches: [ "**" ] workflow_dispatch: schedule: - cron: '30 13 * * 6' From eca7d89cfce91ca69a94dac3c3c7dcf7ea269376 Mon Sep 17 00:00:00 2001 From: Aravind Nair <22199259+aravindvnair99@users.noreply.github.com> Date: Sun, 26 Feb 2023 19:04:40 +0530 Subject: [PATCH 06/28] Perform dependency review on push and schedule --- .github/workflows/dependency-review.yml | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml index 4883f1e..d33991b 100644 --- a/.github/workflows/dependency-review.yml +++ b/.github/workflows/dependency-review.yml @@ -1,5 +1,12 @@ -name: 'Dependency Review' -on: [pull_request] +name: 'Dependency review' +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "**" ] + workflow_dispatch: + schedule: + - cron: '45 15 * * 5' permissions: contents: read @@ -9,9 +16,9 @@ jobs: dependency-review: runs-on: ubuntu-latest steps: - - name: 'Checkout Repository' + - name: 'Checkout repository' uses: actions/checkout@main - - name: 'Dependency Review' + - name: 'Dependency review' uses: actions/dependency-review-action@main with: comment-summary-in-pr: true From 5b75fe6a5ffcf6535a2a41b965b5252fff3a80cc Mon Sep 17 00:00:00 2001 From: Aravind Nair <22199259+aravindvnair99@users.noreply.github.com> Date: Sun, 26 Feb 2023 19:26:59 +0530 Subject: [PATCH 07/28] Pin action version in CodeQL --- .github/workflows/codeql.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index f51bc11..0bb8689 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -23,13 +23,13 @@ jobs: language: [ 'python' ] steps: - name: Checkout repository - uses: actions/checkout@main + uses: actions/checkout@v3 - name: Initialize CodeQL - uses: github/codeql-action/init@main + uses: github/codeql-action/init@v2 with: languages: ${{ matrix.language }} queries: security-and-quality - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@main + uses: github/codeql-action/analyze@v2 with: category: "/language:${{matrix.language}}" From 143e118f1a889632cd51c7864d922c5ff6e1a238 Mon Sep 17 00:00:00 2001 From: Aravind Nair <22199259+aravindvnair99@users.noreply.github.com> Date: Sun, 26 Feb 2023 19:55:13 +0530 Subject: [PATCH 08/28] Pin action version in Dependency review --- .github/workflows/dependency-review.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml index d33991b..09d23a7 100644 --- a/.github/workflows/dependency-review.yml +++ b/.github/workflows/dependency-review.yml @@ -17,8 +17,8 @@ jobs: runs-on: ubuntu-latest steps: - name: 'Checkout repository' - uses: actions/checkout@main + uses: actions/checkout@v3 - name: 'Dependency review' - uses: actions/dependency-review-action@main + uses: actions/dependency-review-action@v3 with: comment-summary-in-pr: true From b2aafe405760860ca44da7fe7644f10ee2fa4e0f Mon Sep 17 00:00:00 2001 From: Aravind Nair <22199259+aravindvnair99@users.noreply.github.com> Date: Sun, 26 Feb 2023 19:58:10 +0530 Subject: [PATCH 09/28] Fix formatting in dependency-review-action --- .github/workflows/dependency-review.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml index 09d23a7..323a33c 100644 --- a/.github/workflows/dependency-review.yml +++ b/.github/workflows/dependency-review.yml @@ -1,4 +1,4 @@ -name: 'Dependency review' +name: Dependency review on: push: branches: [ "master" ] @@ -6,7 +6,7 @@ on: branches: [ "**" ] workflow_dispatch: schedule: - - cron: '45 15 * * 5' + - cron: 45 15 * * 5 permissions: contents: read @@ -16,9 +16,9 @@ jobs: dependency-review: runs-on: ubuntu-latest steps: - - name: 'Checkout repository' + - name: Checkout repository uses: actions/checkout@v3 - - name: 'Dependency review' + - name: Dependency review uses: actions/dependency-review-action@v3 with: comment-summary-in-pr: true From e337347cb39d1edd76745f15d36efa332c950ddb Mon Sep 17 00:00:00 2001 From: Aravind Nair <22199259+aravindvnair99@users.noreply.github.com> Date: Sun, 26 Feb 2023 19:59:16 +0530 Subject: [PATCH 10/28] Fix formatting in dependency-review-action --- .github/workflows/dependency-review.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml index 323a33c..2ed2dc8 100644 --- a/.github/workflows/dependency-review.yml +++ b/.github/workflows/dependency-review.yml @@ -1,9 +1,8 @@ name: Dependency review on: push: - branches: [ "master" ] + branches: master pull_request: - branches: [ "**" ] workflow_dispatch: schedule: - cron: 45 15 * * 5 From 6e502d247d15714967431fc983b1113274cfe919 Mon Sep 17 00:00:00 2001 From: pseusys Date: Sun, 26 Feb 2023 18:38:51 +0100 Subject: [PATCH 11/28] graph redrawn --- sources/graphics_chart_drawer.py | 19 +++++++++++-------- sources/main.py | 2 +- sources/yearly_commit_calculator.py | 9 +++++---- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/sources/graphics_chart_drawer.py b/sources/graphics_chart_drawer.py index 786091e..c8b0112 100644 --- a/sources/graphics_chart_drawer.py +++ b/sources/graphics_chart_drawer.py @@ -1,6 +1,6 @@ from typing import Dict -from numpy import arange, array, add, amax +from numpy import arange, array, add, amax, zeros import matplotlib.patches as mpatches import matplotlib.pyplot as plt @@ -9,6 +9,7 @@ from manager_download import DownloadManager as DM MAX_LANGUAGES = 5 # Number of top languages to add to chart, for each year quarter GRAPH_PATH = "assets/bar_graph.png" # Chart saving path. +GRAPH_Y_ZOOM = 1.3 async def create_loc_graph(yearly_data: Dict, save_path: str): @@ -27,26 +28,28 @@ async def create_loc_graph(yearly_data: Dict, save_path: str): languages_all_loc = dict() for i, y in enumerate(sorted(yearly_data.keys())): for q in yearly_data[y].keys(): - langs = sorted(yearly_data[y][q].keys(), key=lambda n: yearly_data[y][q][n], reverse=True)[0:MAX_LANGUAGES] + langs = sorted(yearly_data[y][q].keys(), key=lambda n: yearly_data[y][q][n]["add"] + yearly_data[y][q][n]["del"], reverse=True)[0:MAX_LANGUAGES] for lang in langs: if lang not in languages_all_loc: - languages_all_loc[lang] = array([[0] * years] * 4) - languages_all_loc[lang][q - 1][i] = yearly_data[y][q][lang] + languages_all_loc[lang] = zeros((years, 4, 2), dtype=int) + languages_all_loc[lang][i][q - 1] = array([yearly_data[y][q][lang]["add"], yearly_data[y][q][lang]["del"]]) fig = plt.figure() ax = fig.add_axes([0, 0, 1.5, 1]) language_handles = [] - cumulative = array([[0] * years] * 4) + cumulative = zeros((years, 4, 2), dtype=int) for key, value in languages_all_loc.items(): color = colors[key]["color"] if colors[key]["color"] is not None else "w" language_handles += [mpatches.Patch(color=color, label=key)] for quarter in range(4): - ax.bar(year_indexes + quarter * 0.21, value[quarter], 0.2, bottom=cumulative[quarter], color=color) - cumulative[quarter] = add(cumulative[quarter], value[quarter]) + ax.bar(year_indexes + quarter * 0.21, value[:, quarter][:, 0], 0.2, bottom=cumulative[:, quarter][:, 0], color=color) + ax.bar(year_indexes + quarter * 0.21, -value[:, quarter][:, 1], 0.2, bottom=-cumulative[:, quarter][:, 1], color=color) + cumulative[:, quarter] = add(cumulative[:, quarter], value[:, quarter]) + ax.axhline(y=0.5, lw=0.5, snap=True, color="k") ax.set_ylabel("LOC added", fontdict=dict(weight="bold")) ax.set_xticks(array([arange(i, i + 0.84, step=0.21) for i in year_indexes]).flatten(), labels=["Q1", "Q2", "Q3", "Q4"] * years) @@ -62,6 +65,6 @@ async def create_loc_graph(yearly_data: Dict, save_path: str): ax.spines["top"].set_visible(False) ax.spines["right"].set_visible(False) - plt.ylim(0, 1.05 * amax(cumulative)) + plt.ylim(top=GRAPH_Y_ZOOM * amax(cumulative[:, 0]), bottom=-GRAPH_Y_ZOOM * amax(cumulative[:, 1])) plt.savefig(save_path, bbox_inches="tight") plt.close(fig) diff --git a/sources/main.py b/sources/main.py index 9b474d8..030725c 100644 --- a/sources/main.py +++ b/sources/main.py @@ -148,7 +148,7 @@ async def get_stats() -> str: if EM.SHOW_LINES_OF_CODE: DBM.i("Adding lines of code info...") - total_loc = sum([yearly_data[y][q][d] for y in yearly_data.keys() for q in yearly_data[y].keys() for d in yearly_data[y][q].keys()]) + total_loc = sum([yearly_data[y][q][d]["add"] for y in yearly_data.keys() for q in yearly_data[y].keys() for d in yearly_data[y][q].keys()]) data = f"{intword(total_loc)} {LM.t('Lines of code')}" stats += f"![Lines of code](https://img.shields.io/badge/{quote(LM.t('From Hello World I have written'))}-{quote(data)}-blue)\n\n" diff --git a/sources/yearly_commit_calculator.py b/sources/yearly_commit_calculator.py index 49bce72..5b6bb80 100644 --- a/sources/yearly_commit_calculator.py +++ b/sources/yearly_commit_calculator.py @@ -11,7 +11,7 @@ from manager_debug import DebugManager as DBM async def calculate_yearly_commit_data(repositories: Dict) -> Dict: """ Calculate commit data by years. - Commit data includes difference between contribution additions and deletions in each quarter of each recorded year. + Commit data includes contribution additions and deletions in each quarter of each recorded year. :param repositories: user repositories info dictionary. :returns: Commit quarter yearly data dictionary. @@ -21,7 +21,7 @@ async def calculate_yearly_commit_data(repositories: Dict) -> Dict: total = len(repositories["data"]["user"]["repositories"]["nodes"]) for ind, repo in enumerate(repositories["data"]["user"]["repositories"]["nodes"]): if repo["name"] not in EM.IGNORED_REPOS: - repo_name = "private" if repo["isPrivate"] else f"{repo['owner']['login']}/{repo['name']}" + repo_name = "[private]" if repo["isPrivate"] else f"{repo['owner']['login']}/{repo['name']}" DBM.i(f"\t{ind + 1}/{total} Retrieving repo: {repo_name}") await update_yearly_data_with_commit_stats(repo, yearly_data) DBM.g("Yearly commit data calculated!") @@ -55,5 +55,6 @@ async def update_yearly_data_with_commit_stats(repo_details: Dict, yearly_data: if quarter not in yearly_data[curr_year]: yearly_data[curr_year][quarter] = dict() if repo_details["primaryLanguage"]["name"] not in yearly_data[curr_year][quarter]: - yearly_data[curr_year][quarter][repo_details["primaryLanguage"]["name"]] = 0 - yearly_data[curr_year][quarter][repo_details["primaryLanguage"]["name"]] += commit["additions"] - commit["deletions"] + yearly_data[curr_year][quarter][repo_details["primaryLanguage"]["name"]] = {"add": 0, "del": 0} + yearly_data[curr_year][quarter][repo_details["primaryLanguage"]["name"]]["add"] += commit["additions"] + yearly_data[curr_year][quarter][repo_details["primaryLanguage"]["name"]]["del"] += commit["deletions"] From 812d0477c5713923ae82ac13307c7b7e21f7566d Mon Sep 17 00:00:00 2001 From: pseusys Date: Sun, 26 Feb 2023 18:48:37 +0100 Subject: [PATCH 12/28] y_lim adjusted --- sources/graphics_chart_drawer.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sources/graphics_chart_drawer.py b/sources/graphics_chart_drawer.py index c8b0112..d408ae7 100644 --- a/sources/graphics_chart_drawer.py +++ b/sources/graphics_chart_drawer.py @@ -9,7 +9,6 @@ from manager_download import DownloadManager as DM MAX_LANGUAGES = 5 # Number of top languages to add to chart, for each year quarter GRAPH_PATH = "assets/bar_graph.png" # Chart saving path. -GRAPH_Y_ZOOM = 1.3 async def create_loc_graph(yearly_data: Dict, save_path: str): @@ -65,6 +64,6 @@ async def create_loc_graph(yearly_data: Dict, save_path: str): ax.spines["top"].set_visible(False) ax.spines["right"].set_visible(False) - plt.ylim(top=GRAPH_Y_ZOOM * amax(cumulative[:, 0]), bottom=-GRAPH_Y_ZOOM * amax(cumulative[:, 1])) + plt.ylim(top=1.1 * amax(cumulative[:, 0]), bottom=-1.5 * amax(cumulative[:, 1])) plt.savefig(save_path, bbox_inches="tight") plt.close(fig) From ebd55bdb7bec671371dd5cf5753c49a893a13295 Mon Sep 17 00:00:00 2001 From: Aravind Nair <22199259+aravindvnair99@users.noreply.github.com> Date: Mon, 27 Feb 2023 15:07:01 +0530 Subject: [PATCH 13/28] Update codeql.yml --- .github/workflows/codeql.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 0bb8689..a61020d 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -1,10 +1,9 @@ -name: "CodeQL" +name: CodeQL on: push: - branches: [ "master" ] + branches: master pull_request: - branches: [ "**" ] workflow_dispatch: schedule: - cron: '30 13 * * 6' From 9b17f20ed221653a933c9ed9914a91b7a3dbb0ae Mon Sep 17 00:00:00 2001 From: pseusys Date: Mon, 27 Feb 2023 22:20:12 +0100 Subject: [PATCH 14/28] file manager renamed --- sources/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sources/main.py b/sources/main.py index a0bfe78..7bab6ab 100644 --- a/sources/main.py +++ b/sources/main.py @@ -149,8 +149,8 @@ async def get_stats() -> str: if EM.SHOW_LINES_OF_CODE: DBM.i("Adding lines of code info...") total_loc = sum([yearly_data[y][q][d]["add"] for y in yearly_data.keys() for q in yearly_data[y].keys() for d in yearly_data[y][q].keys()]) - data = f"{intword(total_loc)} {LM.t('Lines of code')}" - stats += f"![Lines of code](https://img.shields.io/badge/{quote(LM.t('From Hello World I have written'))}-{quote(data)}-blue)\n\n" + data = f"{intword(total_loc)} {FM.t('Lines of code')}" + stats += f"![Lines of code](https://img.shields.io/badge/{quote(FM.t('From Hello World I have written'))}-{quote(data)}-blue)\n\n" if EM.SHOW_SHORT_INFO: stats += await get_short_github_info() From 7297a84faa923c413270196ddeefcc955382c518 Mon Sep 17 00:00:00 2001 From: pseusys Date: Mon, 27 Feb 2023 22:23:44 +0100 Subject: [PATCH 15/28] workflow file emojis added --- .github/workflows/dependency-review.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml index 2ed2dc8..3c31efd 100644 --- a/.github/workflows/dependency-review.yml +++ b/.github/workflows/dependency-review.yml @@ -14,10 +14,12 @@ permissions: jobs: dependency-review: runs-on: ubuntu-latest + steps: - - name: Checkout repository + - name: Checkout repository 🛎️ uses: actions/checkout@v3 - - name: Dependency review + + - name: Dependency review 👀 uses: actions/dependency-review-action@v3 with: comment-summary-in-pr: true From 55b93c81cdae9e744cb3431420c9ea0affcace25 Mon Sep 17 00:00:00 2001 From: pseusys Date: Mon, 27 Feb 2023 22:28:04 +0100 Subject: [PATCH 16/28] workflow file emojis added --- .github/workflows/codeql.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index a61020d..32d1e4f 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -12,23 +12,28 @@ jobs: analyze: name: Analyze runs-on: ubuntu-latest + permissions: actions: read contents: read security-events: write + strategy: fail-fast: false matrix: language: [ 'python' ] + steps: - - name: Checkout repository + - name: Checkout 🛎️ uses: actions/checkout@v3 - - name: Initialize CodeQL + + - name: Initialize CodeQL 🧑‍💻 uses: github/codeql-action/init@v2 with: languages: ${{ matrix.language }} queries: security-and-quality - - name: Perform CodeQL Analysis + + - name: Perform CodeQL Analysis 📈 uses: github/codeql-action/analyze@v2 with: category: "/language:${{matrix.language}}" From e563addad94bd64be46f50dafa024bad27bf28c6 Mon Sep 17 00:00:00 2001 From: pseusys Date: Tue, 28 Feb 2023 00:28:51 +0100 Subject: [PATCH 17/28] graph height fixed, local yearly data caching added --- sources/graphics_chart_drawer.py | 4 +++- sources/main.py | 4 ++-- sources/manager_file.py | 33 +++++++++++++++++++++++++---- sources/manager_github.py | 6 ++++-- sources/yearly_commit_calculator.py | 11 +++++++++- 5 files changed, 48 insertions(+), 10 deletions(-) diff --git a/sources/graphics_chart_drawer.py b/sources/graphics_chart_drawer.py index d408ae7..a8d9562 100644 --- a/sources/graphics_chart_drawer.py +++ b/sources/graphics_chart_drawer.py @@ -64,6 +64,8 @@ async def create_loc_graph(yearly_data: Dict, save_path: str): ax.spines["top"].set_visible(False) ax.spines["right"].set_visible(False) - plt.ylim(top=1.1 * amax(cumulative[:, 0]), bottom=-1.5 * amax(cumulative[:, 1])) + joined = cumulative.reshape(-1, cumulative.shape[-1]) + plt.ylim(top=1.05 * amax(joined[:, 0]), bottom=-1.05 * amax(joined[:, 1])) + plt.savefig(save_path, bbox_inches="tight") plt.close(fig) diff --git a/sources/main.py b/sources/main.py index 7bab6ab..ff571ee 100644 --- a/sources/main.py +++ b/sources/main.py @@ -188,8 +188,8 @@ async def main(): if GHM.update_readme(stats): DBM.g("Readme updated!") else: - GHM.set_github_output(stats) - DBM.g("Debug run, readme not updated. Check the latest comment for the generated stats.") + if GHM.set_github_output(stats): + DBM.g("Debug run, readme not updated. Check the latest comment for the generated stats.") await DM.close_remote_resources() diff --git a/sources/manager_file.py b/sources/manager_file.py index 741b681..4ffe203 100644 --- a/sources/manager_file.py +++ b/sources/manager_file.py @@ -1,6 +1,7 @@ -from json import load -from os.path import join -from typing import Dict +from os.path import join, isfile +from pickle import load as load_pickle, dump as dump_pickle +from json import load as load_json +from typing import Dict, Optional from manager_environment import EnvironmentManager as EM @@ -29,7 +30,7 @@ class FileManager: :param file: Localization file path, related to current file (in sources root). """ with open(join("sources", file), encoding="utf-8") as config_file: - data = load(config_file) + data = load_json(config_file) FileManager._LOCALIZATION = data[EM.LOCALE] @staticmethod @@ -55,3 +56,27 @@ class FileManager: name = join("assets", name) if assets else name with open(name, "a" if append else "w", encoding="utf-8") as file: file.write(content) + + @staticmethod + def cache_binary(name: str, content: Optional[Dict] = None, assets: bool = False) -> Optional[Dict]: + """ + Save binary output file if provided or read if content is None. + + :param name: File name. + :param content: File content (utf-8 string) or None. + :param assets: True for saving to 'assets' directory, false otherwise. + :returns: File cache contents if content is None, None otherwise. + """ + name = join("assets", name) if assets else name + if content is None and not isfile(name): + return None + + with open(name, "rb" if content is None else "wb") as file: + if content is None: + try: + return load_pickle(file) + except Exception: + return None + else: + dump_pickle(content, file) + return None diff --git a/sources/manager_github.py b/sources/manager_github.py index 8bff82a..ba68cd3 100644 --- a/sources/manager_github.py +++ b/sources/manager_github.py @@ -106,7 +106,7 @@ class GitHubManager: return False @staticmethod - def set_github_output(stats: str): + def set_github_output(stats: str) -> bool: """ Outputs readme data as current action output instead of committing it. @@ -114,13 +114,15 @@ class GitHubManager: """ DBM.i("Setting README contents as action output...") if "GITHUB_OUTPUT" not in environ.keys(): - raise Exception("Not in GitHub environment ('GITHUB_OUTPUT' not defined)!") + DBM.p("Not in GitHub environment, not setting action output!") + return False prefix = "README stats current output:" eol = "".join(choice(ascii_letters) for _ in range(10)) FM.write_file(environ["GITHUB_OUTPUT"], f"README_CONTENT<<{eol}\n{prefix}\n\n{stats}\n{eol}\n", append=True) DBM.g("Action output set!") + return True @staticmethod def update_chart(chart_path: str) -> str: diff --git a/sources/yearly_commit_calculator.py b/sources/yearly_commit_calculator.py index 9fd528c..fb714da 100644 --- a/sources/yearly_commit_calculator.py +++ b/sources/yearly_commit_calculator.py @@ -19,9 +19,16 @@ async def calculate_yearly_commit_data(repositories: Dict) -> Dict: :returns: Commit quarter yearly data dictionary. """ DBM.i("Calculating yearly commit data...") + if EM.DEBUG_RUN: + content = FM.cache_binary("yearly_data.pick", assets=True) + if content is not None: + DBM.g("Yearly data restored from cache!") + return content + else: + DBM.w("No cached yearly data found, recalculating...") + yearly_data = dict() total = len(repositories["data"]["user"]["repositories"]["nodes"]) - for ind, repo in enumerate(repositories["data"]["user"]["repositories"]["nodes"]): if repo["name"] not in EM.IGNORED_REPOS: repo_name = "[private]" if repo["isPrivate"] else f"{repo['owner']['login']}/{repo['name']}" @@ -30,7 +37,9 @@ async def calculate_yearly_commit_data(repositories: Dict) -> Dict: DBM.g("Yearly commit data calculated!") if EM.DEBUG_RUN: + FM.cache_binary("yearly_data.pick", yearly_data, assets=True) FM.write_file("yearly_data.json", dumps(yearly_data), assets=True) + DBM.g("Yearly data saved to cache!") return yearly_data From d43cbe81b233d4fb3f52aaef46bc3371f35b4cb3 Mon Sep 17 00:00:00 2001 From: pseusys Date: Tue, 28 Feb 2023 00:41:52 +0100 Subject: [PATCH 18/28] equal offsets on top and on bottom --- sources/graphics_chart_drawer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sources/graphics_chart_drawer.py b/sources/graphics_chart_drawer.py index a8d9562..f49a9da 100644 --- a/sources/graphics_chart_drawer.py +++ b/sources/graphics_chart_drawer.py @@ -64,8 +64,8 @@ async def create_loc_graph(yearly_data: Dict, save_path: str): ax.spines["top"].set_visible(False) ax.spines["right"].set_visible(False) - joined = cumulative.reshape(-1, cumulative.shape[-1]) - plt.ylim(top=1.05 * amax(joined[:, 0]), bottom=-1.05 * amax(joined[:, 1])) + max_value = amax(cumulative.flatten()) + plt.ylim(top=1.05 * max_value, bottom=-1.05 * max_value) plt.savefig(save_path, bbox_inches="tight") plt.close(fig) From 2d576ee38025acff1485c6226d84b1d158b0827a Mon Sep 17 00:00:00 2001 From: pseusys Date: Tue, 28 Feb 2023 00:42:26 +0100 Subject: [PATCH 19/28] multiplication exported --- sources/graphics_chart_drawer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sources/graphics_chart_drawer.py b/sources/graphics_chart_drawer.py index f49a9da..d287408 100644 --- a/sources/graphics_chart_drawer.py +++ b/sources/graphics_chart_drawer.py @@ -64,8 +64,8 @@ async def create_loc_graph(yearly_data: Dict, save_path: str): ax.spines["top"].set_visible(False) ax.spines["right"].set_visible(False) - max_value = amax(cumulative.flatten()) - plt.ylim(top=1.05 * max_value, bottom=-1.05 * max_value) + max_offset = 1.05 * amax(cumulative.flatten()) + plt.ylim(top=max_offset, bottom=-max_offset) plt.savefig(save_path, bbox_inches="tight") plt.close(fig) From a6b49829f571b337d3ce23c74849cdea7ccad9f6 Mon Sep 17 00:00:00 2001 From: pseusys Date: Tue, 28 Feb 2023 00:44:59 +0100 Subject: [PATCH 20/28] concurrency added as workflow runs not instantly --- .github/workflows/codeql.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 32d1e4f..b44c2ba 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -8,6 +8,10 @@ on: schedule: - cron: '30 13 * * 6' +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + jobs: analyze: name: Analyze From 991e714082af0dea691af28e126770e3460dc2b5 Mon Sep 17 00:00:00 2001 From: pseusys Date: Tue, 28 Feb 2023 01:05:09 +0100 Subject: [PATCH 21/28] height offset, equalized --- sources/graphics_chart_drawer.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sources/graphics_chart_drawer.py b/sources/graphics_chart_drawer.py index d287408..70806d3 100644 --- a/sources/graphics_chart_drawer.py +++ b/sources/graphics_chart_drawer.py @@ -64,8 +64,11 @@ async def create_loc_graph(yearly_data: Dict, save_path: str): ax.spines["top"].set_visible(False) ax.spines["right"].set_visible(False) - max_offset = 1.05 * amax(cumulative.flatten()) - plt.ylim(top=max_offset, bottom=-max_offset) + max_offset = 0.05 * amax(cumulative.flatten()) + joined = cumulative.reshape(-1, cumulative.shape[-1]) + max_additions = amax(joined[:, 0]) + max_deletions = amax(joined[:, 1]) + plt.ylim(top=max_additions + max_offset, bottom=-max_deletions - max_offset) plt.savefig(save_path, bbox_inches="tight") plt.close(fig) From 12989d35adfbc0ebe86b29c5304043507ce21ba5 Mon Sep 17 00:00:00 2001 From: pseusys Date: Tue, 28 Feb 2023 17:26:52 +0100 Subject: [PATCH 22/28] retries added to GitHub GraphQL API requests --- sources/manager_download.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sources/manager_download.py b/sources/manager_download.py index 71db5d9..79ef636 100644 --- a/sources/manager_download.py +++ b/sources/manager_download.py @@ -121,7 +121,7 @@ GITHUB_API_QUERIES = { """, "hide_outdated_comment": """ mutation { - minimizeComment(input: {classifier:OUTDATED, subjectId: "$id"}) { + minimizeComment(input: {classifier: OUTDATED, subjectId: "$id"}) { clientMutationId } } @@ -227,7 +227,7 @@ class DownloadManager: return await DownloadManager._get_remote_resource(resource, safe_load) @staticmethod - async def _fetch_graphql_query(query: str, **kwargs) -> Dict: + async def _fetch_graphql_query(query: str, retries_count: int = 10, **kwargs) -> Dict: """ Execute GitHub GraphQL API simple query. :param query: Dynamic query identifier. @@ -241,6 +241,8 @@ class DownloadManager: ) if res.status_code == 200: return res.json() + elif res.status_code == 502 and retries_count > 0: + return await DownloadManager._fetch_graphql_query(query, retries_count - 1, **kwargs) else: raise Exception(f"Query '{query}' failed to run by returning code of {res.status_code}: {res.json()}") From c4880d8c4fd5c461edd615166f11c6c4da88b625 Mon Sep 17 00:00:00 2001 From: pseusys Date: Tue, 28 Feb 2023 23:04:22 +0100 Subject: [PATCH 23/28] merge error fixed --- sources/manager_file.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/manager_file.py b/sources/manager_file.py index 5469eb9..28041b6 100644 --- a/sources/manager_file.py +++ b/sources/manager_file.py @@ -30,7 +30,7 @@ class FileManager: :param file: Localization file path, related to current file (in sources root). """ with open(join(dirname(__file__), file), encoding="utf-8") as config_file: - data = load(config_file) + data = load_json(config_file) FileManager._LOCALIZATION = data[EM.LOCALE] @staticmethod From 629925595bad56d9b1890042c00163fb4c819808 Mon Sep 17 00:00:00 2001 From: pseusys Date: Wed, 1 Mar 2023 00:28:13 +0100 Subject: [PATCH 24/28] persian translation added --- sources/translation.json | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/sources/translation.json b/sources/translation.json index 899130e..2d9642c 100644 --- a/sources/translation.json +++ b/sources/translation.json @@ -701,5 +701,42 @@ "private repositories": "%d Приватных репозиторіїв", "I am an Early": "Я рання 🐤", "I am a Night": "Я нічна 🦉" + }, + "fa": { + "Monday": "دوشنبه", + "Tuesday": "سه‌شنبه", + "Wednesday": "چهارشنبه", + "Thursday": "پنج‌شنبه", + "Friday": "جمعه", + "Saturday": "شنبه", + "Sunday": "یک‌شنبه", + "Morning": "صبح", + "Daytime": "طول روز", + "Evening": "عصر", + "Night": "شب", + "Languages": "زبان‌ها", + "Editors": "ادیتورها", + "operating system": "سیستم‌عامل‌ها", + "Projects": "پروژه‌ها", + "Timezone": "منطقه‌ی زمانی", + "Contributions in the year": "%s مشارکت‌ها در سال جاری %s", + "Used in GitHub's Storage": "%s مصرف فضای گیت‌هاب", + "Opted to Hire": "جویای‌کار", + "Not Opted to Hire": "دنبال‌کار نیست", + "Profile Views": "بازدید‌های پروفایل", + "From Hello World I have written": "از اولین کدم تا کنون %s کد نوشته‌ام.", + "I am Most Productive on": "بیشتر در %s فعالیت دارم", + "This Week I Spend My Time On": "این هفته بیشتر روی این موضوعات کار کردم", + "I Mostly Code in": "من بیشتر کدهام %s هست.", + "Timeline": "زمان‌بندی", + "No Activity Tracked This Week": "این هفته فعالیتی نبوده", + "My GitHub Data": "اطلاعات گیت‌هاب من", + "Lines of code": "خط‌های کد", + "public repository": "%d رپیوزیتوری‌ عمومی", + "public repositories": "%d ریپوزیتوری‌های عمومی", + "private repository": "%d ریپوزیتوری‌ شخصی", + "private repositories": "%d ریپوزیتوری‌های شخصی", + "I am an Early": "من یک 🐤 سحر‌خیزم", + "I am a Night": "من یک 🦉 شبم" } } From 286476d7283bb63048ddae068571c04b6a40284e Mon Sep 17 00:00:00 2001 From: Aravind Nair <22199259+aravindvnair99@users.noreply.github.com> Date: Fri, 10 Mar 2023 02:35:21 +0530 Subject: [PATCH 25/28] Set dependency-review to only check PRs --- .github/workflows/dependency-review.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml index 3c31efd..6a26cd5 100644 --- a/.github/workflows/dependency-review.yml +++ b/.github/workflows/dependency-review.yml @@ -1,11 +1,5 @@ name: Dependency review -on: - push: - branches: master - pull_request: - workflow_dispatch: - schedule: - - cron: 45 15 * * 5 +on: pull_request permissions: contents: read From aa4ce162d110de7b365f774568f9a0b89f43e863 Mon Sep 17 00:00:00 2001 From: Anmol Singh Date: Sat, 11 Mar 2023 13:45:49 +0530 Subject: [PATCH 26/28] Create codeql.yml --- .github/workflows/codeql.yml | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .github/workflows/codeql.yml diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..b44c2ba --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,43 @@ +name: CodeQL + +on: + push: + branches: master + pull_request: + workflow_dispatch: + schedule: + - cron: '30 13 * * 6' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'python' ] + + steps: + - name: Checkout 🛎️ + uses: actions/checkout@v3 + + - name: Initialize CodeQL 🧑‍💻 + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + queries: security-and-quality + + - name: Perform CodeQL Analysis 📈 + uses: github/codeql-action/analyze@v2 + with: + category: "/language:${{matrix.language}}" From d578767c31e57571da41b1420f2ecce7c565530d Mon Sep 17 00:00:00 2001 From: Aravind Nair <22199259+aravindvnair99@users.noreply.github.com> Date: Sat, 11 Mar 2023 23:00:45 +0530 Subject: [PATCH 27/28] Update codeql.yml --- .github/workflows/codeql.yml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index b44c2ba..fd24e97 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -30,12 +30,25 @@ jobs: steps: - name: Checkout 🛎️ uses: actions/checkout@v3 - + + - name: Setup Python 3.8 🐍 + uses: actions/setup-python@v4 + with: + python-version: 3.8 + cache: 'pip' + + - name: Install dependencies 📥 + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + echo "CODEQL_PYTHON=$(which python)" >> $GITHUB_ENV + - name: Initialize CodeQL 🧑‍💻 uses: github/codeql-action/init@v2 with: languages: ${{ matrix.language }} queries: security-and-quality + setup-python-dependencies: false - name: Perform CodeQL Analysis 📈 uses: github/codeql-action/analyze@v2 From 85a6d7f129f0b40681df42c104a919a877d6ed8b Mon Sep 17 00:00:00 2001 From: Aravind Nair <22199259+aravindvnair99@users.noreply.github.com> Date: Sun, 12 Mar 2023 02:19:38 +0530 Subject: [PATCH 28/28] Enable pip caching in CI --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 57455e6..eaa22cc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,6 +21,7 @@ jobs: uses: actions/setup-python@v4 with: python-version: 3.8 + cache: 'pip' - name: Install Dependencies 📥 run: pip install -r requirements.txt