glyptodont 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/main.yml +23 -0
- data/.gitignore +11 -0
- data/.glyptodont.yaml +10 -0
- data/.rspec +3 -0
- data/.rubocop.yml +15 -0
- data/.tool-versions +1 -0
- data/Brewfile +5 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +21 -0
- data/README.md +97 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/exe/glyptodont +7 -0
- data/glyptodont.gemspec +31 -0
- data/lib/glyptodont.rb +38 -0
- data/lib/glyptodont/checkers/age.rb +42 -0
- data/lib/glyptodont/checkers/counter.rb +38 -0
- data/lib/glyptodont/configuration.rb +40 -0
- data/lib/glyptodont/formatting.rb +18 -0
- data/lib/glyptodont/options.rb +57 -0
- data/lib/glyptodont/todo_researcher.rb +79 -0
- data/lib/glyptodont/version.rb +5 -0
- data/script/bootstrap +30 -0
- data/script/cibuild +18 -0
- data/script/console +15 -0
- data/script/setup +12 -0
- data/script/test +20 -0
- data/script/update +9 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2ad92f48b0fac0e3a90a61d375ccb01f187c79a79070bb801cac3d30f13585e3
|
4
|
+
data.tar.gz: eec6a97e7ab90f1bbd557f5e8fbfc4e6f5809f7aa21f030a1b1f5eae124f1288
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b1daa8bc22b0345c15c8c6f19b394f236e9169007f402b934c94a55b5076ac4ce0c21e9b1c5a49300a5276490b2366df4e68ebc731ece3a89d4b1e12f4eb7c2a
|
7
|
+
data.tar.gz: d1238f2ffbde7b028bc65405ffe0e9b1573f4f8fc86450a2fd1a5cd1ceece15ef4b3bd8e6d7662c0418c7861311d1084c39f0b5dd9931c35b99a3a81b9369e33
|
@@ -0,0 +1,23 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on: [push,pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
strategy:
|
8
|
+
fail-fast: false
|
9
|
+
matrix:
|
10
|
+
ruby: ['2.4', '2.5', '2.6', '2.7', '3.0']
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
steps:
|
13
|
+
- uses: actions/checkout@v2
|
14
|
+
- name: Set up Ruby
|
15
|
+
uses: ruby/setup-ruby@v1
|
16
|
+
with:
|
17
|
+
ruby-version: ${{ matrix.ruby }}
|
18
|
+
- name: Run the default task
|
19
|
+
run: |
|
20
|
+
gem install bundler
|
21
|
+
sudo apt install cmake
|
22
|
+
bundle install
|
23
|
+
./script/cibuild
|
data/.gitignore
ADDED
data/.glyptodont.yaml
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
---
|
2
|
+
ignore:
|
3
|
+
- README.md:10
|
4
|
+
- README.md:15
|
5
|
+
- lib/glyptodont/checkers/counter.rb:28
|
6
|
+
- lib/glyptodont/checkers/counter.rb:30
|
7
|
+
- lib/glyptodont/todo_researcher.rb:32
|
8
|
+
- lib/glyptodont/todo_researcher.rb:33
|
9
|
+
- lib/glyptodont/todo_researcher.rb:34
|
10
|
+
- lib/glyptodont/todo_researcher.rb:35
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
AllCops:
|
2
|
+
NewCops: enable
|
3
|
+
SuggestExtensions: false
|
4
|
+
TargetRubyVersion: 2.4.0
|
5
|
+
|
6
|
+
Style/StringLiterals:
|
7
|
+
Enabled: true
|
8
|
+
EnforcedStyle: double_quotes
|
9
|
+
|
10
|
+
Style/StringLiteralsInInterpolation:
|
11
|
+
Enabled: true
|
12
|
+
EnforcedStyle: double_quotes
|
13
|
+
|
14
|
+
Layout/LineLength:
|
15
|
+
Max: 120
|
data/.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 3.0.0
|
data/Brewfile
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at paj+github@johnsy.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Pete Johns
|
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,97 @@
|
|
1
|
+
# Glyptodont
|
2
|
+
|
3
|
+
Use this gem if you have ever deployed code to production without doing all of
|
4
|
+
your to-dos.
|
5
|
+
|
6
|
+
## Introduction
|
7
|
+
|
8
|
+
All of the glyptodonts have fossilised. This is a tool to ensure that your TODOs
|
9
|
+
are eradicated before this can happen to them.
|
10
|
+
|
11
|
+
If you've ever been caught out because a TODO in production code has not been
|
12
|
+
don, this gem is for ***you***!
|
13
|
+
|
14
|
+
## Development status [![Ruby](https://github.com/johnsyweb/glyptodont/actions/workflows/main.yml/badge.svg)](https://github.com/johnsyweb/glyptodont/actions/workflows/main.yml)
|
15
|
+
|
16
|
+
This was written after I was bitten by a TODO not being _done_ at work. I expect
|
17
|
+
to build it into our CI pipeline and see what it catches.
|
18
|
+
|
19
|
+
After checking out the project, run `script/setup` to install dependencies. Then,
|
20
|
+
run `script/tests` to run the tests. You can also run `script/console` for an
|
21
|
+
interactive prompt that will allow you to experiment.
|
22
|
+
|
23
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To
|
24
|
+
release a new version, update the version number in `version.rb`, and then run
|
25
|
+
`bundle exec rake release`, which will create a git tag for the version, push
|
26
|
+
git commits and the created tag, and push the `.gem` file to
|
27
|
+
[rubygems.org](https://rubygems.org).
|
28
|
+
|
29
|
+
## Getting started [![Gem version](https://img.shields.io/gem/v/glyptodont.svg?style=flat-square)](https://github.com/johnysweb/glyptodont) [![Gem downloads](https://img.shields.io/gem/dt/glyptodont.svg?style=flat-square)](https://rubygems.org/gems/glyptodont)
|
30
|
+
|
31
|
+
Add this line to your application's Gemfile:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
gem 'glyptodont'
|
35
|
+
```
|
36
|
+
|
37
|
+
And then execute:
|
38
|
+
|
39
|
+
```sh
|
40
|
+
bundle install
|
41
|
+
```
|
42
|
+
|
43
|
+
Or install it yourself as:
|
44
|
+
|
45
|
+
```sh
|
46
|
+
gem install glyptodont
|
47
|
+
```
|
48
|
+
|
49
|
+
## Usage
|
50
|
+
|
51
|
+
```
|
52
|
+
Usage: glyptodont [options]
|
53
|
+
-d, --directory DIRECTORY Git repository to search for TODOs (default '.')
|
54
|
+
-t, --threshold TODOS Maximum number of TODOs to allow (default 10)
|
55
|
+
-m, --max-age DAYS Maximum number of days to allow TODOs to stay (default 14)
|
56
|
+
--version Show version
|
57
|
+
```
|
58
|
+
|
59
|
+
## Configuration
|
60
|
+
|
61
|
+
glyptodont looks for an optional `.glyptodont.yaml` configuration file in the
|
62
|
+
root of the directory being scanned, which contains an `ignore` list of
|
63
|
+
`file_name:line_number` pairs to ignore when researching TODOs. This may be
|
64
|
+
useful if you have, for example, Spanish language text in your project.
|
65
|
+
|
66
|
+
### _Exempli gratiā_
|
67
|
+
|
68
|
+
```yaml
|
69
|
+
---
|
70
|
+
ignore:
|
71
|
+
- lib/glyptodont/checkers/counter.rb:28
|
72
|
+
- lib/glyptodont/todo_researcher.rb:34
|
73
|
+
```
|
74
|
+
|
75
|
+
## Requirements
|
76
|
+
|
77
|
+
- Ruby (tested against v2.4 and above)
|
78
|
+
- Git
|
79
|
+
- CMake
|
80
|
+
|
81
|
+
## Contributing
|
82
|
+
|
83
|
+
Bug reports and pull requests are welcome on GitHub at
|
84
|
+
<https://github.com/johnsyweb/glyptodont>. This project is intended to be a
|
85
|
+
safe, welcoming space for collaboration, and contributors are expected to adhere
|
86
|
+
to the [code of
|
87
|
+
conduct](https://github.com/johnsyweb/glyptodont/blob/master/CODE_OF_CONDUCT.md).
|
88
|
+
|
89
|
+
## License [![license](https://img.shields.io/github/license/mashape/apistatus.svg?style=flat-square)](https://github.com/johnsyweb/glyptodont/blob/HEAD/LICENSE.txt)
|
90
|
+
|
91
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
92
|
+
|
93
|
+
## Code of Conduct
|
94
|
+
|
95
|
+
Everyone interacting in the Glyptodont project's codebases, issue trackers, chat
|
96
|
+
rooms and mailing lists is expected to follow the [code of
|
97
|
+
conduct](https://github.com/johnsyweb/glyptodont/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "glyptodont"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/exe/glyptodont
ADDED
data/glyptodont.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/glyptodont/version"
|
4
|
+
|
5
|
+
GITHUB_URL = "https://github.com/johnsyweb/glyptodont/"
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "glyptodont"
|
9
|
+
spec.version = Glyptodont::VERSION
|
10
|
+
spec.authors = ["Pete Johns"]
|
11
|
+
spec.email = ["paj+github@johnsy.com"]
|
12
|
+
|
13
|
+
spec.summary = "A bit like `git grep 'T0D0'`, but better." # .tr("0", "O")
|
14
|
+
spec.description = "Use this gem if you have ever deployed code to production without doing all of your to-dos"
|
15
|
+
spec.homepage = GITHUB_URL
|
16
|
+
spec.license = "MIT"
|
17
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
18
|
+
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
+
spec.metadata["source_code_uri"] = GITHUB_URL
|
21
|
+
spec.metadata["changelog_uri"] = "#{GITHUB_URL}blob/HEAD/CHANGELOG.md"
|
22
|
+
|
23
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
%w[git rugged].each { |gem| spec.add_dependency(gem) }
|
31
|
+
end
|
data/lib/glyptodont.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "glyptodont/checkers/age"
|
4
|
+
require_relative "glyptodont/checkers/counter"
|
5
|
+
require_relative "glyptodont/configuration"
|
6
|
+
require_relative "glyptodont/formatting"
|
7
|
+
require_relative "glyptodont/options"
|
8
|
+
require_relative "glyptodont/todo_researcher"
|
9
|
+
|
10
|
+
require "forwardable"
|
11
|
+
|
12
|
+
# This is where the magic happens
|
13
|
+
module Glyptodont
|
14
|
+
class << self
|
15
|
+
def check
|
16
|
+
@options = Options.new
|
17
|
+
@configuration = Configuration.new(directory)
|
18
|
+
|
19
|
+
todos = TodoResearcher.new(directory, ignore).research
|
20
|
+
|
21
|
+
checks = [
|
22
|
+
Checkers::Counter.new(todos: todos, threshold: threshold),
|
23
|
+
Checkers::Age.new(todos: todos, threshold: max_age_in_days)
|
24
|
+
].freeze
|
25
|
+
|
26
|
+
checks.each { |check| puts check.check }
|
27
|
+
|
28
|
+
checks.all?(&:passed?)
|
29
|
+
end
|
30
|
+
|
31
|
+
attr_reader :configuration, :options
|
32
|
+
|
33
|
+
extend Forwardable
|
34
|
+
|
35
|
+
def_delegator :@configuration, :ignore
|
36
|
+
def_delegators :@options, :directory, :threshold, :max_age_in_days
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Glyptodont
|
4
|
+
module Checkers
|
5
|
+
# Checks that the age of TODOs is below the specified threshold
|
6
|
+
class Age
|
7
|
+
def initialize(todos:, threshold:)
|
8
|
+
@todos = todos
|
9
|
+
@threshold = threshold
|
10
|
+
end
|
11
|
+
|
12
|
+
def check
|
13
|
+
@age, @reportable_todos = oldest_todos
|
14
|
+
message
|
15
|
+
end
|
16
|
+
|
17
|
+
def passed?
|
18
|
+
todos.empty? || age <= threshold
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
attr_reader :todos, :threshold, :age, :reportable_todos
|
24
|
+
|
25
|
+
def message
|
26
|
+
if todos.empty?
|
27
|
+
"Nothing left to do"
|
28
|
+
elsif passed?
|
29
|
+
"At #{Glyptodont.pluralize(age, "day")}, TODOs are fresh enough for now"
|
30
|
+
else
|
31
|
+
"Some TODOs are too stale at #{Glyptodont.pluralize(age, "day")} old:\n" +
|
32
|
+
reportable_todos.map { |t| Glyptodont.format_todo(t) }.join("\n")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def oldest_todos
|
37
|
+
todos.group_by { |todo| todo[:age] }
|
38
|
+
.max_by { |age, _group| age }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Glyptodont
|
4
|
+
module Checkers
|
5
|
+
# Checks that the number of TODOs is below the specified threshold
|
6
|
+
class Counter
|
7
|
+
def initialize(todos:, threshold:)
|
8
|
+
@threshold = threshold
|
9
|
+
@todos = todos
|
10
|
+
end
|
11
|
+
|
12
|
+
def check
|
13
|
+
@count = todos.size
|
14
|
+
@reportable_todos = passed? ? todos : []
|
15
|
+
message
|
16
|
+
end
|
17
|
+
|
18
|
+
def passed?
|
19
|
+
count <= threshold
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def message
|
25
|
+
if count.zero?
|
26
|
+
"All done"
|
27
|
+
elsif passed?
|
28
|
+
"#{Glyptodont.pluralize(count, "TODO")}: This is tolerable"
|
29
|
+
else
|
30
|
+
"#{Glyptodont.pluralize(count, "TODO")}: There is work to be done:\n" +
|
31
|
+
todos.map { |t| Glyptodont.format_todo(t) }.join("\n")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
attr_reader :todos, :threshold, :count
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "set"
|
4
|
+
require "yaml"
|
5
|
+
|
6
|
+
module Glyptodont
|
7
|
+
# Allow for configuring the tool
|
8
|
+
class Configuration
|
9
|
+
FILENAME = ".glyptodont.yaml"
|
10
|
+
def initialize(directory)
|
11
|
+
@config_filename = File.join(directory, FILENAME)
|
12
|
+
end
|
13
|
+
|
14
|
+
def ignore
|
15
|
+
@ignore ||= extract_ignore_set || []
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
attr_reader :config_filename
|
21
|
+
|
22
|
+
def config
|
23
|
+
@config ||= begin
|
24
|
+
YAML.load_file(config_filename)
|
25
|
+
rescue Errno::ENOENT
|
26
|
+
{}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def extract_ignore_set
|
31
|
+
config.fetch("ignore", []).map do |line|
|
32
|
+
parts = line.split(":", 2)
|
33
|
+
{
|
34
|
+
file: parts[0],
|
35
|
+
line: parts[1].to_i
|
36
|
+
}
|
37
|
+
end.to_set
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# String formatting methods
|
4
|
+
module Glyptodont
|
5
|
+
class << self
|
6
|
+
def pluralize(items, text)
|
7
|
+
if items == 1
|
8
|
+
"1 #{text}"
|
9
|
+
else
|
10
|
+
"#{items} #{text}s"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def format_todo(todo)
|
15
|
+
format("%<file>s:%<line>s: %<text>s -- %<name>s @ %<time>s", todo)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "version"
|
4
|
+
|
5
|
+
require "optparse"
|
6
|
+
|
7
|
+
module Glyptodont
|
8
|
+
# Command-line options for the tool
|
9
|
+
class Options
|
10
|
+
attr_reader :directory, :threshold, :max_age_in_days
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@directory = "."
|
14
|
+
@threshold = 10
|
15
|
+
@max_age_in_days = 14
|
16
|
+
parse
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def parse
|
22
|
+
OptionParser.new do |opts|
|
23
|
+
opts.banner = "Usage: #{opts.program_name} [options]"
|
24
|
+
|
25
|
+
directory_option(opts)
|
26
|
+
threshold_option(opts)
|
27
|
+
max_age_in_days_option(opts)
|
28
|
+
version_option(opts)
|
29
|
+
end.parse!(ARGV)
|
30
|
+
end
|
31
|
+
|
32
|
+
def directory_option(opts)
|
33
|
+
opts.on("-d", "--directory DIRECTORY", String, "Git repository to search for TODOs (default '.')") do |d|
|
34
|
+
@directory = d
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def threshold_option(opts)
|
39
|
+
opts.on("-t", "--threshold TODOS", Integer, "Maximum number of TODOs to allow (default 10)") do |t|
|
40
|
+
@threshold = t
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def max_age_in_days_option(opts)
|
45
|
+
opts.on("-m", "--max-age DAYS", Integer, "Maximum number of days to allow TODOs to stay (default 14)") do |m|
|
46
|
+
@max_age_in_days = m
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def version_option(opts)
|
51
|
+
opts.on_tail("--version", "Show version") do
|
52
|
+
puts VERSION
|
53
|
+
exit
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "git"
|
4
|
+
require "rugged"
|
5
|
+
|
6
|
+
module Glyptodont
|
7
|
+
# Finds all the TODOs in a directory managed by Git, who last touched them and when.
|
8
|
+
class TodoResearcher
|
9
|
+
def initialize(directory, ignore)
|
10
|
+
@directory = directory
|
11
|
+
@ignore = ignore
|
12
|
+
end
|
13
|
+
|
14
|
+
def research
|
15
|
+
annotate(exclude_ignored(extract_details(git.grep(keyword_rexexp))))
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
attr_reader :directory, :ignore
|
21
|
+
|
22
|
+
def git
|
23
|
+
Git.open(directory)
|
24
|
+
end
|
25
|
+
|
26
|
+
def keyword_rexexp
|
27
|
+
"\\b\\(#{keywords.join('\|')}\\)\\b"
|
28
|
+
end
|
29
|
+
|
30
|
+
def keywords
|
31
|
+
%w[
|
32
|
+
FIXME
|
33
|
+
HACK
|
34
|
+
TODO
|
35
|
+
XXX
|
36
|
+
]
|
37
|
+
end
|
38
|
+
|
39
|
+
def extract_details(todos)
|
40
|
+
todos.flat_map do |sha, matches|
|
41
|
+
file = sha.split(":", 2).last
|
42
|
+
matches.map do |match|
|
43
|
+
{
|
44
|
+
file: file,
|
45
|
+
line: match[0],
|
46
|
+
text: match[1].strip
|
47
|
+
}
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def exclude_ignored(todos)
|
53
|
+
todos.reject { |todo| ignore.include?(todo.slice(:file, :line)) }
|
54
|
+
end
|
55
|
+
|
56
|
+
def annotate(todos)
|
57
|
+
todos.map do |todo|
|
58
|
+
annotation = annotate_line(file_path: todo[:file], line_number: todo[:line])
|
59
|
+
todo.merge(annotation).merge(age: days_since(annotation[:time]))
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def annotate_line(file_path:, line_number:)
|
64
|
+
line_info(file_path: file_path, line_number: line_number)[:final_signature]
|
65
|
+
end
|
66
|
+
|
67
|
+
def line_info(file_path:, line_number:)
|
68
|
+
Rugged::Blame.new(repository, file_path).for_line(line_number)
|
69
|
+
end
|
70
|
+
|
71
|
+
def repository
|
72
|
+
@repository ||= Rugged::Repository.new(directory)
|
73
|
+
end
|
74
|
+
|
75
|
+
def days_since(timestamp)
|
76
|
+
(Time.now - timestamp).to_i / (24 * 60 * 60)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
data/script/bootstrap
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
|
3
|
+
# script/bootstrap: Resolve all dependencies that the application requires to
|
4
|
+
# run.
|
5
|
+
|
6
|
+
set -e
|
7
|
+
|
8
|
+
cd "$(dirname "$0")/.."
|
9
|
+
|
10
|
+
if [ -f "Brewfile" ] && [ "$(uname -s)" = "Darwin" ]; then
|
11
|
+
brew bundle check >/dev/null 2>&1 || {
|
12
|
+
echo "==> Installing Homebrew dependencies…"
|
13
|
+
brew bundle
|
14
|
+
}
|
15
|
+
fi
|
16
|
+
|
17
|
+
if [ -f ".tool-versions" ]; then
|
18
|
+
echo "==> Installing Ruby…"
|
19
|
+
which bundle >/dev/null 2>&1 || {
|
20
|
+
gem install bundler
|
21
|
+
asdf reshim ruby
|
22
|
+
}
|
23
|
+
fi
|
24
|
+
|
25
|
+
if [ -f "Gemfile" ]; then
|
26
|
+
echo "==> Installing gem dependencies…"
|
27
|
+
bundle check --path vendor/gems >/dev/null 2>&1 || {
|
28
|
+
bundle install --path vendor/gems --quiet --without production
|
29
|
+
}
|
30
|
+
fi
|
data/script/cibuild
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
|
3
|
+
# script/cibuild: Setup environment for CI to run tests. This is primarily
|
4
|
+
# designed to run on the continuous integration server.
|
5
|
+
|
6
|
+
set -e
|
7
|
+
|
8
|
+
cd "$(dirname "$0")/.."
|
9
|
+
|
10
|
+
echo "Tests started at…"
|
11
|
+
date "+%H:%M:%S"
|
12
|
+
|
13
|
+
# run tests
|
14
|
+
echo "Running tests…"
|
15
|
+
date "+%H:%M:%S"
|
16
|
+
|
17
|
+
# run tests.
|
18
|
+
script/test
|
data/script/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
|
3
|
+
# script/console: Launch a console for the application. Optionally allow an
|
4
|
+
# environment to be passed in to let the script handle the
|
5
|
+
# specific requirements for connecting to a console for that
|
6
|
+
# environment.
|
7
|
+
|
8
|
+
set -e
|
9
|
+
|
10
|
+
cd "$(dirname "$0")/.."
|
11
|
+
|
12
|
+
# no argument provided, so just run the local console in the development
|
13
|
+
# environment. Ensure the application is up to date first.
|
14
|
+
script/update
|
15
|
+
bin/console
|
data/script/setup
ADDED
data/script/test
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
|
3
|
+
# script/test: Run test suite for application. Optionally pass in a path to an
|
4
|
+
# individual test file to run a single test.
|
5
|
+
|
6
|
+
|
7
|
+
set -e
|
8
|
+
|
9
|
+
cd "$(dirname "$0")/.."
|
10
|
+
|
11
|
+
[ -z "$DEBUG" ] || set -x
|
12
|
+
|
13
|
+
echo "==> Running tests…"
|
14
|
+
|
15
|
+
if [ -n "$1" ]; then
|
16
|
+
# pass arguments to test call. This is useful for calling a single test.
|
17
|
+
bundle exec rspec "$1"
|
18
|
+
else
|
19
|
+
bundle exec rspec
|
20
|
+
fi
|
data/script/update
ADDED
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: glyptodont
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pete Johns
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-03-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: git
|
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: rugged
|
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
|
+
description: Use this gem if you have ever deployed code to production without doing
|
42
|
+
all of your to-dos
|
43
|
+
email:
|
44
|
+
- paj+github@johnsy.com
|
45
|
+
executables:
|
46
|
+
- glyptodont
|
47
|
+
extensions: []
|
48
|
+
extra_rdoc_files: []
|
49
|
+
files:
|
50
|
+
- ".github/workflows/main.yml"
|
51
|
+
- ".gitignore"
|
52
|
+
- ".glyptodont.yaml"
|
53
|
+
- ".rspec"
|
54
|
+
- ".rubocop.yml"
|
55
|
+
- ".tool-versions"
|
56
|
+
- Brewfile
|
57
|
+
- CHANGELOG.md
|
58
|
+
- CODE_OF_CONDUCT.md
|
59
|
+
- Gemfile
|
60
|
+
- LICENSE.txt
|
61
|
+
- README.md
|
62
|
+
- Rakefile
|
63
|
+
- bin/console
|
64
|
+
- exe/glyptodont
|
65
|
+
- glyptodont.gemspec
|
66
|
+
- lib/glyptodont.rb
|
67
|
+
- lib/glyptodont/checkers/age.rb
|
68
|
+
- lib/glyptodont/checkers/counter.rb
|
69
|
+
- lib/glyptodont/configuration.rb
|
70
|
+
- lib/glyptodont/formatting.rb
|
71
|
+
- lib/glyptodont/options.rb
|
72
|
+
- lib/glyptodont/todo_researcher.rb
|
73
|
+
- lib/glyptodont/version.rb
|
74
|
+
- script/bootstrap
|
75
|
+
- script/cibuild
|
76
|
+
- script/console
|
77
|
+
- script/setup
|
78
|
+
- script/test
|
79
|
+
- script/update
|
80
|
+
homepage: https://github.com/johnsyweb/glyptodont/
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
metadata:
|
84
|
+
homepage_uri: https://github.com/johnsyweb/glyptodont/
|
85
|
+
source_code_uri: https://github.com/johnsyweb/glyptodont/
|
86
|
+
changelog_uri: https://github.com/johnsyweb/glyptodont/blob/HEAD/CHANGELOG.md
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: 2.4.0
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubygems_version: 3.2.11
|
103
|
+
signing_key:
|
104
|
+
specification_version: 4
|
105
|
+
summary: A bit like `git grep 'T0D0'`, but better.
|
106
|
+
test_files: []
|