Skip to content

Commit f40ccc1

Browse files
author
Kieran BW
committed
2020.3 - 2020/01/22
1 parent 63bbe18 commit f40ccc1

6 files changed

Lines changed: 57 additions & 48 deletions

File tree

ActiveGithub.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,4 @@
1818
gitrepo.logPrint("{} out of {} Forked repos are alive and newer than the source!"
1919
.format(len(aliveRepos), len(forkedRepos)), "bold")
2020
for aliveRepo in aliveRepos:
21-
gitrepo.logPrint("Name: {}\n- Latest update: {}\n- Link: {}\n- Stars: {}"
22-
.format(aliveRepo["full_name"], aliveRepo["pushed_at"], aliveRepo["html_url"],
23-
aliveRepo["stargazers_count"]))
21+
gitrepo.printRepo(aliveRepo)

CHANGELOG.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@ patch-level version changes can be found in [commit messages](../../commits/mast
88
## 2020.1 - 2020/01/17
99
- Updated ActiveGithub.py, gitrepo.py, UserReposActive.py. Added UserReposTraffic.py
1010

11-
1211
## 2020.2 - 2020/01/21
1312
- Added GitHubRepl.py with basic functionality - I aim for feature parity with
1413
github.com
15-
- Additions and optimisations to lib changes to signatures and new functions are
16-
in bold
14+
- Changes to signatures and new functions are in bold
1715
- getGithubApiRequest(urlExcBase, **jsonOnly=True**)
1816
- sourceAlive(**repoData**, lifespan)
1917
- getListOfAliveForks(**repoData**, lifespan, enableNewer=True)
@@ -25,3 +23,13 @@ patch-level version changes can be found in [commit messages](../../commits/mast
2523
- Optimisations of lib and UserReposActive (UserReposActive.py:5(forEachRepo)
2624
originally took 10.92s and now takes 9.197s per call) - 15% speed improvement
2725
Using cProfile
26+
27+
## 2020.3 - 2020/01/22
28+
- Optimisations to getPaginatedGithubApiRequest (12.49s to 8.94s per call) - 28%
29+
speed improvement when getting a list of forked repos that are alive and newer
30+
than user starred repos
31+
- Changes to signatures and new functions are in bold
32+
- **printIssue**(issue)
33+
- **printUser**(user)
34+
- **printGist**(gist)
35+
- **printRepo**(repo)

GitHubRepl.py

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,12 @@ def printMarkdown(raw, maxpages=0):
1313
paginatedList(md, 30, print, maxpages)
1414

1515

16-
def printRepo(repo):
17-
try:
18-
gitrepo.logPrint("{}"
19-
.format(("[\033[91mArchived\033[00m] " if repo["archived"] else "") + repo["name"]), "bold")
20-
except:
21-
return
22-
description = repo["description"] if "description" in repo else "[description]"
23-
language = repo["language"] if "language" in repo else "[unknown]"
24-
try:
25-
licenseName = repo["license"]["name"]
26-
except:
27-
licenseName = "[unknown]"
28-
updated = repo["updated_at"] if "updated_at" in repo else "[unknown]"
29-
gitrepo.logPrint("{}\nLanguage: {} License: {} Last Updated: {}"
30-
.format(description, language, licenseName, updated))
31-
gitrepo.logPrint("Link: {}" .format(repo["html_url"]))
32-
3316

3417
def listRepos(data, user):
3518
userRepos = gitrepo.getListOfUserRepos(user, data)
36-
paginatedList(userRepos, 8, printRepo)
37-
38-
def printIssue(issue):
39-
gitrepo.logPrint(("[\033[91mClosed\033[00m] " if issue["state"] == "closed" else "")
40-
+ issue["title"], "bold")
41-
gitrepo.logPrint(issue["updated_at"])
19+
paginatedList(userRepos, 8, gitrepo.printRepo)
4220

43-
def printUser(user):
44-
gitrepo.logPrint(user["login"], "bold")
45-
gitrepo.logPrint(user["html_url"])
4621

47-
def printGist(gist):
48-
gitrepo.logPrint(gist["description"], "bold")
49-
gitrepo.logPrint("Files: {}" .format(list(gist["files"].keys())), "bold")
50-
gitrepo.logPrint(gist["html_url"])
5122

5223
def paginatedList(iterable, perPage, printFunc, maxpages=0):
5324
totalPages = len(iterable) // perPage + 1
@@ -100,14 +71,14 @@ def profile(user=None):
10071
def gists(user=None):
10172
user = username if user is None else user
10273
userGists = gitrepo.getUserGists(user)
103-
paginatedList(userGists, 30, printGist)
74+
paginatedList(userGists, 30, gitrepo.printGist)
10475

10576
def showrepo(repo, user=None):
10677
clear()
10778
user = username if user is None else user
10879
rawMarkdown = gitrepo.getReadme(user+"/"+repo)
10980
repoText = gitrepo.getRepo(user+"/"+repo)
110-
printRepo(repoText)
81+
gitrepo.printRepo(repoText)
11182
gitrepo.logPrint("README", "bold")
11283
printMarkdown(rawMarkdown, 1)
11384

@@ -119,17 +90,17 @@ def showreadme(repo, user=None):
11990

12091
def searchissues(searchTerm):
12192
issues = gitrepo.search(searchTerm, context="issues")
122-
paginatedList(issues, 30, printIssue)
93+
paginatedList(issues, 30, gitrepo.printIssue)
12394

12495

12596
def searchrepos(searchTerm):
12697
searchRepos = gitrepo.search(searchTerm, context="repositories")
127-
paginatedList(searchRepos, 10, printRepo)
98+
paginatedList(searchRepos, 10, gitrepo.printRepo)
12899

129100

130101
def searchusers(searchTerm):
131102
users = gitrepo.search(searchTerm, context="users")
132-
paginatedList(users, 30, printUser)
103+
paginatedList(users, 30, gitrepo.printUser)
133104

134105

135106
functions = {"exit": replexit, "help": replhelp, "repos": repos, "stars": stars,

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
Checks that a repo is active and gets a list of active forks
1717

18+
Turns out that I could have used https://github.com/PyGithub/PyGithub. Oh well gitrepo.py does what I need for this project.
19+
1820
## ActiveGithub.py
1921
### Input
2022
- Set the repo lifespan (weeks - eg. 1 - default=36)>

UserReposActive.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ def forEachRepo(sourceRepo):
1818
gitrepo.logPrint("{} out of {} Forked repos are alive and newer than the source!"
1919
.format(len(aliveRepos), len(forkedRepos)), "bold")
2020
for aliveRepo in aliveRepos:
21-
gitrepo.logPrint("Name: {}\n- Latest update: {}\n- Link: {}\n- Stars: {}"
22-
.format(aliveRepo["full_name"], aliveRepo["pushed_at"], aliveRepo["html_url"],
23-
aliveRepo["stargazers_count"]))
21+
gitrepo.printRepo(aliveRepo)
2422

2523

2624
username, death = gitrepo.getUsernameAndLifespan()

gitrepo.py

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,17 @@ def getListOfUserRepos(username, context):
8686

8787

8888
def getPaginatedGithubApiRequest(apiUrl):
89+
firstPage = getGithubApiRequest(apiUrl+"?per_page=100", False)
90+
iterable = firstPage.json()
8991
try:
90-
lastPage = int(getGithubApiRequest(
91-
apiUrl+"?per_page=100", False).links['last']['url'].split("&page=")[1])
92+
lastPage = int(firstPage.links['last']['url'].split("&page=")[1])
9293
except:
9394
lastPage = 1
9495
pageLimit = 5
9596
if lastPage > pageLimit:
9697
logPrint("There are over {} pages! Limiting to {} pages" .format(pageLimit, pageLimit), "warning")
9798
lastPage = pageLimit
98-
iterable = []
99-
for page in range(1, lastPage + 1):
99+
for page in range(2, lastPage + 1):
100100
iterationsInstance = getGithubApiRequest(apiUrl+"?per_page=100&page="+str(page))
101101
iterable.extend(iterationsInstance)
102102
return iterable
@@ -150,3 +150,35 @@ def search(searchTerm, context="repositories"):
150150

151151
def getUserGists(username):
152152
return getPaginatedGithubApiRequest("users/"+username+"/gists")
153+
154+
155+
def printIssue(issue):
156+
logPrint(("[\033[91mClosed\033[00m] " if issue["state"] == "closed" else "")
157+
+ issue["title"], "bold")
158+
logPrint(issue["updated_at"])
159+
160+
def printUser(user):
161+
logPrint(user["login"], "bold")
162+
logPrint(user["html_url"])
163+
164+
def printGist(gist):
165+
logPrint(gist["description"], "bold")
166+
logPrint("Files: {}" .format(list(gist["files"].keys())), "bold")
167+
logPrint(gist["html_url"])
168+
169+
def printRepo(repo):
170+
try:
171+
logPrint("{}"
172+
.format(("[\033[91mArchived\033[00m] " if repo["archived"] else "") + repo["name"]), "bold")
173+
except:
174+
return
175+
description = repo["description"] if "description" in repo else "[description]"
176+
language = repo["language"] if "language" in repo else "[unknown]"
177+
try:
178+
licenseName = repo["license"]["name"]
179+
except:
180+
licenseName = "[unknown]"
181+
updated = repo["updated_at"] if "updated_at" in repo else "[unknown]"
182+
logPrint("{}\nLanguage: {}, License: {}, Last Updated: {}"
183+
.format(description, language, licenseName, updated))
184+
logPrint("Link: {}" .format(repo["html_url"]))

0 commit comments

Comments
 (0)