swh.lister.bitbucket.lister module

class swh.lister.bitbucket.lister.BitbucketListerState(last_repo_cdate: Optional[datetime.datetime] = None)[source]

Bases: object

State of Bitbucket lister

last_repo_cdate: Optional[datetime.datetime] = None

Creation date and time of the last listed repository during an incremental pass

class swh.lister.bitbucket.lister.BitbucketLister(scheduler: swh.scheduler.interface.SchedulerInterface, page_size: int = 1000, incremental: bool = True, credentials: Optional[Dict[str, Dict[str, List[Dict[str, str]]]]] = None)[source]

Bases: swh.lister.pattern.Lister[swh.lister.bitbucket.lister.BitbucketListerState, List[Dict[str, Any]]]

List origins from Bitbucket using its API.

Bitbucket API has the following rate-limit configuration:

  • 60 requests per hour for anonymous users

  • 1000 requests per hour for authenticated users

The lister is working in anonymous mode by default but Bitbucket account credentials can be provided to perform authenticated requests.

LISTER_NAME: str = 'bitbucket'
INSTANCE = 'bitbucket'
API_URL = 'https://api.bitbucket.org/2.0/repositories'
state_from_dict(d: Dict[str, Any]) swh.lister.bitbucket.lister.BitbucketListerState[source]

Convert the state stored in the scheduler backend (as a dict), to the concrete StateType for this lister.

state_to_dict(state: swh.lister.bitbucket.lister.BitbucketListerState) Dict[str, Any][source]

Convert the StateType for this lister to its serialization as dict for storage in the scheduler.

Values must be JSON-compatible as that’s what the backend database expects.

set_credentials(username: Optional[str], password: Optional[str]) None[source]

Set basic authentication headers with given credentials.

page_request(last_repo_cdate: str) requests.models.Response[source]
get_pages() Iterator[List[Dict[str, Any]]][source]

Retrieve a list of pages of listed results. This is the main loop of the lister.

Returns

an iterator of raw pages fetched from the platform currently being listed.

get_origins_from_page(page: List[Dict[str, Any]]) Iterator[swh.scheduler.model.ListedOrigin][source]

Convert a page of Bitbucket repositories into a list of ListedOrigins.

commit_page(page: List[Dict[str, Any]]) None[source]

Update the currently stored state using the latest listed page.

finalize() None[source]

Custom hook to finalize the lister state before returning from the main loop.

This method must set updated if the lister has done some work.

If relevant, this method can use :meth`get_state_from_scheduler` to merge the current lister state with the one from the scheduler backend, reducing the risk of race conditions if we’re running concurrent listings.

This method is called in a finally block, which means it will also run when the lister fails.