-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Vadim Liventsev
committed
Mar 24, 2022
1 parent
76baa08
commit 6eac4b9
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# pip install GitPython==3.* | ||
from git import GitCommandError, Repo | ||
|
||
from programlib import Program | ||
|
||
GIT_USER = 'Vadim Liventsev' | ||
GIT_EMAIL = '[email protected]' | ||
GITHUB_USERNAME = 'vadim0x60' | ||
GITHUB_PASSWORD = 'GITHUB_PASSWORD' | ||
GITHUB_REPO = 'programlib.git' | ||
|
||
github_remote = f'https://{GITHUB_USERNAME}:{GITHUB_PASSWORD}@github.com/{GITHUB_USERNAME}/{GITHUB_REPO}' | ||
|
||
def upload_file(repo, filename, message=None): | ||
if not message: | ||
message = f'added {filename}' | ||
|
||
repo.index.add(filename) | ||
repo.index.commit(message) | ||
repo.remotes.origin.pull() | ||
repo.remotes.origin.push() | ||
|
||
def ensure_correct_repo(remote, path): | ||
try: | ||
repo = Repo.clone_from(remote, path) | ||
except GitCommandError: | ||
repo = Repo(path) | ||
assert repo.remotes.origin.url == remote | ||
|
||
repo.config_writer().set_value('user', 'name', GIT_USER).release() | ||
repo.config_writer().set_value('user', 'email', GIT_EMAIL).release() | ||
return repo | ||
|
||
# Create a program | ||
program = Program(source='print("Hello, world!")', language='Python') | ||
|
||
# Test it | ||
assert program.run() == ['Hello, world!'] | ||
|
||
# Upload it to GitHub | ||
repo = ensure_correct_repo(github_remote, 'programs') | ||
program.save('programs/hello.py') | ||
upload_file(repo, 'hello.py') |