Skip to content

Commit 242bb1f

Browse files
authored
Merge pull request #20 from openaustralia/chore/update-gem-metadata
Fill in gem metadata and refresh README
2 parents 2b511e4 + 7f0fa56 commit 242bb1f

11 files changed

Lines changed: 450 additions & 81 deletions

File tree

‎.rubocop.yml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ AllCops:
55
NewCops: enable
66
SuggestExtensions: false
77
TargetRubyVersion: 3.2
8+
9+
Metrics/BlockLength:
10+
Exclude:
11+
- "spec/**/*"

‎.rubocop_todo.yml‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9-
# Offense count: 1
10-
# This cop supports safe autocorrection (--autocorrect).
11-
Gemspec/RequireMFA:
12-
Exclude:
13-
- 'morph-cli.gemspec'
14-
159
# Offense count: 8
1610
# This cop supports safe autocorrection (--autocorrect).
1711
# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle.

‎CHANGELOG.md‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
### Changed
11+
12+
- Require Ruby 3.3 or later (was Ruby 2.7)
13+
- Replace unmaintained `rest-client` with `faraday` + `faraday-multipart`
14+
- Replace unmaintained `archive-tar-minitar` with `minitar` 1.x
15+
- Write the upload tarball to a temporary file instead of the shared `/tmp/out` path
16+
- Load `~/.morph` config with safe YAML loading
17+
- Fill in gem metadata: homepage, source code, bug tracker and changelog URIs; require
18+
MFA for manual pushes to RubyGems
19+
20+
### Added
21+
22+
- SimpleCov coverage reporting and a much expanded test suite (CLI and HTTP behaviour
23+
tested with WebMock, no network access in tests)
24+
25+
## [0.2.5] and earlier
26+
27+
No changelog was kept for releases up to and including 0.2.5. See the
28+
[commit history](https://github.com/openaustralia/morph-cli/commits/main) for details.
29+
30+
[Unreleased]: https://github.com/openaustralia/morph-cli/compare/v0.2.5...HEAD
31+
[0.2.5]: https://github.com/openaustralia/morph-cli/releases/tag/v0.2.5

‎Gemfile‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ group :development, :test do
88
gem "rake", "~> 13.0"
99
gem "rspec", "~> 3.0"
1010
gem "rubocop"
11+
gem "simplecov", require: false
12+
gem "webmock", "~> 3.0"
1113
end

‎README.md‎

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,67 @@
1-
[![Gem Version](https://badge.fury.io/rb/morph-cli.png)](http://badge.fury.io/rb/morph-cli)
1+
[![Gem Version](https://img.shields.io/gem/v/morph-cli)](https://rubygems.org/gems/morph-cli)
22
[![CI](https://github.com/openaustralia/morph-cli/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/openaustralia/morph-cli/actions/workflows/ci.yml)
33

4-
# Morph Commandline
4+
# Morph CLI
55

6-
Runs Morph scrapers from the commandline.
6+
Runs [morph.io](https://morph.io) scrapers from the command line.
77

8-
Actually it will run them on the Morph server identically to the real thing. That means not installing a bucket load of libraries
9-
and bits and bobs that are already installed with the Morph scraper environments.
8+
Actually it will run them on the morph.io server identically to the real thing.
9+
That means not installing a bucket load of libraries and bits and bobs that are
10+
already installed with the morph.io scraper environments.
1011

11-
To run a scraper in your local directory
12+
## Installation
13+
14+
You'll need Ruby 3.2 or later. Then
15+
16+
gem install morph-cli
17+
18+
## Usage
19+
20+
To run the scraper in your current directory
1221

1322
morph
1423

1524
Yup, that's it.
1625

17-
It runs the code that's there right now. It doesn't need to be checked into git or anything.
26+
It runs the code that's there right now. It doesn't need to be checked into git
27+
or anything.
28+
29+
The first time you run it, it will ask for your morph.io API key, which it
30+
saves in `~/.morph`.
1831

1932
For help
2033

2134
morph help
2235

23-
## Installation
36+
## Limitations
2437

25-
You'll need Ruby >= 1.9 and then
38+
It uploads your code every time. So if it's big it might take a little while.
39+
Scrapers are not usually so I'm hoping this won't really be an issue.
2640

27-
gem install morph-cli
41+
It doesn't yet return you the resulting sqlite database (or use the one you
42+
might have locally).
2843

29-
## Limitations
44+
## Development
3045

31-
It uploads your code everytime. So if it's big it might take a little while. Scrapers are not usually so I'm hoping this won't really be an issue
46+
After checking out the repo, run `bundle install` to install dependencies.
47+
Then run the tests with
3248

33-
It doesn't yet return you the resulting sqlite database (or use the one you might have locally)
49+
bundle exec rspec
3450

3551
## Contributing
3652

53+
Contributions are welcome! Please see the
54+
[OpenAustralia Foundation contributing guide](https://github.com/openaustralia/.github/blob/main/.github/CONTRIBUTING.md)
55+
for how we work: GitHub Flow, draft pull requests, signed-off commits (DCO)
56+
and our contributor licence agreement.
57+
3758
1. Fork it
38-
2. Create your feature branch (`git checkout -b my-new-feature`)
39-
3. Commit your changes (`git commit -am 'Add some feature'`)
40-
4. Push to the branch (`git push origin my-new-feature`)
41-
5. Create new Pull Request
59+
2. Create your feature branch (`git checkout -b feature/my-new-feature`)
60+
3. Commit your changes (`git commit -s -am 'Add some feature'`)
61+
4. Push to the branch (`git push origin feature/my-new-feature`)
62+
5. Create a new pull request
63+
64+
## License
65+
66+
The gem is available as open source under the terms of the
67+
[MIT License](LICENSE.txt).

‎bin/morph‎

Lines changed: 2 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,9 @@
11
#!/usr/bin/env ruby
22
# Commandline client for controlling morph and running scrapers and things
33

4-
require "thor"
54
# TODO: Do compression on the tar file
65
# require 'zlib'
7-
require 'morph-cli'
8-
9-
class MorphThor < Thor
10-
class_option :dev, default: false, type: :boolean, desc: "Run against development Morph (for morph developers)"
11-
12-
desc "[execute]", "execute morph scraper"
13-
option :directory, default: Dir.getwd
14-
15-
def execute
16-
config = MorphCLI.load_config
17-
env_config = if options[:dev]
18-
config[:development]
19-
else
20-
config[:production]
21-
end
22-
23-
config = ask_and_save_api_key(env_config, config) if env_config[:api_key].nil?
24-
25-
api_key_is_valid = false
26-
until api_key_is_valid
27-
begin
28-
MorphCLI.execute(options[:directory], options[:dev], env_config)
29-
api_key_is_valid = true
30-
rescue Faraday::UnauthorizedError
31-
puts "Your key isn't working. Let's try again."
32-
config = ask_and_save_api_key(env_config, config)
33-
rescue Faraday::ConnectionFailed => e
34-
warn "Morph doesn't look to be running at #{env_config[:base_url]} (#{e})"
35-
exit(1)
36-
rescue Faraday::ServerError => e
37-
warn "Uh oh. Something has gone wrong on the Morph server at #{env_config[:base_url]} (#{e})"
38-
exit(1)
39-
rescue Faraday::Error => e
40-
warn "Request to #{env_config[:base_url]} failed (#{e})"
41-
exit(1)
42-
end
43-
end
44-
end
45-
46-
desc "version", "Show Morph version number and quit"
47-
def version
48-
puts "Morph CLI #{MorphCLI::VERSION}"
49-
exit
50-
end
51-
52-
no_commands do
53-
def ask_and_save_api_key(env_config, config)
54-
env_config[:api_key] = ask("What is your key? (Go to #{env_config[:base_url]}/settings)")
55-
MorphCLI.save_config(config)
56-
config
57-
end
58-
end
59-
end
6+
require "morph-cli/cli"
607

618
# If morph is run without any parameters it's the same as "morph execute"
62-
MorphThor.start(ARGV.empty? ? ["execute"] : ARGV)
9+
MorphCLI::CLI.start(ARGV.empty? ? ["execute"] : ARGV)

‎lib/morph-cli/cli.rb‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# frozen_string_literal: true
2+
3+
require 'thor'
4+
require 'morph-cli'
5+
6+
module MorphCLI
7+
# Thor command line interface for running Morph scrapers
8+
class CLI < Thor
9+
def self.exit_on_failure?
10+
true
11+
end
12+
13+
class_option :dev, default: false, type: :boolean, desc: 'Run against development Morph (for morph developers)'
14+
15+
desc '[execute]', 'execute morph scraper'
16+
option :directory, default: Dir.getwd
17+
18+
def execute
19+
config = MorphCLI.load_config
20+
env_config = if options[:dev]
21+
config[:development]
22+
else
23+
config[:production]
24+
end
25+
26+
config = ask_and_save_api_key(env_config, config) if env_config[:api_key].nil?
27+
28+
api_key_is_valid = false
29+
until api_key_is_valid
30+
begin
31+
MorphCLI.execute(options[:directory], options[:dev], env_config)
32+
api_key_is_valid = true
33+
rescue Faraday::UnauthorizedError
34+
puts "Your key isn't working. Let's try again."
35+
config = ask_and_save_api_key(env_config, config)
36+
rescue Faraday::ConnectionFailed => e
37+
warn "Morph doesn't look to be running at #{env_config[:base_url]} (#{e})"
38+
exit(1)
39+
rescue Faraday::ServerError => e
40+
warn "Uh oh. Something has gone wrong on the Morph server at #{env_config[:base_url]} (#{e})"
41+
exit(1)
42+
rescue Faraday::Error => e
43+
warn "Request to #{env_config[:base_url]} failed (#{e})"
44+
exit(1)
45+
end
46+
end
47+
end
48+
49+
desc 'version', 'Show Morph version number and quit'
50+
def version
51+
puts "Morph CLI #{MorphCLI::VERSION}"
52+
exit
53+
end
54+
55+
no_commands do
56+
def ask_and_save_api_key(env_config, config)
57+
env_config[:api_key] = ask("What is your key? (Go to #{env_config[:base_url]}/settings)")
58+
MorphCLI.save_config(config)
59+
config
60+
end
61+
end
62+
end
63+
end

‎morph-cli.gemspec‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,23 @@ Gem::Specification.new do |spec|
77
spec.version = MorphCLI::VERSION
88
spec.authors = ["Matthew Landauer"]
99
spec.email = ["matthew@oaf.org.au"]
10-
spec.description = "Command line interface for Morph"
11-
spec.summary = "Command line interface for Morph"
12-
spec.homepage = ""
10+
spec.summary = "Run morph.io scrapers from the command line"
11+
spec.description = "Command line interface for morph.io. Uploads the scraper in the " \
12+
"current directory to a morph.io server, runs it there and streams " \
13+
"the output back to your terminal."
14+
spec.homepage = "https://github.com/openaustralia/morph-cli"
1315
spec.license = "MIT"
1416

1517
spec.required_ruby_version = ">= 3.2"
1618

19+
spec.metadata = {
20+
"homepage_uri" => "https://github.com/openaustralia/morph-cli",
21+
"source_code_uri" => "https://github.com/openaustralia/morph-cli",
22+
"bug_tracker_uri" => "https://github.com/openaustralia/morph-cli/issues",
23+
"changelog_uri" => "https://github.com/openaustralia/morph-cli/blob/main/CHANGELOG.md",
24+
"rubygems_mfa_required" => "true"
25+
}
26+
1727
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
1828
spec.executables = %w[morph]
1929
spec.require_paths = ["lib"]

0 commit comments

Comments
 (0)