Spaces:
Paused
Paused
File size: 2,100 Bytes
34450be | 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 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)
|