1515 > GitHub action variable: ${{ github.event.pull_request.number }}
1616'''
1717
18+
1819def 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+
3559def 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+
3872def 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+
73126def 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+
128200if __name__ == '__main__' :
129- main ()
201+ main ()
0 commit comments