Changeset View
Changeset View
Standalone View
Standalone View
swh/web/save_origin_webhooks/sourceforge.py
Show All 28 Lines | def is_forge_request(self, request: Request) -> bool: | ||||
request.headers.get("User-Agent", "") | request.headers.get("User-Agent", "") | ||||
== "Allura Webhook (https://allura.apache.org/)" | == "Allura Webhook (https://allura.apache.org/)" | ||||
) | ) | ||||
def is_push_event(self, request: Request) -> bool: | def is_push_event(self, request: Request) -> bool: | ||||
# SourceForge only support webhooks for push events | # SourceForge only support webhooks for push events | ||||
return True | return True | ||||
def extract_repo_url_and_visit_type(self, request: Request) -> Tuple[str, str]: | def extract_repo_info(self, request: Request) -> Tuple[str, str, bool]: | ||||
repo_url = "" | repo_url = "" | ||||
visit_type = "" | visit_type = "" | ||||
private = False | |||||
project_full_name = request.data.get("repository", {}).get("full_name") | project_full_name = request.data.get("repository", {}).get("full_name") | ||||
if project_full_name: | if project_full_name: | ||||
project_name = project_full_name.split("/")[2] | project_name = project_full_name.split("/")[2] | ||||
project_api_url = self.SOURCE_FORGE_API_PROJECT_URL_PATTERN.format( | project_api_url = self.SOURCE_FORGE_API_PROJECT_URL_PATTERN.format( | ||||
project_name=project_name | project_name=project_name | ||||
) | ) | ||||
response = requests.get(project_api_url) | response = requests.get(project_api_url) | ||||
if response.ok: | if response.ok: | ||||
project_data = response.json() | project_data = response.json() | ||||
private = project_data.get("private", False) | |||||
for tool in project_data.get("tools", []): | for tool in project_data.get("tools", []): | ||||
if tool.get("mount_point") == "code" and tool.get( | if tool.get("mount_point") == "code" and tool.get( | ||||
"url", "" | "url", "" | ||||
).endswith(project_full_name): | ).endswith(project_full_name): | ||||
repo_url = tool.get( | repo_url = tool.get( | ||||
"clone_url_https_anon", tool.get("clone_url_ro", "") | "clone_url_https_anon", tool.get("clone_url_ro", "") | ||||
) | ) | ||||
visit_type = tool.get("name", "") | visit_type = tool.get("name", "") | ||||
return repo_url, visit_type | return repo_url, visit_type, private | ||||
api_origin_save_webhook_sourceforge = SourceforgeOriginSaveWebhookReceiver() | api_origin_save_webhook_sourceforge = SourceforgeOriginSaveWebhookReceiver() |