Skip to content

Convert to legacy format #14

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

Merged
merged 1 commit into from
Dec 21, 2018
Merged

Convert to legacy format #14

merged 1 commit into from
Dec 21, 2018

Conversation

gjvis
Copy link
Contributor

@gjvis gjvis commented Dec 20, 2018

  • Ready for review
  • Follows CONTRIBUTING rules
  • Reviewed by Snyk internal team

What does this PR do?

Exposes a way to convert dep-graph's to the legacy tree format.

"Package manager" and "package type" must be handled out of band by the
consumer, as "package manager" exists only on dep-graphs and "package
type" exists only on legacy trees.

Given legacy tree's have a very ill-defined structure, the conversion
can be lossy. This commit adds test fixtures that cover all of the data
that is preserved in conversion. If something is not in a fixture, then
it is not guaranteed to be preserved (e.g. package licence metadata).

It is expected that future releases of this library will formalise and
preserve more of the semi-structured data that exists on legacy trees, as
needed.

@gjvis gjvis self-assigned this Dec 20, 2018
@gjvis gjvis force-pushed the feat/to-legacy-tree branch 2 times, most recently from 7e3b5c6 to a4c6dcd Compare December 20, 2018 17:21
@gjvis gjvis changed the title wip: to dep-tree Convert to legacy format Dec 20, 2018
@gjvis gjvis requested a review from michael-go December 20, 2018 17:39
Copy link
Contributor

@robcresswell robcresswell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing jumping out at me, looks sane. Minor stylistic comments and one small concern, but happy for them to be ignored if not relevant.

May also be worth adding a cyclic fixture and expecting it to throw, then changing the assertion later on so you can tdd it a bit. Again, may be beyond the scope here.

if (depGraph.pkgManager.repositories
&& depGraph.pkgManager.repositories.length
&& ['apk', 'apt', 'deb', 'rpm'].indexOf(depGraph.pkgManager.name) >= 0) {
const [name, version] = depGraph.pkgManager.repositories[0].alias.split(':');
Copy link
Contributor

@robcresswell robcresswell Dec 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does alias always exist? I don't have the context around it, but looks like something that could throw some funny errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, adding tests and refactoring slightly to error out if we can't construct targetOS on a linux "pkgManager" (cc @darscan @michael-go)

@gjvis gjvis force-pushed the feat/to-legacy-tree branch from a4c6dcd to 50f9fb0 Compare December 21, 2018 15:39
Exposes a way to convert dep-graph's to the legacy tree format.

"Package manager" and "package type" must be handled out of band by the
consumer, as "package manager" exists only on dep-graphs and "package
type" exists only on legacy trees.

Given legacy tree's have a very ill-defined structure, the conversion
can be lossy. This commit adds test fixtures that cover all of the data
that is preserved in conversion. If something is not in a fixture, then
it is not guaranteed to be preserved (e.g. package licence metadata).

It is expected that future releases of this library will formalise and
preserve more of the semi-structured data that exists on legacy trees, as
needed.
@gjvis gjvis force-pushed the feat/to-legacy-tree branch from 50f9fb0 to caef817 Compare December 21, 2018 15:46
@gjvis gjvis merged commit c60d332 into master Dec 21, 2018
@gjvis gjvis deleted the feat/to-legacy-tree branch December 21, 2018 16:02
@snyksec
Copy link

snyksec commented Dec 21, 2018

🎉 This PR is included in version 1.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants