|
2 | 2 | import json
|
3 | 3 | import sys
|
4 | 4 | import re
|
| 5 | +from datetime import datetime |
5 | 6 |
|
6 | 7 | if __name__ == "__main__":
|
7 | 8 | assert(len(sys.argv) == 4)
|
|
13 | 14 | "Authorization": f"token {token}"
|
14 | 15 | }
|
15 | 16 |
|
16 |
| - # Get the latest commit details |
17 |
| - repo_name = "Hunterdii/GeeksforGeeks-POTD" # Correct repo |
18 |
| - commit_url = f"https://api.github.com/repos/{repo_name}/commits?sha=main" |
| 17 | + # Correct repository name |
| 18 | + repo_name = "Hunterdii/GeeksforGeeks-POTD" |
19 | 19 |
|
20 |
| - # Make the request to fetch the latest commit |
| 20 | + # Get the latest commit details for the correct repository |
| 21 | + commit_url = f"https://api.github.com/repos/{repo_name}/commits?sha=main" |
21 | 22 | response = requests.get(commit_url, headers=headers)
|
22 | 23 |
|
23 | 24 | if response.status_code != 200:
|
24 | 25 | print(f"Error fetching commit details: {response.text}")
|
25 | 26 | sys.exit(1)
|
26 | 27 |
|
27 |
| - # Parse the response JSON to get commit details |
28 | 28 | commit_data = response.json()[0]
|
29 | 29 | commit_sha = commit_data['sha']
|
30 | 30 | commit_message = commit_data['commit']['message']
|
31 | 31 | commit_date = commit_data['commit']['committer']['date']
|
32 | 32 |
|
33 |
| - # Extract the question name or solution identifier from the commit message |
34 |
| - # Assuming commit message starts with the identifier, like "01(Nov) Solution Name" |
35 |
| - solution_identifier = commit_message.split(":")[0] |
| 33 | + # Extract the question name or solution identifier from the commit message (e.g., "01(Nov) Solution Name") |
| 34 | + solution_identifier = commit_message.split(":")[0] # Assuming commit message starts with the identifier |
36 | 35 |
|
37 | 36 | # Generate the badge URL dynamically based on the solution
|
38 | 37 | badge_url = f"https://img.shields.io/badge/Solution-{solution_identifier}-blue"
|
|
46 | 45 | content = readme.read()
|
47 | 46 |
|
48 | 47 | # Update the commit link and the badge in the README file
|
49 |
| - new_content = re.sub(r"(?<=<!--START_SECTION:latest-commit-->)[\s\S]*(?=<!--END_SECTION:latest-commit-->)", f" {commit_link} ", content) |
50 |
| - new_content = re.sub(r"(?<=<!--START_SECTION:potd-badge-->)[\s\S]*(?=<!--END_SECTION:potd-badge-->)", f" {badge_link} ", new_content) |
| 48 | + new_content = re.sub(r"(?<=<!--START_SECTION:latest-commit-->)[\s\S]*(?=<!--END_SECTION:latest-commit-->)", commit_link, content) |
| 49 | + new_content = re.sub(r"(?<=<!--START_SECTION:potd-badge-->)[\s\S]*(?=<!--END_SECTION:potd-badge-->)", badge_link, new_content) |
51 | 50 |
|
52 | 51 | # Write the updated content back to README
|
53 | 52 | with open(readmePath, "w") as readme:
|
|
0 commit comments