Skip to content

Commit e7f414a

Browse files
committed
Added forks control logic
1 parent d789397 commit e7f414a

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

action.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@ inputs:
1313
description: "How much description you want to Display"
1414
required: False
1515
default: 50
16+
allow_forks:
17+
description: "Control if you want forks count"
18+
required: False
19+
default: True
1620

1721
runs:
1822
using: "composite"
1923
steps:
2024
- run: python -m pip install PyGithub
2125
shell: bash
22-
- run: python ${{ github.action_path }}/main-script.py ${{ inputs.gh_token }} ${{ inputs.file_name }} ${{ github.workspace }} ${{ inputs.max_repo_description }}
26+
- run: python ${{ github.action_path }}/main-script.py ${{ inputs.gh_token }} ${{ inputs.file_name }} ${{ github.workspace }} ${{ inputs.max_repo_description }} ${{ inputs.allow_forks }}
2327
shell: bash
2428
branding:
2529
icon: "award"

main-script.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def rewriteContents(old_content, new_content):
1515
git = Github(sys.argv[1])
1616
start = git.rate_limiting[0]
1717
max_repo_description = int(sys.argv[4])
18+
allow_forks = bool(sys.argv[5])
1819
print(f'Request left at start of the script: {start}')
1920

2021
user_object = git.get_user()
@@ -33,7 +34,8 @@ def rewriteContents(old_content, new_content):
3334
if 'project' in repo_topics:
3435
project_data[f'{repo}'] = {'repo_description': repo_object.description if len(repo_object.description) < max_repo_description else repo_object.description[:max_repo_description] + '...',
3536
'repo_stars': int(repo_object.stargazers_count),
36-
'repo_link': f'https://github.com/{git_username}/{repo}'
37+
'repo_link': f'https://github.com/{git_username}/{repo}',
38+
'repo_forks': int(repo_object.forks_count)
3739
}
3840

3941
else:
@@ -62,10 +64,14 @@ def rewriteContents(old_content, new_content):
6264
contents = readmeRepo.get_contents(f'{sys.argv[2]}')
6365

6466
newContent = []
65-
for project, project_detail in project_data_sorted.items():
66-
newContent.append(
67-
f'\n* [{project}]({project_detail["repo_link"]}) {project_detail["repo_stars"]}⭐ ({project_detail["repo_description"]})')
68-
67+
if allow_forks:
68+
for project, project_detail in project_data_sorted.items():
69+
newContent.append(
70+
f'\n* [{project}]({project_detail["repo_link"]}) {project_detail["repo_stars"]}⭐, {project_detail["repo_forks"]}🍴 ({project_detail["repo_description"]})')
71+
else:
72+
for project, project_detail in project_data_sorted.items():
73+
newContent.append(
74+
f'\n* [{project}]({project_detail["repo_link"]}) {project_detail["repo_stars"]}⭐ ({project_detail["repo_description"]})')
6975

7076
newContent = ' '.join(newContent)
7177
rewrittenReadme = rewriteContents(readme, newContent)

0 commit comments

Comments
 (0)