├── requirements.txt ├── images ├── config.png └── preview.png ├── CONTRIBUTING.md ├── LICENSE ├── action.yml ├── main-script.py ├── CODE_OF_CONDUCT.md └── README.md /requirements.txt: -------------------------------------------------------------------------------- 1 | PyGithub==1.53 -------------------------------------------------------------------------------- /images/config.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaustubhgupta/readme-projects-display/HEAD/images/config.png -------------------------------------------------------------------------------- /images/preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaustubhgupta/readme-projects-display/HEAD/images/preview.png -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to readme-projects-display 2 | 👍🎉 First off, thanks for taking the time to contribute! 🎉👍 3 | 4 | Contributions are always appreciated as **no contribution is too small.** 5 | **We are here to learn and grow along with the community** 6 | 7 | 8 | # Submitting Contributions 9 | - **Perfom all the initials:** Fork the repo, clone your version locally, add upstream to my repo `https://github.com/kaustubhgupta/readme-projects-display`, create a new branch. If you're not aware of all these terminologies, there are ton of resources available on internet. 10 | 11 | - **Choosing the Issue:** You can create issues for bugs, new features, documentation errors or anything you want to add. Open a new issue and we will have the discussion about it. 12 | 13 | - **Local Setup:** Python needs to installed beforehand. Other than this, you should create a new environment for this project and install all the requirements via pip ( `pip install -r requirements.txt`) 14 | 15 | 16 | **Important:** Make sure to check the docs for more detailed descriptions of various parameters and files used. 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Kaustubh 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 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: Readme Projects Display 2 | author: Kaustubh Gupta 3 | description: Updates Readme/specified file with latest projects information 4 | inputs: 5 | gh_token: 6 | description: "Github Personal Access token" 7 | required: True 8 | file_name: 9 | description: "Name of the file" 10 | required: False 11 | default: README.md 12 | max_repo_description: 13 | description: "How much description you want to Display" 14 | required: False 15 | default: 50 16 | allow_forks: 17 | description: "Control if you want forks count" 18 | required: False 19 | default: True 20 | project_sort_by: 21 | description: "Sorting the projects according to count of number of stars or forks" 22 | required: False 23 | default: 'stars' 24 | 25 | runs: 26 | using: "composite" 27 | steps: 28 | - run: python -m pip install PyGithub 29 | shell: bash 30 | - run: python ${{ github.action_path }}/main-script.py ${{ inputs.gh_token }} ${{ inputs.file_name }} ${{ github.workspace }} ${{ inputs.max_repo_description }} ${{ inputs.allow_forks }} ${{ inputs.project_sort_by }} 31 | shell: bash 32 | branding: 33 | icon: "award" 34 | color: "blue" 35 | -------------------------------------------------------------------------------- /main-script.py: -------------------------------------------------------------------------------- 1 | from github import Github 2 | import pathlib 3 | import re 4 | import sys 5 | import json 6 | 7 | 8 | def rewriteContents(old_content, new_content): 9 | r = re.compile( 10 | r'.*', re.DOTALL) 11 | new_content_formated = '{}'.format( 12 | new_content) 13 | return r.sub(new_content_formated, old_content) 14 | 15 | git = Github(sys.argv[1]) 16 | start = git.rate_limiting[0] 17 | max_repo_description = int(sys.argv[4]) 18 | allow_forks = bool(sys.argv[5]) 19 | project_sort_by = sys.argv[6] 20 | print(f'Request left at start of the script: {start}') 21 | 22 | user_object = git.get_user() 23 | git_username = user_object.login 24 | 25 | repo_list = [repo.name for repo in user_object.get_repos()] 26 | project_data = {} 27 | 28 | print("=====================REPO CHECK BEGINS=============================") 29 | for repo in repo_list: 30 | print(f'Repo being checked: {repo}') 31 | try: 32 | repo_object = git.get_repo(git_username + '/' + repo) 33 | repo_topics = repo_object.get_topics() 34 | if len(repo_topics) != 0: 35 | if 'project' in repo_topics: 36 | project_data[f'{repo}'] = {'repo_description': repo_object.description if len(repo_object.description) < max_repo_description else repo_object.description[:max_repo_description] + '...', 37 | 'repo_stars': int(repo_object.stargazers_count), 38 | 'repo_link': f'https://github.com/{git_username}/{repo}', 39 | 'repo_forks': int(repo_object.forks_count) 40 | } 41 | 42 | else: 43 | continue 44 | else: 45 | continue 46 | except: 47 | continue 48 | 49 | 50 | end = git.rate_limiting[0] 51 | print(f'Request left at end of the script: {end}') 52 | print(f'Requests Consumed in this process: {start - end}') 53 | print("=====================REPO CHECK ENDS=============================") 54 | 55 | sort_key = 'repo_' + project_sort_by 56 | project_data_sorted = dict( 57 | sorted(project_data.items(), key=lambda x: x[1][sort_key])[::-1]) 58 | 59 | 60 | repoName = sys.argv[3].split('/')[-1] 61 | readme_path = sys.argv[3] + f'/{sys.argv[2]}' 62 | with open(readme_path, 'r', encoding='utf-8') as f: 63 | readme = f.read() 64 | 65 | readmeRepo = git.get_repo(f"{git_username}/{repoName}") 66 | contents = readmeRepo.get_contents(f'{sys.argv[2]}') 67 | 68 | newContent = [] 69 | if allow_forks: 70 | for project, project_detail in project_data_sorted.items(): 71 | newContent.append( 72 | f'\n* [{project}]({project_detail["repo_link"]}) **{project_detail["repo_stars"]}⭐, {project_detail["repo_forks"]}** forks ({project_detail["repo_description"]})') 73 | else: 74 | for project, project_detail in project_data_sorted.items(): 75 | newContent.append( 76 | f'\n* [{project}]({project_detail["repo_link"]}) **{project_detail["repo_stars"]}⭐** ({project_detail["repo_description"]})') 77 | 78 | newContent = ' '.join(newContent) 79 | rewrittenReadme = rewriteContents(readme, newContent) 80 | print("=====================RESULTS=============================") 81 | if rewrittenReadme != readme: 82 | print("Repo Contents Updated") 83 | readmeRepo.update_file(contents.path, "Updating Projects Section", 84 | rewrittenReadme, contents.sha) 85 | else: 86 | print("No change detected in file contents") 87 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## My Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, I as 6 | contributor and maintainer pledge to making participation in my project and 7 | my 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 | ## My 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 that could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## My Responsibilities 35 | 36 | The project maintainer is responsible for clarifying the standards of acceptable 37 | behavior and is expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | The project maintainer has 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 the project maintainer. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing or otherwise unacceptable behavior may be 58 | reported by contacting the project maintainer at [LinkedIn](https://www.linkedin.com/in/kaustubh-gupta). 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 maintainer 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 maintainer who does 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 https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![readme-projects-display](https://socialify.git.ci/kaustubhgupta/readme-projects-display/image?description=1&font=KoHo&forks=1&issues=1&language=1&owner=1&pattern=Floating%20Cogs&pulls=1&stargazers=1&theme=Light) 2 |

