Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swh-lister
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Antoine R. Dumont
swh-lister
Commits
847a8d34
Verified
Commit
847a8d34
authored
6 years ago
by
Antoine R. Dumont
Browse files
Options
Downloads
Patches
Plain Diff
swh.lister.gitlab: Add Incremental lister behavior
Related T989
parent
ccd0525c
Loading
Loading
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
swh/lister/core/paging_lister.py
+18
-1
18 additions, 1 deletion
swh/lister/core/paging_lister.py
swh/lister/gitlab/lister.py
+2
-2
2 additions, 2 deletions
swh/lister/gitlab/lister.py
swh/lister/gitlab/tasks.py
+23
-1
23 additions, 1 deletion
swh/lister/gitlab/tasks.py
with
43 additions
and
4 deletions
swh/lister/core/paging_lister.py
+
18
−
1
View file @
847a8d34
...
...
@@ -79,7 +79,14 @@ class PageByPageLister(SWHListerBase):
# You probably don't need to override anything below this line.
def
run
(
self
,
min_bound
=
None
,
max_bound
=
None
):
def
check_existence
(
self
,
injected_repos
):
"""
Given a list of injected repos, check if we already have them.
"""
# FIXME: Implement the check
return
False
def
run
(
self
,
min_bound
=
None
,
max_bound
=
None
,
check_existence
=
False
):
"""
Main entry function. Sequentially fetches repository data from the
service according to the basic outline in the class
docstring. Continually fetching sublists until either there
...
...
@@ -89,6 +96,9 @@ class PageByPageLister(SWHListerBase):
Args:
min_bound: optional page to start from
max_bound: optional page to stop at
check_existence (bool): optional existence check (for
incremental lister whose sort
order is inverted)
Returns:
nothing
...
...
@@ -99,6 +109,7 @@ class PageByPageLister(SWHListerBase):
self
.
min_page
=
min_bound
self
.
max_page
=
max_bound
already_seen
=
False
while
self
.
is_within_bounds
(
page
,
self
.
min_page
,
self
.
max_page
):
logging
.
info
(
'
listing repos starting at %s
'
%
page
)
...
...
@@ -106,12 +117,18 @@ class PageByPageLister(SWHListerBase):
response
,
injected_repos
=
self
.
ingest_data
(
page
)
next_page
=
self
.
get_next_target_from_response
(
response
)
if
check_existence
:
already_seen
=
self
.
check_existence
(
injected_repos
)
# termination condition
if
(
next_page
is
None
)
or
(
next_page
==
page
):
logging
.
info
(
'
stopping after page %s, no next link found
'
%
page
)
break
elif
already_seen
:
logging
.
info
(
'
Repositories already seen, stopping
'
)
break
else
:
page
=
next_page
...
...
This diff is collapsed.
Click to expand it.
swh/lister/gitlab/lister.py
+
2
−
2
View file @
847a8d34
...
...
@@ -12,7 +12,7 @@ from .models import GitLabModel
class
GitLabLister
(
PageByPageHttpLister
):
# Template path expecting an integer that represents the page id
PATH_TEMPLATE
=
'
/projects?page=%d&order_by=id
&sort=asc&simple=true
'
PATH_TEMPLATE
=
'
/projects?page=%d&order_by=id
'
API_URL_INDEX_RE
=
re
.
compile
(
r
'
^.*/projects.*page=(\d+).*
'
)
MODEL
=
GitLabModel
LISTER_NAME
=
'
gitlab
'
...
...
@@ -103,7 +103,7 @@ class GitLabLister(PageByPageHttpLister):
return
None
def
get_pages_information
(
self
):
"""
Determine
some
pages information.
"""
Determine pages information.
"""
response
=
self
.
transport_head
(
identifier
=
1
)
...
...
This diff is collapsed.
Click to expand it.
swh/lister/gitlab/tasks.py
+
23
−
1
View file @
847a8d34
...
...
@@ -17,13 +17,16 @@ class GitLabListerTask(ListerTaskBase):
class
RangeGitLabLister
(
GitLabListerTask
,
RangeListerTask
):
"""
GitLab lister
work
in
g
on specified range
(start, end) arguments.
"""
Range
GitLab lister
(list available orig
in
s
on specified range
)
"""
task_queue
=
'
swh_lister_gitlab_refresh
'
class
FullGitLabRelister
(
GitLabListerTask
):
"""
Full GitLab lister (list all available origins from the api).
"""
task_queue
=
'
swh_lister_gitlab_refresh
'
def
run_task
(
self
,
*
args
,
**
kwargs
):
...
...
@@ -41,3 +44,22 @@ class FullGitLabRelister(GitLabListerTask):
range_task
=
RangeGitLabLister
()
group
(
range_task
.
s
(
minv
,
maxv
,
*
args
,
**
kwargs
)
for
minv
,
maxv
in
ranges
)()
class
IncrementalGitLabLister
(
ListerTaskBase
):
"""
Incremental GitLab lister (list only new available origins).
"""
task_queue
=
'
swh_lister_gitlab_discover
'
def
new_lister
(
self
,
api_baseurl
=
'
https://gitlab.com/api/v4
'
,
instance
=
'
gitlab.com
'
,):
# will invert the order of the lister's result
return
GitLabLister
(
instance
=
instance
,
api_baseurl
=
api_baseurl
,
sort
=
'
desc
'
)
def
run_task
(
self
,
*
args
,
**
kwargs
):
lister
=
self
.
new_lister
(
*
args
,
**
kwargs
)
# will check for existing data and exit when found
return
lister
.
run
(
min_bound
=
None
,
max_bound
=
None
,
check_existence
=
True
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment