specular 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +74 -0
- data/LICENSE.txt +21 -0
- data/README.md +74 -0
- data/Rakefile +6 -0
- data/VERSION +1 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/specular +95 -0
- data/lib/specular.rb +184 -0
- data/lib/specular/integration.rb +31 -0
- data/lib/specular/integration/github.rb +79 -0
- data/lib/specular/integration/slack.rb +24 -0
- data/lib/specular/support.rb +19 -0
- data/lib/specular/version.rb +5 -0
- data/specular.gemspec +33 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c34275b2fe69d228a69f3a8cf3b716c52f8529b76bca2f6073afe69b0ba90de7
|
4
|
+
data.tar.gz: 447d501c2a15e313690ebf3382a38829bb43e257e53775f8242e6b9c1a9497b4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5a5ed975158df099fe874c32f69cc8c7bdf24f436106259fe288960ec632a771f236fc271f9f43be94fa32488c2f1a21b7d2176072a9cc58ff7b8929e241a8de
|
7
|
+
data.tar.gz: f5c43c21574f9dd9b1da061ee67dcca36135c68a1999cce3793c8fc22d903055256d621e17f29da98357491323be70d703d0ad1fddf6685b5f13e775f113221f
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at tadman@postageapp.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
specular (0.5.0)
|
5
|
+
graphql-client
|
6
|
+
liquid
|
7
|
+
slack-ruby-client
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
activesupport (6.0.3.4)
|
13
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
|
+
i18n (>= 0.7, < 2)
|
15
|
+
minitest (~> 5.1)
|
16
|
+
tzinfo (~> 1.1)
|
17
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
18
|
+
concurrent-ruby (1.1.7)
|
19
|
+
diff-lcs (1.4.4)
|
20
|
+
faraday (1.1.0)
|
21
|
+
multipart-post (>= 1.2, < 3)
|
22
|
+
ruby2_keywords
|
23
|
+
faraday_middleware (1.0.0)
|
24
|
+
faraday (~> 1.0)
|
25
|
+
gli (2.19.2)
|
26
|
+
graphql (1.11.6)
|
27
|
+
graphql-client (0.16.0)
|
28
|
+
activesupport (>= 3.0)
|
29
|
+
graphql (~> 1.8)
|
30
|
+
hashie (4.1.0)
|
31
|
+
i18n (1.8.5)
|
32
|
+
concurrent-ruby (~> 1.0)
|
33
|
+
liquid (4.0.3)
|
34
|
+
minitest (5.14.2)
|
35
|
+
multipart-post (2.1.1)
|
36
|
+
rake (13.0.1)
|
37
|
+
rspec (3.10.0)
|
38
|
+
rspec-core (~> 3.10.0)
|
39
|
+
rspec-expectations (~> 3.10.0)
|
40
|
+
rspec-mocks (~> 3.10.0)
|
41
|
+
rspec-core (3.10.0)
|
42
|
+
rspec-support (~> 3.10.0)
|
43
|
+
rspec-expectations (3.10.0)
|
44
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
45
|
+
rspec-support (~> 3.10.0)
|
46
|
+
rspec-mocks (3.10.0)
|
47
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
48
|
+
rspec-support (~> 3.10.0)
|
49
|
+
rspec-support (3.10.0)
|
50
|
+
ruby2_keywords (0.0.2)
|
51
|
+
slack-ruby-client (0.15.1)
|
52
|
+
faraday (>= 1.0)
|
53
|
+
faraday_middleware
|
54
|
+
gli
|
55
|
+
hashie
|
56
|
+
websocket-driver
|
57
|
+
thread_safe (0.3.6)
|
58
|
+
tzinfo (1.2.8)
|
59
|
+
thread_safe (~> 0.1)
|
60
|
+
websocket-driver (0.7.3)
|
61
|
+
websocket-extensions (>= 0.1.0)
|
62
|
+
websocket-extensions (0.1.5)
|
63
|
+
zeitwerk (2.4.1)
|
64
|
+
|
65
|
+
PLATFORMS
|
66
|
+
ruby
|
67
|
+
|
68
|
+
DEPENDENCIES
|
69
|
+
rake
|
70
|
+
rspec
|
71
|
+
specular!
|
72
|
+
|
73
|
+
BUNDLED WITH
|
74
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 PostageApp Ltd., Scott Tadman
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Specular
|
2
|
+
|
3
|
+
Specular is an RSpec to GitHub Issues bridging tool where the
|
4
|
+
output of an RSpec run is read, and if necessary, converted
|
5
|
+
into Markdown and posted to a GitHub Issue.
|
6
|
+
|
7
|
+
When running tests in a Continuous Integration environment like
|
8
|
+
GitHub Actions the output is often buried in a log. This makes
|
9
|
+
identifying specific test failures difficult.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'specular'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
```shell
|
22
|
+
bundle install
|
23
|
+
```
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
```shell
|
28
|
+
gem install specular
|
29
|
+
```
|
30
|
+
|
31
|
+
## Configuration
|
32
|
+
|
33
|
+
To create GitHub issues requires a [Personal Access Token](https://github.com/settings/tokens).
|
34
|
+
|
35
|
+
## Usage
|
36
|
+
|
37
|
+
The command-line interface is the most straightforward:
|
38
|
+
|
39
|
+
```shell
|
40
|
+
rspec --format json | specular
|
41
|
+
```
|
42
|
+
|
43
|
+
If the test run was successful then `specular` will return status code 0,
|
44
|
+
otherwise -1. This can be disabled with the `--clean-exit` option to avoid
|
45
|
+
returning a failing exit code and breaking an execution chain.
|
46
|
+
|
47
|
+
## Development
|
48
|
+
|
49
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then,
|
50
|
+
run `rake spec` to run the tests. You can also run `bin/console` for an
|
51
|
+
interactive prompt that will allow you to experiment.
|
52
|
+
|
53
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
54
|
+
To release a new version, update the version number in `version.rb`, and then
|
55
|
+
run `bundle exec rake release`, which will create a git tag for the version,
|
56
|
+
push git commits and tags, and push the `.gem` file to
|
57
|
+
[Rubygems](https://rubygems.org).
|
58
|
+
|
59
|
+
## Contributing
|
60
|
+
|
61
|
+
Bug reports and pull requests are welcome on [GitHub](https://github.com/postageapp/specular).
|
62
|
+
This project is intended to be a safe, welcoming space for collaboration, and
|
63
|
+
contributors are expected to adhere to the
|
64
|
+
[Code of Conduct](https://github.com/postageapp/specular/blob/master/CODE_OF_CONDUCT.md).
|
65
|
+
|
66
|
+
## License
|
67
|
+
|
68
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
69
|
+
|
70
|
+
## Code of Conduct
|
71
|
+
|
72
|
+
Everyone interacting in the Specular project's codebases, issue trackers, chat
|
73
|
+
rooms and mailing lists is expected to follow the
|
74
|
+
[Code of Conduct](https://github.com/postageapp/specular/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.5.0
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "specular"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/specular
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# == Imports ================================================================
|
4
|
+
|
5
|
+
$LOAD_PATH << File.expand_path('../lib', __dir__)
|
6
|
+
|
7
|
+
require 'optparse'
|
8
|
+
require 'yaml'
|
9
|
+
require 'json'
|
10
|
+
|
11
|
+
require 'specular'
|
12
|
+
|
13
|
+
# == Constants ==============================================================
|
14
|
+
|
15
|
+
DEFAULTS = {
|
16
|
+
slack_token: ENV['SLACK_TOKEN'],
|
17
|
+
github_token: ENV['GH_TOKEN'],
|
18
|
+
repo: ENV['GIT_REPO'],
|
19
|
+
ref: ENV['GIT_REF']
|
20
|
+
}.freeze
|
21
|
+
|
22
|
+
# == Main ===================================================================
|
23
|
+
|
24
|
+
options = {
|
25
|
+
}
|
26
|
+
|
27
|
+
program = OptionParser.new do |opts|
|
28
|
+
opts.on('-s', '--silent')
|
29
|
+
opts.on('--slack-token TOKEN', 'Post notification to Slack at given TOKEN')
|
30
|
+
opts.on('--github-token TOKEN', 'Access GitHub using given access token')
|
31
|
+
opts.on('-I', '--issue', 'Create GitHub issue')
|
32
|
+
opts.on('-M', '--message', 'Create Slack message')
|
33
|
+
opts.on('--show-passing', 'Show passing tests')
|
34
|
+
opts.on('--show-skipped', 'Show skipped tests')
|
35
|
+
opts.on('-a', '--show-all', 'Show all tests')
|
36
|
+
opts.on('-A', '--always', 'Always create an issue, even on success')
|
37
|
+
opts.on('-o', '--output', 'Display generated issue')
|
38
|
+
opts.on('-f', '--config FILE', 'Read defaults from given file (YAML format)')
|
39
|
+
opts.on('-x', '--clean-exit', 'Do not exit with failing error code on test failure')
|
40
|
+
opts.on('-r', '--repo URL', 'Base repository URL')
|
41
|
+
opts.on('-R', '--ref REF', 'Use git branch ref in links')
|
42
|
+
end
|
43
|
+
|
44
|
+
program.parse(ARGV, into: options)
|
45
|
+
|
46
|
+
options.transform_keys! do |k|
|
47
|
+
k.to_s.tr('-', '_').to_sym
|
48
|
+
end
|
49
|
+
|
50
|
+
config_default_path = File.expand_path('.specular', Dir.pwd)
|
51
|
+
|
52
|
+
if (options[:config])
|
53
|
+
unless (File.exist?(options[:config]))
|
54
|
+
$stderr.puts("Could not read config file %s" % options[:config])
|
55
|
+
exit(-11)
|
56
|
+
end
|
57
|
+
elsif (File.exist?(config_default_path))
|
58
|
+
options[:config] = config_default_path
|
59
|
+
end
|
60
|
+
|
61
|
+
if (options[:config])
|
62
|
+
config = YAML.load(
|
63
|
+
File.read(options[:config]),
|
64
|
+
symbolize_names: true
|
65
|
+
).transform_keys do |k|
|
66
|
+
k.to_s.tr('-', '_').to_sym
|
67
|
+
end
|
68
|
+
|
69
|
+
options = config.merge(options)
|
70
|
+
end
|
71
|
+
|
72
|
+
options = DEFAULTS.merge(options)
|
73
|
+
|
74
|
+
results = JSON.parse($stdin.read, symbolize_names: true)
|
75
|
+
|
76
|
+
specular = Specular.new(
|
77
|
+
results,
|
78
|
+
**options
|
79
|
+
)
|
80
|
+
|
81
|
+
if (options[:output])
|
82
|
+
puts specular.report(title: true)
|
83
|
+
end
|
84
|
+
|
85
|
+
if ((options[:always] or specular.failures?) and options[:issue])
|
86
|
+
specular.create_issue!
|
87
|
+
end
|
88
|
+
|
89
|
+
if ((options[:always] or specular.failures?) and options[:message])
|
90
|
+
specular.post_message!
|
91
|
+
end
|
92
|
+
|
93
|
+
if (!options[:clean_exit] and specular.failures?)
|
94
|
+
exit(-1)
|
95
|
+
end
|
data/lib/specular.rb
ADDED
@@ -0,0 +1,184 @@
|
|
1
|
+
require 'open3'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
require 'liquid'
|
5
|
+
|
6
|
+
require 'specular/version'
|
7
|
+
|
8
|
+
class Specular
|
9
|
+
# == Constants ============================================================
|
10
|
+
|
11
|
+
STATUS_LABEL = {
|
12
|
+
failed: 'Failed 🛑',
|
13
|
+
passed: 'Passed ✅',
|
14
|
+
skipped: 'Skipped ⚠️'
|
15
|
+
}.freeze
|
16
|
+
|
17
|
+
MESSAGE_EVENTS = %i[ default success failure ].freeze
|
18
|
+
|
19
|
+
MESSAGES = {
|
20
|
+
slack: {
|
21
|
+
default: 'RSpec tests for {% if repo %}<{{repo}}|{{name}}>{% else %}{{name}}{% endif %} have {% if created_issues.github.url %}<{{created_issues.github.url}}|{{result}}>{% else %}{{result}}{% endif %}'
|
22
|
+
},
|
23
|
+
github: {
|
24
|
+
default: 'RSpec test report ({{result}})'
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
REF_DEFAULT = 'main'
|
29
|
+
|
30
|
+
# == Extensions ===========================================================
|
31
|
+
|
32
|
+
# == Exceptions ===========================================================
|
33
|
+
|
34
|
+
class Error < StandardError; end
|
35
|
+
|
36
|
+
# == Properties ===========================================================
|
37
|
+
|
38
|
+
attr_reader :results
|
39
|
+
|
40
|
+
# == Class Methods ========================================================
|
41
|
+
|
42
|
+
# == Instance Methods =====================================================
|
43
|
+
|
44
|
+
def initialize(results, **context)
|
45
|
+
@results = results
|
46
|
+
@context = context
|
47
|
+
|
48
|
+
if (@context[:repo] and !@context[:repo].end_with?('/'))
|
49
|
+
@context[:repo] = '%s/' % @context[:repo]
|
50
|
+
end
|
51
|
+
|
52
|
+
@context[:result] = self.failures? ? :failed : :passed
|
53
|
+
|
54
|
+
@context[:messages] = MESSAGES.keys.to_h do |type|
|
55
|
+
[
|
56
|
+
type,
|
57
|
+
MESSAGE_EVENTS.to_h do |event|
|
58
|
+
[
|
59
|
+
event,
|
60
|
+
@context.dig(:messages, type, event) || MESSAGES.dig(type, event)
|
61
|
+
]
|
62
|
+
end
|
63
|
+
]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def git_ref
|
68
|
+
@context[:ref] ||= Open3.popen3('git', 'rev-parse', 'HEAD') do |_sin, sout, _serr, _proc|
|
69
|
+
sout.readlines.first.chomp
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def failures?
|
74
|
+
@results.dig(:summary, :failure_count) > 0
|
75
|
+
end
|
76
|
+
|
77
|
+
def message(service: :github)
|
78
|
+
Liquid::Template.parse(
|
79
|
+
@context.dig(:messages, service, @context[:result]) ||
|
80
|
+
@context.dig(:messages, service, :default)
|
81
|
+
).render(Specular::Support.stringify_keys(@context))
|
82
|
+
end
|
83
|
+
|
84
|
+
def examples
|
85
|
+
if (@context.dig(:show, :all))
|
86
|
+
@results[:examples]
|
87
|
+
else
|
88
|
+
@results[:examples].select do |example|
|
89
|
+
example[:status] == 'failed'
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def status_label(status)
|
95
|
+
STATUS_LABEL[status.to_sym] || status
|
96
|
+
end
|
97
|
+
|
98
|
+
def source_link(file, line)
|
99
|
+
if (@context[:repo])
|
100
|
+
'[`%s:%d`](%s#L%d)' % [
|
101
|
+
file,
|
102
|
+
line,
|
103
|
+
URI.join(
|
104
|
+
@context[:repo] + 'blob/%s/' % [
|
105
|
+
self.git_ref,
|
106
|
+
],
|
107
|
+
file
|
108
|
+
),
|
109
|
+
line
|
110
|
+
]
|
111
|
+
else
|
112
|
+
'`%s:%d`' % [
|
113
|
+
file,
|
114
|
+
line
|
115
|
+
]
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def result_format(result)
|
120
|
+
return unless (result)
|
121
|
+
|
122
|
+
"```\n%s%s```\n" % [
|
123
|
+
result,
|
124
|
+
result.end_with?("\n") ? "" : "\n"
|
125
|
+
]
|
126
|
+
end
|
127
|
+
|
128
|
+
def report(title: false)
|
129
|
+
[
|
130
|
+
*(title ? ("<!-- %s -->\n" % self.message(service: :github)) : ()),
|
131
|
+
"## Test Results\n",
|
132
|
+
self.examples.map do |example|
|
133
|
+
case (example[:status])
|
134
|
+
when 'failed'
|
135
|
+
"### %s\n\n**Status:** %s\n**Source:** %s\n\n%s" % [
|
136
|
+
example[:full_description],
|
137
|
+
status_label(example[:status]),
|
138
|
+
source_link(example[:file_path], example[:line_number]),
|
139
|
+
result_format(example.dig(:exception, :message))
|
140
|
+
]
|
141
|
+
else
|
142
|
+
"### %s\n\n**Status:** %s\n**Source:** %s\n\n" % [
|
143
|
+
example[:full_description],
|
144
|
+
status_label(example[:status]),
|
145
|
+
source_link(example[:file_path], example[:line_number])
|
146
|
+
]
|
147
|
+
end
|
148
|
+
end,
|
149
|
+
"## Summary\n\n**Duration:** %.2fs\n**Failures:** %d\n" % [
|
150
|
+
@results.dig(:summary, :duration),
|
151
|
+
@results.dig(:summary, :failure_count)
|
152
|
+
],
|
153
|
+
"## Git Context\n**Ref:** %s" % [
|
154
|
+
self.git_ref
|
155
|
+
]
|
156
|
+
].join("\n")
|
157
|
+
end
|
158
|
+
|
159
|
+
def create_issue!(services = %i[ github ])
|
160
|
+
@context[:created_issues] = services.to_h do |service|
|
161
|
+
[
|
162
|
+
service,
|
163
|
+
Specular::Integration.for(service, @context).create_issue!(
|
164
|
+
title: self.message(service: service),
|
165
|
+
body: self.report
|
166
|
+
)
|
167
|
+
]
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
def post_message!(services = %i[ slack ])
|
172
|
+
@context[:posted_messages] = services.to_h do |service|
|
173
|
+
[
|
174
|
+
service,
|
175
|
+
Specular::Integration.for(service, @context).post_message!(
|
176
|
+
message: self.message(service: service)
|
177
|
+
)
|
178
|
+
]
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
require_relative 'specular/integration'
|
184
|
+
require_relative 'specular/support'
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Specular::Integration
|
2
|
+
INTEGRATIONS = { }
|
3
|
+
|
4
|
+
def self.for(name, context)
|
5
|
+
integration = INTEGRATIONS[name]
|
6
|
+
|
7
|
+
integration.new(
|
8
|
+
**integration.extract_args(context)
|
9
|
+
)
|
10
|
+
end
|
11
|
+
|
12
|
+
class Base
|
13
|
+
def self.handler(*names)
|
14
|
+
names.each do |name|
|
15
|
+
INTEGRATIONS[name] = self
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.arguments(*args)
|
20
|
+
define_singleton_method(:extract_args) do |context|
|
21
|
+
args.to_h do |arg|
|
22
|
+
[ arg, context[arg] ]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
Dir.glob(File.expand_path('integration/*.rb', __dir__)).each do |path|
|
30
|
+
require path
|
31
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'graphql/client'
|
2
|
+
require 'graphql/client/http'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
class Specular::Integration::GitHub < Specular::Integration::Base
|
6
|
+
handler :github
|
7
|
+
arguments :github_token, :repo
|
8
|
+
|
9
|
+
def initialize(github_token:, repo:)
|
10
|
+
@https = GraphQL::Client::HTTP.new('https://api.github.com/graphql') do
|
11
|
+
define_method(:headers) do |_context|
|
12
|
+
{
|
13
|
+
"User-Agent": "Specular/#{Specular.version}",
|
14
|
+
"Authorization": "Bearer #{github_token}"
|
15
|
+
}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
@repo = repo
|
20
|
+
|
21
|
+
@schema = GraphQL::Client.load_schema(@https)
|
22
|
+
@client = GraphQL::Client.new(schema: @schema, execute: @https)
|
23
|
+
|
24
|
+
@client.allow_dynamic_queries = true
|
25
|
+
end
|
26
|
+
|
27
|
+
def repository_query
|
28
|
+
@repository_query ||= @client.parse <<-'GRAPHQL'
|
29
|
+
query ($name: String!, $owner: String!) {
|
30
|
+
repository(name: $name, owner: $owner) {
|
31
|
+
id
|
32
|
+
}
|
33
|
+
}
|
34
|
+
GRAPHQL
|
35
|
+
end
|
36
|
+
|
37
|
+
def issue_mutation
|
38
|
+
@issue_mutation ||= @client.parse <<-'GRAPHQL'
|
39
|
+
mutation ($input: CreateIssueInput!) {
|
40
|
+
createIssue(input: $input) {
|
41
|
+
issue {
|
42
|
+
url
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}
|
46
|
+
GRAPHQL
|
47
|
+
end
|
48
|
+
|
49
|
+
def repository_id
|
50
|
+
owner, name = URI.parse(@repo).path.split('/')[1,2]
|
51
|
+
|
52
|
+
result = @client.query(
|
53
|
+
self.repository_query,
|
54
|
+
variables: {
|
55
|
+
name: name,
|
56
|
+
owner: owner
|
57
|
+
}
|
58
|
+
)
|
59
|
+
|
60
|
+
result.data.repository.id
|
61
|
+
end
|
62
|
+
|
63
|
+
def create_issue!(title:, body:)
|
64
|
+
result = @client.query(
|
65
|
+
self.issue_mutation,
|
66
|
+
variables: {
|
67
|
+
input: {
|
68
|
+
title: title,
|
69
|
+
body: body,
|
70
|
+
repositoryId: self.repository_id
|
71
|
+
}
|
72
|
+
}
|
73
|
+
)
|
74
|
+
|
75
|
+
{
|
76
|
+
url: result.data.create_issue.issue.url
|
77
|
+
}
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'slack-ruby-client'
|
2
|
+
|
3
|
+
class Specular::Integration::Slack < Specular::Integration::Base
|
4
|
+
handler :slack
|
5
|
+
arguments :slack_token, :slack_channel
|
6
|
+
|
7
|
+
def initialize(slack_token:, slack_channel:)
|
8
|
+
@slack_token = slack_token
|
9
|
+
@slack_channel = slack_channel
|
10
|
+
|
11
|
+
Slack::Web::Client.configure do |config|
|
12
|
+
config.token = slack_token
|
13
|
+
end
|
14
|
+
|
15
|
+
@client = Slack::Web::Client.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def post_message!(message:)
|
19
|
+
@client.chat_postMessage(
|
20
|
+
channel: @slack_channel,
|
21
|
+
text: message
|
22
|
+
)
|
23
|
+
end
|
24
|
+
end
|
data/specular.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require_relative 'lib/specular/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'specular'
|
5
|
+
spec.version = Specular.version
|
6
|
+
spec.authors = [ 'Scott Tadman' ]
|
7
|
+
spec.email = [ 'tadman@postageapp.com' ]
|
8
|
+
|
9
|
+
spec.summary = %q{RSpec to GitHub/Slack bridge tool}
|
10
|
+
spec.description = %q{Exports results from RSpec to GitHub, GitHub Issues, and Slack}
|
11
|
+
spec.homepage = 'https://github.com/postageapp/specular'
|
12
|
+
spec.license = 'MIT'
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
|
14
|
+
|
15
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org/'
|
16
|
+
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
18
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
19
|
+
spec.metadata['changelog_uri'] = spec.homepage
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.bindir = 'exe'
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = %w[ lib ]
|
29
|
+
|
30
|
+
spec.add_runtime_dependency 'liquid'
|
31
|
+
spec.add_runtime_dependency 'graphql-client'
|
32
|
+
spec.add_runtime_dependency 'slack-ruby-client'
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: specular
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Scott Tadman
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-11-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: liquid
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: graphql-client
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: slack-ruby-client
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Exports results from RSpec to GitHub, GitHub Issues, and Slack
|
56
|
+
email:
|
57
|
+
- tadman@postageapp.com
|
58
|
+
executables:
|
59
|
+
- specular
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".travis.yml"
|
66
|
+
- CODE_OF_CONDUCT.md
|
67
|
+
- Gemfile
|
68
|
+
- Gemfile.lock
|
69
|
+
- LICENSE.txt
|
70
|
+
- README.md
|
71
|
+
- Rakefile
|
72
|
+
- VERSION
|
73
|
+
- bin/console
|
74
|
+
- bin/setup
|
75
|
+
- exe/specular
|
76
|
+
- lib/specular.rb
|
77
|
+
- lib/specular/integration.rb
|
78
|
+
- lib/specular/integration/github.rb
|
79
|
+
- lib/specular/integration/slack.rb
|
80
|
+
- lib/specular/support.rb
|
81
|
+
- lib/specular/version.rb
|
82
|
+
- specular.gemspec
|
83
|
+
homepage: https://github.com/postageapp/specular
|
84
|
+
licenses:
|
85
|
+
- MIT
|
86
|
+
metadata:
|
87
|
+
allowed_push_host: https://rubygems.org/
|
88
|
+
homepage_uri: https://github.com/postageapp/specular
|
89
|
+
source_code_uri: https://github.com/postageapp/specular
|
90
|
+
changelog_uri: https://github.com/postageapp/specular
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: 2.6.0
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubygems_version: 3.1.4
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: RSpec to GitHub/Slack bridge tool
|
110
|
+
test_files: []
|