way_of_working 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +30 -0
  3. data/CODE_OF_CONDUCT.md +133 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +101 -0
  6. data/exe/way_of_working +5 -0
  7. data/lib/tasks/audit_gems.rake +60 -0
  8. data/lib/way_of_working/cli.rb +125 -0
  9. data/lib/way_of_working/generators/changelog/init.rb +110 -0
  10. data/lib/way_of_working/generators/code_of_conduct/init.rb +32 -0
  11. data/lib/way_of_working/generators/decision_record/init.rb +29 -0
  12. data/lib/way_of_working/generators/decision_record/new.rb +67 -0
  13. data/lib/way_of_working/generators/linter/exec.rb +77 -0
  14. data/lib/way_of_working/generators/linter/init.rb +60 -0
  15. data/lib/way_of_working/generators/rake_tasks/init.rb +47 -0
  16. data/lib/way_of_working/git/repo_reader.rb +72 -0
  17. data/lib/way_of_working/git/summary_tag.rb +27 -0
  18. data/lib/way_of_working/paths.rb +16 -0
  19. data/lib/way_of_working/sub_command_base.rb +16 -0
  20. data/lib/way_of_working/tasks.rb +8 -0
  21. data/lib/way_of_working/templates/.github/linters/.markdown-link-check.json +13 -0
  22. data/lib/way_of_working/templates/.github/linters/rubocop_defaults.yml +55 -0
  23. data/lib/way_of_working/templates/.github/workflows/mega-linter.yml +82 -0
  24. data/lib/way_of_working/templates/.mega-linter.yml +129 -0
  25. data/lib/way_of_working/templates/.rubocop +1 -0
  26. data/lib/way_of_working/templates/CODE_OF_CONDUCT.md.tt +134 -0
  27. data/lib/way_of_working/templates/docs/decisions/README.md +7 -0
  28. data/lib/way_of_working/templates/docs/decisions/adr-template.md.tt +79 -0
  29. data/lib/way_of_working/version.rb +5 -0
  30. data/lib/way_of_working.rb +10 -0
  31. data/way_of_working.gemspec +43 -0
  32. metadata +121 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c8af659ec8270a7df5b2333d631565faf9c7aa836be80dcfe704981d2d8f7336
