Skip to content

Commit

Permalink
Add test for GitHub GQL API
Browse files Browse the repository at this point in the history
Signed-off-by: Keshav Priyadarshi <[email protected]>
  • Loading branch information
keshav-space committed Dec 11, 2023
1 parent 54a0607 commit 128d8bc
Show file tree
Hide file tree
Showing 14 changed files with 5,387 additions and 178 deletions.
59 changes: 30 additions & 29 deletions src/fetchcode/package_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,36 @@ def fetch_github_tags_gql(purl):
yield PackageVersion(value=name, release_date=release_date)


GQL_QUERY = """
query getTags($name: String!, $owner: String!, $after: String)
{
repository(name: $name, owner: $owner) {
refs(refPrefix: "refs/tags/", first: 100, after: $after) {
totalCount
pageInfo {
endCursor
hasNextPage
}
nodes {
name
target {
... on Commit {
committedDate
}
... on Tag {
target {
... on Commit {
committedDate
}
}
}
}
}
}
}
}"""


def fetch_github_tag_nodes(purl):
"""
Yield node name/target mappings for Git tags of the ``purl``.
Expand All @@ -551,35 +581,6 @@ def fetch_github_tag_nodes(purl):
}
},
"""
GQL_QUERY = """
query getTags($name: String!, $owner: String!, $after: String)
{
repository(name: $name, owner: $owner) {
refs(refPrefix: "refs/tags/", first: 100, after: $after) {
totalCount
pageInfo {
endCursor
hasNextPage
}
nodes {
name
target {
... on Commit {
committedDate
}
... on Tag {
target {
... on Commit {
committedDate
}
}
}
}
}
}
}
}"""

variables = {
"owner": purl.namespace,
"name": purl.name,
Expand Down
10 changes: 5 additions & 5 deletions tests/data/package_versions/cargo_mock_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"created_at": "2023-09-11T15:54:25.449371+00:00",
"description": "A modifying, multiplexer tcp proxy server tool and library.",
"documentation": null,
"downloads": 118,
"downloads": 121,
"exact_match": false,
"homepage": null,
"id": "yprox",
Expand All @@ -23,7 +23,7 @@
"max_version": "0.2.0",
"name": "yprox",
"newest_version": "0.2.0",
"recent_downloads": 118,
"recent_downloads": 108,
"repository": "https://github.com/fcoury/yprox",
"updated_at": "2023-11-13T15:21:46.464930+00:00",
"versions": [
Expand Down Expand Up @@ -53,7 +53,7 @@
"crate_size": 37493,
"created_at": "2023-11-13T15:21:46.464930+00:00",
"dl_path": "/api/v1/crates/yprox/0.2.0/download",
"downloads": 36,
"downloads": 37,
"features": {},
"id": 953512,
"license": "MIT",
Expand Down Expand Up @@ -94,7 +94,7 @@
"crate_size": 40059,
"created_at": "2023-11-12T17:01:58.462018+00:00",
"dl_path": "/api/v1/crates/yprox/0.1.1/download",
"downloads": 32,
"downloads": 33,
"features": {},
"id": 952742,
"license": "MIT",
Expand Down Expand Up @@ -135,7 +135,7 @@
"crate_size": 39483,
"created_at": "2023-09-11T15:54:25.449371+00:00",
"dl_path": "/api/v1/crates/yprox/0.1.0/download",
"downloads": 50,
"downloads": 51,
"features": {},
"id": 894733,
"license": "MIT",
Expand Down
8 changes: 4 additions & 4 deletions tests/data/package_versions/composer_mock_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
"source": {
"url": "https://github.com/laravel/laravel.git",
"type": "git",
"reference": "e57d15ac8f71ac65eb974b7a535804b6552bf4f1"
"reference": "3142d3feb916d93683c020189c00f4e89d6ab385"
},
"dist": {
"url": "https://api.github.com/repos/laravel/laravel/zipball/e57d15ac8f71ac65eb974b7a535804b6552bf4f1",
"url": "https://api.github.com/repos/laravel/laravel/zipball/3142d3feb916d93683c020189c00f4e89d6ab385",
"type": "zip",
"shasum": "",
"reference": "e57d15ac8f71ac65eb974b7a535804b6552bf4f1"
"reference": "3142d3feb916d93683c020189c00f4e89d6ab385"
},
"type": "project",
"time": "2023-12-05T19:45:52+00:00",
"time": "2023-12-11T08:17:19+00:00",
"autoload": {
"psr-4": {
"App\\": "app/",
Expand Down
8 changes: 4 additions & 4 deletions tests/data/package_versions/gem_mock_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"built_at": "2014-09-12T00:00:00.000Z",
"created_at": "2014-09-12T15:01:59.662Z",
"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 ",
"downloads_count": 3344,
"downloads_count": 3345,
"metadata": {},
"number": "0.0.4",
"summary": "Automatically check the ruby-advisory-db Database for advisories in your installed Gems.",
Expand All @@ -24,7 +24,7 @@
"built_at": "2014-09-11T00:00:00.000Z",
"created_at": "2014-09-11T10:22:40.909Z",
"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 ",
"downloads_count": 2181,
"downloads_count": 2182,
"metadata": {},
"number": "0.0.3",
"summary": "Automatically check the ruby-advisory-db Database for advisories in your installed Gems.",
Expand All @@ -44,7 +44,7 @@
"built_at": "2014-09-11T00:00:00.000Z",
"created_at": "2014-09-11T10:16:26.784Z",
"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 ",
"downloads_count": 2170,
"downloads_count": 2171,
"metadata": {},
"number": "0.0.2",
"summary": "Automatically check the ruby-advisory-db Database for advisories in your installed Gems.",
Expand All @@ -64,7 +64,7 @@
"built_at": "2014-09-11T00:00:00.000Z",
"created_at": "2014-09-11T10:11:38.199Z",
"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 ",
"downloads_count": 2175,
"downloads_count": 2176,
"metadata": {},
"number": "0.0.1",
"summary": "Automatically check the ruby-advisory-db Database for advisories in your installed Gems.",
Expand Down
Loading

0 comments on commit 128d8bc

Please sign in to comment.