-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
update_readme.py
48 lines (46 loc) · 1.8 KB
/
update_readme.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import sys
import os
import requests
import base64
def update_readme(artifact_url):
headers = {
"Authorization": f"Bearer {os.environ['GIT_TOKEN']}",
"Content-Type": "application/json"
}
response = requests.get(
f"https://api.github.com/repos/{os.environ['GITHUB_REPOSITORY']}/contents/README.md",
headers=headers
)
if response.status_code == 200:
readme_content = response.json()
readme_content_decoded = base64.b64decode(readme_content["content"]).decode("utf-8")
lines = readme_content_decoded.split("\n")
lines[320] = f"{artifact_url}"
new_content = "\n".join(lines)
update_data = {
"message": "feat: Update manager download link to latest",
"content": base64.b64encode(new_content.encode()).decode("utf-8"),
"sha": readme_content["sha"],
"committer": {
"name": "github-actions[bot]",
"email": "41898282+github-actions[bot]@users.noreply.github.com"
},
"author": {
"name": "github-actions[bot]",
"email": "41898282+github-actions[bot]@users.noreply.github.com"
}
}
response = requests.put(
f"https://api.github.com/repos/{os.environ['GITHUB_REPOSITORY']}/contents/README.md",
headers=headers,
json=update_data
)
if response.status_code == 200:
print("README updated successfully.")
else:
print(f"Failed to update README. Status code: {response.status_code}")
else:
print(f"Failed to fetch README. Status code: {response.status_code}")
if __name__ == "__main__":
artifact_url = sys.argv[1]
update_readme(artifact_url)