Skip to content

Commit 938599b

Browse files
Merge branch 'main' into minecode-pipeline-npm
Signed-off-by: Ayan Sinha Mahapatra <[email protected]>
2 parents 478b5e8 + 065c87a commit 938599b

File tree

13 files changed

+627
-24
lines changed

13 files changed

+627
-24
lines changed

minecode/tests/collectors/test_github.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ def test_github_get_all_versions(self):
3535
"matchcode-toolkit-v3.0.0",
3636
"matchcode-toolkit-v1.1.1",
3737
"minecode-pipelines/v0.0.1b3",
38+
"minecode-pipelines/v0.0.1b4",
39+
"minecode-pipelines/v0.0.1b5",
40+
"minecode-pipelines/v0.0.1b6",
41+
"minecode-pipelines/v0.0.1b7",
42+
"minecode-pipelines/v0.0.1b8",
3843
]
3944
for item in versions:
4045
self.assertIn(item, expected)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
#
3+
# http://nexb.com and https://github.com/aboutcode-org/scancode.io
4+
# The ScanCode.io software is licensed under the Apache License version 2.0.
5+
# Data generated with ScanCode.io is provided as-is without warranties.
6+
# ScanCode is a trademark of nexB Inc.
7+
#
8+
# You may not use this software except in compliance with the License.
9+
# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0
10+
# Unless required by applicable law or agreed to in writing, software distributed
11+
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12+
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
13+
# specific language governing permissions and limitations under the License.
14+
#
15+
# Data Generated with ScanCode.io is provided on an "AS IS" BASIS, WITHOUT WARRANTIES
16+
# OR CONDITIONS OF ANY KIND, either express or implied. No content created from
17+
# ScanCode.io should be considered or used as legal advice. Consult an Attorney
18+
# for any legal advice.
19+
#
20+
# ScanCode.io is a free software code scanning tool from nexB Inc. and others.
21+
# Visit https://github.com/aboutcode-org/scancode.io for support and download.
22+
23+
from scanpipe.pipelines import Pipeline
24+
from scanpipe.pipes import federatedcode
25+
26+
from minecode_pipelines import pipes
27+
from minecode_pipelines.pipes import alpine
28+
29+
30+
class MineAlpine(Pipeline):
31+
"""
32+
Mine all packageURLs from an alpine index and publish them to
33+
a FederatedCode repo.
34+
"""
35+
36+
@classmethod
37+
def steps(cls):
38+
return (
39+
cls.check_federatedcode_eligibility,
40+
cls.collect_packages_from_alpine,
41+
cls.delete_cloned_repos,
42+
)
43+
44+
def check_federatedcode_eligibility(self):
45+
"""
46+
Check if the project fulfills the following criteria for
47+
pushing the project result to FederatedCode.
48+
"""
49+
federatedcode.check_federatedcode_configured_and_available(logger=self.log)
50+
51+
def collect_packages_from_alpine(self):
52+
self.repos = alpine.collect_packages_from_alpine(logger=self.log)
53+
54+
def delete_cloned_repos(self):
55+
pipes.delete_cloned_repos(repos=self.repos, logger=self.log)

minecode_pipelines/pipelines/mine_pypi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
from scanpipe.pipelines import Pipeline
2424
from scanpipe.pipes import federatedcode
2525

26-
from minecode_pipelines.pipes import pypi
2726
from minecode_pipelines import pipes
27+
from minecode_pipelines.pipes import pypi
2828

2929

3030
class MinePypi(Pipeline):

minecode_pipelines/pipes/__init__.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ def compress_packages_file(packages_file, compressed_packages_file):
4040

4141

4242
def decompress_packages_file(compressed_packages_file, name):
43-
4443
packages_file = get_temp_file(name)
4544
with gzip.open(compressed_packages_file, "rb") as f_in:
4645
with open(packages_file, "wb") as f_out:
@@ -145,18 +144,31 @@ def get_packages_file_from_checkpoint(config_repo, checkpoint_path, name):
145144

146145

147146
def fetch_checkpoint_by_git(cloned_repo, checkpoint_path):
148-
149147
cloned_repo.remotes.origin.pull()
150148
return os.path.join(cloned_repo.working_dir, checkpoint_path)
151149

152150

153-
def write_packageurls_to_file(repo, base_dir, packageurls):
151+
def write_packageurls_to_file(repo, base_dir, packageurls, append=False):
152+
if not isinstance(packageurls, list):
153+
raise Exception("`packageurls` needs to be a list")
154+
154155
purl_file_rel_path = os.path.join(base_dir, PURLS_FILENAME)
155156
purl_file_full_path = Path(repo.working_dir) / purl_file_rel_path
157+
if append and purl_file_full_path.exists():
158+
existing_purls = load_data_from_yaml_file(purl_file_full_path)
159+
packageurls = existing_purls.extend(packageurls)
156160
write_data_to_yaml_file(path=purl_file_full_path, data=packageurls)
157161
return purl_file_rel_path
158162

159163

164+
def load_data_from_yaml_file(path):
165+
if isinstance(path, str):
166+
path = Path(path)
167+
168+
with open(path, encoding="utf-8") as f:
169+
return saneyaml.load(f.read())
170+
171+
160172
def write_data_to_yaml_file(path, data):
161173
if isinstance(path, str):
162174
path = Path(path)

0 commit comments

Comments
 (0)