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

feat(bugs): fallback to email, if provided, when URL is not available #3052

Merged
merged 1 commit into from Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/content/commands/npm-bugs.md
Expand Up @@ -15,9 +15,9 @@ aliases: issues
### Description

This command tries to guess at the likely location of a package's bug
tracker URL, and then tries to open it using the `--browser` config param.
If no package name is provided, it will search for a `package.json` in the
current folder and use the `name` property.
tracker URL or the `mailto` URL of the support email, and then tries to
open it using the `--browser` config param. If no package name is provided, it
will search for a `package.json` in the current folder and use the `name` property.

### Configuration

Expand Down
3 changes: 3 additions & 0 deletions lib/bugs.js
Expand Up @@ -43,6 +43,9 @@ class Bugs extends BaseCommand {

if (typeof mani.bugs === 'object' && mani.bugs.url)
return mani.bugs.url

if (typeof mani.bugs === 'object' && mani.bugs.email)
return `mailto:${mani.bugs.email}`
}

// try to get it from the repo, if possible
Expand Down
14 changes: 13 additions & 1 deletion test/lib/bugs.js
Expand Up @@ -31,6 +31,16 @@ const pacote = {
version: '1.2.3',
repository: { url: 'https://github.com/foo/repoobj' },
}
: spec === 'mailtest' ? {
name: 'mailtest',
version: '3.7.4',
bugs: { email: 'hello@example.com' },
}
: spec === 'secondmailtest' ? {
name: 'secondmailtest',
version: '0.1.1',
bugs: { email: 'ABC432abc@a.b.example.net' },
}
: spec === '.' ? {
name: 'thispkg',
version: '1.2.3',
Expand Down Expand Up @@ -59,14 +69,16 @@ t.test('usage', (t) => {
t.end()
})

t.test('open bugs urls', t => {
t.test('open bugs urls & emails', t => {
const expect = {
nobugs: 'https://www.npmjs.com/package/nobugs',
'bugsobj-nourl': 'https://www.npmjs.com/package/bugsobj-nourl',
bugsurl: 'https://bugzilla.localhost/bugsurl',
bugsobj: 'https://bugzilla.localhost/bugsobj',
repourl: 'https://github.com/foo/repourl/issues',
repoobj: 'https://github.com/foo/repoobj/issues',
mailtest: 'mailto:hello@example.com',
secondmailtest: 'mailto:ABC432abc@a.b.example.net',
'.': 'https://example.com',
}
const keys = Object.keys(expect)
Expand Down