-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRepoUpdate.py
More file actions
40 lines (34 loc) · 1.55 KB
/
RepoUpdate.py
File metadata and controls
40 lines (34 loc) · 1.55 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
# git hub repo writer
# repo at https://github.com/SVVSDICAI/FishNetStreamCapture
import os
from git import Repo
import sys
PATH_OF_GIT_REPO = r'./FishNetStreamCapture'
COMMIT_MESSAGE = "automated update"
GITHUB_KEY = os.getenv('GITHUB_KEY')
if len(sys.argv) > 1 and sys.argv[1] == "init": # if this file is run from the terminal (python RepoUpdate.py init) to initialize the github login info and clone the repo to the current directory
# if the user provides a repo link, use that instead of the default PATH_OF_GIT_REPO
if len(sys.argv) == 3:
PATH_OF_GIT_REPO = sys.argv[2]
print("cloning repo")
# github login info
username = "automated"
remote = f"https://{username}:{GITHUB_KEY}@github.com/SVVSDICAI/FishNetStreamCapture.git"
remote = remote.replace("\n", "")
print(remote)
Repo.clone_from(remote, PATH_OF_GIT_REPO) # This must be run initially to ensure that the github login info is set
def git_push(PATH_OF_GIT_REPO=PATH_OF_GIT_REPO, origin="origin"): # function to push the updates to github
try:
repo = Repo(PATH_OF_GIT_REPO)
repo.git.add(update=True)
repo.index.commit(COMMIT_MESSAGE)
origin = repo.remote(name=origin)
print("pushing changes...")
origin.push()
except:
print("Some error occured while pushing the code")
def git_pull(PATH_OF_GIT_REPO=PATH_OF_GIT_REPO): # function to pull from github
print("pulling repo...")
repo = Repo(PATH_OF_GIT_REPO)
origin = repo.remotes.origin
origin.pull()