Skip to content

Commit

Permalink
Merge pull request #93 from bswinnerton/send-link-to-things
Browse files Browse the repository at this point in the history
Add support for sending a GitHub link to Things
  • Loading branch information
bswinnerton authored Nov 11, 2017
2 parents b1e0485 + 3a0fc0b commit 1ffcaeb
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 43 deletions.
Binary file added Contents/Resources/thingsTemplate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 11 additions & 10 deletions Contents/Scripts/bundle.min.js

Large diffs are not rendered by default.

45 changes: 29 additions & 16 deletions Contents/Scripts/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,20 @@ class GitHubLB {
// Matching:
// https://github.com/bswinnerton/dotfiles/blob/master/ack/ackrc.symlink#L6
if (input.match(GITHUB_LINK_FORMAT)) {
return this.openLinkShortnerMenu(input);
return [
{
title: 'Shorten link',
icon: 'linkTemplate.png',
action: 'shortenLink',
actionArgument: input,
},
{
title: 'Add to things',
icon: 'thingsTemplate.png',
action: 'addToThings',
actionArgument: input,
}
];
}

// Matching:
Expand Down Expand Up @@ -132,21 +145,6 @@ class GitHubLB {
];
}

openLinkShortnerMenu(link, options) {
if (LaunchBar.options.commandKey == 1) {
this.shortenLink(link);
} else {
return [
{
title: 'Shorten link',
icon: 'linkTemplate.png',
action: 'shortenLink',
actionArgument: link,
},
];
}
}

