Skip to content

Commit 4289f64

Browse files
authored
Merge pull request #851 from GeoffRiley/PCC38
PCC38 GeoffRiley — HacktoberFest Checker
2 parents fa6f5fb + 9ccef50 commit 4289f64

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

38/GeoffRiley/git_check.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
from datetime import date
2+
3+
from bottle import run, template, request, post, get
4+
from github import Github, GithubException
5+
6+
7+
@get('/')
8+
def login():
9+
return '''
10+
<h1>HacktoberFest Checker</h1>
11+
<h2>Login</h2>
12+
<p>Please enter your Github username</p>
13+
<form action="/" method="post">
14+
Github username: <input name="username" type="text" />
15+
</form>
16+
'''
17+
18+
19+
@post('/')
20+
def search_prs():
21+
# Statements taken from https://github.com/pybites/hacktoberfest-checker/blob/master/controllers/index.js
22+
statements = [
23+
"It's not too late to start!",
24+
"Off to a great start, keep going!",
25+
"Half way there, keep it up!",
26+
"So close!",
27+
"Way to go!",
28+
"Now you're just showing off!"
29+
]
30+
# Extract the username entered in the web form
31+
username = request.forms.get('username')
32+
33+
# check with GitHub that the entered username actually exists… if not show the unknown template
34+
gh = Github()
35+
try:
36+
user = gh.get_user(username).name
37+
except GithubException:
38+
return template('unknown')
39+
40+
# Now we're going to grab a list of all the PRs put through by the user… there should be more checking though, ie:
41+
# for invalid and spam labels at the very least.
42+
try:
43+
# Query based upon:
44+
# const options = {
45+
# q: `-label:invalid
46+
# +created:2017-09-30T00:00:00-12:00..2017-10-31T23:59:59-12:00
47+
# +type:pr
48+
# +is:public
49+
# +author:${username}`
50+
# };
51+
# from https://github.com/pybites/hacktoberfest-checker/blob/master/controllers/index.js
52+
# The was written for 2017, so it needs to be updated for *this* year,
53+
# we can automagically pick the current year:
54+
year = str(date.today().year)
55+
# Request a list of PRs within the specific date range…
56+
query = f'{year}-09-30T00:00:00-12:00..{year}-10-31T23:59:59-12:00'
57+
pr_list = gh.search_issues('', author=username, type='pr', created=query)
58+
except GithubException:
59+
# any errors from GitHub at this stage we just assumes means no PRs found
60+
pr_list = []
61+
pr_list.totalCount = 0
62+
63+
# We're going to pick out the details for each PR that we want to display to the user
64+
pr_detail = {"url": [], "title": [], "date": []}
65+
# Provided there are PRs, loop through them extracting the url, title and date into the pr_detail arrays
66+
if pr_list.totalCount > 0:
67+
for pr in pr_list:
68+
pr_detail["url"].append(pr.pull_request.html_url)
69+
pr_detail["title"].append(pr.title)
70+
pr_detail["date"].append(pr.created_at)
71+
72+
pr_count = len(pr_detail["title"])
73+
return template('pr_list', pr_data=pr_detail, name=pr_list[0].user.name,
74+
prs=pr_detail["title"], dates=pr_detail["date"], urls=pr_detail["url"],
75+
pr_count=pr_count, statement=statements[pr_count])
76+
77+
return template('pr_list', pr_count=0, name=user, statement=statements[0])
78+
79+
80+
run(host='localhost', port=8080)

38/GeoffRiley/views/pr_list.tpl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<h1>HacktoberFest Checker</h1>
2+
<h2>{{name}}</h2>
3+
<p>You have {{pr_count}} out of 4 PRs completed this October.</p>
4+
<p><strong>{{statement}}</strong></p>
5+
%if 'prs' in locals():
6+
<ul>
7+
%for pr,date,url in zip(prs,dates,urls):
8+
<li><a href={{url}}>{{pr}}</a> created on {{date}}</li>
9+
%end
10+
</ul>
11+
%end

38/GeoffRiley/views/unknown.tpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<h1>HacktoberFest Checker</h1>
2+
<p>Sorry, could not find a user on Github with that name, please check and <a href="/">try again</a>.</p>

0 commit comments

Comments
 (0)