-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub_commit.py
More file actions
51 lines (39 loc) · 1.71 KB
/
github_commit.py
File metadata and controls
51 lines (39 loc) · 1.71 KB
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
49
50
51
import os
from github import Github
from dotenv import load_dotenv
def commit_to_github():
# Load environment variables (from .env file)
load_dotenv()
pat = os.environ.get("GITHUB_PAT")
repo_name = os.environ.get("GITHUB_REPO")
if not pat or not repo_name:
print("Error: GITHUB_PAT or GITHUB_REPO not found in your environment.")
print("Please ensure they are defined in your .env file.")
return
try:
print(f"Connecting to GitHub repository: {repo_name}...")
g = Github(pat)
repo = g.get_repo(repo_name)
files_to_update = ["app.py", "pdf_utils.py"]
for file_path in files_to_update:
try:
# Read local file content
with open(file_path, "r", encoding="utf-8") as f:
local_content = f.read()
# Get remote file to retrieve its SHA (required for updating)
remote_file = repo.get_contents(file_path)
# Push the update
repo.update_file(
path=remote_file.path,
message=f"Update {file_path} for manual/scheduled PDF naming routing",
content=local_content,
sha=remote_file.sha
)
print(f"✅ Successfully committed changes for {file_path}")
except Exception as e:
print(f"❌ Failed to commit {file_path}: {e}")
print("\nAll done! Changes are now online.")
except Exception as e:
print(f"❌ GitHub connection failed: {e}")
if __name__ == "__main__":
commit_to_github()