Skip to content

Commit 512ad74

Browse files
authored
Updating logging script and Adding automation workflows
Merge pull request #4 from iamwatchdogs/updates
2 parents 95a8ee6 + a5de64c commit 512ad74

File tree

8 files changed

+279
-4
lines changed

8 files changed

+279
-4
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: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,24 @@
1212
'''
1313

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

1634
# Setting default return values
1735
table_start = None
@@ -42,6 +60,18 @@ def find_table_points(lines):
4260

4361

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

4676
# Retrieving Environmental variables
4777
REPO_NAME = os.environ.get('REPO_NAME')

.github/scripts/update_contributors_log.py

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@
1616
'''
1717

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

2033
# Setting default value
2134
project_title = 'root'
@@ -26,16 +39,43 @@ def get_project_title(pr_data):
2639
project_title = i["path"]
2740
break
2841

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

3355
return project_title
3456

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

3869
def get_demo_path(pr_data):
70+
"""
71+
Retrieves the demo path for the pull request.
72+
73+
Args:
74+
pr_data (dict): The pull request data containing information about the pull request.
75+
76+
Returns:
77+
str: The demo path of the pull request.
78+
"""
3979

4080
# Getting required values
4181
REPO_NAME = os.environ.get('REPO_NAME')
@@ -44,9 +84,18 @@ def get_demo_path(pr_data):
4484
# Handling a base case
4585
if PROJECT_NAME == 'root':
4686
return f'https://github.com/{REPO_NAME}/'
87+
88+
url_path = PROJECT_NAME
89+
90+
# Setting custom path for workflow maintance
91+
SPECIAL_CASES = ['{workflows}', '{scripts}', '{others}']
92+
if PROJECT_NAME in SPECIAL_CASES:
93+
url_path = '.github'
94+
if PROJECT_NAME in SPECIAL_CASES[:2]:
95+
url_path += f'/{PROJECT_NAME[1:-1]}'
4796

4897
# Setting default value
49-
demo_path = f'https://github.com/{REPO_NAME}/tree/main/{PROJECT_NAME}'
98+
demo_path = f'https://github.com/{REPO_NAME}/tree/main/{url_path}'
5099
found_required_path = False
51100

52101
# Iterating through the "files" list
@@ -71,6 +120,24 @@ def get_demo_path(pr_data):
71120
return demo_path
72121

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

75142
# Setting required file paths
76143
CURRENT_PR_DETAILS_PATH = 'pr.json'

.github/scripts/update_index_md.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,24 @@
1212
'''
1313

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

1634
# Setting default return values
1735
table_start = None
@@ -42,6 +60,18 @@ def find_table_points(lines):
4260

4361

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

4676
# Retrieving Environmental variables
4777
REPO_NAME = os.environ.get('REPO_NAME')
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/[email protected]
18+
with:
19+
configuration-path: '.github/auto-assign-config.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/Notebook/ "view contributions").

.github/workflows/auto-labeler.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: hacktoberfest-labeler
2+
3+
on:
4+
pull_request_target:
5+
types: [opened, reopened, closed]
6+
7+
8+
permissions:
9+
contents: read
10+
pull-requests: write
11+
12+
jobs:
13+
auto-labeler:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Check for hacktoberfest season
17+
id: check-month
18+
run: |
19+
current_month=$(date +'%m')
20+
if [ "$current_month" == "10" ]; then
21+
echo "is_october=true" >> $GITHUB_OUTPUT
22+
else
23+
echo "is_october=false" >> $GITHUB_OUTPUT
24+
fi
25+
26+
- name: Creating config file
27+
env:
28+
ACTION: ${{ github.event.action }}
29+
run: |
30+
touch ./hacktoberfest-labeler.yml
31+
32+
if [ "$ACTION" != "closed" ]; then
33+
echo "hacktoberfest:" > hacktoberfest-labeler.yml
34+
else
35+
echo "hacktoberfest-accepted:" > hacktoberfest-labeler.yml
36+
fi
37+
echo "- changed-files:" >> hacktoberfest-labeler.yml
38+
echo " - any-glob-to-any-file: '**'" >> hacktoberfest-labeler.yml
39+
40+
echo "Created the config file:"
41+
echo "------------------------"
42+
cat ./hacktoberfest-labeler.yml
43+
44+
- name: Label the PRs
45+
if: steps.check-month.outputs.is_october == 'true' ||
46+
github.event.pull_request.merged == 'true' &&
47+
contains(github.event.pull_request.labels.*.name, 'hacktoberfest')
48+
uses: actions/[email protected]
49+
with:
50+
configuration-path: ./hacktoberfest-labeler.yml

.github/workflows/stale.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: close-stale-issue-and-prs
2+
3+
on:
4+
schedule:
5+
- cron: '30 1 * * *'
6+
7+
permissions:
8+
contents: write
9+
issues: write
10+
pull-requests: write
11+
12+
jobs:
13+
stale:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/stale@v8
17+
with:
18+
stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.'
19+
stale-pr-message: 'This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.'
20+
close-issue-message: 'This issue was closed because it has been stalled for 5 days with no activity.'
21+
close-pr-message: 'This PR was closed because it has been stalled for 10 days with no activity.'
22+
days-before-issue-stale: 30
23+
days-before-pr-stale: 45
24+
days-before-issue-close: 5
25+
days-before-pr-close: 10

0 commit comments

Comments
 (0)