def handler(create_client: Callable[[], aiohttp.ClientSession], server: ni_abc.ServerHost,
cla_records: ni_abc.CLAHost) -> Callable[[web.Request], Awaitable[web.Response]]:
"""Create a closure to handle requests from the contribution host."""
async def respond(request: web.Request) -> web.Response:
"""Handle a webhook trigger from the contribution host."""
async with create_client() as client:
try:
contribution = await ContribHost.process(server, request, client)
usernames = await contribution.usernames()
server.log("Usernames: " + str(usernames))
trusted_users = server.trusted_users()
usernames_to_check = usernames - trusted_users
cla_status = await cla_records.check(client, usernames_to_check)
server.log("CLA status: " + str(cla_status))
# With a work queue, one could make the updating of the
# contribution a work item and return an HTTP 202 response.
await contribution.update(cla_status)
return web.Response(status=http.HTTPStatus.OK)
except ni_abc.ResponseExit as exc:
return exc.response
except Exception as exc:
server.log_exception(exc)
return web.Response(
status=http.HTTPStatus.INTERNAL_SERVER_ERROR)
return respond
评论列表
文章目录