Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
snippets
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
Model registry
Operate
Environments
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
Platform
Development
snippets
Commits
5c1190cd
Commit
5c1190cd
authored
3 months ago
by
Antoine Lambert
Browse files
Options
Downloads
Patches
Plain Diff
Add a Python script to extract celery task parameters from Sentry issue
parent
b7de52f0
No related branches found
Branches containing commit
Tags
swh-deposit-20231106.1
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
anlambert/generate_csv_scheduler_tasks_from_sentry_issue.py
+83
-0
83 additions, 0 deletions
anlambert/generate_csv_scheduler_tasks_from_sentry_issue.py
with
83 additions
and
0 deletions
anlambert/generate_csv_scheduler_tasks_from_sentry_issue.py
0 → 100755
+
83
−
0
View file @
5c1190cd
#!/usr/bin/env python3
# Copyright (C) 2025 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
import
csv
import
json
import
sys
import
click
import
requests
@click.command
()
@click.option
(
"
--sentry-url
"
,
"
-u
"
,
default
=
"
https://sentry.softwareheritage.org
"
,
show_default
=
True
,
help
=
"
Sentry URL
"
,
required
=
True
,
)
@click.option
(
"
--sentry-token
"
,
"
-t
"
,
default
=
None
,
envvar
=
"
SENTRY_TOKEN
"
,
help
=
(
"
Bearer token required to communicate with Sentry API (can also be provided
"
"
in SENTRY_TOKEN environment variable)
"
),
required
=
True
,
)
@click.option
(
"
--sentry-issue-number
"
,
"
-i
"
,
help
=
"
Sentry issue number to extract celery task parameters
"
,
required
=
True
,
)
@click.option
(
"
--environment
"
,
"
-e
"
,
default
=
""
,
help
=
"
Filter on environment: production or staging, both are selected by default
"
,
required
=
True
,
)
@click.argument
(
"
task_type
"
,
nargs
=
1
,
required
=
True
)
def
run
(
sentry_url
,
sentry_token
,
sentry_issue_number
,
environment
,
task_type
):
"""
Extract celery task parameters from a Sentry issue related to a Software Heritage
loader and dumps a CSV file to stdout that can be consumed by the CLI command :
swh scheduler task schedule --columns type --columns kwargs <csv_file>.
"""
sentry_api_base_url
=
f
"
{
sentry_url
.
rstrip
(
'
/
'
)
}
/api/0
"
sentry_issue_events_url
=
(
f
"
{
sentry_api_base_url
}
/issues/
{
sentry_issue_number
}
/events/?full=true
"
)
auth_header
=
{
"
Authorization
"
:
f
"
Bearer
{
sentry_token
}
"
}
task_params
=
{}
csv_writer
=
csv
.
writer
(
sys
.
stdout
)
while
True
:
response
=
requests
.
get
(
sentry_issue_events_url
,
headers
=
auth_header
)
events
=
response
.
json
()
if
not
events
:
break
for
event
in
events
:
task_param
=
event
.
get
(
"
context
"
,
{}).
get
(
"
celery-job
"
,
{}).
get
(
"
kwargs
"
)
if
task_param
:
task_params
[
tuple
(
task_param
.
values
())]
=
task_param
sentry_issue_events_url
=
response
.
links
.
get
(
"
next
"
,
{}).
get
(
"
url
"
)
for
task_param
in
task_params
.
values
():
csv_writer
.
writerow
([
task_type
,
json
.
dumps
(
task_param
)])
if
__name__
==
"
__main__
"
:
run
()
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