Skip to content

Commit 10b90c6

Browse files
authored
Add next_version to ecosystem helpers. (#270)
This is useful for converting ranges from other formats.
1 parent a2bc342 commit 10b90c6

File tree

9 files changed

+560
-2
lines changed

9 files changed

+560
-2
lines changed

cloudbuild.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ steps:
2222
- name: 'gcr.io/oss-vdb/ci'
2323
dir: docker/importer
2424
args: ['bash', '-x', 'run_tests.sh']
25+
- name: 'gcr.io/oss-vdb/ci'
26+
dir: lib
27+
args: ['bash', '-x', 'run_tests.sh']
2528
- name: 'gcr.io/cloud-builders/gcloud'
2629
entrypoint: 'bash'
2730
args: [ '-c', "gcloud secrets versions access latest --secret=integration-test-account --format='get(payload.data)' | tr '_-' '/+' | base64 -d > /workspace/service_account.json" ]

docker/ci/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ RUN apt-get update && \
1919
google-cloud-sdk-datastore-emulator
2020

2121
COPY daemon.json /etc/docker/daemon.json
22+
ENTRYPOINT []

lib/Pipfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[[source]]
2+
url = "https://pypi.python.org/simple"
3+
verify_ssl = true
4+
name = "pypi"
5+
6+
[packages]
7+
google-cloud-ndb = "*"
8+
semver = "*"
9+
pyyaml = "*"
10+
pygit2 = "*"
11+
12+
[dev-packages]

lib/Pipfile.lock

Lines changed: 471 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/osv/bug_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import unittest
1717

18-
import bug
18+
from . import bug
1919

2020

2121
class NormalizeTest(unittest.TestCase):

lib/osv/ecosystems.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@ def _before_limits(self, version, limits):
3434
return any(
3535
self.sort_key(version) < self.sort_key(limit) for limit in limits)
3636

37+
def next_version(self, package, version):
38+
"""Get the next version after the given version."""
39+
versions = self.enumerate_versions(package, version, fixed=None)
40+
if versions and versions[0] != version:
41+
# Version does not exist, so use the first one that would sort
42+
# after it (which is what enumerate_versions returns).
43+
return versions[0]
44+
45+
if len(versions) > 1:
46+
return versions[1]
47+
48+
return None
49+
3750
def sort_key(self, version):
3851
"""Sort key."""
3952
raise NotImplementedError
@@ -88,6 +101,15 @@ def enumerate_versions(self, package, introduced, fixed, limits=None):
88101
del fixed
89102
del limits
90103

104+
def next_version(self, package, version):
105+
"""Get the next version after the given version."""
106+
del package # Unused.
107+
parsed_version = semver_index.parse(version)
108+
if parsed_version.prerelease:
109+
return version + '.0'
110+
111+
return version + '-0'
112+
91113
@property
92114
def is_semver(self):
93115
return True

lib/osv/ecosystems_test.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright 2021 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""Bug helper tests."""
15+
16+
import unittest
17+
18+
from . import ecosystems
19+
20+
21+
class GetNextVersionTest(unittest.TestCase):
22+
"""get_next_version tests."""
23+
24+
def test_pypi(self):
25+
ecosystem = ecosystems.get('PyPI')
26+
self.assertEqual('1.36.0rc1', ecosystem.next_version('grpcio', '1.35.0'))
27+
self.assertEqual('1.36.1', ecosystem.next_version('grpcio', '1.36.0'))
28+
self.assertEqual('0.3.0', ecosystem.next_version('grpcio', '0'))
29+
30+
def test_maven(self):
31+
ecosystem = ecosystems.get('Maven')
32+
self.assertEqual('1.36.0',
33+
ecosystem.next_version('io.grpc:grpc-core', '1.35.1'))
34+
self.assertEqual('0.7.0', ecosystem.next_version('io.grpc:grpc-core', '0'))
35+
36+
def test_semver(self):
37+
ecosystem = ecosystems.get('Go')
38+
self.assertEqual('1.0.0-0', ecosystem.next_version('blah', '1.0.0'))
39+
self.assertEqual('1.0.0-pre.0', ecosystem.next_version('blah', '1.0.0-pre'))
40+
41+
42+
if __name__ == '__main__':
43+
unittest.main()

lib/run_tests.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash -ex
2+
3+
unset PIP_NO_BINARY
4+
pipenv sync
5+
pipenv run python -m unittest osv.bug_test
6+
pipenv run python -m unittest osv.ecosystems_test

lib/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
setuptools.setup(
2121
name='osv',
22-
version='0.0.7',
22+
version='0.0.8',
2323
author='OSV authors',
2424
author_email='osv-discuss@googlegroups.com',
2525
description='Open Source Vulnerabilities library',

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy