-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre-github-move.py
More file actions
119 lines (101 loc) · 3.58 KB
/
Copy pathpre-github-move.py
File metadata and controls
119 lines (101 loc) · 3.58 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import os
import subprocess
import json
from common.params import Params as p
for repo in p.repos:
#
# Clone the repo and create a new branch
#
try:
# Create a new directory for the Bitbucket repository
if not os.path.exists('bitbucketRepo'):
os.mkdir('bitbucketRepo')
# Change to the Bitbucket directory
os.chdir('bitbucketRepo')
# Clone the repository
cloneCommand = f'git clone git@bitbucket.org:learningpool/{repo["bitbucketName"]}.git'
os.system(cloneCommand)
# Change to the repository directory
os.chdir(repo["bitbucketName"])
# Create a new branch
subprocess.call(['git', 'checkout', '-b', p.branchName])
except:
print('Failed to clone the repository and create a new branch.')
print('Exiting program.')
exit()
#
# Update the package.json
#
try:
if p.manualPackageJsonBool == True:
p.updatePackageJson(repo["githubName"])
else:
# Read the package.json and write it the data variable
with open('package.json', 'r') as f:
data = json.load(f)
# Update the homepage key
data['homepage'] = f'https://github.com/HT2-Labs/{repo["githubName"]}'
# Update the private key
data['private'] = 'true'
# Update the 'repository' key
data['repository'] = {
'type': 'git',
'url': f'git+https://github.com/HT2-Labs/{repo["githubName"]}.git'
}
# Add the Semantic Release devDependencies
if p.addSemanticReleaseBool == True:
data['devDependencies'] = {
"@semantic-release/commit-analyzer": "^9.0.2",
"@semantic-release/git": "^10.0.1",
"@semantic-release/github": "^8.0.7",
"@semantic-release/release-notes-generator": "^10.0.3",
"conventional-changelog-eslint": "^3.0.9",
"semantic-release": "19.0.3"
}
# Install the new dependencies
subprocess.call([{p.packageManager}, 'install'])
# Write the updated data back to the package.json file
with open('package.json', 'w') as f:
json.dump(data, f, indent=4)
except:
print('Failed to update the package.json file.')
print('Exiting program.')
exit()
#
# Create directories
#
try:
if p.createDirectoriesBool == True:
p.createDirectories()
except:
print('Failed to create directories.')
print('Exiting program.')
exit()
#
# Create files
#
try:
if p.createFilesBool == True:
p.createFiles()
except:
print('Failed to create files.')
print('Exiting program.')
exit()
#
# Push the new branch to the repo
#
try:
# Add the new files
gitAddCMD = ['git', 'add'] # Command to add files
addFilesCMD = gitAddCMD + p.filesToAdd # Add files specified in the params.py file
subprocess.call(addFilesCMD)
# Commit the new files
subprocess.call(['git', 'commit', '-m', p.commitMessage])
# Push the new branch to the remote repository
subprocess.call(['git', 'push', '-u', 'origin', p.branchName])
# Change back to the root directory
os.chdir("../..")
except:
print('Failed to push the new branch to the Bitbucket repository.')
print('Exiting program.')
exit()