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

Add resolver that generates lockfile patch GitHub PRs #1132

Open
wants to merge 3 commits into
base: file-github-pr-cli
Choose a base branch
from

Conversation

freeqaz
Copy link
Member

@freeqaz freeqaz commented Feb 16, 2023

This is a GraphQL resolver that, when called with a vulnerability and package, will generate a GitHub Pull Request to the lockfile.

Current Limitations:

  • Only works for a single package at a time (batch PRs will come later)
  • Isn't wired up to the front-end
  • The GraphQL resolver is untested (but it should work)

Fixes #1030

This is a GraphQL resolver that, when called with a vulnerability and package,
will generate a GitHub Pull Request to the lockfile.

Current Limitations:
- Only works for a single package at a time (batch PRs will come later)
- Isn't wired up to the front-end
- The GraphQL resolver is untested (but it should work)
Copy link
Contributor

@breadchris breadchris left a comment

Choose a reason for hiding this comment

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

Some comments of how the code could be better. But looks fine.

.replace(/yarn\.lock$/, '')
.replace(/package-lock\.json$/, '');

await checkProjectIsAuthorized(projectId, ctx);
Copy link
Contributor

Choose a reason for hiding this comment

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

can you leave a comment that this will throw on error? I find it confusing to have a line of code whose side effect is not clear.

Copy link
Member Author

Choose a reason for hiding this comment

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

I renamed the function so that this is consistent everywhere in the repo.

Copy link
Contributor

@factoidforrest factoidforrest left a comment

Choose a reason for hiding this comment

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

nice!


const newPackageSlug = args.new_package_slug;
if (!newPackageSlug) {
throw new GraphQLYogaError('No new package slug provided');
Copy link
Contributor

Choose a reason for hiding this comment

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

We could probably DRY up this to just be a param checking function that takes an array of property names as strings. I bet we could throw that in utils and call it a day.

Just a thought, not like an urgent change obv

repo,
normalizedPackageManifestPath,
// TODO: Make this less hacky and brittle
packageManifestPath.endsWith('package-lock.json') ? 'npm' : 'yarn',
Copy link
Contributor

Choose a reason for hiding this comment

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

This is probably not a safe check. I think we should expand this into a function that throws if it doesnt look npm-y or yarn-y.

Pnpm exists, and so on and so forth. Bun too! haha

pullRequestUrl: pullRequestResult.pullRequestUrl,
};
} catch (error) {
// TODO: temporary error handler until i figure out how to deal with global errors in yoga which seems maybe impossible
Copy link
Contributor

Choose a reason for hiding this comment

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

It's impossible unless we drop yoga for apollo, or at least, difficult, i tried. we need to go to apollo anyway because yoga is just a sucky wrapper around apollo.

Apollo stinks but it at least has that part working.

You may as well wrap this unknown error in a nice graphqlError because yoga will catch it anyway, and return something nebulous to the client. So you might as well just throw new "GraphQLYogaError("An Unknown error occurred while attempting to update dependencies") I have it set up so those will render out to the user in an alert.

That way it at least looks better on the client

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

Successfully merging this pull request may close these issues.

3 participants