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