Skip to content

Commit bee41ec

Browse files
committed
Refactor and add tests for better maintainability
1 parent fff0208 commit bee41ec

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2206
-686
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
*.alfredworkflow
2+
build/
3+
coverage/

Gemfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# frozen_string_literal: true
2+
3+
source 'https://rubygems.org'
4+
ruby '>= 2.5.0'
5+
6+
group :development do
7+
gem 'dotenv', '~> 2.7', require: 'dotenv/load'
8+
gem 'rake', '~> 13.0', require: false
9+
end
10+
11+
group :test do
12+
gem 'minitest', '~> 5.14', require: 'minitest/autorun'
13+
gem 'minitest-ci', '~> 3.4', require: false
14+
gem 'minitest-reporters', '~> 1.4'
15+
gem 'mocha', '~> 1.11', require: 'mocha/minitest'
16+
gem 'simplecov', '~> 0.19', require: false
17+
gem 'webmock', '~> 3.10', require: 'webmock/minitest'
18+
end
19+
20+
group :development, :test do
21+
gem 'pry-byebug'
22+
end

Gemfile.lock

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
addressable (2.7.0)
5+
public_suffix (>= 2.0.2, < 5.0)
6+
ansi (1.5.0)
7+
builder (3.2.4)
8+
byebug (11.1.3)
9+
coderay (1.1.3)
10+
crack (0.4.4)
11+
docile (1.3.2)
12+
dotenv (2.7.6)
13+
hashdiff (1.0.1)
14+
method_source (1.0.0)
15+
minitest (5.14.2)
16+
minitest-ci (3.4.0)
17+
minitest (>= 5.0.6)
18+
minitest-reporters (1.4.2)
19+
ansi
20+
builder
21+
minitest (>= 5.0)
22+
ruby-progressbar
23+
mocha (1.11.2)
24+
pry (0.13.1)
25+
coderay (~> 1.1)
26+
method_source (~> 1.0)
27+
pry-byebug (3.9.0)
28+
byebug (~> 11.0)
29+
pry (~> 0.13.0)
30+
public_suffix (4.0.6)
31+
rake (13.0.1)
32+
ruby-progressbar (1.10.1)
33+
simplecov (0.19.1)
34+
docile (~> 1.1)
35+
simplecov-html (~> 0.11)
36+
simplecov-html (0.12.3)
37+
webmock (3.10.0)
38+
addressable (>= 2.3.6)
39+
crack (>= 0.3.2)
40+
hashdiff (>= 0.4.0, < 2.0.0)
41+
42+
PLATFORMS
43+
ruby
44+
45+
DEPENDENCIES
46+
dotenv (~> 2.7)
47+
minitest (~> 5.14)
48+
minitest-ci (~> 3.4)
49+
minitest-reporters (~> 1.4)
50+
mocha (~> 1.11)
51+
pry-byebug
52+
rake (~> 13.0)
53+
simplecov (~> 0.19)
54+
webmock (~> 3.10)
55+
56+
RUBY VERSION
57+
ruby 2.6.6p146
58+
59+
BUNDLED WITH
60+
1.17.3

README.md

Lines changed: 59 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,74 @@
1-
## Install
1+
# Github Repos workflow for Alfred
22

