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

Support url based evaluation #1

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

SparshithNR
Copy link
Collaborator

@SparshithNR SparshithNR commented Feb 1, 2021

Support URL as input.

Cases covered:
1. Github repo URL
2. Private Github Repo (token needed)
3. Braches in the repo
4. External URL which can return package.json, yarn.lock, npmrc (optional) files

Test cases added for each case
All operations are done in memory

$ bin/supported https://test.githubprivate.com/stefanpenner/supported
Private instances of github needs token. To generate token follow https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token
Missing required flag
	--token, -t

lib/read-from-url.js Outdated Show resolved Hide resolved
lib/read-from-url.js Outdated Show resolved Hide resolved
lib/read-from-url.js Outdated Show resolved Hide resolved
lib/read-from-url.js Outdated Show resolved Hide resolved
lib/read-from-url.js Outdated Show resolved Hide resolved
lib/read-from-url.js Outdated Show resolved Hide resolved
// Generate token using https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token
npx supported https://github.com/stefanpenner/supported
npx supported https://github.com/stefanpenner/supported/tree/some-branch
npx supported https://test.githubprivate.com/stefanpenner/supported -t $TOKEN
Copy link
Collaborator

Choose a reason for hiding this comment

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

The GITHUB_TOKEN environment variable is a convention which we can piggy back on more details

I have fine having -t as a way to override, but if a user has $GITHUB_TOKEN already set It would be great if we could seamlessly use that.

What do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We may also want to provide a link to documentation which helps people generate said token.

Copy link
Collaborator Author

@SparshithNR SparshithNR Apr 1, 2021

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorry for the delayed response on this.
I checked to see if I can find GITHUB_TOKEN in my local. I couldn't find this. Do you have it in your local environment?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added documentation in the readme file

README.md Show resolved Hide resolved
lib/help.js Outdated Show resolved Hide resolved
hostUrl: flags.hostUrl,
});
// if project root is a URL then use homedir as root
projectRoot = require('os').homedir();
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is surprising, I understanding reading the npmrc from the the homedir, but what if someone has a spurious lockfile or package.json in there homedir? This happens surprisingly often, and leads to a confusing and potentially tricky problem too debug.

Is there a more resilient alternative?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We are not using lock file or package.json from the homedir even if it exists. those are all read from in-memory files passed. The only npmrc we read is from homedir to avoid possible settings in the current project. The hope is not to have any custom npmrc in homedir.

...localConfig,
};
} catch (e) {
throw new Error(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm always nervous about catching all errors, is there a way to detect the expected exception if there was a parse failure and provide a nicer error? (assuming the existing error isn't itself already nice)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can append the actual error this error so that we are not hiding actual error.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In the new change, I have appended the actual error.
I personally didn't see any error. I have just put the try-catch just to put a nice error message before we throw the actual error stack.

lib/read-from-url.js Outdated Show resolved Hide resolved
lib/read-from-url.js Outdated Show resolved Hide resolved
@stefanpenner stefanpenner mentioned this pull request May 5, 2021
3 tasks
sparshithNR added 7 commits May 11, 2021 16:16
Cases covered:
1. Github repo URL
2. Private Github Repo (token needed)
3. Braches in the repo
4. External URL which can return package.json, yarn.lock, npmrc (optional) files

Test cases added for each cases
All operations done in memory
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.

2 participants