├── .github └── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── .gitignore ├── CODE_OF_CONDUCT.md ├── Dockerfile ├── GenerateREADME.py ├── LICENSE ├── README.md ├── ReadmeMaker.py ├── action.yml ├── example ├── README.md └── readme-info-schedule.yml ├── githubQuery.py ├── requirements.txt └── utility.py /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: "" 5 | labels: "" 6 | assignees: "" 7 | --- 8 | 9 | **Is your feature request related to a problem? Please describe.** 10 | A clear and concise description of what the problem is. Ex. I'm always frustrated when ... 11 | 12 | **Describe the solution you'd like** 13 | A clear and concise description of what you want to happen. 14 | 15 | **Describe alternatives you've considered** 16 | A clear and concise description of any alternative solutions or features you've considered. 17 | 18 | **Additional context** 19 | Add any other context or screenshots about the feature request here. 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Developement 2 | .vscode 3 | .env 4 | .venv 5 | **/__pycache__/** 6 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | - Using welcoming and inclusive language 18 | - Being respectful of differing viewpoints and experiences 19 | - Gracefully accepting constructive criticism 20 | - Focusing on what is best for the community 21 | - Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | - The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | - Trolling, insulting/derogatory comments, and personal or political attacks 28 | - Public or private harassment 29 | - Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | - Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at [jainamvipul.desai2019@vitstudent.ac.in](mailto:jainamvipul.desai2019@vitstudent.ac.in). All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at 72 | 73 | For answers to common questions about this code of conduct, see 74 | 75 | 76 | [homepage]: https://www.contributor-covenant.org 77 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM nikolaik/python-nodejs:latest 2 | 3 | # Install dependencies. 4 | COPY requirements.txt /requirements.txt 5 | COPY GenerateREADME.py /GenerateREADME.py 6 | COPY githubQuery.py /githubQuery.py 7 | COPY ReadmeMaker.py /ReadmeMaker.py 8 | COPY utility.py /utility.py 9 | RUN pip install -r requirements.txt 10 | 11 | ENV NPM_CONFIG_PREFIX=/home/node/.npm-global 12 | 13 | RUN npm -g config set user root 14 | 15 | RUN npm install -g vega-lite vega-cli canvas 16 | 17 | # Run the file 18 | ENTRYPOINT ["python", "/GenerateREADME.py"] -------------------------------------------------------------------------------- /GenerateREADME.py: -------------------------------------------------------------------------------- 1 | # Python: 3.8.x 2 | 3 | # System Imports 4 | from os import getenv 5 | from datetime import datetime 6 | from traceback import print_exc 7 | 8 | 9 | # Third Party Imports 10 | from github import Github 11 | from dotenv import load_dotenv 12 | import humanize 13 | from pytz import utc, timezone 14 | 15 | # Custom Imports 16 | from githubQuery import * 17 | from ReadmeMaker import ReadmeGenerator 18 | from utility import makeCommitList, makeLanguageList 19 | 20 | # Load Environment Variables 21 | load_dotenv() 22 | 23 | # Get TOKEN 24 | ghtoken = getenv('INPUT_GH_TOKEN') 25 | 26 | 27 | def getDailyCommitData(repositoryList: list) -> str: 28 | print("Generating Daily Commit Data... ") 29 | 30 | if getenv('INPUT_TIMEZONE') == None: 31 | tz = "Asia/Kolkata" 32 | else: 33 | tz = getenv('INPUT_TIMEZONE') 34 | 35 | morning = 0 # 4 - 10 36 | daytime = 0 # 10 - 16 37 | evening = 0 # 16 - 22 38 | nighttime = 0 # 0 - 4 39 | 40 | for repository in repositoryList: 41 | result = Query.runGithubGraphqlQuery( 42 | createCommittedDateQuery.substitute(owner=repository["owner"]["login"], name=repository["name"], id=id)) 43 | try: 44 | commitedDates = result["data"]["repository"]["ref"]["target"]["history"]["edges"] 45 | 46 | for committedDate in commitedDates: 47 | date = datetime.strptime(committedDate["node"]["committedDate"], 48 | "%Y-%m-%dT%H:%M:%SZ").replace(tzinfo=utc).astimezone( 49 | timezone(tz)) 50 | 51 | hour = date.hour 52 | 53 | if 6 <= hour < 12: 54 | morning += 1 55 | if 12 <= hour < 18: 56 | daytime += 1 57 | if 18 <= hour < 24: 58 | evening += 1 59 | if 0 <= hour < 6: 60 | nighttime += 1 61 | except Exception: 62 | print("ERROR", repository["name"], "is private!") 63 | 64 | totalCommits = morning + daytime + evening + nighttime 65 | 66 | if morning + daytime >= evening + nighttime: 67 | title = "I'm an early 🐤" 68 | else: 69 | title = "I'm a night 🦉" 70 | 71 | eachDay = [ 72 | {"name": "🌞 Morning", "text": str( 73 | morning) + " commits", "percent": round((morning / totalCommits) * 100, 2)}, 74 | {"name": "🌆 Daytime", "text": str( 75 | daytime) + " commits", "percent": round((daytime / totalCommits) * 100, 2)}, 76 | {"name": "🌃 Evening", "text": str( 77 | evening) + " commits", "percent": round((evening / totalCommits) * 100, 2)}, 78 | {"name": "🌙 Night", "text": str( 79 | nighttime) + " commits", "percent": round((nighttime / totalCommits) * 100, 2)}, 80 | ] 81 | 82 | print("Daily Commit Data created!") 83 | 84 | return "**" + title + "** \n" + """ 85 | | | | | | 86 | | --- | --- | --- | --- | 87 | """ + makeCommitList(eachDay) + """ 88 | | | | | |\n""" 89 | 90 | 91 | def getWeeklyCommitData(repositoryList: list) -> str: 92 | print("Generating Weekly Commit Data... ") 93 | 94 | tz = getenv('INPUT_TIMEZONE') 95 | 96 | weekdays = [0, 0, 0, 0, 0, 0, 0] 97 | 98 | for repository in repositoryList: 99 | result = Query.runGithubGraphqlQuery( 100 | createCommittedDateQuery.substitute(owner=username, name=repository["name"], id=id)) 101 | try: 102 | commitedDates = result["data"]["repository"]["ref"]["target"]["history"]["edges"] 103 | 104 | for committedDate in commitedDates: 105 | date = datetime.strptime(committedDate["node"]["committedDate"], 106 | "%Y-%m-%dT%H:%M:%SZ").replace(tzinfo=utc).astimezone( 107 | timezone(tz)) 108 | 109 | weekday = date.strftime('%A') 110 | 111 | if weekday == "Monday": 112 | weekdays[0] += 1 113 | if weekday == "Tuesday": 114 | weekdays[1] += 1 115 | if weekday == "Wednesday": 116 | weekdays[2] += 1 117 | if weekday == "Thursday": 118 | weekdays[3] += 1 119 | if weekday == "Friday": 120 | weekdays[4] += 1 121 | if weekday == "Saturday": 122 | weekdays[5] += 1 123 | if weekday == "Sunday": 124 | weekdays[6] += 1 125 | 126 | except Exception as exception: 127 | print("ERROR", repository["name"]) 128 | 129 | totalCommits = sum(weekdays) 130 | 131 | dayOfWeek = [ 132 | {"name": "Monday", "text": str( 133 | weekdays[0]) + " commits", "percent": round((weekdays[0] / totalCommits) * 100, 2)}, 134 | {"name": "Tuesday", "text": str( 135 | weekdays[1]) + " commits", "percent": round((weekdays[1] / totalCommits) * 100, 2)}, 136 | {"name": "Wednesday", "text": str( 137 | weekdays[2]) + " commits", "percent": round((weekdays[2] / totalCommits) * 100, 2)}, 138 | {"name": "Thursday", "text": str( 139 | weekdays[3]) + " commits", "percent": round((weekdays[3] / totalCommits) * 100, 2)}, 140 | {"name": "Friday", "text": str( 141 | weekdays[4]) + " commits", "percent": round((weekdays[4] / totalCommits) * 100, 2)}, 142 | {"name": "Saturday", "text": str( 143 | weekdays[5]) + " commits", "percent": round((weekdays[5] / totalCommits) * 100, 2)}, 144 | {"name": "Sunday", "text": str( 145 | weekdays[6]) + " commits", "percent": round((weekdays[6] / totalCommits) * 100, 2)}, 146 | ] 147 | 148 | max_element = { 149 | 'percent': 0 150 | } 151 | 152 | for day in dayOfWeek: 153 | if day['percent'] > max_element['percent']: 154 | max_element = day 155 | 156 | print("Weekly Commit Data created!") 157 | 158 | title = 'I\'m Most Productive on ' + max_element['name'] + 's' 159 | return "📅 **" + title + "** \n"+""" 160 | | | | | | 161 | | --- | --- | --- | --- | 162 | """ + makeCommitList(dayOfWeek) + """ 163 | | | | | |\n""" 164 | 165 | 166 | def getLanguagesPerRepo() -> str: 167 | print("Generating Most used Language... ", end="") 168 | 169 | language_count = {} 170 | total = 0 171 | result = Query.runGithubGraphqlQuery( 172 | repositoryListQuery.substitute(username=username, id=id)) 173 | 174 | for repo in result['data']['user']['repositories']['edges']: 175 | if repo['node']['primaryLanguage'] is None: 176 | continue 177 | language = repo['node']['primaryLanguage']['name'] 178 | color_code = repo['node']['primaryLanguage']['color'] 179 | total += 1 180 | if language not in language_count.keys(): 181 | language_count[language] = {} 182 | language_count[language]['count'] = 1 183 | else: 184 | language_count[language]['count'] = language_count[language]['count'] + 1 185 | language_count[language]['color'] = color_code 186 | data = [] 187 | sorted_labels = list(language_count.keys()) 188 | sorted_labels.sort(key=lambda x: language_count[x]['count'], reverse=True) 189 | most_language_repo = sorted_labels[0] 190 | for label in sorted_labels: 191 | percent = round(language_count[label]['count'] / total * 100, 2) 192 | data.append({ 193 | "name": label, 194 | "text": str(language_count[label]['count']) + " repos", 195 | "percent": percent 196 | }) 197 | 198 | print("Done") 199 | title = "My 💖 languages " + most_language_repo 200 | return "**" + title + "** \n" + """ 201 | | | | | | 202 | | --- | --- | --- | --- | 203 | """ + makeLanguageList(data) + """ 204 | | | | | |\n""" 205 | 206 | 207 | def getProfileViews() -> str: 208 | 209 | data = Query.runGithubAPIQuery(getProfileViewQuery.substitute( 210 | owner=username, repo=username)) 211 | 212 | return ('**✨ ' + str(data["count"]) + ' people were here!**\n\n') 213 | 214 | 215 | def getLinesOfCode(repositoryList): 216 | print("Generating Lines Of Code... ", end="") 217 | totalLOC = 0 218 | for repository in repositoryList: 219 | try: 220 | # time.sleep(0.7) 221 | datas = Query.runGithubAPIQuery(getLinesOfCodeQuery.substitute( 222 | owner=repository["owner"]["login"], repo=repository["name"])) 223 | for data in datas: 224 | totalLOC += (data[1] - data[2]) 225 | except Exception as execption: 226 | print(execption) 227 | print("Done") 228 | return ("**From Hello World I have written " + humanize.intword(int(totalLOC)) + " Lines of Code ✍️**\n\n") 229 | 230 | 231 | def getTotalContributions(): 232 | data = Query.runGithubContributionsQuery(username) 233 | total = data['years'][0]['total'] 234 | year = data['years'][0]['year'] 235 | return "**🏆 " + humanize.intcomma(total) + " Contributions in year " + year + "**\n\n" 236 | 237 | 238 | def generateData() -> str: 239 | 240 | stats = "" 241 | print("Generating new README Data... ") 242 | 243 | ReadmeMaker = ReadmeGenerator(readme.content) 244 | 245 | result = Query.runGithubGraphqlQuery( 246 | createContributedRepoQuery.substitute(username=username)) 247 | nodes = result["data"]["user"]["repositoriesContributedTo"]["nodes"] 248 | 249 | repos = [d for d in nodes if d['isFork'] is False] 250 | 251 | if getenv('INPUT_SHOW_TOTAL_CONTRIBUTIONS') == 'True': 252 | stats = getTotalContributions() 253 | ReadmeMaker.generateTotalContributions(stats) 254 | if getenv("INPUT_SHOW_LINES_OF_CODE") == 'True': 255 | stats = getLinesOfCode(repos) 256 | ReadmeMaker.generateLinesOfCodeStats(stats) 257 | if getenv("INPUT_SHOW_PROFILE_VIEWS") == 'True': 258 | stats = getProfileViews() 259 | ReadmeMaker.generateProfileViewsStats(stats) 260 | if getenv("INPUT_SHOW_DAILY_COMMIT") == 'True': 261 | stats = getDailyCommitData(repos) 262 | ReadmeMaker.generateDailyStats(stats) 263 | if getenv("INPUT_SHOW_WEEKLY_COMMIT") == 'True': 264 | stats = getWeeklyCommitData(repos) 265 | ReadmeMaker.generateWeeklyStats(stats) 266 | if getenv("INPUT_SHOW_LANGUAGE") == 'True': 267 | stats = getLanguagesPerRepo() 268 | ReadmeMaker.generateMostUsedLanguage(stats) 269 | 270 | print("README data created!") 271 | 272 | newREADME = ReadmeMaker.getREADME() 273 | return newREADME 274 | 275 | 276 | if __name__ == "__main__": 277 | try: 278 | if ghtoken is None: 279 | raise Exception("Token not available") 280 | 281 | # Strart the Calculation 282 | githubObject = Github(ghtoken) 283 | headers = {"Authorization": "Bearer " + ghtoken} 284 | 285 | Query = RunQuery(headers) 286 | # Execute the query 287 | user_data = Query.runGithubGraphqlQuery(userInfoQuery) 288 | username = user_data["data"]["viewer"]["login"] 289 | id = user_data["data"]["viewer"]["id"] 290 | 291 | print("Running task for... ", username) 292 | 293 | # Get user repository 294 | repo = githubObject.get_repo(f"{username}/{username}") 295 | 296 | readme = repo.get_readme() 297 | 298 | # Running task now ... 299 | newREADME = generateData() 300 | 301 | repo.update_file(path=readme.path, message="⤴ Auto Updated README", 302 | content=newREADME, sha=readme.sha, branch='master') 303 | except Exception as e: 304 | print_exc() 305 | print("ERROR:: ", str(e)) 306 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Jainam Desai 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

✨README Info Generator ✨

2 | 3 |

4 | 5 | 6 | 7 | 8 | 9 | Star Badge 10 | 11 |

12 | 13 | 14 | 15 | Flex your Stats with this highly customizable tool!
16 | Are you an early 🐤 or a night 🦉?
17 | When are you most productive during the day?
18 | What are languages you code in?
19 | 20 |
21 | 22 | ## Setup 23 | 24 | 1. You need to update the markdown file(.md) with the `START_SECTION` and `STOP_SECTION` comments. You can refer [this](#entry-points) section for updating it. 25 | 26 | 2. You'll need a GitHub API Token with `repo` and `user` scope from [here](https://github.com/settings/tokens) if you're running the action to get commit metrics 27 | 28 | > enabling the `repo` scope seems **DANGEROUS**
29 | > but this GitHub Action only accesses your commit timestamp and lines of code added or deleted in repository you contributed. 30 | 31 | 3. You need to save the GitHub API Token in the repository secrets. You can find that in the Settings of your repository. Be sure to save those as GitHub Personal Access Token as `GH_TOKEN=` 32 | 33 | 4. You can enable and disable feature flags based on requirements. See [this](#flags-available). 34 | 35 | 5. For the final step you need to add an `.yml` file in your workflows folder. You can copy/paste [this](./example/readme-info-schedule.yml) example file and enable/disable flags as you wish!. 36 | 37 | ### The Required fields are 38 | 39 | > GH_TOKEN Your GitHub token explainer in Step 2. 40 | > TIMEZONE Your timezone, defaults to "Asia/Kolkata" for India. 41 | 42 | ### Entry Points 43 | 44 | Add a comment to your `README.md` like this: 45 | 46 | ```md 47 | 48 | 49 | ``` 50 | 51 | See this example [file](./example/README.md). You can put these Entry Points anywhere and in any order you please! 🤷‍♂️ 52 | 53 | ## Flags Available 54 | 55 | `SHOW_LINES_OF_CODE` flag can be set to `True` to show the Lines of code writen till date 56 | 57 | ```text 58 | From Hello World I have written 1.6 million Lines of Code ✍️ 59 | ``` 60 | 61 | `SHOW_PROFILE_VIEWS` flag can be set to `False` to hide the Profile views 62 | 63 | ```text 64 | ✨ 216 people were here! 65 | ``` 66 | 67 | `SHOW_DAILY_COMMIT` flag can be set to `False` to hide the commit stat 68 | 69 | ```text 70 | I'm a night 🦉 71 | 72 | 🌞 Morning 57 commits ████░░░░░░░░░░░░░░░░░░░░░ 16.76% 73 | 🌆 Daytime 85 commits ██████░░░░░░░░░░░░░░░░░░░ 25.0% 74 | 🌃 Evening 128 commits █████████░░░░░░░░░░░░░░░░ 37.65% 75 | 🌙 Night 70 commits █████░░░░░░░░░░░░░░░░░░░░ 20.59% 76 | 77 | ``` 78 | 79 | `SHOW_WEEKLY_COMMIT` flag can be set to `False` to hide the commit stat 80 | 81 | ```text 82 | 📅 I'm Most Productive on Mondays 83 | 84 | Monday 64 commits █████░░░░░░░░░░░░░░░░░░░░ 21.19% 85 | Tuesday 33 commits ██░░░░░░░░░░░░░░░░░░░░░░░ 10.93% 86 | Wednesday 59 commits █████░░░░░░░░░░░░░░░░░░░░ 19.54% 87 | Thursday 41 commits ███░░░░░░░░░░░░░░░░░░░░░░ 13.58% 88 | Friday 40 commits ███░░░░░░░░░░░░░░░░░░░░░░ 13.25% 89 | Saturday 35 commits ███░░░░░░░░░░░░░░░░░░░░░░ 11.59% 90 | Sunday 30 commits ██░░░░░░░░░░░░░░░░░░░░░░░ 9.93% 91 | 92 | ``` 93 | 94 | `SHOW_LANGUAGE` flag can be set to `False` to hide the Number of repository in different language and framework 95 | 96 | ```text 97 | My 💖 languages Python 98 | 99 | Python 12 repos █████████████░░░░░░░░░░░░ 54.55% 100 | JavaScript 7 repos ████████░░░░░░░░░░░░░░░░░ 31.82% 101 | CSS 2 repos ██░░░░░░░░░░░░░░░░░░░░░░░ 9.09% 102 | HTML 1 repos █░░░░░░░░░░░░░░░░░░░░░░░░ 4.55% 103 | 104 | ``` 105 | 106 | `SHOW_TOTAL_CONTRIBUTIONS` flag can be set to `False` to hide the total Number of Contributions 107 | 108 | ```text 109 | 🏆 531 Contributions in year 2020 110 | ``` 111 | 112 | ### Inspired By 🚀 113 | 114 | > [matchai/awesome-pinned-gists](https://github.com/matchai/awesome-pinned-gists) 115 | > [athul/waka-readme](https://github.com/athul/waka-readme) 116 | > [anmol098/waka-readme-stats](https://github.com/anmol098/waka-readme-stats) 117 | 118 | ```text 119 | Liked this Project? Why not 🌟 it? 120 | ``` 121 | 122 | > Made with 🖤 by Jainam Desai 123 | -------------------------------------------------------------------------------- /ReadmeMaker.py: -------------------------------------------------------------------------------- 1 | from re import sub 2 | from base64 import b64decode 3 | 4 | 5 | # TODO: Make for each Section 6 | 7 | class ReadmeGenerator(): 8 | 9 | def __init__(self, readme): 10 | self.readme = self.decodeREADME(readme) 11 | 12 | def getREADME(self): 13 | return self.readme 14 | 15 | def generateDailyStats(self, stats: str): 16 | print("Generating Daily Section... ", end="") 17 | START_COMMENT = '' 18 | END_COMMENT = '' 19 | daily_commit_in_readme = f"{START_COMMENT}\n{stats}\n{END_COMMENT}" 20 | listReg = f"{START_COMMENT}[\\s\\S]+{END_COMMENT}" 21 | 22 | self.readme = sub(listReg, daily_commit_in_readme, self.readme) 23 | print("Done") 24 | 25 | def generateWeeklyStats(self, stats: str): 26 | print("Generating Weekly Section... ", end="") 27 | START_COMMENT = '' 28 | END_COMMENT = '' 29 | weekly_commit_in_readme = f"{START_COMMENT}\n{stats}\n{END_COMMENT}" 30 | listReg = f"{START_COMMENT}[\\s\\S]+{END_COMMENT}" 31 | 32 | self.readme = sub(listReg, weekly_commit_in_readme, self.readme) 33 | print("Done") 34 | 35 | def generateProfileViewsStats(self, stats: str): 36 | print("Generating Profile Views Section... ", end="") 37 | START_COMMENT = '' 38 | END_COMMENT = '' 39 | profile_views_in_readme = f"{START_COMMENT}\n{stats}\n{END_COMMENT}" 40 | listReg = f"{START_COMMENT}[\\s\\S]+{END_COMMENT}" 41 | 42 | self.readme = sub(listReg, profile_views_in_readme, self.readme) 43 | print("Done") 44 | 45 | def generateLinesOfCodeStats(self, stats: str): 46 | print("Generating Lines Of Code Section... ", end="") 47 | START_COMMENT = '' 48 | END_COMMENT = '' 49 | lines_of_code_in_readme = f"{START_COMMENT}\n{stats}\n{END_COMMENT}" 50 | listReg = f"{START_COMMENT}[\\s\\S]+{END_COMMENT}" 51 | 52 | self.readme = sub(listReg, lines_of_code_in_readme, self.readme) 53 | print("Done") 54 | 55 | def generateMostUsedLanguage(self, stats: str): 56 | print("Generating Lines Of Code Section... ", end="") 57 | START_COMMENT = '' 58 | END_COMMENT = '' 59 | language_in_readme = f"{START_COMMENT}\n{stats}\n{END_COMMENT}" 60 | listReg = f"{START_COMMENT}[\\s\\S]+{END_COMMENT}" 61 | 62 | self.readme = sub(listReg, language_in_readme, self.readme) 63 | print("Done") 64 | 65 | def generateTotalContributions(self, stats: str): 66 | print("Generating Total Contributions Section... ", end="") 67 | START_COMMENT = '' 68 | END_COMMENT = '' 69 | contributions_in_readme = f"{START_COMMENT}\n{stats}\n{END_COMMENT}" 70 | listReg = f"{START_COMMENT}[\\s\\S]+{END_COMMENT}" 71 | 72 | self.readme = sub(listReg, contributions_in_readme, self.readme) 73 | print("Done") 74 | 75 | def generateSayThanks(self): 76 | START_COMMENT = '' 77 | END_COMMENT = '' 78 | stats = "Made with 🖤 by [Jainam Desai](https://th3c0d3br34ker.github.io)" 79 | lines_of_code_in_readme = f"{START_COMMENT}\n{stats}\n{END_COMMENT}" 80 | listReg = f"{START_COMMENT}[\\s\\S]+{END_COMMENT}" 81 | 82 | self.readme = sub(listReg, lines_of_code_in_readme, self.readme) 83 | print("Thank You! ❤") 84 | 85 | @staticmethod 86 | def decodeREADME(data: str): 87 | '''Decode the contents of old README''' 88 | decoded_bytes = b64decode(data) 89 | return str(decoded_bytes, 'utf-8') 90 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: "GitHub README Generator" 2 | author: "Jainam Desai" 3 | description: "A lot of customizable features! ✨" 4 | 5 | inputs: 6 | GH_TOKEN: 7 | description: "GitHub access token with Repo scope" 8 | required: true 9 | default: ${{ github.token }} 10 | 11 | TIMEZONE: 12 | description: "Your Local TimeZone" 13 | required: true 14 | 15 | SHOW_DAILY_COMMIT: 16 | required: false 17 | description: "Shows the number of commit graph in the dev metrics." 18 | default: "True" 19 | 20 | SHOW_WEEKLY_COMMIT: 21 | required: false 22 | description: "Shows day of week you are most productive." 23 | default: "True" 24 | 25 | SHOW_LINES_OF_CODE: 26 | required: false 27 | description: "Show the Total Lines Of Code written Badge till date." 28 | default: "True" 29 | 30 | SHOW_PROFILE_VIEWS: 31 | required: false 32 | description: "Shows the Profile Views." 33 | default: "True" 34 | 35 | SHOW_LANGUAGE: 36 | required: false 37 | description: "Shows the most used language." 38 | default: "True" 39 | 40 | SHOW_TOTAL_CONTRIBUTIONS: 41 | required: false 42 | description: "Shows the total number of contributions." 43 | default: "True" 44 | 45 | runs: 46 | using: "docker" 47 | image: "Dockerfile" 48 | 49 | branding: 50 | icon: "activity" 51 | color: "blue" 52 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # Example README File 2 | 3 | ## Want to use them all 4 | 5 | ```md 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | ``` 24 | 25 | ## For Profile Views Section 26 | 27 | ```md 28 | 29 | 30 | ``` 31 | 32 | ## For Lines of Code Section 33 | 34 | ```md 35 | 36 | 37 | ``` 38 | 39 | ## For Show Total Contributions 40 | 41 | ```md 42 | 43 | 44 | ``` 45 | 46 | ## For Daily Commits Section 47 | 48 | ```md 49 | 50 | 51 | ``` 52 | 53 | ## For Weekly Commits Section 54 | 55 | ```md 56 | 57 | 58 | ``` 59 | 60 | ## For Show Most used Language 61 | 62 | ```md 63 | 64 | 65 | ``` 66 | -------------------------------------------------------------------------------- /example/readme-info-schedule.yml: -------------------------------------------------------------------------------- 1 | name: README Info Update 2 | 3 | on: 4 | schedule: 5 | - cron: "0 0 * * *" 6 | workflow_dispatch: 7 | 8 | jobs: 9 | update-readme: 10 | name: GitHub README Generator 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: th3c0d3br34ker/github-readme-info@master 14 | with: 15 | GH_TOKEN: ${{ secrets.GH_TOKEN }} 16 | TIMEZONE: "Asia/Kolkata" 17 | SHOW_LINES_OF_CODE: "True" 18 | SHOW_PROFILE_VIEWS: "True" 19 | SHOW_DAILY_COMMIT: "True" 20 | SHOW_WEEKLY_COMMIT: "True" 21 | SHOW_LANGUAGE: "True" 22 | SHOW_TOTAL_CONTRIBUTIONS: "True" 23 | -------------------------------------------------------------------------------- /githubQuery.py: -------------------------------------------------------------------------------- 1 | from string import Template 2 | from requests import get, post 3 | 4 | userInfoQuery = """ 5 | { 6 | viewer { 7 | login 8 | id 9 | } 10 | } 11 | """ 12 | 13 | createContributedRepoQuery = Template(""" 14 | query { 15 | user(login: "$username") { 16 | repositoriesContributedTo(last: 100, includeUserRepositories: true) { 17 | nodes { 18 | isFork 19 | name 20 | owner { 21 | login 22 | } 23 | } 24 | } 25 | } 26 | } 27 | """) 28 | 29 | createCommittedDateQuery = Template(""" 30 | query { 31 | repository(owner: "$owner", name: "$name") { 32 | ref(qualifiedName: "master") { 33 | target { 34 | ... on Commit { 35 | history(first: 100, author: { id: "$id" }) { 36 | edges { 37 | node { 38 | committedDate 39 | } 40 | } 41 | } 42 | } 43 | } 44 | } 45 | } 46 | } 47 | """) 48 | 49 | 50 | repositoryListQuery = Template(""" 51 | { 52 | user(login: "$username") { 53 | repositories(orderBy: {field: CREATED_AT, direction: ASC}, last: 100, affiliations: [OWNER, COLLABORATOR, ORGANIZATION_MEMBER], isFork: false) { 54 | totalCount 55 | edges { 56 | node { 57 | object(expression:"master") { 58 | ... on Commit { 59 | history (author: { id: "$id" }){ 60 | totalCount 61 | } 62 | } 63 | } 64 | primaryLanguage { 65 | color 66 | name 67 | id 68 | } 69 | stargazers { 70 | totalCount 71 | } 72 | collaborators { 73 | totalCount 74 | } 75 | createdAt 76 | name 77 | owner { 78 | id 79 | login 80 | } 81 | nameWithOwner 82 | } 83 | } 84 | } 85 | location 86 | createdAt 87 | name 88 | } 89 | } 90 | """) 91 | 92 | 93 | getLinesOfCodeQuery = Template("""/repos/$owner/$repo/stats/code_frequency""") 94 | 95 | getProfileViewQuery = Template( 96 | """/repos/$owner/$repo/traffic/views""") 97 | 98 | getProfileTrafficQuery = Template( 99 | """/repos/$owner/$repo/traffic/popular/referrers""") 100 | 101 | 102 | class RunQuery(): 103 | 104 | def __init__(self, headers): 105 | self.headers = headers 106 | 107 | def runGithubAPIQuery(self, query): 108 | request = get("https://api.github.com" + query, headers=self.headers) 109 | if request.status_code == 200: 110 | return request.json() 111 | else: 112 | raise Exception( 113 | "Query failed to run by returning code of {}. {},... {}".format( 114 | request.status_code, query, str(request.json()))) 115 | 116 | def runGithubGraphqlQuery(self, query) -> dict: 117 | request = post("https://api.github.com/graphql", 118 | json={"query": query}, headers=self.headers) 119 | if request.status_code == 200: 120 | return request.json() 121 | else: 122 | raise Exception("Query failed to run by returning code of {}. {}".format( 123 | request.status_code, query)) 124 | 125 | def runGithubContributionsQuery(self, username): 126 | request = get( 127 | "https://github-contributions.now.sh/api/v1/" + username) 128 | if request.status_code == 200: 129 | return request.json() 130 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | certifi==2022.12.7 2 | chardet==3.0.4 3 | charset-normalizer==2.0.4 4 | cycler==0.10.0 5 | Deprecated==1.2.10 6 | gitdb==4.0.5 7 | GitPython==3.1.30 8 | humanize==3.0.1 9 | idna==2.10 10 | kiwisolver==1.2.0 11 | matplotlib==3.3.0 12 | numpy==1.22.0 13 | Pillow==9.3.0 14 | pycodestyle==2.6.0 15 | PyGithub==1.52 16 | PyJWT==2.4.0 17 | pyparsing==2.4.7 18 | python-dateutil==2.8.1 19 | python-dotenv==0.14.0 20 | pytz==2020.1 21 | requests==2.26.0 22 | six==1.15.0 23 | smmap==3.0.4 24 | toml==0.10.1 25 | urllib3==1.26.6 26 | -------------------------------------------------------------------------------- /utility.py: -------------------------------------------------------------------------------- 1 | # Utility Funtions 2 | 3 | def makeGraph(percent: float) -> str: 4 | '''Make progress graph from API graph''' 5 | pc_rnd = round(percent) 6 | done_block = f"![](https://via.placeholder.com/{(int(pc_rnd * 4))}x22/000000/000000?text=+)" 7 | empty_block = f"![](https://via.placeholder.com/{(400 - int(pc_rnd * 4))}x22/b8b8b8/b8b8b8?=text=+)" 8 | 9 | return done_block+empty_block 10 | 11 | 12 | def makeLanguageList(data: list) -> str: 13 | '''Make List''' 14 | data_list = [] 15 | for l in data: 16 | ln = len(l['name']) 17 | ln_text = len(l['text']) 18 | op = f"""|{l['name'][:25]}{' ' * (25 - ln)}|{l['text']}|{' ' * (20 - ln_text)}{makeGraph(l['percent'])}|{l['percent']}%|""" 19 | data_list.append(op) 20 | return '\n'.join(data_list) 21 | 22 | 23 | def makeCommitList(data: list) -> str: 24 | '''Make List''' 25 | data_list = [] 26 | for l in data[:7]: 27 | ln = len(l['name']) 28 | ln_text = len(l['text']) 29 | op = f"""|{l['name']}{' ' * (25 - ln)}|{l['text']}{' ' * (20 - ln_text)}|{makeGraph(l['percent'])}|{l['percent']}%|""" 30 | data_list.append(op) 31 | return '\n'.join(data_list) 32 | --------------------------------------------------------------------------------