1616'''
1717
1818def 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
3557def 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
3869def 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
73122def 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'
0 commit comments