Skip to content

Commit 5b9f52a

Browse files
authored
Updating logging script and Adding automation workflows
Merge pull request #22 from iamwatchdogs/updates
2 parents 3a6fe7d + 30b7f1b commit 5b9f52a

File tree

8 files changed

+314
-15
lines changed

8 files changed

+314
-15
lines changed

.github/auto-assign-config.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Set to true to add reviewers to pull requests
2+
addReviewers: true
3+
4+
# Set to true to add assignees to pull requests
5+
addAssignees: author
6+
7+
# A list of reviewers to be added to pull requests (GitHub user name)
8+
reviewers:
9+
- iamwatchdogs
10+
11+
# A number of reviewers added to the pull request
12+
# Set 0 to add all the reviewers (default: 0)
13+
numberOfReviewers: 1
14+
15+
# A list of assignees, overrides reviewers if set
16+
# assignees:
17+
# - assigneeA
18+
19+
# A number of assignees to add to the pull request
20+
# Set to 0 to add all of the assignees.
21+
# Uses numberOfReviewers if unset.
22+
# numberOfAssignees: 2
23+
24+
# A list of keywords to be skipped the process that add reviewers if pull requests include it
25+
# skipKeywords:
26+
# - wip

.github/scripts/convert_to_html_tables.py

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,26 @@
1111
> GitHub action variable: ${{ github.repository }}
1212
'''
1313

14+
1415
def find_table_points(lines):
16+
"""
17+
Find table points within a given list of lines.
18+
19+
The table points are determined by the presence of the markers:
20+
<!-- TABLE BEGINS -->
21+
<!-- TABLE ENDS -->
22+
23+
Args:
24+
lines (list): List of lines to search in.
25+
26+
Returns:
27+
tuple: A tuple of two integers containing the start and end indices of
28+
the table points.
29+
30+
Raises:
31+
SystemExit: If the table markers are not found or if the table end
32+
marker appears before the table start marker.
33+
"""
1534

1635
# Setting default return values
1736
table_start = None
@@ -42,6 +61,18 @@ def find_table_points(lines):
4261

4362

4463
def main():
64+
"""
65+
Update the index.md file with the latest contributors data.
66+
67+
This function retrieves the REPO_NAME environment variable and the
68+
CONTRIBUTORS_LOG file path. It then reads the log file and extracts the
69+
data from it. The function then reads the index.md file and calculates
70+
the table points. If the table does not exist, it creates the table
71+
header. The function then iterates over the log data and updates the
72+
table with the latest data. Finally, it updates the index.md file with
73+
the updated data and prints a success message.
74+
75+
"""
4576

4677
# Retrieving Environmental variables
4778
REPO_NAME = os.environ.get('REPO_NAME')
@@ -79,22 +110,29 @@ def main():
79110

80111
# Processing contributors-names
81112
contributors_names = details['contributor-name']
82-
contributors_names_list = [f'<a href="https://github.com/{name}" title="goto {name} profile">{name}</a>' for name in contributors_names]
113+
contributors_names_list = [
114+
f'<a href="https://github.com/{name}" title="goto {name} profile">{name}</a>' for name in contributors_names]
83115
contributors_names_output = ', '.join(contributors_names_list)
84116

85117
# Processing pull-requests
86118
pull_requests = details['pull-request-number']
87-
pull_requests_list = [f'<a href="https://github.com/{REPO_NAME}/pull/{pr}" title="visit pr \#{pr}">{pr}</a>' for pr in pull_requests]
119+
pull_requests_list = [
120+
f'<a href="https://github.com/{REPO_NAME}/pull/{pr}" title="visit pr \#{pr}">{pr}</a>' for pr in pull_requests]
88121
pull_requests_output = ', '.join(pull_requests_list)
89122

90123
# Processing demo-path
91124
demo_path = details['demo-path']
92125
if ' ' in demo_path:
93126
demo_path = '%20'.join(demo_path.split())
94-
demo_path_output = f'<a href="{demo_path}" title="view the result of {title}">/{REPO_NAME}/{title}/</a>'
127+
demo_path_output = f'<a href="{demo_path}" title="view the result of {title}">/{REPO_NAME}/{title}/</a>'
95128
if title == 'root' or title == '{init}':
96-
demo_path_output = f'<a href="{demo_path}" title="view the result of {title}">/{REPO_NAME}/</a>'
97-
129+
demo_path_output = f'<a href="{demo_path}" title="view the result of {title}">/{REPO_NAME}/</a>'
130+
elif title == '{workflows}':
131+
demo_path_output = f'<a href="{demo_path}" title="view the result of {title}">/{REPO_NAME}/.github/workflows</a>'
132+
elif title == '{scripts}':
133+
demo_path_output = f'<a href="{demo_path}" title="view the result of {title}">/{REPO_NAME}/.github/scripts</a>'
134+
elif title == '{others}':
135+
demo_path_output = f'<a href="{demo_path}" title="view the result of {title}">/{REPO_NAME}/.github</a>'
98136

99137
# Appending all data together
100138
updated_lines.append('\t<tr align="center">\n')

.github/scripts/update_contributors_log.py

Lines changed: 78 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,21 @@
1515
> GitHub action variable: ${{ github.event.pull_request.number }}
1616
'''
1717

