import re with open("components/MergePanel.tsx", "r") as f: content = f.read() # Replace stray references to githubToken and profile in fetch fetch_old = """ const response = await fetch('/api/github/merge', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ mainRepo: formattedMain, reposToMerge: formattedRepos, newBranchName, githubToken, profile }) });""" fetch_new = """ const auth = getAuthForRepo(mainRepo.repoId); const response = await fetch('/api/github/merge', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ mainRepo: formattedMain, reposToMerge: formattedRepos, newBranchName, githubToken: auth.token, profile: auth.profile }) });""" content = content.replace(fetch_old, fetch_new) # Replace stray BranchSelector tokens branch_main = """ token={githubToken} profile={profile}""" branch_new_main = """ token={getAuthForRepo(mainRepo.repoId).token} profile={getAuthForRepo(mainRepo.repoId).profile}""" content = content.replace(branch_main, branch_new_main) branch_repo = """ token={githubToken} profile={profile}""" branch_new_repo = """ token={getAuthForRepo(repo.repoId).token} profile={getAuthForRepo(repo.repoId).profile}""" # Wait, let's use regex to catch them content = re.sub(r'token=\{githubToken\}\s*\n\s*profile=\{profile\}', r'token={getAuthForRepo(mainRepo.repoId).token}\n profile={getAuthForRepo(mainRepo.repoId).profile}', content, count=1) content = re.sub(r'token=\{githubToken\}\s*\n\s*profile=\{profile\}', r'token={getAuthForRepo(repo.repoId).token}\n profile={getAuthForRepo(repo.repoId).profile}', content, count=1) with open("components/MergePanel.tsx", "w") as f: f.write(content)