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
|
from app import app
from flask import url_for
from requests_oauthlib import OAuth2Session
def authenticate(access_token):
token = {"scope": [""], "access_token": access_token, "token_type": "bearer"}
github = OAuth2Session(app.config['GITHUB_CLIENT_ID'], token=token)
user_data = github.get('https://api.github.com/user')
if user_data.status_code == 200:
return True
else:
return False
def make_public_ticket(ticket):
new_ticket = ticket.copy()
new_ticket['uri'] = url_for('get_ticket', ticket_id=ticket['id'], _external=True)
return new_ticket
def ticket_to_dict(ticket):
nt = {
'id': ticket.id,
'summary': ticket.summary,
'body': ticket.body,
'opened_at': ticket.opened_at.strftime('%Y-%m-%dT%H:%M:%S'),
'status': ticket.status,
'reason': ticket.reason,
'opened_by': {
'id': ticket.opened_by.id,
'nickname': ticket.opened_by.nickname,
'email': ticket.opened_by.email,
},
}
if ticket.updated_at:
nt['updated_at'] = ticket.updated_at.strftime('%Y-%m-%dT%H:%M:%S')
else:
nt['updated_at'] = None
return nt
|