Skip to content

Commit a314803

Browse files
committed
Add test for GitHub GQL API
Signed-off-by: Keshav Priyadarshi <[email protected]>
1 parent 54a0607 commit a314803

14 files changed

+5386
-178
lines changed

src/fetchcode/package_versions.py

+30-29
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,36 @@ def fetch_github_tags_gql(purl):
537537
yield PackageVersion(value=name, release_date=release_date)
538538

539539

540+
GQL_QUERY = """
541+
query getTags($name: String!, $owner: String!, $after: String)
542+
{
543+
repository(name: $name, owner: $owner) {
544+
refs(refPrefix: "refs/tags/", first: 100, after: $after) {
545+
totalCount
546+
pageInfo {
547+
endCursor
548+
hasNextPage
549+
}
550+
nodes {
551+
name
552+
target {
553+
... on Commit {
554+
committedDate
555+
}
556+
... on Tag {
557+
target {
558+
... on Commit {
559+
committedDate
560+
}
561+
}
562+
}
563+
}
564+
}
565+
}
566+
}
567+
}"""
568+
569+
540570
def fetch_github_tag_nodes(purl):
541571
"""
542572
Yield node name/target mappings for Git tags of the ``purl``.
@@ -551,35 +581,6 @@ def fetch_github_tag_nodes(purl):
551581
}
552582
},
553583
"""
554-
GQL_QUERY = """
555-
query getTags($name: String!, $owner: String!, $after: String)
556-
{
557-
repository(name: $name, owner: $owner) {
558-
refs(refPrefix: "refs/tags/", first: 100, after: $after) {
559-
totalCount
560-
pageInfo {
561-
endCursor
562-
hasNextPage
563-
}
564-
nodes {
565-
name
566-
target {
567-
... on Commit {
568-
committedDate
569-
}
570-
... on Tag {
571-
target {
572-
... on Commit {
573-
committedDate
574-
}
575-
}
576-
}
577-
}
578-
}
579-
}
580-
}
581-
}"""
582-
583584
variables = {
584585
"owner": purl.namespace,
585586
"name": purl.name,

tests/data/package_versions/cargo_mock_data.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"created_at": "2023-09-11T15:54:25.449371+00:00",
77
"description": "A modifying, multiplexer tcp proxy server tool and library.",
88
"documentation": null,
9-
"downloads": 118,
9+
"downloads": 121,
1010
"exact_match": false,
1111
"homepage": null,
1212
"id": "yprox",
@@ -23,7 +23,7 @@
2323
"max_version": "0.2.0",
2424
"name": "yprox",
2525
"newest_version": "0.2.0",
26-
"recent_downloads": 118,
26+
"recent_downloads": 108,
2727
"repository": "https://github.com/fcoury/yprox",
2828
"updated_at": "2023-11-13T15:21:46.464930+00:00",
2929
"versions": [
@@ -53,7 +53,7 @@
5353
"crate_size": 37493,
5454
"created_at": "2023-11-13T15:21:46.464930+00:00",
5555
"dl_path": "/api/v1/crates/yprox/0.2.0/download",
56-
"downloads": 36,
56+
"downloads": 37,
5757
"features": {},
5858
"id": 953512,
5959
"license": "MIT",
@@ -94,7 +94,7 @@
9494
"crate_size": 40059,
9595
"created_at": "2023-11-12T17:01:58.462018+00:00",
9696
"dl_path": "/api/v1/crates/yprox/0.1.1/download",
97-
"downloads": 32,
97+
"downloads": 33,
9898
"features": {},
9999
"id": 952742,
100100
"license": "MIT",
@@ -135,7 +135,7 @@
135135
"crate_size": 39483,
136136
"created_at": "2023-09-11T15:54:25.449371+00:00",
137137
"dl_path": "/api/v1/crates/yprox/0.1.0/download",
138-
"downloads": 50,
138+
"downloads": 51,
139139
"features": {},
140140
"id": 894733,
141141
"license": "MIT",

tests/data/package_versions/composer_mock_data.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@
1818
"source": {
1919
"url": "https://github.com/laravel/laravel.git",
2020
"type": "git",
21-
"reference": "e57d15ac8f71ac65eb974b7a535804b6552bf4f1"
21+
"reference": "3142d3feb916d93683c020189c00f4e89d6ab385"
2222
},
2323
"dist": {
24-
"url": "https://api.github.com/repos/laravel/laravel/zipball/e57d15ac8f71ac65eb974b7a535804b6552bf4f1",
24+
"url": "https://api.github.com/repos/laravel/laravel/zipball/3142d3feb916d93683c020189c00f4e89d6ab385",
2525
"type": "zip",
2626
"shasum": "",
27-
"reference": "e57d15ac8f71ac65eb974b7a535804b6552bf4f1"
27+
"reference": "3142d3feb916d93683c020189c00f4e89d6ab385"
2828
},
2929
"type": "project",
30-
"time": "2023-12-05T19:45:52+00:00",
30+
"time": "2023-12-11T08:17:19+00:00",
3131
"autoload": {
3232
"psr-4": {
3333
"App\\": "app/",

tests/data/package_versions/gem_mock_data.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"built_at": "2014-09-12T00:00:00.000Z",
55
"created_at": "2014-09-12T15:01:59.662Z",
66
"description": "\n This Gem automatically downloads and extracts the ruby-advisory-db Database from Github.\n Than it uses bundler and rubygems to check for advisories in your installed Gems by\n executing a rake task.\n ",
7-
"downloads_count": 3344,
7+
"downloads_count": 3345,
88
"metadata": {},
99
"number": "0.0.4",
1010
"summary": "Automatically check the ruby-advisory-db Database for advisories in your installed Gems.",
@@ -24,7 +24,7 @@
2424
"built_at": "2014-09-11T00:00:00.000Z",
2525
"created_at": "2014-09-11T10:22:40.909Z",
2626
"description": "\n This Gem automatically downloads and extracts the ruby-advisory-db Database from Github.\n Than it uses bundler and rubygems to check for advisories in your installed Gems by\n executing a rake task.\n ",
27-
"downloads_count": 2181,
27+
"downloads_count": 2182,
2828
"metadata": {},
2929
"number": "0.0.3",
3030
"summary": "Automatically check the ruby-advisory-db Database for advisories in your installed Gems.",
@@ -44,7 +44,7 @@
4444
"built_at": "2014-09-11T00:00:00.000Z",
4545
"created_at": "2014-09-11T10:16:26.784Z",
4646
"description": "\n This Gem automatically downloads and extracts the ruby-advisory-db Database from Github.\n Than it uses bundler and rubygems to check for advisories in your installed Gems by\n executing a rake task.\n ",
47-
"downloads_count": 2170,
47+
"downloads_count": 2171,
4848
"metadata": {},
4949
"number": "0.0.2",
5050
"summary": "Automatically check the ruby-advisory-db Database for advisories in your installed Gems.",
@@ -64,7 +64,7 @@
6464
"built_at": "2014-09-11T00:00:00.000Z",
6565
"created_at": "2014-09-11T10:11:38.199Z",
6666
"description": "\n This Gem automatically downloads and extracts the ruby-advisory-db Database from Github.\n Than it uses bundler and rubygems to check for advisories in your installed Gems by\n executing a rake task.\n ",
67-
"downloads_count": 2175,
67+
"downloads_count": 2176,
6868
"metadata": {},
6969
"number": "0.0.1",
7070
"summary": "Automatically check the ruby-advisory-db Database for advisories in your installed Gems.",

0 commit comments

Comments
 (0)