-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithubRepoDelete.py
85 lines (71 loc) · 2.58 KB
/
githubRepoDelete.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
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import os
import csv
from github import Github
from dotenv import load_dotenv
load_dotenv()
class GithubRepoDelete:
def __init__(self):
self.forkedRepo = []
self.githubRepos = []
self.getRepos()
self.extractForkedRepo()
def getRepos(self):
g = Github(os.getenv("ACCESS_TOKEN"))
self.githubRepos = g.get_user().get_repos()
def extractForkedRepo(self):
protectedRepo = self.getProtectedForkedRepo()
for repo in self.githubRepos:
if(repo.private is False and repo.fork is True and repo.name not in protectedRepo):
self.forkedRepo.append(repo)
def printForkedRepo(self):
for repo in self.forkedRepo:
print(repo.name)
print("Parent: ", repo.parent)
# print("Private: ", repo.private)
# print("Fork: ", repo.fork)
print("url: ", repo.parent.html_url)
print("==============")
def getCountOfFokedRepo(self):
# print(len(self.githubRepos))
print(len(self.forkedRepo))
def exportForkedRepoToCsv(self):
try:
with open('forkedRepo.csv', 'w') as csvFile:
writer = csv.writer(csvFile)
writer.writerow(["name", "url", "language", "description"])
for repo in self.forkedRepo:
rowData = [repo.parent.name, repo.parent.html_url, repo.parent.language, repo.parent.description]
print(rowData)
writer.writerow(rowData)
csvFile.close()
print("All Done")
except Exception as ex:
print(ex)
def getProtectedForkedRepo(self):
return [
"go-to-do-app",
"gitignore",
"30-seconds-of-code",
"30-seconds-of-css",
"30-seconds-of-interviews",
"30-seconds-of-react",
"33-js-concepts"
]
def deleteForkedRepo(self):
# counter = 0
protectedRepo = self.getProtectedForkedRepo()
for repo in self.forkedRepo:
if(repo.private is False and repo.fork is True and repo.name not in protectedRepo):
print("Deleting ",repo.name)
repo.delete()
print("Deleted ",repo.name)
# if counter == 2:
# break
# else:
# counter += 1
if __name__ == "__main__":
forkedRepo = GithubRepoDelete()
# forkedRepo.printForkedRepo()
# forkedRepo.getCountOfFokedRepo()
# forkedRepo.exportForkedRepoToCsv()
forkedRepo.deleteForkedRepo()