Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
Updates Notifier
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
Container 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
Picasoft
Technique
Updates Notifier
Commits
2c4a65f2
Verified
Commit
2c4a65f2
authored
3 years ago
by
Gaëtan Blond
Browse files
Options
Downloads
Patches
Plain Diff
Added fetcher factory
parent
6b9f610b
No related branches found
No related tags found
1 merge request
!1
Refactor and clean old code
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
updates_notifier/__init__.py
+1
-0
1 addition, 0 deletions
updates_notifier/__init__.py
updates_notifier/fetchers/__init__.py
+1
-0
1 addition, 0 deletions
updates_notifier/fetchers/__init__.py
updates_notifier/fetchers/utils.py
+99
-0
99 additions, 0 deletions
updates_notifier/fetchers/utils.py
with
101 additions
and
0 deletions
updates_notifier/__init__.py
+
1
−
0
View file @
2c4a65f2
from
.entry
import
Entry
This diff is collapsed.
Click to expand it.
updates_notifier/fetchers/__init__.py
+
1
−
0
View file @
2c4a65f2
from
.project_fetcher
import
ProjectFetcher
from
.project_fetcher
import
ProjectFetcher
from
.utils
import
create_fetchers_from_dict
This diff is collapsed.
Click to expand it.
updates_notifier/fetchers/utils.py
0 → 100644
+
99
−
0
View file @
2c4a65f2
from
typing
import
Any
,
Dict
,
List
,
Type
from
.atom_rss_fetcher
import
AtomRSSFetcher
from
.gitea_fetcher
import
GiteaFetcher
from
.github_fetcher
import
GithubFetcher
from
.gitlab_fetcher
import
GitLabFetcher
from
.project_fetcher
import
ProjectFetcher
_TYPE_ATOM_RSS
=
"
atom_rss
"
_TYPE_GITEA
=
"
gitea
"
_TYPE_GITHUB
=
"
github
"
_TYPE_GITLAB
=
"
gitlab
"
class
FactoryError
(
RuntimeError
):
pass
class
FactoryParamError
(
FactoryError
):
def
__init__
(
self
,
param_name
:
str
,
expected_type
:
Type
,
given_type
:
Type
):
self
.
message
=
(
f
"
Invalid type for parameter
{
param_name
}
, wanted
{
expected_type
.
__name__
}
"
f
"
, but got
{
given_type
.
__name__
}
"
)
self
.
repr
=
(
f
"
<
{
type
(
self
).
__name__
}
param_name=
{
param_name
}
"
f
"
expected_type=
{
expected_type
.
__name__
}
given_type=
{
given_type
.
__name__
}
>
"
)
def
__str__
(
self
)
->
str
:
return
self
.
message
def
__repr__
(
self
)
->
str
:
return
self
.
repr
def
_assert_param_type_is
(
param_name
:
str
,
value
:
Any
,
expected_type
:
Type
)
->
None
:
if
not
isinstance
(
value
,
expected_type
):
raise
FactoryParamError
(
param_name
,
expected_type
,
type
(
value
).
__name__
)
def
create_fetcher
(
fetcher_type
:
str
,
feed_id
:
int
,
name
:
str
,
**
kwargs
)
->
ProjectFetcher
:
if
not
isinstance
(
fetcher_type
,
str
):
raise
FactoryError
(
f
"
Fetcher type must be a str, got
{
type
(
fetcher_type
).
__name__
}
"
)
_assert_param_type_is
(
"
feed_id
"
,
feed_id
,
int
)
_assert_param_type_is
(
"
name
"
,
name
,
str
)
if
fetcher_type
==
_TYPE_ATOM_RSS
:
url
=
kwargs
.
get
(
"
url
"
)
_assert_param_type_is
(
"
url
"
,
url
,
str
)
return
AtomRSSFetcher
(
feed_id
,
name
,
url
)
if
fetcher_type
==
_TYPE_GITEA
:
gitea_host
=
kwargs
.
get
(
"
host
"
)
_assert_param_type_is
(
"
host
"
,
gitea_host
,
str
)
repository
=
kwargs
.
get
(
"
repository
"
)
_assert_param_type_is
(
"
repository
"
,
repository
,
str
)
return
GiteaFetcher
(
feed_id
,
name
,
gitea_host
,
repository
)
if
fetcher_type
==
_TYPE_GITHUB
:
repository
=
kwargs
.
get
(
"
repository
"
)
_assert_param_type_is
(
"
repository
"
,
repository
,
str
)
return
GithubFetcher
(
feed_id
,
name
,
repository
)
if
fetcher_type
==
_TYPE_GITLAB
:
gitlab_host
=
kwargs
.
get
(
"
host
"
)
_assert_param_type_is
(
"
host
"
,
gitlab_host
,
str
)
repository
=
kwargs
.
get
(
"
repository
"
)
_assert_param_type_is
(
"
repository
"
,
repository
,
str
)
return
GitLabFetcher
(
feed_id
,
name
,
gitlab_host
,
repository
)
raise
FactoryError
(
f
"
Invalid fetcher type
'
{
fetcher_type
}
'"
)
def
create_fetchers_from_dict
(
feeds_params
:
List
[
Any
])
->
List
[
ProjectFetcher
]:
assert
isinstance
(
feeds_params
,
list
)
fetchers
:
List
[
ProjectFetcher
]
=
[]
for
idx
,
params
in
enumerate
(
feeds_params
):
try
:
fetchers
.
append
(
create_fetcher
(
**
params
))
except
FactoryError
as
err
:
raise
RuntimeError
(
"
Could not load fetcher at index %s: %s
"
,
idx
,
str
(
err
)
)
from
err
return
fetchers
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