-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from cliffrowley/multiple-project-support
Multiple project support
- Loading branch information
Showing
9 changed files
with
112 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |