-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor and add tests for better maintainability
- Loading branch information
Showing
44 changed files
with
2,206 additions
and
686 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 +1,3 @@ | ||
*.alfredworkflow | ||
build/ | ||
coverage/ |
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,22 @@ | ||
# frozen_string_literal: true | ||
|
||
source 'https://rubygems.org' | ||
ruby '>= 2.5.0' | ||
|
||
group :development do | ||
gem 'dotenv', '~> 2.7', require: 'dotenv/load' | ||
gem 'rake', '~> 13.0', require: false | ||
end | ||
|
||
group :test do | ||
gem 'minitest', '~> 5.14', require: 'minitest/autorun' | ||
gem 'minitest-ci', '~> 3.4', require: false | ||
gem 'minitest-reporters', '~> 1.4' | ||
gem 'mocha', '~> 1.11', require: 'mocha/minitest' | ||
gem 'simplecov', '~> 0.19', require: false | ||
gem 'webmock', '~> 3.10', require: 'webmock/minitest' | ||
end | ||
|
||
group :development, :test do | ||
gem 'pry-byebug' | ||
end |
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,60 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
addressable (2.7.0) | ||
public_suffix (>= 2.0.2, < 5.0) | ||
ansi (1.5.0) | ||
builder (3.2.4) | ||
byebug (11.1.3) | ||
coderay (1.1.3) | ||
crack (0.4.4) | ||
docile (1.3.2) | ||
dotenv (2.7.6) | ||
hashdiff (1.0.1) | ||
method_source (1.0.0) | ||
minitest (5.14.2) | ||
minitest-ci (3.4.0) | ||
minitest (>= 5.0.6) | ||
minitest-reporters (1.4.2) | ||
ansi | ||
builder | ||
minitest (>= 5.0) | ||
ruby-progressbar | ||
mocha (1.11.2) | ||
pry (0.13.1) | ||
coderay (~> 1.1) | ||
method_source (~> 1.0) | ||
pry-byebug (3.9.0) | ||
byebug (~> 11.0) | ||
pry (~> 0.13.0) | ||
public_suffix (4.0.6) | ||
rake (13.0.1) | ||
ruby-progressbar (1.10.1) | ||
simplecov (0.19.1) | ||
docile (~> 1.1) | ||
simplecov-html (~> 0.11) | ||
simplecov-html (0.12.3) | ||
webmock (3.10.0) | ||
addressable (>= 2.3.6) | ||
crack (>= 0.3.2) | ||
hashdiff (>= 0.4.0, < 2.0.0) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
dotenv (~> 2.7) | ||
minitest (~> 5.14) | ||
minitest-ci (~> 3.4) | ||
minitest-reporters (~> 1.4) | ||
mocha (~> 1.11) | ||
pry-byebug | ||
rake (~> 13.0) | ||
simplecov (~> 0.19) | ||
webmock (~> 3.10) | ||
|
||
RUBY VERSION | ||
ruby 2.6.6p146 | ||
|
||
BUNDLED WITH | ||
1.17.3 |
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,32 +1,74 @@ | ||
## Install | ||
# Github Repos workflow for Alfred | ||
|
||
Download from [packal](http://www.packal.org/workflow/github-repos-0) to keep it up to date. | ||
|
||
You can also check the [releases history](https://github.com/edgarjs/alfred-github-repos/releases). | ||
|
||
--- | ||
This is a custom workflow for the [Alfred app][alfred-app] that lets you search and open a Github repository via the Github Search API. | ||
|
||
## Authentication | ||
|
||
1. Call `gh-token` to generate personal access token. | ||
2. Login by calling the `gh-login <email> <token>` action. | ||
You'll need to authenticate with a personal access token that you can generate in the [Github developer settings page][personal-access-token] or by running the `gh-token` command in Alfred. | ||
|
||
After you have copied your personal access token, run `gh-login <your-token>` to set your personal access token. | ||
|
||
## Usage | ||
|
||
1. Search your repositories by calling the `gh <term>` action. | ||
2. Search all repositories by calling the `gha <term>` action. | ||
3. Your repositories are cached. To force re-download cache use `gh-reset-cache` action or choose corresponding item in the `gh <term>` action. | ||
Here's the list of available commands. | ||
|
||
### Global Search: `gh <query>` | ||
|
||
The example above will search for repositories with the string "hello-world" in their name. Internally this uses the [Github Search syntax][github-search], so you can use modifiers like: | ||
|
||
gh hello-world stars:>100 | ||
|
||
This will search only in repositories that have more than 100 stars. | ||
|
||
> Please note that this command only searches in the repository name. This means that your query will be appended with the `in:name` modifier. So when you type in `hello-world`, the final search query sent will be: "hello-world in:name". | ||
### Search your repositories: `repo [query]` | ||
|
||
This command works the same as the previous one (`gh <query>`) but it limits the search to your own repositories. | ||
|
||
### Other Actions | ||
> This includes repositories from your organizations as well. | ||
* `gh-notifications` will open your Github notifications page. | ||
### Search Pull Requests: `pr [query]` | ||
|
||
This command searches within the Pull Requests that you're involved in. | ||
|
||
### Open notifications: `gh-notifications` | ||
|
||
This command just opens your [Github notification][notifications-page] page. | ||
|
||
## Configuring host for Enterprise | ||
|
||
If you're using an Enterprise account, you can call the `gh-host <host>` command. | ||
|
||
--- | ||
|
||
### Enterprise Support | ||
## Contributing | ||
|
||
You can submit your bug reports or feature requests at: | ||
https://github.com/edgarjs/alfred-github-repos/issues | ||
|
||
If you want to submit a Pull Request, please follow these simple guides: | ||
|
||
1. Add a detailed description of what you're changing and why. | ||
2. Add necessary unit tests that cover your changes. | ||
3. Don't increase the version of the workflow in your changes. | ||
|
||
Here are some ideas for Pull Requests: | ||
|
||
- [ ] Make search faster | ||
- [ ] Search commits in a repository | ||
- [ ] Search projects in an organization | ||
- [ ] Improve icon graphics | ||
|
||
If you're using an enterprise account, set your enterprise host with `gh-host <host>`. | ||
## License | ||
|
||
The host value should be something like `https://example.com` | ||
This project is published under the [MIT License](LICENSE.md). | ||
|
||
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 | ||
[alfred-app]: https://www.alfredapp.com/ | ||
[github-search]: https://docs.github.com/en/free-pro-team@latest/github/searching-for-information-on-github/searching-on-github | ||
[download-packal]: https://www.packal.org/workflow/github-repos | ||
[download-releases]: https://github.com/edgarjs/alfred-github-repos/releases | ||
[personal-access-token]: https://github.com/settings/tokens/new?description=Github%20Repos%20Alfred%20workflow&scopes=repo | ||
[pulls-page]: https://github.com/pulls | ||
[notifications-page]: https://github.com/notifications | ||
[alfred-env-vars]: https://www.alfredapp.com/help/workflows/script-environment-variables/ |
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,13 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rake' | ||
require 'rake/testtask' | ||
|
||
Rake::TestTask.new(:test) do |t| | ||
t.libs << 'test' | ||
t.libs << 'apps' | ||
t.libs << 'lib' | ||
t.test_files = FileList['test/**/*_test.rb'] | ||
end | ||
|
||
task default: :test |
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,48 @@ | ||
# frozen_string_literal: true | ||
|
||
$stdout.sync = true | ||
$LOAD_PATH.unshift File.expand_path('lib') | ||
|
||
require 'data_source/client/github' | ||
require 'data_source/pull_requests' | ||
require 'data_source/repositories' | ||
require 'commands/help' | ||
require 'commands/search' | ||
require 'commands/user_repos' | ||
require 'commands/user_pulls' | ||
|
||
class App | ||
class << self | ||
def client | ||
DataSource::Client::Github.new( | ||
host: ENV['GITHUB_HOST'] || 'api.github.com', | ||
access_token: ENV['GITHUB_ACCESS_TOKEN'], | ||
cache_dir: ENV['alfred_workflow_cache'] | ||
) | ||
end | ||
|
||
def repositories | ||
DataSource::Repositories.new(client: client) | ||
end | ||
|
||
def pull_requests | ||
DataSource::PullRequests.new(client: client) | ||
end | ||
|
||
def help | ||
Commands::Help.new | ||
end | ||
|
||
def search | ||
Commands::Search.new(repositories: repositories) | ||
end | ||
|
||
def user_repos | ||
Commands::UserRepos.new(repositories: repositories) | ||
end | ||
|
||
def user_pulls | ||
Commands::UserPulls.new(pull_requests: pull_requests) | ||
end | ||
end | ||
end |
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,49 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
module Apps | ||
class Cli | ||
def initialize(search:, user_repos:, user_pulls:, help:) | ||
@search = search | ||
@user_repos = user_repos | ||
@user_pulls = user_pulls | ||
@help = help | ||
end | ||
|
||
def call(args) | ||
command = extract_command!(args) | ||
raise @help.call(args) unless command | ||
|
||
command.call(args) | ||
end | ||
|
||
private | ||
|
||
def extract_command!(args) | ||
case args.shift | ||
when 'search' then @search | ||
when 'user-repos' then @user_repos | ||
when 'user-pulls' then @user_pulls | ||
when 'help' then @help | ||
end | ||
end | ||
end | ||
end | ||
|
||
if __FILE__ == $0 | ||
require_relative '../app' | ||
|
||
begin | ||
cli = Apps::Cli.new( | ||
search: App.search, | ||
user_repos: App.user_repos, | ||
user_pulls: App.user_pulls, | ||
help: App.help | ||
) | ||
puts cli.call(ARGV) | ||
exit(true) | ||
rescue => error | ||
puts error | ||
exit(false) | ||
end | ||
end |
File renamed without changes
Oops, something went wrong.