4
+ data.tar.gz: 3490bf4f4ee2735b710a555edc6a8759c8390227c2c8a6ea8b5395a54dfd9122
5
+ SHA512:
6
+ metadata.gz: d6cd047c825b78be49b8460c98d65da9259d014aa2888767705c6601190d6630e9c0446e255abb67b903ac5201196b27a218b2f514889fb2eef33b78aad66773
7
+ data.tar.gz: 631e4b3b9c62bd4c8daeaddc8617ddb3454ed2b33ddf08c29dc1219a8efd0a3b4948f9c36141bc579ee1c96be74d4a7671c7cced635004c53cffec3c02f476b4
data/CHANGELOG.md ADDED
@@ -0,0 +1,30 @@
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.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [1.0.0] - 2023-02-17
11
+
12
+ ### Added
13
+
14
+ - Added Markdown Any Decision Records (MADR) with generator commands
15
+ - Added Contributor Covenant Code of Conduct with generator command
16
+ - Added MegaLinter for linting common file formats with generator command and rake task
17
+ - Added Keep a Changelog with generator command
18
+ - Added GitHub Pages documentation site
19
+
20
+ ### Change
21
+
22
+ - Switched from a Rails Engine to (nearly) vanilla Thor, to support non-rails projects
23
+ - Switched to a cached copy of the Code of Conduct
24
+
25
+ ### Fixed
26
+
27
+ - Corrected use of relative paths in the rubocop config file
28
+
29
+ [unreleased]: https://github.com/HealthDataInsight/way_of_working/compare/v1.0.0...HEAD
30
+ [1.0.0]: https://github.com/HealthDataInsight/way_of_working/releases/tag/v1.0.0
@@ -0,0 +1,133 @@
1
+
2
+ # Contributor Covenant Code of Conduct
3
+
4
+ ## Our Pledge
5
+
6
+ We as members, contributors, and leaders pledge to make participation in our
7
+ community a harassment-free experience for everyone, regardless of age, body
8
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
9
+ identity and expression, level of experience, education, socio-economic status,
10
+ nationality, personal appearance, race, caste, color, religion, or sexual
11
+ identity and orientation.
12
+
13
+ We pledge to act and interact in ways that contribute to an open, welcoming,
14
+ diverse, inclusive, and healthy community.
15
+
16
+ ## Our Standards
17
+
18
+ Examples of behavior that contributes to a positive environment for our
19
+ community include:
20
+
21
+ * Demonstrating empathy and kindness toward other people
22
+ * Being respectful of differing opinions, viewpoints, and experiences
23
+ * Giving and gracefully accepting constructive feedback
24
+ * Accepting responsibility and apologizing to those affected by our mistakes,
25
+ and learning from the experience
26
+ * Focusing on what is best not just for us as individuals, but for the overall
27
+ community
28
+
29
+ Examples of unacceptable behavior include:
30
+
31
+ * The use of sexualized language or imagery, and sexual attention or advances of
32
+ any kind
33
+ * Trolling, insulting or derogatory comments, and personal or political attacks
34
+ * Public or private harassment
35
+ * Publishing others' private information, such as a physical or email address,
36
+ without their explicit permission
37
+ * Other conduct which could reasonably be considered inappropriate in a
38
+ professional setting
39
+
40
+ ## Enforcement Responsibilities
41
+
42
+ Community leaders are responsible for clarifying and enforcing our standards of
43
+ acceptable behavior and will take appropriate and fair corrective action in
44
+ response to any behavior that they deem inappropriate, threatening, offensive,
45
+ or harmful.
46
+
47
+ Community leaders have the right and responsibility to remove, edit, or reject
48
+ comments, commits, code, wiki edits, issues, and other contributions that are
49
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
50
+ decisions when appropriate.
51
+
52
+ ## Scope
53
+
54
+ This Code of Conduct applies within all community spaces, and also applies when
55
+ an individual is officially representing the community in public spaces.
56
+ Examples of representing our community include using an official e-mail address,
57
+ posting via an official social media account, or acting as an appointed
58
+ representative at an online or offline event.
59
+
60
+ ## Enforcement
61
+
62
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
63
+ reported to the community leaders responsible for enforcement at
64
+ report.complaints@healthdatainsight.org.uk.
65
+ All complaints will be reviewed and investigated promptly and fairly.
66
+
67
+ All community leaders are obligated to respect the privacy and security of the
68
+ reporter of any incident.
69
+
70
+ ## Enforcement Guidelines
71
+
72
+ Community leaders will follow these Community Impact Guidelines in determining
73
+ the consequences for any action they deem in violation of this Code of Conduct:
74
+
75
+ ### 1. Correction
76
+
77
+ **Community Impact**: Use of inappropriate language or other behavior deemed
78
+ unprofessional or unwelcome in the community.
79
+
80
+ **Consequence**: A private, written warning from community leaders, providing
81
+ clarity around the nature of the violation and an explanation of why the
82
+ behavior was inappropriate. A public apology may be requested.
83
+
84
+ ### 2. Warning
85
+
86
+ **Community Impact**: A violation through a single incident or series of
87
+ actions.
88
+
89
+ **Consequence**: A warning with consequences for continued behavior. No
90
+ interaction with the people involved, including unsolicited interaction with
91
+ those enforcing the Code of Conduct, for a specified period of time. This
92
+ includes avoiding interactions in community spaces as well as external channels
93
+ like social media. Violating these terms may lead to a temporary or permanent
94
+ ban.
95
+
96
+ ### 3. Temporary Ban
97
+
98
+ **Community Impact**: A serious violation of community standards, including
99
+ sustained inappropriate behavior.
100
+
101
+ **Consequence**: A temporary ban from any sort of interaction or public
102
+ communication with the community for a specified period of time. No public or
103
+ private interaction with the people involved, including unsolicited interaction
104
+ with those enforcing the Code of Conduct, is allowed during this period.
105
+ Violating these terms may lead to a permanent ban.
106
+
107
+ ### 4. Permanent Ban
108
+
109
+ **Community Impact**: Demonstrating a pattern of violation of community
110
+ standards, including sustained inappropriate behavior, harassment of an
111
+ individual, or aggression toward or disparagement of classes of individuals.
112
+
113
+ **Consequence**: A permanent ban from any sort of public interaction within the
114
+ community.
115
+
116
+ ## Attribution
117
+
118
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
119
+ version 2.1, available at
120
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
121
+
122
+ Community Impact Guidelines were inspired by
123
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
124
+
125
+ For answers to common questions about this code of conduct, see the FAQ at
126
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
127
+ [https://www.contributor-covenant.org/translations][translations].
128
+
129
+ [homepage]: https://www.contributor-covenant.org
130
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
131
+ [Mozilla CoC]: https://github.com/mozilla/diversity
132
+ [FAQ]: https://www.contributor-covenant.org/faq
133
+ [translations]: https://www.contributor-covenant.org/translations
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Health Data Insight
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,101 @@
1
+ # HDI Engineering Way of Working
2
+ [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](CODE_OF_CONDUCT.md)
3
+ [![MegaLinter](https://github.com/HealthDataInsight/way_of_working/workflows/MegaLinter/badge.svg?branch=main)](https://github.com/HealthDataInsight/way_of_working/actions?query=workflow%3AMegaLinter+branch%3Amain)
4
+ [![Keep a Changelog v1.1.0 badge][changelog-badge]][changelog]
5
+
6
+ ## Introduction
7
+
8
+ This framework will describe a consistent, high-quality approach to Software Engineering at HDI.
9
+
10
+ It is an opinionated approach intending to support rapid development, across numerous projects, by a fungible workforce who can swap between assignments with the minimum friction.
11
+
12
+ It builds on the [twelve-factor app](https://12factor.net) methodology and is intended to be compatible with the [NHS Digital Software Engineering Quality Framework](https://github.com/NHSDigital/software-engineering-quality-framework) and other frameworks like [the GDS Way](https://gds-way.cloudapps.digital).
13
+
14
+ The most significant difference here is that we will be opinionated and make technological and process choices. Of course, users are encouraged to discuss and submit Pull Requests (PRs) if they want changes to the choices made, but by making those choices, we can automate many tedious background tasks that are currently manual.
15
+
16
+ ## Installation
17
+
18
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
19
+
20
+ Install the gem and add to the application's Gemfile by executing:
21
+
22
+ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
23
+
24
+ If bundler is not being used to manage dependencies, install the gem by executing:
25
+
26
+ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
27
+
28
+ ## Usage
29
+
30
+ ### Changelog
31
+
32
+ To add a [keep a changelog v1.1.0](https://keepachangelog.com/en/1.1.0/) changelog to your project, use the following at the command line:
33
+
34
+ way_of_working init changelog
35
+
36
+ ### Code Of Conduct
37
+
38
+ To add a [Contributor Covenant](https://www.contributor-covenant.org/version/2/1/code_of_conduct/) Code of Conduct v2.1 to your project, use the following at the command line:
39
+
40
+ way_of_working init code_of_conduct --contact-method [CONTACT METHOD]
41
+
42
+ You will need to enter a contact method, usually an email address. Please thoroughly read the [enforcement guidelines](https://www.contributor-covenant.org/version/2/1/code_of_conduct/#enforcement-guidelines) section of the code and discuss the implications of adopting the code of conduct.
43
+
44
+ ### Decision Records
45
+
46
+ To add the [Markdown Any Decision Records (MADR)](https://adr.github.io/madr/) v3.0.0 framework to your project, run the following at the command line:
47
+
48
+ way_of_working init decision_record
49
+
50
+ To create a new decision record, run:
51
+
52
+ way_of_working new decision_record [NAME]
53
+
54
+ Where `[NAME]` is the title of your decision record, for example:
55
+
56
+ way_of_working new decision_record "Use Markdown Any Decision Records"
57
+
58
+ ### Linter
59
+
60
+ To add [MegaLinter](https://megalinter.io/) to your project, run the following at the command line:
61
+
62
+ way_of_working init linter
63
+
64
+ to run MegaLinter in your project, run:
65
+
66
+ way_of_working exec linter
67
+
68
+ ### Initialise All Components
69
+
70
+ To add all the Way of Working components to your project, run:
71
+
72
+ way_of_working init all --contact-method [CONTACT METHOD]
73
+
74
+ Providing the Code of Conduct `[CONTACT METHOD]` described above.
75
+
76
+ ### Help
77
+
78
+ More help on using the command line tool is found by using:
79
+
80
+ way_of_working help
81
+
82
+ ## Development
83
+
84
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. This RubyGem was created using `bundle gem --exe way_of_working`.
85
+
86
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
87
+
88
+ ## Contributing
89
+
90
+ Bug reports and pull requests are welcome on GitHub at <https://github.com/HealthDataInsight/way_of_working>. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/HealthDataInsight/way_of_working/blob/main/CODE_OF_CONDUCT.md).
91
+
92
+ ## License
93
+
94
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
95
+
96
+ ## Code of Conduct
97
+
98
+ Everyone interacting in the WayOfWorking project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/HealthDataInsight/way_of_working/blob/main/CODE_OF_CONDUCT.md).
99
+
100
+ [changelog]: ./CHANGELOG.md
101
+ [changelog-badge]: https://img.shields.io/badge/changelog-Keep%20a%20Changelog%20v1.1.0-%23E05735
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'way_of_working'
4
+
5
+ WayOfWorking::CLI.start(ARGV)
@@ -0,0 +1,60 @@
1
+ GEM_VERSION_PLATFORM_REGEXP = /
2
+ \A
3
+ (.*?)
4
+ -((?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*).*?)
5
+ (?:-(java|(?:aarch|arm|x)(?:86)?(?:_)?(?:64)?-(?:darwin|linux|mingw32|mingw-ucrt)))?
6
+ \.gem
7
+ \z
8
+ /ix.freeze
9
+
10
+ namespace :audit do
11
+ desc 'This tasks audits vendored gems, comparing file digests with published ones'
12
+ task :gems do
13
+ require 'digest'
14
+ require 'git'
15
+ require 'highline/import'
16
+ require 'json'
17
+ require 'nokogiri'
18
+ require 'open-uri'
19
+
20
+ git_base = Git.open('.')
21
+ git_user_name = git_base.config('user.name')
22
+ failed = false
23
+
24
+ Dir['vendor/cache/*.gem'].sort.each do |path|
25
+ file_digest = Digest::SHA256.file(path).hexdigest
26
+ file_name = File.basename(path)
27
+ matchdata = GEM_VERSION_PLATFORM_REGEXP.match(file_name)
28
+ gem_name = matchdata[1]
29
+ gem_version = matchdata[2]
30
+ gem_platform = matchdata[3]
31
+
32
+ begin
33
+ api_url = "https://rubygems.org/api/v2/rubygems/#{gem_name}/versions/#{gem_version}.json" \
34
+ "?platform=#{gem_platform || 'ruby'}"
35
+ api_result = JSON.parse(URI.parse(api_url).read)
36
+ published_checksum = api_result['sha']
37
+
38
+ if api_result['yanked'] == true
39
+ puts HighLine.new.color("Yanked Version: #{path} (#{api_url})", :red)
40
+ failed = true
41
+ elsif published_checksum == file_digest
42
+ release = git_base.log.object(path).to_s
43
+
44
+ system "bundle exec rake audit:safe release='#{release}' file='#{path}' " \
45
+ "reviewed_by='#{git_user_name}' " \
46
+ "comments='Checksum matches published version on rubygems.org (#{file_digest})'"
47
+ else
48
+ puts HighLine.new.color("Digest Mismatch: #{path} (#{api_url})", :red)
49
+ puts HighLine.new.color("Published Digest: #{published_checksum}", :red)
50
+ puts HighLine.new.color("File Digest: #{file_digest}", :red)
51
+ failed = true
52
+ end
53
+ rescue OpenURI::HTTPError
54
+ puts HighLine.new.color("Not Found: #{path} (#{api_url})", :yellow)
55
+ end
56
+ end
57
+
58
+ exit(false) if failed
59
+ end
60
+ end
@@ -0,0 +1,125 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'generators/changelog/init'
4
+ require_relative 'generators/code_of_conduct/init'
5
+ require_relative 'generators/decision_record/init'
6
+ require_relative 'generators/decision_record/new'
7
+ require_relative 'generators/linter/exec'
8
+ require_relative 'generators/linter/init'
9
+ require_relative 'generators/rake_tasks/init'
10
+ require_relative 'sub_command_base'
11
+
12
+ module WayOfWorking
13
+ # This class defines the exec (i.e. run) parent command
14
+ class Exec < SubCommandBase
15
+ register(Generators::Linter::Exec, 'linter', 'linter',
16
+ <<~LONGDESC)
17
+ Description:
18
+ This runs the linter on this project
19
+
20
+ Example:
21
+ way_of_working exec linter
22
+ LONGDESC
23
+ end
24
+
25
+ # This class defines the "init" parent command
26
+ class Init < SubCommandBase
27
+ desc 'all --contact-method [CONTACT METHOD]',
28
+ 'This adds all of the available Way of Working components to this project'
29
+ method_option :contact_method, required: true
30
+ def all
31
+ invoke_all
32
+ end
33
+
34
+ register(Generators::Changelog::Init, 'changelog', 'changelog',
35
+ <<~LONGDESC)
36
+ Description:
37
+ This adds the Keep a Changelog v1.1 changelog to the project
38
+
39
+ Example:
40
+ way_of_working init changelog
41
+
42
+ This will create:
43
+ CHANGELOG.md
44
+ LONGDESC
45
+
46
+ register(Generators::CodeOfConduct::Init, 'code_of_conduct',
47
+ 'code_of_conduct --contact-method [CONTACT METHOD]',
48
+ <<~LONGDESC)
49
+ Description:
50
+ This adds the Contributor Covenant v2.1 code of conduct to the project
51
+
52
+ Example:
53
+ way_of_working init code_of_conduct --contact-method "foo@bar.com"
54
+
55
+ This will create:
56
+ CODE_OF_CONDUCT.md
57
+ LONGDESC
58
+
59
+ register(Generators::DecisionRecord::Init, 'decision_record', 'decision_record',
60
+ <<~LONGDESC)
61
+ Description:
62
+ This generator adds Markdown Any Decision Records (MADR) to your project
63
+
64
+ Example:
65
+ way_of_working init decision_record
66
+
67
+ This will create:
68
+ docs/decisions/README.md
69
+ docs/decisions/adr-template.md
70
+ docs/decisions/0000-use-markdown-any-decision-records.md
71
+ LONGDESC
72
+
73
+ register(Generators::Linter::Init, 'linter', 'linter',
74
+ <<~LONGDESC)
75
+ Description:
76
+ Installs MegaLinter config files into the project
77
+
78
+ Example:
79
+ way_of_working init linter
80
+
81
+ This will create:
82
+ .github/workflows/mega-linter.yml
83
+ .mega-linter.yml
84
+ LONGDESC
85
+
86
+ register(Generators::RakeTasks::Init, 'rake_tasks', 'rake_tasks',
87
+ <<~LONGDESC)
88
+ Description:
89
+ Installs Way of Working rake tasks into this project
90
+
91
+ Example:
92
+ way_of_working init rake_tasks
93
+
94
+ This will amend or create:
95
+ Rakefile
96
+ LONGDESC
97
+ end
98
+
99
+ # This class defines the "new" parent command
100
+ class New < SubCommandBase
101
+ register(Generators::DecisionRecord::New, 'decision_record', 'decision_record [NAME]',
102
+ <<~LONGDESC)
103
+ Description:
104
+ This generator adds a new decision record to your project
105
+
106
+ Example:
107
+ way_of_working new decision_record "Title of the decision"
108
+
109
+ This will create:
110
+ docs/decisions/NNNN-title-of-the-decision.md
111
+ LONGDESC
112
+ end
113
+
114
+ # This class defines the top level interface
115
+ class CLI < Thor
116
+ desc 'init [COMPONENT]', 'Initialises Way of Working components'
117
+ subcommand 'init', Init
118
+
119
+ desc 'new [THING]', 'Creates new things'
120
+ subcommand 'new', New
121
+
122
+ desc 'exec [COMPONENT]', 'Executes (runs) the specific component'
123
+ subcommand 'exec', Exec
124
+ end
125
+ end
@@ -0,0 +1,110 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'way_of_working/paths'
4
+ require 'way_of_working/git/repo_reader'
5
+
6
+ module WayOfWorking
7
+ module Generators
8
+ module Changelog
9
+ # This class fetches the CODE_OF_CONDUCT.md and inserts the contact method
10
+ class Init < Thor::Group
11
+ include Thor::Actions
12
+
13
+ source_root ::WayOfWorking.source_root
14
+
15
+ HEADER_TEXT = <<~TEXT
16
+ # Changelog
17
+
18
+ All notable changes to this project will be documented in this file.
19
+
20
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
21
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
22
+
23
+ TEXT
24
+
25
+ def add_changelog_to_project
26
+ create_file 'CHANGELOG.md' do
27
+ HEADER_TEXT + releases + footer
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def releases
34
+ text = "## [Unreleased]\n\n"
35
+ text += added_change_text(:minor)
36
+ text += deprecated_removed_fixed_security_text(:minor)
37
+
38
+ summary_tags.each do |summary_tag|
39
+ text += "## [#{summary_tag.version}] - " \
40
+ "#{summary_tag.commit_date.strftime('%Y-%m-%d')}\n\n"
41
+
42
+ text += added_change_text(summary_tag.change_type)
43
+ text += deprecated_removed_fixed_security_text(summary_tag.change_type)
44
+ end
45
+
46
+ text
47
+ end
48
+
49
+ def added_change_text(tag_change_type)
50
+ return '' if tag_change_type == :patch
51
+
52
+ change_text('Added', 'Detail new feature(s) here', true) +
53
+ change_text('Change', 'Detail change(s) in existing functionality here',
54
+ tag_change_type == :major)
55
+ end
56
+
57
+ def deprecated_removed_fixed_security_text(tag_change_type)
58
+ change_text('Deprecated', 'Detail soon-to-be removed features here') +
59
+ change_text('Removed', 'Detail removed features here', tag_change_type == :major) +
60
+ change_text('Fixed', 'Detail any bug fixes here', true) +
61
+ change_text('Security', 'Detail fixes to vulnerabilities here')
62
+ end
63
+
64
+ # This method adds all of the reference style markdown links
65
+ def footer
66
+ return '' if summary_tags.empty?
67
+
68
+ previous_tag = nil
69
+ footer_text = ''
70
+ summary_tags.each do |summary_tag|
71
+ footer_text += if previous_tag
72
+ release_link(summary_tag.name, previous_tag.name, previous_tag.version)
73
+ else
74
+ release_link(summary_tag.name, 'HEAD', 'Unreleased')
75
+ end
76
+
77
+ previous_tag = summary_tag
78
+ end
79
+
80
+ footer_text += "[#{previous_tag.version}]: #{url}/releases/tag/#{previous_tag.name}\n"
81
+
82
+ footer_text
83
+ end
84
+
85
+ def release_link(start_tag, end_tag, version)
86
+ "[#{version}]: #{url}/compare/#{start_tag}...#{end_tag}\n"
87
+ end
88
+
89
+ def change_text(type, description, likely = false)
90
+ text = "### #{type}\n\n- TODO: #{description}"
91
+ text += ' (if any)' unless likely
92
+ text += "\n\n"
93
+ text
94
+ end
95
+
96
+ def repo_reader
97
+ @repo_reader ||= ::WayOfWorking::Git::RepoReader.new(::Git.open('.'))
98
+ end
99
+
100
+ def summary_tags
101
+ @summary_tags ||= repo_reader.summary_tags.reverse
102
+ end
103
+
104
+ def url
105
+ @url ||= repo_reader.likely_upstream_remote_url
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'way_of_working/paths'
4
+
5
+ module WayOfWorking
6
+ module Generators
7
+ module CodeOfConduct
8
+ # This class fetches the CODE_OF_CONDUCT.md and inserts the contact method
9
+ class Init < Thor::Group
10
+ include Thor::Actions
11
+
12
+ source_root ::WayOfWorking.source_root
13
+
14
+ class_option :contact_method, required: true
15
+
16
+ # Use this method to update the cached template when required
17
+ # def download_and_save_code_of_conduct_template
18
+ # code_of_conduct_file = 'lib/way_of_working/templates/CODE_OF_CONDUCT.md.tt'
19
+
20
+ # get 'https://www.contributor-covenant.org/version/2/1/code_of_conduct/code_of_conduct.md',
21
+ # code_of_conduct_file
22
+ # gsub_file code_of_conduct_file, '[INSERT CONTACT METHOD]',
23
+ # "<%= options['contact_method'] %>"
24
+ # end
25
+
26
+ def add_code_of_conduct_to_project
27
+ template 'CODE_OF_CONDUCT.md'
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'way_of_working/paths'
4
+
5
+ module WayOfWorking
6
+ module Generators
7
+ module DecisionRecord
8
+ # This generator add the MADR files to the doc/decisions folder
9
+ class Init < Thor::Group
10
+ include Thor::Actions
11
+
12
+ source_root ::WayOfWorking.source_root
13
+
14
+ # Templates are from https://github.com/adr/madr/tree/3.0.0/template
15
+ def create_decision_record_files
16
+ copy_file 'docs/decisions/README.md'
17
+
18
+ # from https://raw.githubusercontent.com/adr/madr/3.0.0/template/adr-template.md
19
+ @decision_date = '{YYYY-MM-DD when the decision was last updated}'
20
+ @title = '{short title of solved problem and solution}'
21
+ template 'docs/decisions/adr-template.md'
22
+
23
+ get 'https://raw.githubusercontent.com/adr/madr/3.0.0/template/0000-use-markdown-any-decision-records.md',
24
+ 'docs/decisions/0000-use-markdown-any-decision-records.md'
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end