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