-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGithubClass.py
More file actions
71 lines (53 loc) · 2.2 KB
/
GithubClass.py
File metadata and controls
71 lines (53 loc) · 2.2 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!python
from github import Github
class GithubClass:
def __init__(self, token):
self.token = token
self.client = Github(token)
def get_client(self):
return self.client
def get_names_of_repos(self):
return list(x.name for x in self.client.get_user().get_repos())
def create_repo(self, repo_name):
return self.client.get_user().create_repo(name=repo_name, auto_init=True)
def get_repos(self):
return self.client.get_user().get_repos()
def get_repo(self, repo_name):
repo_list = list(self.get_repo_gen(repo_name))
if len(repo_list) > 0:
return repo_list[0]
else:
return "error"
def get_repo_gen(self, repo_name):
for repo in self.get_repos():
if repo.name == repo_name:
yield repo
def delete_repo(self, repo_name):
repo = self.get_repo(repo_name)
repo.delete()
def get_names_of_branches(self, repo_name):
if repo_name in self.get_names_of_repos():
repo = self.get_repo(repo_name)
return list(x.name for x in repo.get_branches())
else:
pass
def create_branch(self, repo, branch_name):
sha = repo.get_git_ref('heads/master').object.sha
branch = repo.create_git_ref('refs/heads/{}'.format(branch_name), sha)
return branch
def get_branch(self, repo, branch_name):
for branch in repo.get_branches():
if branch.name == branch_name:
return branch
def get_protected_branch(self, repo, branch_name):
return repo.get_protected_branch(branch_name)
def protect_branch(self, repo, branch_name):
repo.protect_branch(branch_name, True, "everyone", ["test"])
def create_file(self, repo, path, message, content, branch):
return repo.create_file(path=path, message=message, content=content, branch=branch)
def get_branch_dir_contents(self, repo, path, branch_name):
return repo.get_dir_contents(path, branch_name)
def convert_github_files(self, files):
for github_file in files:
data_in_files = github_file.decoded_content.decode("utf-8").split('\n')
return data_in_files