phabricator: Allow to pass forge base URL as lister parameter
This commit is contained in:
parent
d1fbccd988
commit
d691c04eb8
3 changed files with 37 additions and 3 deletions
|
@ -5,6 +5,7 @@ from collections import defaultdict
|
|||
import logging
|
||||
import random
|
||||
from typing import Any, Dict, Iterator, List, Optional
|
||||
from urllib.parse import urljoin
|
||||
|
||||
import requests
|
||||
|
||||
|
@ -20,7 +21,18 @@ PageType = List[Dict[str, Any]]
|
|||
|
||||
|
||||
class PhabricatorLister(StatelessLister[PageType]):
|
||||
"""
|
||||
List all repositories hosted on a Phabricator instance.
|
||||
|
||||
Args:
|
||||
url: base URL of a phabricator forge
|
||||
(for instance https://forge.softwareheritage.org)
|
||||
instance: string identifier for the listed forge
|
||||
api_token: authentication token for Conduit API
|
||||
"""
|
||||
|
||||
LISTER_NAME = "phabricator"
|
||||
API_REPOSITORY_PATH = "/api/diffusion.repository.search"
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
|
@ -30,7 +42,9 @@ class PhabricatorLister(StatelessLister[PageType]):
|
|||
api_token: Optional[str] = None,
|
||||
credentials: CredentialsType = None,
|
||||
):
|
||||
super().__init__(scheduler, url, instance, credentials)
|
||||
super().__init__(
|
||||
scheduler, urljoin(url, self.API_REPOSITORY_PATH), instance, credentials
|
||||
)
|
||||
|
||||
self.session = requests.Session()
|
||||
self.session.headers.update(
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
import importlib.resources
|
||||
import json
|
||||
|
||||
from swh.lister.phabricator.lister import get_repo_url
|
||||
from swh.lister.phabricator.lister import PhabricatorLister, get_repo_url
|
||||
|
||||
|
||||
def test_get_repo_url():
|
||||
|
@ -27,3 +27,23 @@ def test_get_repo_url():
|
|||
repo = json.load(f)
|
||||
expected_name = "https://svn.blender.org/svnroot/bf-blender/"
|
||||
assert get_repo_url(repo["attachments"]["uris"]["uris"]) == expected_name
|
||||
|
||||
|
||||
def test_lister_url_param(swh_scheduler):
|
||||
FORGE_BASE_URL = "https://forge.softwareheritage.org"
|
||||
API_REPOSITORY_PATH = "/api/diffusion.repository.search"
|
||||
|
||||
for url in (
|
||||
FORGE_BASE_URL,
|
||||
f"{FORGE_BASE_URL}/",
|
||||
f"{FORGE_BASE_URL}/{API_REPOSITORY_PATH}",
|
||||
f"{FORGE_BASE_URL}/{API_REPOSITORY_PATH}/",
|
||||
):
|
||||
|
||||
lister = PhabricatorLister(
|
||||
scheduler=swh_scheduler, url=FORGE_BASE_URL, instance="swh", api_token="foo"
|
||||
)
|
||||
|
||||
expected_url = f"{FORGE_BASE_URL}{API_REPOSITORY_PATH}"
|
||||
|
||||
assert lister.url == expected_url
|
||||
|
|
|
@ -25,7 +25,7 @@ def test_phabricator_lister_task(
|
|||
lister.run.return_value = lister_stats
|
||||
|
||||
task_params = {
|
||||
"url": "https://forge.softwareheritage.org/api/diffusion.repository.search",
|
||||
"url": "https://forge.softwareheritage.org",
|
||||
"instance": "swh",
|
||||
"api_token": None,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue