1const PackageUrlCmd = require('../package-url-cmd.js')
2
3class Bugs extends PackageUrlCmd {
4  static description = 'Report bugs for a package in a web browser'
5  static name = 'bugs'
6
7  getUrl (spec, mani) {
8    if (mani.bugs) {
9      if (typeof mani.bugs === 'string') {
10        return mani.bugs
11      }
12
13      if (typeof mani.bugs === 'object' && mani.bugs.url) {
14        return mani.bugs.url
15      }
16
17      if (typeof mani.bugs === 'object' && mani.bugs.email) {
18        return `mailto:${mani.bugs.email}`
19      }
20    }
21
22    // try to get it from the repo, if possible
23    const info = this.hostedFromMani(mani)
24    const infoUrl = info?.bugs()
25    if (infoUrl) {
26      return infoUrl
27    }
28
29    // just send them to the website, hopefully that has some info!
30    return `https://www.npmjs.com/package/${mani.name}`
31  }
32}
33
34module.exports = Bugs
35