git ssb

10+

Matt McKegg / patchwork



Tree: 43227d5b2a248b928fbf666ecdf2f1e54a7ecd4b

Files: 43227d5b2a248b928fbf666ecdf2f1e54a7ecd4b / modules / app / sync / external-handler / git.js

1020 bytesRaw
1const nest = require('depnest')
2const {shell} = require('electron')
3const net = require('net')
4
5exports.gives = nest('app.sync.externalHandler')
6
7var externalViewer = 'http://git.scuttlebot.io'
8var localViewer = 'http://localhost:7718'
9
10var gitMessageTypes = [
11 'git-repo',
12 'git-update',
13 'issue',
14 'issue-edit',
15 'pull-request'
16]
17
18exports.create = (api) => {
19 return nest('app.sync.externalHandler', function (msg) {
20 if (!gitMessageTypes.includes(msg.value.content.type)) return
21 return function gitHandler (id) {
22 portInUse(7718, (useLocal) => {
23 shell.openExternal(`${useLocal ? localViewer : externalViewer}/${encodeURIComponent(id)}`)
24 })
25 }
26 })
27}
28
29function portInUse (port, cb) {
30 /* eslint-disable standard/no-callback-literal */
31 // super hacky check!
32 var server = net.createServer(function (socket) {})
33 server.listen(port, '127.0.0.1')
34 server.on('error', function (e) {
35 cb(true)
36 })
37 server.on('listening', function (e) {
38 server.close()
39 cb(false)
40 })
41}
42

Built with git-ssb-web