18+
1819
def get_project_title(pr_data):
20+
"""
21+
Determines the project title based on the file paths in the pull request data.
22+
23+
Args:
24+
pr_data (dict): The pull request data containing file paths.
25+
26+
Returns:
27+
str: The project title derived from the directory name in the file path.
28+
Returns 'root' if changes are made in the root of the repository.
29+
Special cases include '{workflows}', '{scripts}', and '{others}'
30+
for certain paths within the '.github' directory.
31+
32+
"""
1933

2034
# Setting default value
2135
project_title = 'root'
@@ -26,16 +40,45 @@ def get_project_title(pr_data):
2640
project_title = i["path"]
2741
break
2842

29-
# If we find a directory
30-
if project_title != 'root':
31-
project_title = project_title.split('/')[0]
43+
# changes are made in the root of repo
44+
if project_title == 'root':
45+
return project_title
46+
47+
if '.github/workflows' in project_title:
48+
project_title = '{workflows}'
49+
elif '.github/scripts' in project_title:
50+
project_title = '{scripts}'
51+
elif '.github' in project_title:
52+
project_title = '{others}'
53+
else:
54+
project_title = project_title.split('/')[0] # directory name
3255

3356
return project_title
3457

58+
3559
def get_contributor_name(pr_data):
60+
"""
61+
Retrieves the username of the contributor who made the pull request.
62+
63+
Args:
64+
pr_data (dict): The pull request data containing the author's username.
65+
66+
Returns:
67+
str: The username of the contributor.
68+
"""
3669
return pr_data["author"]["login"]
3770

71+
3872
def get_demo_path(pr_data):
73+
"""
74+
Retrieves the demo path for the pull request.
75+
76+
Args:
77+
pr_data (dict): The pull request data containing information about the pull request.
78+
79+
Returns:
80+
str: The demo path of the pull request.
81+
"""
3982

4083
# Getting required values
4184
REPO_NAME = os.environ.get('REPO_NAME')
@@ -45,8 +88,17 @@ def get_demo_path(pr_data):
4588
if PROJECT_NAME == 'root':
4689
return f'https://github.com/{REPO_NAME}/'
4790

91+
url_path = PROJECT_NAME
92+
93+
# Setting custom path for workflow maintance
94+
SPECIAL_CASES = ['{workflows}', '{scripts}', '{others}']
95+
if PROJECT_NAME in SPECIAL_CASES:
96+
url_path = '.github'
97+
if PROJECT_NAME in SPECIAL_CASES[:2]:
98+
url_path += f'/{PROJECT_NAME[1:-1]}'
99+
48100
# Setting default value
49-
demo_path = f'https://github.com/{REPO_NAME}/tree/main/{PROJECT_NAME}'
101+
demo_path = f'https://github.com/{REPO_NAME}/tree/main/{url_path}'
50102
found_required_path = False
51103

52104
# Iterating through the "files" list
@@ -56,7 +108,7 @@ def get_demo_path(pr_data):
56108
demo_path = path
57109
found_required_path = True
58110
break
59-
elif path.lower().endswith('index.md') or path.lower().endswith('readme.md'):
111+
elif path.lower().endswith('index.md') or path.lower().endswith('readme.md'):
60112
demo_path = path
61113
found_required_path = True
62114

@@ -70,7 +122,26 @@ def get_demo_path(pr_data):
70122

71123
return demo_path
72124

125+
73126
def main():
127+
"""
128+
Updates the contributors log file after a pull request has been merged.
129+
130+
This function is to be called in a GitHub Actions workflow after a pull request has been merged.
131+
It reads the details of the current pull request from a JSON file, extracts the required information,
132+
and updates the contributors log file accordingly.
133+
134+
The contributors log file is a JSON file that contains information about each contributor, including
135+
their name, the number of the pull request they contributed to, and the path to their project.
136+
137+
The function dumps the data into the log file and outputs a success message upon completion.
138+
139+
Args:
140+
None
141+
142+
Returns:
143+
None
144+
"""
74145

75146
# Setting required file paths
76147
CURRENT_PR_DETAILS_PATH = 'pr.json'
@@ -125,5 +196,6 @@ def main():
125196
# Output message
126197
print(f'Successfully {operation_name} the log file')
127198

199+
128200
if __name__ == '__main__':
129-
main()
201+
main()