openIssueMenu(issue) {
if (issue.number) {
let fetchedIssue = Issue.fetch(issue.repository, issue.number);
Expand Down Expand Up @@ -426,6 +424,17 @@ class GitHubLB {
LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');
}

addToThings(link) {
let resource = new Resource(link);
let issueOrPullRequest = resource.toObject();

let title = issueOrPullRequest.title;
let todo = encodeURI('Review "' + title + '"');
let url = encodeURI(issueOrPullRequest.url);

LaunchBar.openURL('things:add?title=' + todo + '&notes=' + url);
}

setToken(token) {
Action.preferences.token = token;

Expand Down Expand Up @@ -500,6 +509,10 @@ function shortenLink(link, details) {
return app.shortenLink(link);
}

function addToThings(link) {
return app.addToThings(link);
}

function openSettingsMenu() {
return app.openSettingsMenu();
}
Expand Down
13 changes: 9 additions & 4 deletions Contents/Scripts/issue.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
class Issue {
constructor(repository, number, title) {
constructor(repository, number, title, url) {
this.repository = repository;
this.number = parseInt(number);
this.title = title;
this.number = parseInt(number);
this.title = title;
this.passedUrl = url;
}

get url() {
return 'https://github.com/' + this.repository.nameWithOwner + '/issues/' + this.number;
if (this.passedUrl) {
return this.passedUrl;
} else {
return 'https://github.com/' + this.repository.nameWithOwner + '/issues/' + this.number;
}
}

get shortURL() {
Expand Down
9 changes: 7 additions & 2 deletions Contents/Scripts/pull-request.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
class PullRequest {
constructor(repository, number, title) {
constructor(repository, number, title, url) {
this.repository = repository;
this.number = number;
this.title = title;
this.passedUrl = url;
}

get url() {
return this.repository.url + '/pull/' + this.number;
if (this.passedUrl) {
return this.passedUrl;
} else {
return this.repository.url + '/pull/' + this.number;
}
}

get shortURL() {
Expand Down
61 changes: 61 additions & 0 deletions Contents/Scripts/resource.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
class Resource {
constructor(url) {
this.url = url;
}

toObject() {
const query = `
query($url: URI!) {
resource(url: $url) {
__typename
... on Issue {
title
number
repository {
name
owner {
login
}
}
}
... on PullRequest {
title
number
repository {
name
owner {
login
}
}
}
}
}
`;

let variables = { url: this.url };
let result = GraphQL.execute(query, variables);

if (result) {
if (result.data && result.data.resource) {
let issueOrPullRequest = result.data.resource;

let owner = new Account(issueOrPullRequest.repository.owner.login);
let repository = new Repository(owner, issueOrPullRequest.repository.name);

switch (issueOrPullRequest.__typename) {
case 'Issue':
return new Issue(repository, issueOrPullRequest.number, issueOrPullRequest.title, this.url);
case 'PullRequest':
return new PullRequest(repository, issueOrPullRequest.number, issueOrPullRequest.title, this.url);
}
} else {
return {};
}
} else {
return {};
}
}
}

if (typeof module !== 'undefined') { module.exports.Resource = Resource; }
36 changes: 25 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Download and install the action [here](http://launchbar-github.com).
## Actions

At any point you can either hit enter to navigate into available options, or
hit `` + `enter` to go directly to the corresponding GitHub page.
hit <kbd>⌘</kbd> + <kbd>Enter</kbd> to go directly to the corresponding GitHub
page.

### For a user or organization

Expand All @@ -35,28 +36,40 @@ be fetched:

### For a commit

At any time, paste a commit SHA into LaunchBar and hit `tab`. Start typing
"github" and you should see the action appear, hit `enter`. Once complete, the
action will bring you to the pull request that introduced the commit. If the
commit is associated with multiple pull requests, they will be displayed in a
list.
At any time, paste a commit SHA into LaunchBar and hit <kbd>Tab</kbd>. Start
typing "github" and you should see the action appear, hit <kbd>Enter</kbd>.
Once complete, the action will bring you to the pull request that introduced
the commit. If the commit is associated with multiple pull requests, they will
be displayed in a list.

<p align="center"><img src="screenshots/commit.png" width="668px" /></p>
<p align="center"><img src="screenshots/commit-expanded.png" width="668px" /></p>
<p align="center"><img src="screenshots/commit-pr-list.png" width="668px" /></p>

### Shortening a link

At any time, paste a GitHub link into LaunchBar and hit `tab`. Start typing
"github" and you should see the action appear, hit `enter`. Once complete, the
action will ask you if you want to shorten the link, hit `enter` and the
shortened link will be copied to your clipboard.
At any time, paste a GitHub link into LaunchBar and hit <kbd>Tab</kbd>. Start
typing "github" and you should see the action appear, hit <kbd>Enter</kbd>.
Once complete, the action will ask you if you want to shorten the link, hit
<kbd>Enter</kbd> and the shortened link will be copied to your clipboard.

<p align="center"><img src="screenshots/shorten-link.png" width="668px" /></p>
<p align="center"><img src="screenshots/shorten-link-expanded.png" width="668px" /></p>
<p align="center"><img src="screenshots/shorten-link-final.png" width="668px" /></p>
<p align="center"><img src="screenshots/shorten-link-notification.png" width="378px" /></p>

### Sending a link to [Things][things]

Similarly to shortening a link, you can paste a GitHub link into LaunchBar at
any time and hit <kbd>Tab</kbd>. From there, either find GitHub in the options
or type "github" to have it appear for the first time, then hit
<kbd>Enter</kbd> to open the quick add menu of the Things application.

<p align="center"><img src="screenshots/shorten-link.png" width="668px" /></p>
<p align="center"><img src="screenshots/shorten-link-expanded.png" width="668px" /></p>
<p align="center"><img src="screenshots/send-to-things.png" width="668px" /></p>
<p align="center"><img src="screenshots/send-to-things-final.png" width="668px" /></p>

## Installing

### Automatic
Expand Down Expand Up @@ -142,11 +155,12 @@ script/test

If you set your token using http://launchbar-github.com and are not seeing
repositories belonging to an organization you are a part of, the organization
may have enabled [Organization Application Policies](oap). OAP limits access to
may have enabled [Organization Application Policies][oap]. OAP limits access to
private resources on GitHub unless the OAuth application has been granted
access. You can either [request access][request-oap-access] from an
organization administrator, or instead use a Personal Access Token as [outlined
above](#manual) to get around this problem.

[oap]: https://developer.github.com/changes/2015-01-19-an-integrators-guide-to-organization-application-policies/
[request-oap-access]: https://github.com/settings/connections/applications/7f3d43c8412a4385727e
[things]: https://culturedcode.com/things/
Binary file added screenshots/send-to-things-final.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/send-to-things.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/shorten-link-final.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1ffcaeb

Please sign in to comment.