Compare commits
2 Commits
92287547aa
...
0cd372f6c6
Author | SHA1 | Date | |
---|---|---|---|
0cd372f6c6 | |||
7346fe600c |
|
@ -15,32 +15,27 @@ GITEA_REPO_URL="https://git.bitmessage.org/api/v1"
|
||||||
|
|
||||||
combined = {}
|
combined = {}
|
||||||
|
|
||||||
def get_combined(token):
|
def retrieve(token, kind):
|
||||||
for q in ("review_requested", "assigned"):
|
if kind not in ("review_requested", "assigned"):
|
||||||
|
raise cherrypy.HTTPError(401, 'Unauthorized')
|
||||||
req = urllib.request.Request(GITEA_REPO_URL
|
req = urllib.request.Request(GITEA_REPO_URL
|
||||||
+ f"/repos/issues/search?state=open&{q}=true")
|
+ f"/repos/issues/search?state=open&{kind}=true")
|
||||||
req.add_header("Accept", "application/json")
|
req.add_header("Accept", "application/json")
|
||||||
req.add_header("Authorization", "token " + token)
|
req.add_header("Authorization", "token " + token)
|
||||||
|
|
||||||
timestamp=datetime.datetime.now()
|
retval = {}
|
||||||
print(f"{timestamp} Requesting and parsing {q}")
|
|
||||||
with urllib.request.urlopen(req) \
|
with urllib.request.urlopen(req) as response:
|
||||||
as response:
|
|
||||||
issues = json.load(response)
|
issues = json.load(response)
|
||||||
for issue in issues:
|
for issue in issues:
|
||||||
_id = issue['id']
|
_id = issue['id']
|
||||||
if _id not in combined:
|
retval[_id] = issue
|
||||||
combined[_id] = issue
|
retval[_id]['categories'] = [kind]
|
||||||
combined[_id]['categories'] = []
|
return retval
|
||||||
if q not in combined[_id]['categories']:
|
|
||||||
combined[_id]['categories'].append(q)
|
|
||||||
timestamp=datetime.datetime.now()
|
|
||||||
print(f"{timestamp} Done processing {q}")
|
|
||||||
return combined
|
|
||||||
|
|
||||||
def process_combined(combined):
|
def process(retrieved):
|
||||||
cal = Calendar()
|
cal = Calendar()
|
||||||
for _id, issue in combined.items():
|
for _id, issue in retrieved.items():
|
||||||
todo = Todo()
|
todo = Todo()
|
||||||
todo['uid'] = _id
|
todo['uid'] = _id
|
||||||
todo['dtstamp'] = issue['created_at']
|
todo['dtstamp'] = issue['created_at']
|
||||||
|
@ -60,24 +55,36 @@ def get_token(input_token):
|
||||||
return token
|
return token
|
||||||
|
|
||||||
class Root:
|
class Root:
|
||||||
@cherrypy.expose
|
def _authenticate(self, kind):
|
||||||
def todo(self):
|
|
||||||
cherrypy.response.headers['WWW-Authenticate'] = \
|
cherrypy.response.headers['WWW-Authenticate'] = \
|
||||||
'Basic realm="ICS access"'
|
'Basic realm="ICS access"'
|
||||||
cherrypy.response.headers['Content-Type'] = \
|
cherrypy.response.headers['Content-Type'] = \
|
||||||
'text/calendar'
|
'text/calendar'
|
||||||
cherrypy.response.headers['Content-Disposition'] = \
|
cherrypy.response.headers['Content-Disposition'] = \
|
||||||
'attachment; filename="Gitea TODO.ics"'
|
f'attachment; filename="Gitea {kind}.ics"'
|
||||||
authorization = cherrypy.request.headers.get('Authorization', ':')
|
authorization = cherrypy.request.headers.get('Authorization', ':')
|
||||||
if not authorization:
|
if not authorization:
|
||||||
raise cherrypy.HTTPError(401, 'Unauthorized')
|
raise cherrypy.HTTPError(401, 'Unauthorized')
|
||||||
token = get_token(authorization)
|
token = get_token(authorization)
|
||||||
if not token:
|
if not token:
|
||||||
raise cherrypy.HTTPError(401, 'Unauthorized')
|
raise cherrypy.HTTPError(401, 'Unauthorized')
|
||||||
combined = get_combined(token)
|
return token
|
||||||
if not combined:
|
|
||||||
|
@cherrypy.expose
|
||||||
|
def assigned(self):
|
||||||
|
token = self._authenticate("assigned")
|
||||||
|
retrieved = retrieve(token, "assigned")
|
||||||
|
if not retrieved:
|
||||||
raise cherrypy.HTTPError(401, 'Unauthorized')
|
raise cherrypy.HTTPError(401, 'Unauthorized')
|
||||||
return(process_combined(combined))
|
return(process(retrieved))
|
||||||
|
|
||||||
|
@cherrypy.expose
|
||||||
|
def review_requested(self):
|
||||||
|
token = self._authenticate("review_requested")
|
||||||
|
retrieved = retrieve(token, "review_requested")
|
||||||
|
if not retrieved:
|
||||||
|
raise cherrypy.HTTPError(401, 'Unauthorized')
|
||||||
|
return(process(retrieved))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
cherrypy.config.update({'server.socket_host': '0.0.0.0',
|
cherrypy.config.update({'server.socket_host': '0.0.0.0',
|
||||||
|
|
Loading…
Reference in New Issue
Block a user