.github/scripts/update_index_md.py

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,26 @@
1111
> GitHub action variable: ${{ github.repository }}
1212
'''
1313

14+
1415
def find_table_points(lines):
16+
"""
17+
Find table points within a given list of lines.
18+
19+
The table points are determined by the presence of the markers:
20+
<!-- TABLE BEGINS -->
21+
<!-- TABLE ENDS -->
22+
23+
Args:
24+
lines (list): List of lines to search in.
25+
26+
Returns:
27+
tuple: A tuple of two integers containing the start and end indices of
28+
the table points.
29+
30+
Raises:
31+
SystemExit: If the table markers are not found or if the table end
32+
marker appears before the table start marker.
33+
"""
1534

1635
# Setting default return values
1736
table_start = None
@@ -42,6 +61,18 @@ def find_table_points(lines):
4261

4362

4463
def main():
64+
"""
65+
Update the index.md file with the latest contributors data.
66+
67+
This function retrieves the REPO_NAME environment variable and the
68+
CONTRIBUTORS_LOG file path. It then reads the log file and extracts the
69+
data from it. The function then reads the index.md file and calculates
70+
the table points. If the table does not exist, it creates the table
71+
header. The function then iterates over the log data and updates the
72+
table with the latest data. Finally, it updates the index.md file with
73+
the updated data and prints a success message.
74+
75+
"""
4576

4677
# Retrieving Environmental variables
4778
REPO_NAME = os.environ.get('REPO_NAME')
@@ -64,7 +95,8 @@ def main():
6495
# Creating table header if doesn't exist
6596
if table_end - table_start == 1:
6697
table_header = list()
67-
table_header.append('| Project Title | Contributor Names | Pull Requests | Demo |\n')
98+
table_header.append(
99+
'| Project Title | Contributor Names | Pull Requests | Demo |\n')
68100
table_header.append('| --- | --- | --- | --- |\n')
69101
lines[table_start+1:table_end] = table_header
70102

@@ -76,12 +108,14 @@ def main():
76108

77109
# Processing contributors-names
78110
contributors_names = details['contributor-name']
79-
contributors_names_list = [f'[{name}](https://github.com/{name} "goto {name} profile")' for name in contributors_names]
111+
contributors_names_list = [
112+
f'[{name}](https://github.com/{name} "goto {name} profile")' for name in contributors_names]
80113
contributors_names_output = ', '.join(contributors_names_list)
81114

82115
# Processing pull-requests
83116
pull_requests = details['pull-request-number']
84-
pull_requests_list = [f'[#{pr}](https://github.com/{REPO_NAME}/pull/{pr} "visit pr \#{pr}")' for pr in pull_requests]
117+
pull_requests_list = [
118+
f'[#{pr}](https://github.com/{REPO_NAME}/pull/{pr} "visit pr \#{pr}")' for pr in pull_requests]
85119
pull_requests_output = ', '.join(pull_requests_list)
86120

87121
# Processing demo-path
@@ -91,9 +125,16 @@ def main():
91125
demo_path_output = f'[/{REPO_NAME}/{title}/]({demo_path} "view the result of {title}")'
92126
if title == 'root' or title == '{init}':
93127
demo_path_output = f'[/{REPO_NAME}/]({demo_path} "view the result of {title}")'
128+
elif title == '{workflows}':
129+
demo_path_output = f'[/{REPO_NAME}/.github/workflows]({demo_path} "view the result of {title}")'
130+
elif title == '{scripts}':
131+
demo_path_output = f'[/{REPO_NAME}/.github/scripts]({demo_path} "view the result of {title}")'
132+
elif title == '{others}':
133+
demo_path_output = f'[/{REPO_NAME}/.github]({demo_path} "view the result of {title}")'
94134

95135
# Appending all data together
96-
updated_lines.append(f'| {title} | {contributors_names_output} | {pull_requests_output} | {demo_path_output} |\n')
136+
updated_lines.append(
137+
f'| {title} | {contributors_names_output} | {pull_requests_output} | {demo_path_output} |\n')
97138

98139
# Updating the lines with updated data
99140
lines[table_start+3:table_end] = updated_lines

.github/workflows/auto-assigner.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Auto Assign
2+
3+
on:
4+
pull_request_target:
5+
types: [opened, ready_for_review]
6+
issues:
7+
types: [opened]
8+
9+
permissions:
10+
issues: write
11+
pull-requests: write
12+
13+
jobs:
14+
auto-assign:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: kentaro-m/auto-assign-action@v1.2.5
18+
with:
19+
configuration-path: '.github/auto-assign-config.yml'

.github/workflows/auto-commenter.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Auto-commenter
2+
3+
on:
4+
pull_request_target:
5+
types: [opened, closed]
6+
7+
permissions:
8+
id-token: write
9+
issues: write
10+
pull-requests: write
11+
12+
jobs:
13+
automated-message:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: wow-actions/auto-comment@v1
17+
with:
18+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19+
pullRequestOpened: |
20+
👋 @{{ author }}
21+
Thank you for raising your pull request.
22+
Please make sure you have followed our contributing guidelines. We will review it as soon as possible.
23+
24+
pullRequestClosed: |
25+
👋 @{{ author }} This PR is closed. If you think there's been a mistake, please contact the maintainer @iamwatchdogs.
26+
27+
pullRequestMerged: |
28+
Thank you for contributing @{{ author }}. Make sure to check your contribution on [GitHub Pages](https://grow-with-open-source.github.io/Python-Projects/ "view contributions").

0 commit comments

Comments
 (0)