Skip to content

Commit 8a3676b

Browse files
Merge pull request sahil-sagwekar2652#55 from shubham-deshmukh/main
Added push_repo python script
2 parents de788ba + 5c090b4 commit 8a3676b

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

scripts/push_repo.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env python
2+
3+
import argparse
4+
import os
5+
from github_secrets import GITHUB_API_TOKEN
6+
7+
8+
def parseArgs():
9+
parser = argparse.ArgumentParser(description='Push an existing local repository to a newly created remote repository of the same name') # noqa: E501
10+
parser.add_argument('path',
11+
metavar='PATH',
12+
type=str,
13+
help='Enter the path for existing local repository')
14+
parser.add_argument('url',
15+
metavar='URL',
16+
type=str,
17+
help='Enter the newly created remote repository url (.git)')
18+
parser.add_argument('description',
19+
metavar='DESCRIPTION',
20+
type=str,
21+
help='Enter the description for remote repository')
22+
args = parser.parse_args()
23+
return args
24+
25+
26+
def pushRepo(remote_url):
27+
origin = remote_url[:8] + GITHUB_API_TOKEN + "@" + remote_url[8:]
28+
os.system(f'git push {origin} --mirror')
29+
30+
31+
def main():
32+
path = args.path
33+
remote_url = args.url
34+
35+
os.chdir(path)
36+
if os.path.isdir('./.git') is False:
37+
print("Not in a git directory")
38+
exit()
39+
40+
pushRepo(remote_url)
41+
42+
43+
if __name__ == "__main__":
44+
args = parseArgs()
45+
main()

0 commit comments

Comments
 (0)