forked from SocketDev/socket-python-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit_interface.py
More file actions
29 lines (26 loc) · 957 Bytes
/
git_interface.py
File metadata and controls
29 lines (26 loc) · 957 Bytes
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
from git import Repo
from socketsecurity.core import log
class Git:
repo: Repo
path: str
def __init__(self, path: str):
self.path = path
self.repo = Repo(path)
assert self.repo
self.head = self.repo.head
self.commit = self.head.commit
self.repo_name = self.repo.remotes.origin.url.split('.git')[0].split('/')[-1]
try:
self.branch = self.head.reference
except Exception as error:
self.branch = None
log.debug(error)
self.author = self.commit.author
self.commit_sha = self.commit.binsha
self.commit_message = self.commit.message
self.committer = self.commit.committer
self.show_files = self.repo.git.show(self.commit, name_only=True, format="%n").splitlines()
self.changed_files = []
for item in self.show_files:
if item != "":
self.changed_files.append(item)