|
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 |
| - assert(len(sys.argv) == 4) # Adjusted to expect three arguments + the script name |
8 |
| - handle = "Hunterdii" # The fixed GitHub user handle |
9 |
| - token = sys.argv[1] |
10 |
| - readmePath = sys.argv[2] |
| 8 | + assert(len(sys.argv) == 4) |
| 9 | + handle = sys.argv[1] # GitHub username (e.g., Hunterdii) |
| 10 | + token = sys.argv[2] # GitHub token for authentication |
| 11 | + readmePath = sys.argv[3] # Path to the README.md file |
11 | 12 |
|
12 | 13 | headers = {
|
13 | 14 | "Authorization": f"token {token}"
|
14 | 15 | }
|
15 | 16 |
|
16 |
| - # Set the target repository to the specific repo |
17 |
| - repo_name = "Hunterdii/GeeksforGeeks-POTD" |
18 |
| - commit_url = f"https://api.github.com/repos/{repo_name}/commits?sha=main" |
19 |
| - |
20 |
| - # Fetch the latest commit details |
| 17 | + # Correct the repo name and fetch the latest commit details from the correct repository |
| 18 | + repo_name = "GeeksforGeeks-POTD" # Specify the correct repo name here |
| 19 | + commit_url = f"https://api.github.com/repos/{handle}/{repo_name}/commits?sha=main" |
21 | 20 | response = requests.get(commit_url, headers=headers)
|
22 |
| - |
| 21 | + |
23 | 22 | if response.status_code != 200:
|
24 | 23 | print(f"Error fetching commit details: {response.text}")
|
25 | 24 | sys.exit(1)
|
|
29 | 28 | commit_message = commit_data['commit']['message']
|
30 | 29 | commit_date = commit_data['commit']['committer']['date']
|
31 | 30 |
|
32 |
| - # Extract the question name or solution identifier from the commit message |
| 31 | + # Extract the question name or solution identifier from the commit message (example: "01(Nov) Solution Name") |
33 | 32 | solution_identifier = commit_message.split(":")[0] # Assuming commit message starts with the identifier
|
34 | 33 |
|
35 |
| - # Generate the badge URL dynamically based on the solution identifier |
| 34 | + # Generate the badge URL dynamically based on the solution |
36 | 35 | badge_url = f"https://img.shields.io/badge/Solution-{solution_identifier}-blue"
|
37 |
| - badge_link = f"[](https://github.com/{repo_name}/commit/{commit_sha})" |
| 36 | + badge_link = f"[](https://github.com/{handle}/{repo_name}/commit/{commit_sha})" |
38 | 37 |
|
39 | 38 | # Prepare the commit link
|
40 |
| - commit_link = f"Commit URL: https://github.com/{repo_name}/commit/{commit_sha}" |
| 39 | + commit_link = f"Commit URL: https://github.com/{handle}/{repo_name}/commit/{commit_sha}" |
41 | 40 |
|
42 | 41 | # Update README with the new commit and badge
|
43 | 42 | with open(readmePath, "r") as readme:
|
44 | 43 | content = readme.read()
|
45 | 44 |
|
46 | 45 | # Update the commit link and the badge in the README file
|
47 |
| - new_content = re.sub(r"(?<=<!--START_SECTION:latest-commit-->)[\s\S]*(?=<!--END_SECTION:latest-commit-->)", f" {commit_link} ", content) |
48 |
| - new_content = re.sub(r"(?<=<!--START_SECTION:potd-badge-->)[\s\S]*(?=<!--END_SECTION:potd-badge-->)", f" {badge_link} ", new_content) |
| 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 | 48 |
|
50 | 49 | # Write the updated content back to README
|
51 | 50 | with open(readmePath, "w") as readme:
|
|
0 commit comments