Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarjs committed May 16, 2019
0 parents commit c24596a
Show file tree
Hide file tree
Showing 11 changed files with 734 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.alfredworkflow
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
1. Call `gh-token` to generate personal access token.
2. Login by calling the `gh-login <email> <token>` action.
3. Search any repository by calling the `gh <term>` action.

### Other Actions

* `gh-notifications` will open your Github notifications page.

---

### Enterprise Support

If you're using an enterprise account, set your enterprise host with `gh-host <host>`.

The host value should be something like `https://example.com`

NOTE: This is an experimental feature that may not work as expected, if you find any issues please report them here: https://github.com/edgarjs/alfred-github-repos/issues
91 changes: 91 additions & 0 deletions bin/github-repos
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/usr/bin/env ruby

# frozen_string_literal: true

require_relative '../lib/github_repos'
require 'github/repo_formatter'
require 'github/authorization'
require 'json'

action = ARGV[0]

def usage!
puts 'Usage: github-repos <command>'
puts
puts 'Commands:'
puts ' authenticate <email> <token>'
puts ' search <query>'
puts ' host <hostname>'
exit
end

return usage! unless action

def authenticate(email, token)
return puts(not_authenticated_output) unless email && token

Github::Authorization.store_credentials(email, token)
end

def configure_host(host)
return usage! unless host

Github::Api.configure_host(host)
end

def not_authenticated_output
items = [
{
title: 'You need to authenticate with Github first',
subtitle: 'Hit Enter to open authentication page',
arg: Github::Authorization::AUTHORIZATION_URL
}
]

JSON.generate(items: items)
end

def no_results_output
items = [
{
title: 'No results',
subtitle: 'Try searching for another term'
}
]

JSON.generate(items: items)
end

def error_output
items = [
{
title: 'Invalid response',
subtitle: 'Please check your host and auth configuration'
}
]

JSON.generate(items: items)
end

def search(query)
repos = Github::Api.new.search_repos(query)
return not_authenticated_output unless repos
return no_results_output if repos.empty?

Github::RepoFormatter.new(repos).to_json
rescue Github::Authorization::NotAuthorizedError
not_authenticated_output
rescue JSON::ParserError
error_output
end

case action
when 'host'
configure_host(ARGV[1])
when 'authenticate'
authenticate(ARGV[1], ARGV[2])
when 'search'
puts search(ARGV[1])
else
return usage!
end
Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit c24596a

Please sign in to comment.