@@ -33,7 +33,8 @@ def main() -> None:
3333 repo = g .get_repo (repo_name )
3434 issue = repo .get_issue (number = issue_number )
3535
36- file_match = re .search (r"\b([\w-]+\.ipynb)\b" , issue .body , re .IGNORECASE )
36+ # Regex to find any file with an extension
37+ file_match = re .search (r"\b([\w-]+\.[\w]+)\b" , issue .body , re .IGNORECASE )
3738
3839 if not file_match :
3940 print ("No file found in issue." )
@@ -48,17 +49,44 @@ def main() -> None:
4849 print (f"No files found for { file_name } " )
4950 return
5051
51- print (result [0 ])
52- file = str (base64 .b64decode (result [0 ].content ))[:10000 ]
53- match = re .search (r"Author.+https://github\.com/([^/\)]+)" , file , flags = re .DOTALL )
52+ file_path = result [0 ].path
53+
54+ # Get the commits for the file
55+ commits = repo .get_commits (path = file_path )
56+
57+ # Try to get the author of the first commit
58+ if commits .totalCount > 0 :
59+ # The last commit in the list is the first commit
60+ first_commit = commits [commits .totalCount - 1 ]
61+ if first_commit .author :
62+ username = first_commit .author .login
63+ print (
64+ f"Assigning { username } to Issue #{ issue_number } for File { file_path } based on the first commit."
65+ )
66+ issue .add_to_assignees (username )
67+ return
5468
55- if not match :
56- print (f"No User Found for { file_name } " )
57- return
69+ # If the file is a notebook and the first commit author wasn't found,
70+ # check the notebook metadata as a fallback.
71+ if file_name .endswith (".ipynb" ):
72+ print (
73+ "Could not determine the first commit author, checking the notebook metadata."
74+ )
75+ file_content_encoded = repo .get_contents (file_path ).content
76+ file_content = str (base64 .b64decode (file_content_encoded ))[:10000 ]
77+ match = re .search (
78+ r"Author.+https://github\.com/([^/\)]+)" , file_content , flags = re .DOTALL
79+ )
80+
81+ if match :
82+ username = match .group (1 )
83+ print (
84+ f"Assigning { username } to Issue #{ issue_number } for File { file_path } based on notebook metadata."
85+ )
86+ issue .add_to_assignees (username )
87+ return
5888
59- username = match .group (1 )
60- print (f"Assigning { username } to Issue #{ issue_number } for File { result [0 ].path } " )
61- issue .add_to_assignees (username )
89+ print (f"No User Found for { file_name } " )
6290
6391
6492if __name__ == "__main__" :
0 commit comments