mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-02-21 22:54:11 +08:00
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:
parent
ba76663f5e
commit
ae5429365e
7 changed files with 105 additions and 0 deletions
BIN
internal_packages/github/assets/github@2x.png
Normal file
BIN
internal_packages/github/assets/github@2x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
8
internal_packages/github/keymaps/github.cson
Normal file
8
internal_packages/github/keymaps/github.cson
Normal 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'
|
39
internal_packages/github/lib/github-store.coffee
Normal file
39
internal_packages/github/lib/github-store.coffee
Normal 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()
|
12
internal_packages/github/lib/main.cjsx
Normal file
12
internal_packages/github/lib/main.cjsx
Normal 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
|
33
internal_packages/github/lib/view-on-github-button.cjsx
Normal file
33
internal_packages/github/lib/view-on-github-button.cjsx
Normal 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
|
13
internal_packages/github/package.json
Normal file
13
internal_packages/github/package.json
Normal 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": {
|
||||||
|
}
|
||||||
|
}
|
0
internal_packages/github/stylesheets/github.less
Normal file
0
internal_packages/github/stylesheets/github.less
Normal file
Loading…
Reference in a new issue