Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed version issue in getting package info from rubygems. #84

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Just a dummy commit wiyh changes in tests
Signed-off-by: Jay <[email protected]>
35C4n0r committed Dec 23, 2022

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
commit 621e4445c91f63e6f855d4b5d6621b82e1855050
4 changes: 3 additions & 1 deletion src/fetchcode/package.py
Original file line number Diff line number Diff line change
@@ -311,8 +311,10 @@ def get_rubygems_data_from_purl(purl):
name = purl.name
api_url = f"https://rubygems.org/api/v1/gems/{name}.json"
releases_url = f"https://rubygems.org/api/v1/versions/{name}.json"
releases = get_response(releases_url)
response = get_response(api_url)
releases = get_response(releases_url)
print(response)
# print(releases)
declared_license = response.get("licenses") or None
version = response.get("version")
version_purl = PackageURL(
35C4n0r marked this conversation as resolved.
Show resolved Hide resolved
41 changes: 40 additions & 1 deletion tests/data/rubygems.json
Original file line number Diff line number Diff line change
@@ -1 +1,40 @@
{"0": {"type": "rubygems", "namespace": null, "name": "rubocop", "version": null, "qualifiers": {}, "subpath": null, "primary_language": null, "description": null, "release_date": null, "parties": [], "keywords": [], "homepage_url": "https://rubocop.org/", "download_url": "https://rubygems.org/gems/rubocop-0.89.1.gem", "api_url": "https://rubygems.org/api/v1/gems/rubocop.json", "size": null, "sha1": null, "md5": null, "sha256": null, "sha512": null, "bug_tracking_url": "https://github.com/rubocop-hq/rubocop/issues", "code_view_url": "https://github.com/rubocop-hq/rubocop/", "vcs_url": null, "copyright": null, "license_expression": null, "declared_license": ["MIT"], "notice_text": null, "root_path": null, "dependencies": [], "contains_source_code": null, "source_packages": [], "purl": "pkg:rubygems/rubocop", "repository_homepage_url": null, "repository_download_url": null, "api_data_url": null}}
{
"0": {
"type": "rubygems",
"namespace": null,
"name": "rubocop",
"version": null,
"qualifiers": {},
"subpath": null,
"primary_language": null,
"description": null,
"release_date": null,
"parties": [],
"keywords": [],
"homepage_url": "https://rubocop.org/",
"download_url": "https://rubygems.org/gems/rubocop-0.89.1.gem",
"api_url": "https://rubygems.org/api/v1/gems/rubocop.json",
"size": null,
"sha1": null,
"md5": null,
"sha256": null,
"sha512": null,
"bug_tracking_url": "https://github.com/rubocop-hq/rubocop/issues",
"code_view_url": "https://github.com/rubocop-hq/rubocop/",
"vcs_url": null,
"copyright": null,
"license_expression": null,
"declared_license": [
"MIT"
],
"notice_text": null,
"root_path": null,
"dependencies": [],
"contains_source_code": null,
"source_packages": [],
"purl": "pkg:rubygems/rubocop",
"repository_homepage_url": null,
"repository_download_url": null,
"api_data_url": null
}
}
80 changes: 79 additions & 1 deletion tests/data/rubygems_mock_data.json
Original file line number Diff line number Diff line change
@@ -1 +1,79 @@
{"name":"rubocop","downloads":111809413,"version":"0.89.1","version_downloads":259770,"platform":"ruby","authors":"Bozhidar Batsov, Jonas Arvidsson, Yuji Nakayama","info":" RuboCop is a Ruby code style checking and code formatting tool.\n It aims to enforce the community-driven Ruby Style Guide.\n","licenses":["MIT"],"metadata":{"homepage_uri":"https://rubocop.org/","changelog_uri":"https://github.com/rubocop-hq/rubocop/blob/master/CHANGELOG.md","bug_tracker_uri":"https://github.com/rubocop-hq/rubocop/issues","source_code_uri":"https://github.com/rubocop-hq/rubocop/","documentation_uri":"https://docs.rubocop.org/"},"yanked":false,"sha":"30794116b2804aab1abc74780a201fae5160c1d6a21550ce9786abd3ca0e07fa","project_uri":"https://rubygems.org/gems/rubocop","gem_uri":"https://rubygems.org/gems/rubocop-0.89.1.gem","homepage_uri":"https://rubocop.org/","wiki_uri":null,"documentation_uri":"https://docs.rubocop.org/","mailing_list_uri":null,"source_code_uri":"https://github.com/rubocop-hq/rubocop/","bug_tracker_uri":"https://github.com/rubocop-hq/rubocop/issues","changelog_uri":"https://github.com/rubocop-hq/rubocop/blob/master/CHANGELOG.md","dependencies":{"development":[{"name":"bundler","requirements":"\u003e= 1.15.0, \u003c 3.0"}],"runtime":[{"name":"parallel","requirements":"~\u003e 1.10"},{"name":"parser","requirements":"\u003e= 2.7.1.1"},{"name":"rainbow","requirements":"\u003e= 2.2.2, \u003c 4.0"},{"name":"regexp_parser","requirements":"\u003e= 1.7"},{"name":"rexml","requirements":"\u003e= 0"},{"name":"rubocop-ast","requirements":"\u003e= 0.3.0, \u003c 1.0"},{"name":"ruby-progressbar","requirements":"~\u003e 1.7"},{"name":"unicode-display_width","requirements":"\u003e= 1.4.0, \u003c 2.0"}]}}
{
"name": "rubocop",
"downloads": 281548679,
"version": "1.40.0",
"version_created_at": "2022-12-08T07:50:52.498Z",
"version_downloads": 198668,
"platform": "ruby",
"authors": "Bozhidar Batsov, Jonas Arvidsson, Yuji Nakayama",
"info": " RuboCop is a Ruby code style checking and code formatting tool. It aims to enforce the community-driven Ruby Style Guide. ",
"licenses": [
"MIT"
],
"metadata": {
"homepage_uri": "https://rubocop.org/",
"changelog_uri": "https://github.com/rubocop/rubocop/blob/master/CHANGELOG.md",
"bug_tracker_uri": "https://github.com/rubocop/rubocop/issues",
"source_code_uri": "https://github.com/rubocop/rubocop/",
"documentation_uri": "https://docs.rubocop.org/rubocop/1.40/",
"rubygems_mfa_required": "true"
},
"yanked": false,
"sha": "031881f824594fdb08713d5187c7bf07a11ff83fda869a7dd2d7765f92846a35",
"project_uri": "https://rubygems.org/gems/rubocop",
"gem_uri": "https://rubygems.org/gems/rubocop-1.40.0.gem",
"homepage_uri": "https://rubocop.org/",
"wiki_uri": null,
"documentation_uri": "https://docs.rubocop.org/rubocop/1.40/",
"mailing_list_uri": null,
"source_code_uri": "https://github.com/rubocop/rubocop/",
"bug_tracker_uri": "https://github.com/rubocop/rubocop/issues",
"changelog_uri": "https://github.com/rubocop/rubocop/blob/master/CHANGELOG.md",
"funding_uri": null,
"dependencies": {
"development": [
{
"name": "bundler",
"requirements": ">= 1.15.0, < 3.0"
}
],
"runtime": [
{
"name": "json",
"requirements": "~> 2.3"
},
{
"name": "parallel",
"requirements": "~> 1.10"
},
{
"name": "parser",
"requirements": ">= 3.1.2.1"
},
{
"name": "rainbow",
"requirements": ">= 2.2.2, < 4.0"
},
{
"name": "regexp_parser",
"requirements": ">= 1.8, < 3.0"
},
{
"name": "rexml",
"requirements": ">= 3.2.5, < 4.0"
},
{
"name": "rubocop-ast",
"requirements": ">= 1.23.0, < 2.0"
},
{
"name": "ruby-progressbar",
"requirements": "~> 1.7"
},
{
"name": "unicode-display_width",
"requirements": ">= 1.4.0, < 3.0"
}
]
}
}
14 changes: 10 additions & 4 deletions tests/test_package.py
Original file line number Diff line number Diff line change
@@ -56,9 +56,9 @@ def test_npm_packages(mock_get):

@mock.patch("fetchcode.package.get_response")
def test_pypi_packages(mock_get):
side_effect = [file_data("tests/data/pypi_mock_data.json")]
side_effect = [file_data("./data/pypi_mock_data.json")]
purl = "pkg:pypi/flask"
expected_data = file_data("tests/data/pypi.json")
expected_data = file_data("./data/pypi.json")
mock_get.side_effect = side_effect
packages = list(info(purl))
match_data(packages, expected_data)
@@ -90,13 +90,19 @@ def test_bitbucket_packages(mock_get):
match_data(packages, expected_data)


# @mock.patch("fetchcode.package.get_response")
@mock.patch("fetchcode.package.get_response")
def test_rubygems_packages(mock_get):
side_effect = [file_data("tests/data/rubygems_mock_data.json")]
# print(mock_get)
side_effect = [file_data("./data/rubygems_mock_data.json"), file_data("./data/rubygems_mock_data2.json")]
# side_effect2 = [file_data("./data/rubygems_mock_data2.json")]
purl = "pkg:rubygems/rubocop"
expected_data = file_data("tests/data/rubygems.json")
expected_data = file_data("./data/rubygems.json")
mock_get.side_effect = side_effect
# mock_get2.side_effect = side_effect
packages = list(info(purl))
# print(packages)
# print(packages, expected_data)
match_data(packages, expected_data)