3-
Download from [packal](http://www.packal.org/workflow/github-repos-0) to keep it up to date.
4-
5-
You can also check the [releases history](https://github.com/edgarjs/alfred-github-repos/releases).
6-
7-
---
3+
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.
84

95
## Authentication
106

11-
1. Call `gh-token` to generate personal access token.
12-
2. Login by calling the `gh-login <email> <token>` action.
7+
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.
8+
9+
After you have copied your personal access token, run `gh-login <your-token>` to set your personal access token.
1310

1411
## Usage
1512

16-
1. Search your repositories by calling the `gh <term>` action.
17-
2. Search all repositories by calling the `gha <term>` action.
18-
3. Your repositories are cached. To force re-download cache use `gh-reset-cache` action or choose corresponding item in the `gh <term>` action.
13+
Here's the list of available commands.
14+
15+
### Global Search: `gh <query>`
16+
17+
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:
18+
19+
gh hello-world stars:>100
20+
21+
This will search only in repositories that have more than 100 stars.
22+
23+
> 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".
24+
25+
### Search your repositories: `repo [query]`
26+
27+
This command works the same as the previous one (`gh <query>`) but it limits the search to your own repositories.
1928

20-
### Other Actions
29+
> This includes repositories from your organizations as well.
2130
22-
* `gh-notifications` will open your Github notifications page.
31+
### Search Pull Requests: `pr [query]`
32+
33+
This command searches within the Pull Requests that you're involved in.
34+
35+
### Open notifications: `gh-notifications`
36+
37+
This command just opens your [Github notification][notifications-page] page.
38+
39+
## Configuring host for Enterprise
40+
41+
If you're using an Enterprise account, you can call the `gh-host <host>` command.
2342

2443
---
2544

26-
### Enterprise Support
45+
## Contributing
46+
47+
You can submit your bug reports or feature requests at:
48+
https://github.com/edgarjs/alfred-github-repos/issues
49+
50+
If you want to submit a Pull Request, please follow these simple guides:
51+
52+
1. Add a detailed description of what you're changing and why.
53+
2. Add necessary unit tests that cover your changes.
54+
3. Don't increase the version of the workflow in your changes.
55+
56+
Here are some ideas for Pull Requests:
57+
58+
- [ ] Make search faster
59+
- [ ] Search commits in a repository
60+
- [ ] Search projects in an organization
61+
- [ ] Improve icon graphics
2762

28-
If you're using an enterprise account, set your enterprise host with `gh-host <host>`.
63+
## License
2964

30-
The host value should be something like `https://example.com`
65+
This project is published under the [MIT License](LICENSE.md).
3166

32-
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
67+
[alfred-app]: https://www.alfredapp.com/
68+
[github-search]: https://docs.github.com/en/free-pro-team@latest/github/searching-for-information-on-github/searching-on-github
69+
[download-packal]: https://www.packal.org/workflow/github-repos
70+
[download-releases]: https://github.com/edgarjs/alfred-github-repos/releases
71+
[personal-access-token]: https://github.com/settings/tokens/new?description=Github%20Repos%20Alfred%20workflow&scopes=repo
72+
[pulls-page]: https://github.com/pulls
73+
[notifications-page]: https://github.com/notifications
74+
[alfred-env-vars]: https://www.alfredapp.com/help/workflows/script-environment-variables/

Rakefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
require 'rake'
4+
require 'rake/testtask'
5+
6+
Rake::TestTask.new(:test) do |t|
7+
t.libs << 'test'
8+
t.libs << 'apps'
9+
t.libs << 'lib'
10+
t.test_files = FileList['test/**/*_test.rb']
11+
end
12+
13+
task default: :test

app.rb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# frozen_string_literal: true
2+
3+
$stdout.sync = true
4+
$LOAD_PATH.unshift File.expand_path('lib')
5+
6+
require 'data_source/client/github'
7+
require 'data_source/pull_requests'
8+
require 'data_source/repositories'
9+
require 'commands/help'
10+
require 'commands/search'
11+
require 'commands/user_repos'
12+
require 'commands/user_pulls'
13+
14+
class App
15+
class << self
16+
def client
17+
DataSource::Client::Github.new(
18+
host: ENV['GITHUB_HOST'] || 'api.github.com',
19+
access_token: ENV['GITHUB_ACCESS_TOKEN'],
20+
cache_dir: ENV['alfred_workflow_cache']
21+
)
22+
end
23+
24+
def repositories
25+
DataSource::Repositories.new(client: client)
26+
end
27+
28+
def pull_requests
29+
DataSource::PullRequests.new(client: client)
30+
end
31+
32+
def help
33+
Commands::Help.new
34+
end
35+
36+
def search
37+
Commands::Search.new(repositories: repositories)
38+
end
39+
40+
def user_repos
41+
Commands::UserRepos.new(repositories: repositories)
42+
end
43+
44+
def user_pulls
45+
Commands::UserPulls.new(pull_requests: pull_requests)
46+
end
47+
end
48+
end

apps/cli

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
module Apps
5+
class Cli
6+
def initialize(search:, user_repos:, user_pulls:, help:)
7+
@search = search
8+
@user_repos = user_repos
9+
@user_pulls = user_pulls
10+
@help = help
11+
end
12+
13+
def call(args)
14+
command = extract_command!(args)
15+
raise @help.call(args) unless command
16+
17+
command.call(args)
18+
end
19+
20+
private
21+
22+
def extract_command!(args)
23+
case args.shift
24+
when 'search' then @search
25+
when 'user-repos' then @user_repos
26+
when 'user-pulls' then @user_pulls
27+
when 'help' then @help
28+
end
29+
end
30+
end
31+
end
32+
33+
if __FILE__ == $0
34+
require_relative '../app'
35+
36+
begin
37+
cli = Apps::Cli.new(
38+
search: App.search,
39+
user_repos: App.user_repos,
40+
user_pulls: App.user_pulls,
41+
help: App.help
42+
)
43+
puts cli.call(ARGV)
44+
exit(true)
45+
rescue => error
46+
puts error
47+
exit(false)
48+
end
49+
end
File renamed without changes.

0 commit comments

Comments
 (0)