-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
50 lines (41 loc) · 1.45 KB
/
main.py
File metadata and controls
50 lines (41 loc) · 1.45 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
import subprocess
import os
def run_git_command(command):
result = subprocess.run(command, shell=True, capture_output=True, text=True)
return result.stdout.strip()
def get_changed_files():
output = run_git_command("git status --porcelain")
files = [line[3:] for line in output.splitlines() if line]
return files
def generate_commit_message(files):
if not files:
return "🔄 No changes detected"
messages = []
for file in files:
if file.endswith(".java"):
messages.append(f"🛠️ Modified {file}")
elif file.endswith(".py"):
messages.append(f"🛠️ Modified {file}")
elif file.endswith(".html") or file.endswith(".css"):
messages.append(f"🎨 Style change in {file}")
elif file.lower().startswith("readme"):
messages.append("📝 Updated README")
else:
messages.append(f"🔧 Changed {file}")
return " | ".join(messages)
def main():
if not os.path.exists(".git"):
print("❌ Not a Git repository.")
return
files = get_changed_files()
if not files:
print("✅ Nothing to commit.")
return
commit_message = generate_commit_message(files)
print(f"📋 Commit message: {commit_message}")
run_git_command("git add .")
run_git_command(f'git commit -m "{commit_message}"')
run_git_command("git push")
print("🚀 Pushed to remote.")
if __name__ == "__main__":
main()