Skip to content
Snippets Groups Projects
Select Git revision
  • 7efcc8b8dc9053af679697641e78a286bf4f3630
  • master default protected
  • amend_commit
  • next
  • dev/nomodifiable
  • dev/discard_vselect
  • dev/catch_shell_error
  • dev/mapping_2
  • dev/close
  • dev/issue_123
  • dev/issue_71
  • dev/mapping
  • dev/remove_end_commit
  • dev/stash
  • dev/test_commit
  • dev/save_commmit_msg
  • dev/push
  • dev/git_diff
  • dev/undo
  • gh-pages
  • dev/display
  • 1.8.0
  • 1.7.3
  • 1.7.2
  • 1.7.1
  • 1.7.0
  • 1.6.0
  • 1.5.2
  • 1.5.1
  • 1.5.0
  • 1.4.2
  • 1.4.1
  • 1.4
  • 1.3
  • 1.2
  • 1.0
  • 1.1
37 results

addSubmodule_diff.expect

Blame
  • badge-cli.js 1.19 KiB
    import { fileURLToPath, URL } from 'url'
    import config from 'config'
    import got from 'got'
    import emojic from 'emojic'
    import Server from '../core/server/server.js'
    import trace from '../core/base-service/trace.js'
    
    function normalizeBadgeUrl(url) {
      // Provide a base URL in order to accept fragments.
      const { pathname, searchParams } = new URL(url, 'http://example.com')
      let newPath = pathname.replace('.svg', '')
      if (!newPath.endsWith('.json')) {
        newPath = `${newPath}.json`
      }
      return `${newPath}?${searchParams.toString()}`
    }
    
    async function traceBadge(badgeUrl) {
      const server = new Server(config.util.toObject())
      await server.start()
      const body = await got(
        `${server.baseUrl.replace(/\/$/, '')}${badgeUrl}`,
      ).json()
      trace.logTrace('outbound', emojic.shield, 'Rendered badge', body)
      await server.stop()
    }
    
    async function main() {
      if (process.argv.length < 3) {
        console.error(`Usage: node ${fileURLToPath(import.meta.url)} badge-url`)
        process.exit(1)
      }
      const [, , url] = process.argv
      const normalized = normalizeBadgeUrl(url)
      await traceBadge(normalized)
    }
    
    ;(async () => {
      try {
        await main()
      } catch (e) {
        console.error(e)
        process.exit(1)
      }
    })()