Changeset View
Changeset View
Standalone View
Standalone View
swh/web/save_origin_webhooks/generic_receiver.py
Show All 10 Lines | |||||
from swh.web.api.apidoc import api_doc | from swh.web.api.apidoc import api_doc | ||||
from swh.web.api.apiurls import APIUrls, api_route | from swh.web.api.apiurls import APIUrls, api_route | ||||
from swh.web.save_code_now.origin_save import create_save_origin_request | from swh.web.save_code_now.origin_save import create_save_origin_request | ||||
from swh.web.utils.exc import BadInputExc | from swh.web.utils.exc import BadInputExc | ||||
webhooks_api_urls = APIUrls() | webhooks_api_urls = APIUrls() | ||||
SUPPORTED_FORGE_TYPES = set() | |||||
class OriginSaveWebhookReceiver(abc.ABC): | class OriginSaveWebhookReceiver(abc.ABC): | ||||
FORGE_TYPE: str | FORGE_TYPE: str | ||||
WEBHOOK_GUIDE_URL: str | WEBHOOK_GUIDE_URL: str | ||||
REPO_TYPES: str | REPO_TYPES: str | ||||
@abc.abstractmethod | @abc.abstractmethod | ||||
def is_forge_request(self, request: Request) -> bool: | def is_forge_request(self, request: Request) -> bool: | ||||
... | ... | ||||
Show All 32 Lines | def __init__(self): | ||||
either **accepted**, **rejected** or **pending** | either **accepted**, **rejected** or **pending** | ||||
:statuscode 200: save request for repository has been successfully created | :statuscode 200: save request for repository has been successfully created | ||||
from the webhook payload. | from the webhook payload. | ||||
:statuscode 400: no save request has been created due to invalid POST | :statuscode 400: no save request has been created due to invalid POST | ||||
request or missing data in webhook payload | request or missing data in webhook payload | ||||
""" | """ | ||||
self.__name__ = "api_origin_save_webhook_{self.FORGE_TYPE.lower()}" | self.__name__ = "api_origin_save_webhook_{self.FORGE_TYPE.lower()}" | ||||
SUPPORTED_FORGE_TYPES.add(self.FORGE_TYPE.lower()) | |||||
api_doc( | api_doc( | ||||
f"/origin/save/webhook/{self.FORGE_TYPE.lower()}/", | f"/origin/save/webhook/{self.FORGE_TYPE.lower()}/", | ||||
category="Request archival", | category="Request archival", | ||||
)(self) | )(self) | ||||
api_route( | api_route( | ||||
f"/origin/save/webhook/{self.FORGE_TYPE.lower()}/", | f"/origin/save/webhook/{self.FORGE_TYPE.lower()}/", | ||||
f"api-1-origin-save-webhook-{self.FORGE_TYPE.lower()}", | f"api-1-origin-save-webhook-{self.FORGE_TYPE.lower()}", | ||||
methods=["POST"], | methods=["POST"], | ||||
Show All 38 Lines | ) -> Dict[str, Any]: | ||||
f"Visit type could not be determined for repository {repo_url}." | f"Visit type could not be determined for repository {repo_url}." | ||||
) | ) | ||||
if private: | if private: | ||||
raise BadInputExc( | raise BadInputExc( | ||||
f"Repository {repo_url} is private and cannot be cloned without authentication." | f"Repository {repo_url} is private and cannot be cloned without authentication." | ||||
) | ) | ||||
save_request = create_save_origin_request( | save_request = create_save_origin_request( | ||||
visit_type=visit_type, origin_url=repo_url | visit_type=visit_type, | ||||
origin_url=repo_url, | |||||
from_webhook=True, | |||||
webhook_origin=self.FORGE_TYPE.lower(), | |||||
) | ) | ||||
return { | return { | ||||
"origin_url": save_request["origin_url"], | "origin_url": save_request["origin_url"], | ||||
"visit_type": save_request["visit_type"], | "visit_type": save_request["visit_type"], | ||||
"save_request_date": save_request["save_request_date"], | "save_request_date": save_request["save_request_date"], | ||||
"save_request_status": save_request["save_request_status"], | "save_request_status": save_request["save_request_status"], | ||||
} | } |