-
Notifications
You must be signed in to change notification settings - Fork 0
/
packager_github.py
53 lines (31 loc) · 1.37 KB
/
packager_github.py
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
from generalpackager import PACKAGER_GITHUB_API
from git import Repo
class _PackagerGitHub:
""" Sync metadata. """
def __init__(self):
self.commit_sha = "master"
def sync_github_metadata(self):
""" Sync GitHub with local metadata.
:param generalpackager.Packager self: """
self.github.set_website(self.pypi.url)
self.github.set_description(self.localrepo.metadata.description)
self.github.set_topics(*self.get_topics())
def commit_and_push(self, message=None, tag=False):
""" Commit and push this local repo to GitHub.
Return short sha1 of pushed commit.
:param generalpackager.Packager self:
:param message:
:param tag: """
repo = Repo(str(self.path))
repo.git.add(A=True)
repo.index.commit(message=str(message) or "Automatic commit.")
remote = repo.remote()
remote.set_url(f"https://Mandera:{PACKAGER_GITHUB_API}@github.com/{self.github.owner}/{self.name}.git")
if tag:
tag_ref = repo.create_tag(f"v{self.localrepo.metadata.version}", force=True)
remote.push(refspec=tag_ref)
try:
self.commit_sha = remote.push()[0].summary.split("..")[1].rstrip()
except OSError: # Just suppressing weird invalid handle error
pass
return self.commit_sha