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
b0883eed
Commit
b0883eed
authored
1 year ago
by
Roberto Di Cosmo
Browse files
Options
Downloads
Patches
Plain Diff
Add support for generating fqid
parent
fb07e568
No related branches found
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 @
b0883eed
...
...
@@ -13,11 +13,10 @@ import json
from
gql
import
gql
,
Client
from
gql.transport.aiohttp
import
AIOHTTPTransport
# GraphQL API endpoint
API_URL
=
"
https://archive.softwareheritage.org/graphql/
"
def
get_dir_latest
(
url
,
bearer_token
):
# GraphQL API endpoint
# GraphQL query with parameters for origin URL and number of commits
query
=
gql
(
"""
query getOriginEntries($url: String!) {
...
...
@@ -36,6 +35,7 @@ def get_dir_latest(url, bearer_token):
}
node {
...on Revision {
swhid
directory {
swhid
}
...
...
@@ -68,8 +68,12 @@ def get_dir_latest(url, bearer_token):
return
None
else
:
directory
=
response
[
"
origin
"
][
"
latestSnapshot
"
][
"
branches
"
][
"
nodes
"
][
0
][
"
target
"
][
"
node
"
][
"
directory
"
]
swhid
=
directory
[
"
swhid
"
]
return
swhid
dir_swhid
=
directory
[
"
swhid
"
]
snapshot
=
response
[
"
origin
"
][
"
latestSnapshot
"
]
snp_swhid
=
snapshot
[
"
swhid
"
]
revision
=
response
[
"
origin
"
][
"
latestSnapshot
"
][
"
branches
"
][
"
nodes
"
][
0
][
"
target
"
][
"
node
"
]
rev_swhid
=
revision
[
"
swhid
"
]
return
(
dir_swhid
,
rev_swhid
,
snp_swhid
)
# now return
...
...
@@ -83,8 +87,13 @@ def get_dir_latest(url, bearer_token):
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
))
@click.option
(
'
--nofqid
'
,
is_flag
=
True
,
help
=
'
Print core directory SWHID instead of fully qualified directory SWHID.
'
)
def
main
(
url
,
swh_bearer_token
,
nofqid
):
d
,
r
,
s
=
get_dir_latest
(
url
,
swh_bearer_token
)
if
nofqid
:
print
(
d
)
else
:
print
(
f
"
{
d
}
;origin=
{
url
}
;visit=
{
s
}
;anchor=
{
r
}
"
)
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