3 | 4 | 5 | 6 |

7 | 8 | GitHub's Profile readme is a great tool to showcase your skills and projects to potential recruiters/developers. This GitHub action allows you to update a particular section of README with your Project details. These include the project name, stars, and a controllable amount of description. 9 | 10 |

11 | 12 |

13 | 14 | ## Getting Your Profile Ready 15 | 16 | - Add this comment in your README.md/specified file: 17 | ``` 18 | 19 | 20 | ``` 21 | 22 | - The repositories need to have `project` topics to add them to the project section. 23 | 24 | - A GitHub personal access token will be needed which can be obtained by going to Settings > Developer Settings > Personal Access Tokens. 25 |
26 | 27 | _Note: If you give personal repositories access then they will be added to the sections but their links will not work for others_ 28 | 29 | 30 | ## Action Setup 31 | 32 | GitHub actions can be integrated into any repository. Create a new folder called `.github/workflows/.yml`. Paste the following starter code: 33 | 34 | ```yml 35 | name: Update Projects 36 | on: 37 | schedule: 38 | - cron: '0 0 * * *' 39 | # This makes the action run at the end of every day. Customize this accordingly or you can also trigger this action for GitHub events (Pull, Push). Check the GitHub actions page for that. 40 | workflow_dispatch: 41 | # workflow_dispatch allows you to trigger the action any time manually 42 | 43 | jobs: 44 | update-readme-with-projects: 45 | name: Update this repo's README with latest project updates 46 | runs-on: ubuntu-latest 47 | steps: 48 | - uses: actions/checkout@v2 49 | - uses: kaustubhgupta/readme-projects-display@master 50 | with: 51 | gh_token: ${{ secrets.TOKEN }} # Create a secret to store the access token 52 | ``` 53 | 54 | ## Available Options 55 | 56 | | Option | Default Value | Description | Required | Example | 57 | | -------------- | ------------- | ---------------------------------------------------------------------------- | -------- | ------- | 58 | | `gh_token` | NA | GitHub Personal Access token | Yes | NA | 59 | | `file_name` | `README.md` | Name of the readme file or any other file containing the comment mentioned above. Note: The file needs to be at the root of the repository. (Dynamic paths coming in next version!) | No | myfile.txt/ myfile.html | 60 | | `max_repo_description` | 50 | How much description you want to Display | No | 40 | 61 | | `allow_forks` | True | Control if you want to display the number of forks of the repository | No | False | 62 | | `project_sort_by` | `stars` | Control the sorting of projects by `'stars'` or `'forks'` | No | `'forks'` | 63 | 64 | ## Examples 65 | - [My Workflow File](https://github.com/kaustubhgupta/kaustubhgupta/blob/master/.github/workflows/project-updater.yml) 66 | 67 | **Happy?? Do Star ⭐ this Repo. 🤩** 68 | 69 | ## License 70 | 71 | [![MIT Licence](https://img.shields.io/github/license/kaustubhgupta/PortfolioFy)](https://choosealicense.com/licenses/mit/) 72 | --------------------------------------------------------------------------------