Skip to content

Commit

Permalink
Merge pull request #12 from cliffrowley/multiple-project-support
Browse files Browse the repository at this point in the history
Multiple project support
  • Loading branch information
cliffrowley committed Jun 11, 2015
2 parents de3fe3c + e9a7646 commit 10dfc86
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 90 deletions.
38 changes: 28 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
# Open in GitHub for [Mac|Windows]
# Open in GitHub App

Opens the current project in [GitHub for Mac](http://mac.github.com) or [GitHub for Windows](https://windows.github.com/) with <kbd>ctrl-alt-g</kbd>.
Opens the current project in GitHub app for [Mac](http://mac.github.com) or [Windows](https://windows.github.com/).

![Screenshot](https://dl.dropboxusercontent.com/u/303485845/Atom/packages/open-in-github-app/open-in-github-app.png)
## Features

---
* Supports Mac and Windows.
* Supports multiple project folders.

Uses code from Atom's [open-on-github](https://github.com/atom/open-on-github)
package, which is released under the following license:
## Keymaps

> Copyright (c) 2014 GitHub Inc.
On both platforms the default keymap is <kbd>ctrl-alt-g</kbd>.

> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
## Windows

> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
The GitHub app behaves very differently on Windows. Most notably there doesn't seem to be a way to launch the app with a local directory (only a repository URL), which has a few implications:

> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* If the repository URL is not known to the app then it will simply open with whichever repository you last had selected.
* If the repository URL _is_ known to the app but isn't where it expects to find it, then the app will prompt you to clone the repository.

Essentially you just need to ensure that the GitHub app is already aware of your repository before you try launching it via Atom. And if at any point you move your local repository, ensure the GitHub app is aware of this.

We've asked GitHub to update the app to allow launching with a local directory, but so far our request seems to have fallen on deaf ears. If by some miracle our request is implemented, we'll update this package and unify the behaviour.

## Mac

The app pretty much behaves as you would expect and if your project directory is not known to the GitHub app it will be added to its sidebar and remembered.

## Authors

* Cliff Rowley ([cliffrowley](https://github.com/cliffrowley))
* James Sconfitto ([jugglingnutcase](https://github.com/jugglingnutcase))

## Contributing

[Issues](https://github.com/cliffrowley/atom-open-in-github-app/issues) and [pull requests](https://github.com/cliffrowley/atom-open-in-github-app/pulls) are always welcome!
9 changes: 0 additions & 9 deletions keymaps/open-in-github-app.cson
Original file line number Diff line number Diff line change
@@ -1,11 +1,2 @@
# Keybindings require three things to be fully defined: A selector that is
# matched against the focused element, the keystroke and the command to
# execute.
#
# Below is a basic keybinding which registers on all platforms by applying to
# the root workspace element.

# For more detailed documentation see
# https://atom.io/docs/latest/advanced/keymaps
'atom-workspace':
'ctrl-alt-g': 'open-in-github-app:open'
5 changes: 5 additions & 0 deletions lib/open-github-app.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
switch process.platform
when 'darwin'
module.exports = require('./open-github-app/mac')
when 'win32'
module.exports = require('./open-github-app/windows')
5 changes: 5 additions & 0 deletions lib/open-github-app/mac.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
shell = require 'shell'
path = require 'path'

module.exports = (projectPath) ->
shell.openExternal "github-mac://openRepo/#{path.resolve(projectPath)}"
9 changes: 9 additions & 0 deletions lib/open-github-app/windows.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
shell = require 'shell'
giturlparse = require 'giturlparse'

{Directory} = require 'atom'

module.exports = (projectPath) ->
atom.project.repositoryForDirectory(new Directory(projectPath)).then (repo) ->
url = giturlparse(repo.getOriginURL()).toString('https')
shell.openExternal "github-windows://openRepo/#{url}"
88 changes: 19 additions & 69 deletions lib/open-in-github-app.coffee
Original file line number Diff line number Diff line change
@@ -1,75 +1,25 @@
exec = require("child_process").exec
shell = require('shell')
{CompositeDisposable} = require 'atom'

ProjectPathListView = require './project-path-list-view'

module.exports =
subscriptions: null

activate: (state) ->
atom.commands.add 'atom-workspace', 'open-in-github-app:open', => @openApp()
@subscriptions = new CompositeDisposable
@subscriptions.add atom.commands.add 'atom-workspace', 'open-in-github-app:open', => @openApp()

openApp: ->
@path = atom.project?.getPath()
deactivate: ->
@subscriptions.destroy()

if process.platform is 'darwin'
exec "open -a GitHub.app #{@path}" if @path?
openApp: ->
projectPaths = atom.project?.getPaths()

if projectPaths.length is 0
atom.notifications.addInfo 'Open in GitHub App',
detail: 'This project has no folders!',
dismissable: true
else if projectPaths.length is 1
require('./open-github-app')(projectPaths[0])
else
repo = atom.project.getRepo()
protocol = "github-windows://openRepo/"

if repo?
url = @githubRepoUrl(repo)
protocol = protocol + "#{url}" if url?

branch = @branchName(repo)
protocol = protocol + "?branch=#{branch}" if branch?

shell.openExternal protocol

# Based on https://github.com/atom/open-on-github/blob/50b38b91acb0eb5e123dad49ba8ad3a82906ca5c/lib/github-file.coffee:

githubRepoUrl: (repo) ->
url = @gitUrl(repo)

if not url?
return null

if url.match /https:\/\/[^\/]+\// # e.g., https://github.com/foo/bar.git
url = url.replace(/\.git$/, '')
else if url.match /git@[^:]+:/ # e.g., git@github.com:foo/bar.git
url = url.replace /^git@([^:]+):(.+)$/, (match, host, repoPath) ->
repoPath = repoPath.replace(/^\/+/, '') # replace leading slashes
"http://#{host}/#{repoPath}".replace(/\.git$/, '')
else if url.match /^git:\/\/[^\/]+\// # e.g., git://github.com/foo/bar.git
url = "http#{url.substring(3).replace(/\.git$/, '')}"

url = url.replace(/\/+$/, '')

return url unless @isBitbucketUrl(url)

gitUrl: (repo) ->
remoteOrBestGuess = @remoteName(repo) ? 'origin'
repo.getConfigValue("remote.#{remoteOrBestGuess}.url", @path)

remoteName: (repo) ->
shortBranch = repo.getShortHead(@path)
return null unless shortBranch

branchRemote = repo.getConfigValue("branch.#{shortBranch}.remote", @path)
return null unless branchRemote?.length > 0

branchRemote

isBitbucketUrl: (url) ->
return true if url.indexOf('git@bitbucket.org') is 0

try
{host} = parseUrl(url)
host is 'bitbucket.org'

branchName: (repo) ->
shortBranch = repo.getShortHead(@path)
return null unless shortBranch

branchMerge = repo.getConfigValue("branch.#{shortBranch}.merge", @path)
return shortBranch unless branchMerge?.length > 11
return shortBranch unless branchMerge.indexOf('refs/heads/') is 0

branchMerge.substring(11)
new ProjectPathListView(projectPaths)
27 changes: 27 additions & 0 deletions lib/project-path-list-view.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{$$, SelectListView} = require 'atom-space-pen-views'

module.exports =
class ProjectPathListView extends SelectListView
initialize: (@projectPaths) ->
super
@setItems @projectPaths.map (path) -> {path: path}
@show()
@focusFilterEditor()

show: ->
@panel ?= atom.workspace.addModalPanel item: this
@panel.show()

cancelled: ->
@hide()

hide: ->
@panel?.destroy()

viewForItem: ({path}) ->
$$ ->
@li path

confirmed: ({path}) ->
require('./open-github-app')(path)
@cancel()
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
"engines": {
"atom": ">=0.174.0 <2.0.0"
},
"dependencies": {},
"readme": "# Open in GitHub for [Mac|Windows]\n\n Opens the current project in [GitHub for Mac](http://mac.github.com) or [GitHub for Windows](https://windows.github.com/) with <kbd>ctrl-alt-g</kbd>.",
"dependencies": {
"atom-space-pen-views": "^2.0.5",
"giturlparse": "^1.2.0"
},
"readme": "# Open in GitHub App\n\nOpens the current project in GitHub app for [Mac](http://mac.github.com) or [Windows](https://windows.github.com/).\n\n## Features\n\n * Supports Mac and Windows.\n * Supports multiple project folders.\n\n## Keymaps\n\nOn both platforms the default keymap is <kbd>ctrl-alt-g</kbd>.\n\n## Windows\n\nThe GitHub app behaves very differently on Windows. Most notably there doesn't seem to be a way to launch the app with a local directory (only a repository URL), which has a few implications:\n\n * If the repository URL is not known to the app then it will simply open with whichever repository you last had selected.\n * If the repository URL _is_ known to the app but isn't where it expects to find it, then the app will prompt you to clone the repository.\n\n Essentially you just need to ensure that the GitHub app is already aware of your repository before you try launching it via Atom. And if at any point you move your local repository, ensure the GitHub app is aware of this.\n\n We've asked GitHub to update the app to allow launching with a local directory, but so far our request seems to have fallen on deaf ears. If by some miracle our request is implemented, we'll update this package and unify the behaviour.\n\n## Mac\n\n The app pretty much behaves as you would expect and if your project directory is not known to the GitHub app it will be added to its sidebar and remembered.\n\n## Authors\n\n * Cliff Rowley ([cliffrowley](https://github.com/cliffrowley))\n * James Sconfitto ([jugglingnutcase](https://github.com/jugglingnutcase))\n\n## Contributing\n\n[Issues](https://github.com/cliffrowley/atom-open-in-github-app/issues) and [pull requests](https://github.com/cliffrowley/atom-open-in-github-app/pulls) are always welcome!\n",
"readmeFilename": "README.md"
}
14 changes: 14 additions & 0 deletions scripts/prepublish.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
##
# Updates the package.json readme field from the README.md.
#

fs = require('fs')

fs.readFile "#{__dirname}/../package.json", 'utf8', (err, data) ->
throw(err) if err
obj = JSON.parse data
fs.readFile "#{__dirname}/../README.md", 'utf8', (err, data) ->
throw(err) if err
obj['readme'] = data #data.replace(/\n/g, '\\n').replace(/"/, '\\"')
fs.writeFile "#{__dirname}/../package.json", JSON.stringify(obj, null, ' '), (err) ->
throw(err) if err

0 comments on commit 10dfc86

Please sign in to comment.