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
Show file tree
Hide file tree
Changes from all commits
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
34 changes: 28 additions & 6 deletions src/fetchcode/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.

from attr import attrs, attrib

from packageurl.contrib.route import NoRouteAvailable
import requests
from packageurl import PackageURL
from packageurl.contrib.route import NoRouteAvailable
from packageurl.contrib.route import Router
import requests

from fetchcode.packagedcode_models import Package

Expand Down Expand Up @@ -169,7 +167,7 @@ def get_npm_data_from_purl(purl):
@router.route("pkg:pypi/.*")
def get_pypi_data_from_purl(purl):
"""
Generate `Package` object from the `purl` string of npm type
Generate `Package` object from the `purl` string of pypi type
35C4n0r marked this conversation as resolved.
Show resolved Hide resolved
"""
purl = PackageURL.from_string(purl)
name = purl.name
Expand Down Expand Up @@ -314,16 +312,40 @@ def get_rubygems_data_from_purl(purl):
api_url = f"https://rubygems.org/api/v1/gems/{name}.json"
response = get_response(api_url)
declared_license = response.get("licenses") or None
version = response.get("version")
new_purl = PackageURL(
type=purl.type, name=name, version=version
)
homepage_url = response.get("homepage_uri")
code_view_url = response.get("source_code_uri")
bug_tracking_url = response.get("bug_tracker_uri")
download_url = response.get("gem_uri")
release_date = response.get("version_created_at")
yield Package(
homepage_url=homepage_url,
api_url=api_url,
bug_tracking_url=bug_tracking_url,
code_view_url=code_view_url,
declared_license=declared_license,
download_url=download_url,
**purl.to_dict(),
release_date=release_date,
**new_purl.to_dict()
)

releases_url = f"https://rubygems.org/api/v1/versions/{name}.json"
releases = get_response(releases_url)
for release in releases:
version = release.get("number")
release_date = release.get("created_at")
version_purl = PackageURL(
type=purl.type, name=name, version=version
)
yield Package(
homepage_url=homepage_url,
api_url=api_url,
bug_tracking_url=bug_tracking_url,
code_view_url=code_view_url,
declared_license=declared_license,
release_date=release_date,
**version_purl.to_dict()
)
2 changes: 1 addition & 1 deletion tests/data/rubygems.json

Large diffs are not rendered by default.

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"
}
]
}
}
Loading