Skip to content

Commit f8269f4

Browse files
Filter Composer development versions by their version value
Signed-off-by: Ali Zulfiqar <codewithfourtix@gmail.com>
1 parent 27c4fc9 commit f8269f4

2 files changed

Lines changed: 36 additions & 4 deletions

File tree

src/fetchcode/package_versions.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -409,15 +409,12 @@ def fetch_version_info(version_info: str, escaped_pkg: str) -> Optional[PackageV
409409

410410
def composer_extract_versions(resp: dict, pkg: str) -> Iterable[PackageVersion]:
411411
for item in get_item(resp, "packages", pkg) or []:
412-
if "dev-" in item:
413-
continue
414-
415412
# This if statement ensures, that all_versions contains only released versions
416413
# See https://github.com/composer/composer/blob/44a4429978d1b3c6223277b875762b2930e83e8c/doc/articles/versions.md#tags # nopep8
417414
# for explanation of removing 'v'
418415
time = item.get("time")
419416
version = item.get("version")
420-
if not version:
417+
if not version or version.startswith("dev-") or version.endswith("-dev"):
421418
continue
422419
yield PackageVersion(
423420
value=cleaned_version(version),
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# fetchcode is a free software tool from nexB Inc. and others.
2+
# Visit https://github.com/aboutcode-org/fetchcode for support and download.
3+
4+
# Copyright (c) nexB Inc. and others. All rights reserved.
5+
# http://nexb.com and http://aboutcode.org
6+
7+
# This software is licensed under the Apache License version 2.0.
8+
9+
# You may not use this software except in compliance with the License.
10+
# You may obtain a copy of the License at:
11+
# http://apache.org/licenses/LICENSE-2.0
12+
# Unless required by applicable law or agreed to in writing, software distributed
13+
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14+
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations under the License.
16+
17+
from fetchcode.package_versions import composer_extract_versions
18+
19+
20+
def test_composer_filters_development_versions():
21+
response = {
22+
"packages": {
23+
"vendor/example": [
24+
{"version": "dev-main"},
25+
{"version": "1.x-dev"},
26+
{"version": "v1.2.3"},
27+
{"version": "1.3.0-beta1"},
28+
{},
29+
]
30+
}
31+
}
32+
assert [item.value for item in composer_extract_versions(response, "vendor/example")] == [
33+
"1.2.3",
34+
"1.3.0-beta1",
35+
]

0 commit comments

Comments
 (0)