feat(github): add GitHub plugin

Summary:
Adding a simple GitHub plugin that shows a button on the thread view.

If we detect the "open in github" links, then we'll show the button on the
thread.

Test Plan: manual

Reviewers: dillon, bengotow

Reviewed By: bengotow

Differential Revision: https://phab.nylas.com/D1959
This commit is contained in:
Evan Morikawa 2015-09-01 11:57:06 -07:00
parent 31714407f9
commit e4a57aaf12
7 changed files with 105 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View file

@ -0,0 +1,8 @@
'body.platform-darwin':
'cmd-G': 'github:open'
'body.platform-linux':
'ctrl-G': 'github:open'
'body.platform-win32':
'ctrl-G': 'github:open'

View file

@ -0,0 +1,39 @@
_ = require 'underscore'
NylasStore = require 'nylas-store'
{MessageStore} = require 'nylas-exports'
class GithubStore extends NylasStore
constructor: ->
@listenTo MessageStore, @_onMessageStoreChanged
link: -> @_link
_onMessageStoreChanged: ->
return unless MessageStore.threadId()
itemIds = _.pluck(MessageStore.items(), "id")
return if itemIds.length is 0 or _.isEqual(itemIds, @_lastItemIds)
@_lastItemIds = itemIds
@_link = if @_isRelevantThread() then @_findGitHubLink() else null
@trigger()
_findGitHubLink: ->
msg = MessageStore.items()[0]
if not msg.body
# The msg body may be null if it's collapsed. In that case, use the
# last message. This may be less relaiable since the last message
# might be a side-thread that doesn't contain the link in the quoted
# text.
msg = _.last(MessageStore.items())
# https://regex101.com/r/aW8bI4/2
re = /<a.*?href=['"](.*?)['"].*?view.*?it.*?on.*?github.*?\/a>/gmi
firstMatch = re.exec(msg.body)
if firstMatch
link = firstMatch[1] # [0] is the full match and [1] is the matching group
return link
else return null
_isRelevantThread: ->
_.any (MessageStore.thread().participants ? []), (contact) ->
(/@github\.com/gi).test(contact.email)
module.exports = new GithubStore()

View file

@ -0,0 +1,12 @@
{ComponentRegistry} = require 'nylas-exports'
ViewOnGithubButton = require "./view-on-github-button"
module.exports =
activate: (@state={}) ->
ComponentRegistry.register ViewOnGithubButton,
roles: ['message:Toolbar']
deactivate: ->
ComponentRegistry.unregister(ViewOnGithubButton)
serialize: -> @state

View file

@ -0,0 +1,33 @@
shell = require 'shell'
React = require 'react'
GithubStore = require './github-store'
{RetinaImg} = require 'nylas-component-kit'
class ViewOnGithubButton extends React.Component
@displayName: "ViewOnGithubButton"
@containerRequired: false
constructor: (@props) ->
@state = link: null
componentDidMount: =>
@_unlisten = GithubStore.listen =>
@setState link: GithubStore.link()
@_keymapUnlisten = atom.commands.add 'body', {
'github:open': @_openLink
}
componentWillUnmount: =>
@_unlisten?()
@_keymapUnlisten?.dispose()
render: ->
return null unless @state.link
<button className="btn btn-toolbar"
onClick={@_openLink}
data-tooltip={"Visit Thread on GitHub"}><RetinaImg mode={RetinaImg.Mode.ContentIsMask} url="nylas://github/assets/github@2x.png" /></button>
_openLink: =>
shell.openExternal(@state.link) if @state.link
module.exports = ViewOnGithubButton

View file

@ -0,0 +1,13 @@
{
"name": "github",
"version": "0.1.0",
"main": "./lib/main",
"description": "Github integration in Nylas",
"license": "Proprietary",
"private": true,
"engines": {
"atom": "*"
},
"dependencies": {
}
}