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
d715aaf9
Commit
d715aaf9
authored
2 years ago
by
vlorentz
Browse files
Options
Downloads
Patches
Plain Diff
Make user_agent a parameter of GitHubSession
So it can be set when used by other packages
parent
2d04244c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
Loading
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
swh/lister/github/lister.py
+4
-1
4 additions, 1 deletion
swh/lister/github/lister.py
swh/lister/github/utils.py
+4
-4
4 additions, 4 deletions
swh/lister/github/utils.py
with
8 additions
and
5 deletions
swh/lister/github/lister.py
+
4
−
1
View file @
d715aaf9
...
...
@@ -14,6 +14,7 @@ import iso8601
from
swh.scheduler.interface
import
SchedulerInterface
from
swh.scheduler.model
import
ListedOrigin
from
..
import
USER_AGENT
from
..pattern
import
CredentialsType
,
Lister
from
.utils
import
GitHubSession
,
MissingRateLimitReset
...
...
@@ -85,7 +86,9 @@ class GitHubLister(Lister[GitHubListerState, List[Dict[str, Any]]]):
self
.
relisting
=
self
.
first_id
is
not
None
or
self
.
last_id
is
not
None
self
.
github_session
=
GitHubSession
(
credentials
=
self
.
credentials
)
self
.
github_session
=
GitHubSession
(
credentials
=
self
.
credentials
,
user_agent
=
USER_AGENT
)
def
state_from_dict
(
self
,
d
:
Dict
[
str
,
Any
])
->
GitHubListerState
:
return
GitHubListerState
(
**
d
)
...
...
This diff is collapsed.
Click to expand it.
swh/lister/github/utils.py
+
4
−
4
View file @
d715aaf9
...
...
@@ -17,8 +17,6 @@ from tenacity import (
wait_exponential
,
)
from
..
import
USER_AGENT
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -52,7 +50,9 @@ class GitHubSession:
"""
Manages a :class:`requests.Session` with (optionally) multiple credentials,
and cycles through them when reaching rate-limits.
"""
def
__init__
(
self
,
credentials
:
Optional
[
List
[
Dict
[
str
,
str
]]]
=
None
)
->
None
:
def
__init__
(
self
,
user_agent
:
str
,
credentials
:
Optional
[
List
[
Dict
[
str
,
str
]]]
=
None
)
->
None
:
"""
Initialize a requests session with the proper headers for requests to
GitHub.
"""
self
.
credentials
=
credentials
...
...
@@ -62,7 +62,7 @@ class GitHubSession:
self
.
session
=
requests
.
Session
()
self
.
session
.
headers
.
update
(
{
"
Accept
"
:
"
application/vnd.github.v3+json
"
,
"
User-Agent
"
:
USER_AGENT
}
{
"
Accept
"
:
"
application/vnd.github.v3+json
"
,
"
User-Agent
"
:
user_agent
}
)
self
.
anonymous
=
not
self
.
credentials
...
...
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