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
88a96ced
Commit
88a96ced
authored
1 year ago
by
Roberto Di Cosmo
Browse files
Options
Downloads
Patches
Plain Diff
Update script to get dir swhid using GraphQL: look for main branch
parent
3a850c75
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
rdicosmo/getdirswhid.py
+15
-6
15 additions, 6 deletions
rdicosmo/getdirswhid.py
with
15 additions
and
6 deletions
rdicosmo/getdirswhid.py
+
15
−
6
View file @
88a96ced
...
...
@@ -11,7 +11,7 @@ import click
import
requests
import
json
def
get_dir_latest
(
origin_url
):
def
get_dir_latest
(
origin_url
,
bearer_token
):
# GraphQL API endpoint
url
=
"
https://archive.softwareheritage.org/graphql/
"
...
...
@@ -25,7 +25,7 @@ def get_dir_latest(origin_url):
latestStatus(requireSnapshot: true, allowedStatuses: [full]) {{
snapshot {{
swhid
branches(first: 1, types: [revision]) {{
branches(first: 1
0, nameInclude:
"
main
"
, types: [revision]) {{
pageInfo {{
endCursor
hasNextPage
...
...
@@ -56,6 +56,8 @@ def get_dir_latest(origin_url):
# Headers
headers
=
{
"
Content-Type
"
:
"
application/json
"
}
if
(
bearer_token
):
headers
[
"
Authorization
"
]
=
"
Bearer
"
+
bearer_token
# Request payload
payload
=
{
"
query
"
:
query
}
...
...
@@ -65,7 +67,7 @@ def get_dir_latest(origin_url):
# Parse the JSON response
data
=
response
.
json
()
# Extract the SWHIDs of the commits
directory
=
data
[
"
data
"
][
"
origin
"
][
"
latestVisit
"
][
"
latestStatus
"
][
"
snapshot
"
][
"
branches
"
][
"
nodes
"
][
0
][
"
target
"
][
"
node
"
][
"
directory
"
]
swhid
=
directory
[
"
swhid
"
]
...
...
@@ -76,9 +78,16 @@ def get_dir_latest(origin_url):
@click.command
()
@click.option
(
'
--url
'
,
prompt
=
'
Software origin URL
'
,
help
=
'
The URL of the software origin.
'
)
def
main
(
url
):
print
(
get_dir_latest
(
url
))
@click.option
(
"
-a
"
,
"
--swh-bearer-token
"
,
default
=
""
,
metavar
=
"
SWHTOKEN
"
,
show_default
=
True
,
help
=
"
bearer token to bypass SWH API rate limit
"
,
)
def
main
(
url
,
swh_bearer_token
):
print
(
get_dir_latest
(
url
,
swh_bearer_token
))
if
__name__
==
'
__main__
'
:
main
()
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