B4U 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.rspec +5 -0
- data/.rubocop.yml +8 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENCE +21 -0
- data/README.md +104 -0
- data/Rakefile +12 -0
- data/exe/B4U +145 -0
- data/lib/B4U/error.rb +16 -0
- data/lib/B4U/linter.rb +21 -0
- data/lib/B4U/runner.rb +28 -0
- data/lib/B4U/string_methods.rb +31 -0
- data/lib/B4U/version.rb +5 -0
- data/lib/B4U.rb +35 -0
- metadata +57 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: ff78d0ea5014a0fca34de15bdff0406ebb3b666bfb480ca8891961248d0164a8
|
|
4
|
+
data.tar.gz: 9ad3d17206045b432aee3de3f5fac057517a477cead2785a474baa37946b2e57
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: d40a900ca9642a99c598a78fc6a257d3d7d6419951a695f7eb12c74e9c05bf4178b21c29a8af239acafbda8c2829b8867ab7d7a58e0957f5867f0839e7c97837
|
|
7
|
+
data.tar.gz: c8d9f5663e45d76709f6e0347ac5920363ae5783098b21fd987f42c4dc4ab3933a3c3541dd0146d511774f7c3ffd8c0e329c16c9b42c98ef0c627521a24c6a74
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.4.2
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
|
10
|
+
identity and orientation.
|
|
11
|
+
|
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
|
13
|
+
diverse, inclusive, and healthy community.
|
|
14
|
+
|
|
15
|
+
## Our Standards
|
|
16
|
+
|
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
|
18
|
+
community include:
|
|
19
|
+
|
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
|
24
|
+
and learning from the experience
|
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
|
26
|
+
community
|
|
27
|
+
|
|
28
|
+
Examples of unacceptable behavior include:
|
|
29
|
+
|
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
|
31
|
+
any kind
|
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
|
33
|
+
* Public or private harassment
|
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
|
35
|
+
without their explicit permission
|
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
37
|
+
professional setting
|
|
38
|
+
|
|
39
|
+
## Enforcement Responsibilities
|
|
40
|
+
|
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
|
44
|
+
or harmful.
|
|
45
|
+
|
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
|
49
|
+
decisions when appropriate.
|
|
50
|
+
|
|
51
|
+
## Scope
|
|
52
|
+
|
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
|
54
|
+
an individual is officially representing the community in public spaces.
|
|
55
|
+
Examples of representing our community include using an official email address,
|
|
56
|
+
posting via an official social media account, or acting as an appointed
|
|
57
|
+
representative at an online or offline event.
|
|
58
|
+
|
|
59
|
+
## Enforcement
|
|
60
|
+
|
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
62
|
+
reported to the community leaders responsible for enforcement at
|
|
63
|
+
[INSERT CONTACT METHOD].
|
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
|
65
|
+
|
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
|
67
|
+
reporter of any incident.
|
|
68
|
+
|
|
69
|
+
## Enforcement Guidelines
|
|
70
|
+
|
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
|
73
|
+
|
|
74
|
+
### 1. Correction
|
|
75
|
+
|
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
|
77
|
+
unprofessional or unwelcome in the community.
|
|
78
|
+
|
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
|
82
|
+
|
|
83
|
+
### 2. Warning
|
|
84
|
+
|
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
|
86
|
+
actions.
|
|
87
|
+
|
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
|
93
|
+
ban.
|
|
94
|
+
|
|
95
|
+
### 3. Temporary Ban
|
|
96
|
+
|
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
|
98
|
+
sustained inappropriate behavior.
|
|
99
|
+
|
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
|
101
|
+
communication with the community for a specified period of time. No public or
|
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
|
104
|
+
Violating these terms may lead to a permanent ban.
|
|
105
|
+
|
|
106
|
+
### 4. Permanent Ban
|
|
107
|
+
|
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
|
111
|
+
|
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
|
113
|
+
community.
|
|
114
|
+
|
|
115
|
+
## Attribution
|
|
116
|
+
|
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
118
|
+
version 2.1, available at
|
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
|
120
|
+
|
|
121
|
+
Community Impact Guidelines were inspired by
|
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
|
123
|
+
|
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
|
127
|
+
|
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/LICENCE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 HM Government (Driver and Vehicle Licensing Agency)
|
|
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 all
|
|
13
|
+
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 THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# B4U
|
|
2
|
+
|
|
3
|
+
B4U is a configurable multithreaded task runner designed to integrate into any git project. It allows you to implement your own quality checks before git actions (commits, pushes, etc.).
|
|
4
|
+
|
|
5
|
+
B4U is intended to be fast, configurable and (importantly) not annoying.
|
|
6
|
+
|
|
7
|
+
## Quick Start
|
|
8
|
+
|
|
9
|
+
1. **Install:** `gem install B4U`
|
|
10
|
+
2. **Initialize:** `B4U --init`
|
|
11
|
+
3. **Configure tasks** in `.B4U/commit.yml` and `.B4U/push.yml`
|
|
12
|
+
4. **Commit these files** to your version control
|
|
13
|
+
5. **Team setup:** `B4U --enable` (after cloning)
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
Install the gem:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
gem install B4U
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Or add to your Gemfile:
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
bundle add B4U
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Configuration
|
|
30
|
+
|
|
31
|
+
B4U uses YAML configuration files in the `.B4U` directory:
|
|
32
|
+
|
|
33
|
+
- `.B4U/commit.yml` - Tasks to run before commits
|
|
34
|
+
- `.B4U/push.yml` - Tasks to run before pushes
|
|
35
|
+
|
|
36
|
+
### Configuration Format
|
|
37
|
+
|
|
38
|
+
Each task requires a `name` and `command`. Optionally add `ignore: true` for non-blocking tasks:
|
|
39
|
+
|
|
40
|
+
```yaml
|
|
41
|
+
linters:
|
|
42
|
+
- name: "Unit tests"
|
|
43
|
+
command: "bundle exec rspec"
|
|
44
|
+
ignore: true # Won't block commit if this fails
|
|
45
|
+
- name: "Rubocop"
|
|
46
|
+
command: "bundle exec rubocop"
|
|
47
|
+
- name: "ESLint"
|
|
48
|
+
command: "npm run lint"
|
|
49
|
+
- name: "Type checking"
|
|
50
|
+
command: "npm run type-check"
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
**Important:** Tasks run in parallel, so only use read-only commands to avoid conflicts.
|
|
54
|
+
|
|
55
|
+
## Usage
|
|
56
|
+
|
|
57
|
+
### Command Line Options
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
B4U --help # Show help
|
|
61
|
+
B4U --version # Show version
|
|
62
|
+
B4U --init # Initialize B4U in current project
|
|
63
|
+
B4U --enable # Enable B4U hooks in current project
|
|
64
|
+
B4U --commit # Run pre-commit tasks
|
|
65
|
+
B4U --push # Run pre-push tasks
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Setup
|
|
69
|
+
|
|
70
|
+
Running `B4U --init` will:
|
|
71
|
+
- Create a `.B4U` directory with configuration files.
|
|
72
|
+
- Set up git hooks for pre-commit and pre-push events.
|
|
73
|
+
|
|
74
|
+
Running `B4U --enable` will:
|
|
75
|
+
- Set up your local git hooks for pre-commit and pre-push events.
|
|
76
|
+
|
|
77
|
+
**Important:** Anyone who clones the project needs to run `B4U --enable` to activate the hooks locally so should add this to your setup script and/or README.md.
|
|
78
|
+
|
|
79
|
+
## Troubleshooting
|
|
80
|
+
|
|
81
|
+
**"Command not found: B4U"**
|
|
82
|
+
- If you're seeing this error and you already have installed B4U, it is likely caused by your IDE or version manager.
|
|
83
|
+
|
|
84
|
+
B4U runs by calling itself from the shell scripts in the `.B4U` folder, so you can add any logic needed to point to the correct version of Ruby or even install the gem to the current version.
|
|
85
|
+
|
|
86
|
+
## Contributing
|
|
87
|
+
|
|
88
|
+
Bug reports and pull requests are welcome on GitHub. This project is intended to be a safe, welcoming space for collaboration.
|
|
89
|
+
|
|
90
|
+
1. Fork the repository.
|
|
91
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`).
|
|
92
|
+
3. Commit your changes (`git commit -am 'Add amazing feature'`).
|
|
93
|
+
4. Push to the branch (`git push origin feature/amazing-feature`).
|
|
94
|
+
5. Open a Pull Request.
|
|
95
|
+
|
|
96
|
+
Please make sure to update tests as appropriate and adhere to the [code of conduct](CODE_OF_CONDUCT.md).
|
|
97
|
+
|
|
98
|
+
## License
|
|
99
|
+
|
|
100
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
101
|
+
|
|
102
|
+
## Code of Conduct
|
|
103
|
+
|
|
104
|
+
Everyone interacting in the B4U project's codebases, issue trackers, and discussions is expected to follow the [code of conduct](CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/exe/B4U
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require 'optparse'
|
|
5
|
+
require 'B4U'
|
|
6
|
+
require 'open3'
|
|
7
|
+
require 'fileutils'
|
|
8
|
+
require 'logger'
|
|
9
|
+
require 'yaml'
|
|
10
|
+
|
|
11
|
+
def setup_new_project
|
|
12
|
+
if Dir.exist? '.git'
|
|
13
|
+
if File.exist?(File.join(Dir.pwd, '.B4U'))
|
|
14
|
+
puts 'Found existing .B4U directory, exiting...'.red.bold
|
|
15
|
+
exit 1
|
|
16
|
+
else
|
|
17
|
+
FileUtils.mkdir '.B4U'
|
|
18
|
+
hooks = %w[commit push]
|
|
19
|
+
hooks.each do |hook_name|
|
|
20
|
+
set_config(hook_name)
|
|
21
|
+
set_hooks(hook_name)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
else
|
|
25
|
+
puts "Couldn't find .git folder in the current directory: #{Dir.pwd}".red.bold
|
|
26
|
+
exit 1
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def hook_executable(hook_name)
|
|
31
|
+
<<~BASH
|
|
32
|
+
#!/bin/sh
|
|
33
|
+
|
|
34
|
+
if ! command -v B4U 2>&1 >/dev/null
|
|
35
|
+
then
|
|
36
|
+
echo "B4U gem is not installed"
|
|
37
|
+
echo "You should install it using:"
|
|
38
|
+
echo "gem install B4U"
|
|
39
|
+
exit 1
|
|
40
|
+
fi
|
|
41
|
+
B4U --#{hook_name}
|
|
42
|
+
BASH
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def config_file(hook_name)
|
|
46
|
+
<<~YAML
|
|
47
|
+
linters:
|
|
48
|
+
- placeholder:
|
|
49
|
+
name: Add your pre #{hook_name} tasks to .B4U/#{hook_name}.yml
|
|
50
|
+
command: echo "B4U is working, but you haven't set your pre-#{hook_name} tasks"; exit 1
|
|
51
|
+
ignore: false
|
|
52
|
+
YAML
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def set_hooks(hook_name)
|
|
56
|
+
filename = ".B4U/pre-#{hook_name}"
|
|
57
|
+
File.open(filename, 'w') do |file|
|
|
58
|
+
file.write(hook_executable(hook_name))
|
|
59
|
+
end
|
|
60
|
+
File.chmod(0o755, filename)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def set_config(hook_name)
|
|
64
|
+
filename = ".B4U/#{hook_name}.yml"
|
|
65
|
+
File.open(filename, 'w') do |file|
|
|
66
|
+
file.write(config_file(hook_name))
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def enable_git_hooks
|
|
71
|
+
system('git config core.hooksPath .B4U')
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def parse_arguments
|
|
75
|
+
options = {}
|
|
76
|
+
# rubocop:disable Metrics/BlockLength
|
|
77
|
+
OptionParser.new do |opts|
|
|
78
|
+
opts.banner = 'Usage: B4U [options]'
|
|
79
|
+
|
|
80
|
+
opts.on('-h', '--help', 'Show help message') do
|
|
81
|
+
puts 'B4U - B4U is a configurable multithreaded task runner that is triggered by git actions'
|
|
82
|
+
puts 'usage: B4U [options]'
|
|
83
|
+
puts ' --init Create a new config file in the current directory'
|
|
84
|
+
puts ' --enable Add B4U hooks to your local git config in this repo'
|
|
85
|
+
puts ' --commit Runs B4U using the config in .B4U/commit.yml'
|
|
86
|
+
puts ' --push Runs B4U using the config in .B4U/push.yml'
|
|
87
|
+
puts ' --no-colour Disable colour output'
|
|
88
|
+
puts ' -h, --help Show help message'
|
|
89
|
+
puts ' -v, --version Show version'
|
|
90
|
+
exit
|
|
91
|
+
end
|
|
92
|
+
opts.on('-v', '--version', 'Show version') do
|
|
93
|
+
puts B4U::VERSION
|
|
94
|
+
exit
|
|
95
|
+
end
|
|
96
|
+
opts.on('--no-colour', 'Enable colour output') do
|
|
97
|
+
options[:no_colour] = true
|
|
98
|
+
end
|
|
99
|
+
opts.on('--init', 'init',
|
|
100
|
+
'Setup B4U in the current directory') do
|
|
101
|
+
String.enable_colour unless options[:no_colour]
|
|
102
|
+
setup_new_project
|
|
103
|
+
puts "Initialized B4U in #{Dir.pwd}".bg_green
|
|
104
|
+
puts 'you should add the .B4U directory to version control'.cyan.bold
|
|
105
|
+
enable_git_hooks
|
|
106
|
+
exit
|
|
107
|
+
end
|
|
108
|
+
opts.on('--enable', 'enable', 'Add B4U to your local git config') do
|
|
109
|
+
enable_git_hooks
|
|
110
|
+
puts 'Added B4U to the config for this project'.green
|
|
111
|
+
exit
|
|
112
|
+
end
|
|
113
|
+
opts.on('--commit', 'Run pre commit hooks') do
|
|
114
|
+
options[:config_file] = '.B4U/commit.yml'
|
|
115
|
+
end
|
|
116
|
+
opts.on('--push', 'Run pre push hooks') do
|
|
117
|
+
options[:config_file] = '.B4U/push.yml'
|
|
118
|
+
end
|
|
119
|
+
end.parse!
|
|
120
|
+
# rubocop:enable Metrics/BlockLength
|
|
121
|
+
options
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def run_B4U(options)
|
|
125
|
+
String.enable_colour unless options[:no_colour]
|
|
126
|
+
config = if options[:config_file]
|
|
127
|
+
begin
|
|
128
|
+
YAML.load_file(options[:config_file])
|
|
129
|
+
rescue StandardError
|
|
130
|
+
puts "Couldn't load config file: #{options[:config_file]} in from directory #{Dir.pwd}".red.bold
|
|
131
|
+
exit 1
|
|
132
|
+
end
|
|
133
|
+
else
|
|
134
|
+
puts "You need to give B4U a command, run 'B4U -h' for help".red.bold
|
|
135
|
+
exit 1
|
|
136
|
+
end
|
|
137
|
+
B4U.lint(config:)
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
begin
|
|
141
|
+
options = parse_arguments
|
|
142
|
+
run_B4U(options)
|
|
143
|
+
rescue OptionParser::InvalidOption, OptionParser::InvalidArgument => e
|
|
144
|
+
puts e.message
|
|
145
|
+
end
|
data/lib/B4U/error.rb
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
class LinterError < StandardError
|
|
2
|
+
attr_reader :linter, :console_output
|
|
3
|
+
def initialize(linter:, console_output:, msg: 'Linter error')
|
|
4
|
+
@linter = linter
|
|
5
|
+
@console_output = console_output
|
|
6
|
+
super(msg)
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
class StructureError < StandardError
|
|
11
|
+
attr_reader :files
|
|
12
|
+
def initialize(files:, msg: 'Structure error')
|
|
13
|
+
@files = files
|
|
14
|
+
super(msg)
|
|
15
|
+
end
|
|
16
|
+
end
|
data/lib/B4U/linter.rb
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
class Linter
|
|
2
|
+
attr_reader :name, :command, :ignore
|
|
3
|
+
|
|
4
|
+
def initialize(name:, command:, ignore: false)
|
|
5
|
+
@name = name
|
|
6
|
+
@command = command
|
|
7
|
+
@ignore = ignore
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def run
|
|
11
|
+
console_output, status = Open3.capture2e(command)
|
|
12
|
+
if status.success?
|
|
13
|
+
puts "✅ - #{name}".green
|
|
14
|
+
elsif ignore
|
|
15
|
+
puts "❌ - #{name} (ignored)".magenta
|
|
16
|
+
else
|
|
17
|
+
puts "❌ - #{name}".red
|
|
18
|
+
raise LinterError.new(linter: name, console_output:)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
data/lib/B4U/runner.rb
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module B4U
|
|
2
|
+
class LinterRunner
|
|
3
|
+
def initialize(linters)
|
|
4
|
+
@linters = linters
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def run_all
|
|
8
|
+
errors = @linters.map do |linter|
|
|
9
|
+
Thread.new do
|
|
10
|
+
begin
|
|
11
|
+
linter.run
|
|
12
|
+
nil
|
|
13
|
+
rescue LinterError => e
|
|
14
|
+
e
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end.map(&:join).filter_map(&:value)
|
|
18
|
+
unless errors.empty?
|
|
19
|
+
puts "\n"
|
|
20
|
+
errors.each do |error|
|
|
21
|
+
puts "Linter '#{error.linter}' failed with the following output:".bold
|
|
22
|
+
puts error.console_output.red
|
|
23
|
+
end
|
|
24
|
+
exit 1
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
class String
|
|
2
|
+
class << self
|
|
3
|
+
attr_accessor :colour_enabled
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
def self.enable_colour
|
|
7
|
+
self.colour_enabled = true
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.disable_colour
|
|
11
|
+
self.colour_enabled = false
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def colorize(code)
|
|
15
|
+
return self unless String.colour_enabled
|
|
16
|
+
|
|
17
|
+
"\e[#{code}m#{self}\e[0m"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def red = colorize(31)
|
|
21
|
+
|
|
22
|
+
def green = colorize(32)
|
|
23
|
+
|
|
24
|
+
def magenta = colorize(35)
|
|
25
|
+
|
|
26
|
+
def cyan = colorize(36)
|
|
27
|
+
|
|
28
|
+
def bg_green = colorize(42)
|
|
29
|
+
|
|
30
|
+
def bold = colorize(1)
|
|
31
|
+
end
|
data/lib/B4U/version.rb
ADDED
data/lib/B4U.rb
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'B4U/runner'
|
|
4
|
+
require_relative 'B4U/string_methods'
|
|
5
|
+
require_relative 'B4U/linter'
|
|
6
|
+
require_relative 'B4U/version'
|
|
7
|
+
require_relative 'B4U/error'
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
module B4U
|
|
11
|
+
def self.lint(config:)
|
|
12
|
+
ProjectChecker.ensure_project_root!(config['required-files']) unless config['required-files'].nil?
|
|
13
|
+
puts "Project structure valid, running #{config['linters'].count} linting steps...".green
|
|
14
|
+
linters = config['linters'].map do |linter|
|
|
15
|
+
Linter.new(
|
|
16
|
+
name: linter['name'],
|
|
17
|
+
command: linter['command'],
|
|
18
|
+
ignore: linter.fetch('ignore', false),
|
|
19
|
+
)
|
|
20
|
+
end
|
|
21
|
+
puts "Before you do that we are just going to check: #{linters.map(&:name)}".cyan.bold
|
|
22
|
+
|
|
23
|
+
runner = LinterRunner.new(linters)
|
|
24
|
+
runner.run_all
|
|
25
|
+
puts 'All linters passed!'.bg_green
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
class ProjectChecker
|
|
29
|
+
def self.ensure_project_root!(required_files)
|
|
30
|
+
puts 'Checking project structure...'.cyan
|
|
31
|
+
missing_files = required_files.reject { |file| File.exist?(file) }
|
|
32
|
+
raise StructureError.new(files: missing_files, msg: "Missing project files: #{missing_files.join(', ')}") unless missing_files.empty?
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: B4U
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Driver and Vehicle Licensing Agency (DVLA)
|
|
8
|
+
- Niall James
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
email:
|
|
14
|
+
- niall.james@dvla.gov.uk
|
|
15
|
+
executables:
|
|
16
|
+
- B4U
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- ".rspec"
|
|
21
|
+
- ".rubocop.yml"
|
|
22
|
+
- ".ruby-version"
|
|
23
|
+
- CHANGELOG.md
|
|
24
|
+
- CODE_OF_CONDUCT.md
|
|
25
|
+
- LICENCE
|
|
26
|
+
- README.md
|
|
27
|
+
- Rakefile
|
|
28
|
+
- exe/B4U
|
|
29
|
+
- lib/B4U.rb
|
|
30
|
+
- lib/B4U/error.rb
|
|
31
|
+
- lib/B4U/linter.rb
|
|
32
|
+
- lib/B4U/runner.rb
|
|
33
|
+
- lib/B4U/string_methods.rb
|
|
34
|
+
- lib/B4U/version.rb
|
|
35
|
+
homepage: https://github.com/dvla/B4U
|
|
36
|
+
licenses:
|
|
37
|
+
- MIT
|
|
38
|
+
metadata:
|
|
39
|
+
source_code_uri: https://github.com/dvla/B4U/browse
|
|
40
|
+
rdoc_options: []
|
|
41
|
+
require_paths:
|
|
42
|
+
- lib
|
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: 3.1.0
|
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
49
|
+
requirements:
|
|
50
|
+
- - ">="
|
|
51
|
+
- !ruby/object:Gem::Version
|
|
52
|
+
version: '0'
|
|
53
|
+
requirements: []
|
|
54
|
+
rubygems_version: 3.6.7
|
|
55
|
+
specification_version: 4
|
|
56
|
+
summary: Multithreaded Ruby lint runner
|
|
57
|
+
test_files: []
|