Fixes
All checks were successful
buildbot/multibuild_parent Build done.
buildbot/travis_bionic Build done.

This commit is contained in:
Peter Šurda 2024-04-15 19:26:02 +08:00
parent 7346fe600c
commit 0cd372f6c6
Signed by: PeterSurda
GPG Key ID: 3E47497CF67ABB95

View File

@ -15,11 +15,11 @@ GITEA_REPO_URL="https://git.bitmessage.org/api/v1"
combined = {} combined = {}
def retrieve(token, relationship): def retrieve(token, kind):
if relationship not in ("review_requested", "assigned"): if kind not in ("review_requested", "assigned"):
raise cherrypy.HTTPError(401, 'Unauthorized') 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&{relationship}=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)
@ -30,7 +30,7 @@ def retrieve(token, relationship):
for issue in issues: for issue in issues:
_id = issue['id'] _id = issue['id']
retval[_id] = issue retval[_id] = issue
retval[_id]['categories'] = [relationship] retval[_id]['categories'] = [kind]
return retval return retval
def process(retrieved): def process(retrieved):
@ -55,13 +55,13 @@ def get_token(input_token):
return token return token
class Root: class Root:
def _authenticate(self): def _authenticate(self, kind):
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')
@ -72,7 +72,7 @@ class Root:
@cherrypy.expose @cherrypy.expose
def assigned(self): def assigned(self):
token = self._authenticate() token = self._authenticate("assigned")
retrieved = retrieve(token, "assigned") retrieved = retrieve(token, "assigned")
if not retrieved: if not retrieved:
raise cherrypy.HTTPError(401, 'Unauthorized') raise cherrypy.HTTPError(401, 'Unauthorized')
@ -80,8 +80,8 @@ class Root:
@cherrypy.expose @cherrypy.expose
def review_requested(self): def review_requested(self):
token = self._authenticate() token = self._authenticate("review_requested")
retrieved = retrieve(token, "assigned") retrieved = retrieve(token, "review_requested")
if not retrieved: if not retrieved:
raise cherrypy.HTTPError(401, 'Unauthorized') raise cherrypy.HTTPError(401, 'Unauthorized')
return(process(retrieved)) return(process(retrieved))