trello_tool 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d4cfb13afc59a0bbc26ff8d073ec8205a8be3186078586626f2b1d1a6678534b
4
+ data.tar.gz: 24100d779e70261e15fd631cf8cc8c6e15bbfe52b4c14e020759244c10ac91f2
5
+ SHA512:
6
+ metadata.gz: 0645b48ad54aea192469652a91a4d809c502cd32a97a440dbde72a40992ad365ba948c465d8c8e8705b424367f80783111cd36bf13530ad289f8515611a9d34e
7
+ data.tar.gz: a1a50a0449d75ddd376931d32caf80f057ca973d5825a003d4bee9b5ded2d89aea22501ae235cedebc78e40d89314b972773e701ffb330261aae5dbc314d633b
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,22 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ AllCops:
4
+ NewCops: enable
5
+ TargetRubyVersion: 3.0
6
+ Lint/AmbiguousBlockAssociation:
7
+ Enabled: true
8
+ Exclude:
9
+ - "spec/**/*" # https://github.com/rubocop/rubocop/issues/4222
10
+
11
+ Metrics/BlockLength:
12
+ AllowedMethods:
13
+ - "no_commands" # thor
14
+ Exclude:
15
+ - "spec/**/*.rb"
16
+
17
+ Style/FetchEnvVar:
18
+ Enabled: false
19
+
20
+ Style/StringLiterals:
21
+ Enabled: true
22
+ EnforcedStyle: double_quotes
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,34 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config --exclude-limit 100`
3
+ # on 2023-12-17 17:00:42 UTC using RuboCop version 1.59.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 3
10
+ # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
11
+ Metrics/AbcSize:
12
+ Max: 35
13
+
14
+ # Offense count: 1
15
+ # Configuration parameters: AllowedMethods, AllowedPatterns.
16
+ Metrics/CyclomaticComplexity:
17
+ Max: 8
18
+
19
+ # Offense count: 5
20
+ # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
21
+ Metrics/MethodLength:
22
+ Max: 17
23
+
24
+ # Offense count: 1
25
+ # Configuration parameters: AllowedMethods, AllowedPatterns.
26
+ Metrics/PerceivedComplexity:
27
+ Max: 9
28
+
29
+ # Offense count: 5
30
+ # This cop supports safe autocorrection (--autocorrect).
31
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
32
+ # URISchemes: http, https
33
+ Layout/LineLength:
34
+ Max: 137
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.2.0] - 2022-05-21
4
+
5
+ * added `summarize_as_md_long`
6
+
7
+ ## [0.1.0] - 2022-05-21
8
+
9
+ - Initial release
@@ -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 tim@red56.uk. 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
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in trello_tool.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "= 1.59.0"
13
+
14
+ case ENV["TEST_PSYCH_ON"]
15
+ when "3"
16
+ gem "psych", "< 4"
17
+ when "4"
18
+ gem "psych", "> 3"
19
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Tim Diggins
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,98 @@
1
+ # TrelloTool
2
+
3
+ Tool for doing basic things to a dev trello using the api.
4
+ This is for a software development context where the software has explicit version numbers
5
+ (ie. typically not in a Continuous Delivery situation)
6
+
7
+ The tool envisages a main trello board with the following lists:
8
+
9
+ * (some optional lists at the beginning -- "Triage" and "Reference" by default)
10
+ * "To do"
11
+ * "Doing"
12
+ * (at least one "done" list -- "Done" by default)
13
+ * "Next version" (for things that have been merged but not deployed)
14
+ * (a set of lists named after the version numbers e.g. "v1.2.3", "v1.2.2", etc)
15
+ * (a divider list starting with `[` and ending with `]` (which might be empty or contain chores done during that time) named after a month or a sprint, e.g. "[ December ]" or "[ Sprint 1st Sep - 13th Sep ]" etc)
16
+
17
+ And another board where you archive these lists as they become old
18
+
19
+ ## Installation
20
+
21
+ Add this line to your application's Gemfile:
22
+
23
+ ```ruby
24
+ gem 'trello_tool', group: :development
25
+ ```
26
+
27
+ And then execute:
28
+
29
+ $ bundle install
30
+
31
+ Or install it yourself as:
32
+
33
+ $ gem install trello_tool
34
+
35
+
36
+ ### Tool Configuration
37
+
38
+ `bin/trello_tool config` will create a trello_tool.yml file with defaults in it if it doesn't already exist
39
+
40
+ (This will be in a config directory if you have one, otherwise in the root folder).
41
+ You will want to add this to your repo to allow this to be shared in your project
42
+
43
+ You need to configure a couple of things:
44
+
45
+ * `main_board_url` - this will look something like "https://trello.com/b/sOmeBOarDiD/optional-board-name"
46
+ * `archive_board_url`
47
+
48
+ You can also configure some defaults
49
+
50
+ * `next_version_list_name` = "next version"
51
+ * `todo_list_name` = "TO DO"
52
+ * `doing_list_name` = "-- DOING --"
53
+ * `initial_list_names` = ["Triage", "Reference"]
54
+ * `done_list_names` = ["Done"]
55
+ * `version_template` = "v%s"
56
+ * `divider_template` = "[%s]"
57
+ * `too_many_doing` = 2
58
+ * `too_many_todo` = 10
59
+
60
+
61
+ ### Trello Authorisation
62
+
63
+ You need to set the following environment variables to give trello_tool access to your lists
64
+
65
+ * `TRELLO_DEVELOPER_PUBLIC_KEY` -- you can find this at https://trello.com/app-key/
66
+ * `TRELLO_MEMBER_TOKEN` -- you can create one at https://trello.com/app-key/ "generate a Token"
67
+
68
+ You can also read more at https://github.com/jeremytregunna/ruby-trello
69
+
70
+ ## Usage
71
+
72
+ * bin/trello/health
73
+ trello/health
74
+
75
+ ## Development
76
+
77
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
78
+
79
+ 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).
80
+
81
+ ### Setup git pre-commit hook
82
+
83
+ After you clone this repo for the first time you can link in the pre-commit
84
+ script so that rubocop is checked before you commit (you can skip the pre-commit hook with )
85
+
86
+ ln -nfs $(pwd)/config/githooks/pre-commit ./.git/hooks/pre-commit
87
+
88
+ ## Contributing
89
+
90
+ Bug reports and pull requests are welcome on GitHub at https://github.com/timdiggins/trello_tool. 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/timdiggins/trello_tool/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 TrelloTool project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/timdiggins/trello_tool/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,4 @@
1
+ #!/bin/bash
2
+
3
+ echo "checking rubocop (committing files only)"
4
+ git diff --cached --name-only | xargs ls | xargs rubocop --force-exclusion
data/exe/trello_tool ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ $LOAD_PATH << File.expand_path("../lib", File.dirname(__FILE__))
5
+ require File.expand_path("../lib/trello_tool_thor", File.dirname(__FILE__))
6
+
7
+ TrelloToolThor.start
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "psych"
4
+
5
+ module TrelloTool
6
+ # wraps configuration of key features of Trello Tool and automatically pulls in
7
+ # from a yml file in a specific location and can generate on demand
8
+ module DefaultConfiguration
9
+ FILE_NAME = "trello_tool.yml"
10
+ DEFAULTS = {
11
+ main_board_url: nil,
12
+ archive_board_url: nil,
13
+ next_version_list_name: "next version",
14
+ todo_list_name: "TO DO",
15
+ doing_list_name: "-- DOING --",
16
+ initial_list_names: %w[Triage Reference],
17
+ done_list_names: ["Done"],
18
+ version_template: "v%s",
19
+ divider_template: "[%s]",
20
+ too_many_doing: 2,
21
+ too_many_todo: 10
22
+ }.freeze
23
+ end
24
+ Configuration = Struct.new(*DefaultConfiguration::DEFAULTS.keys, keyword_init: true) do
25
+ include DefaultConfiguration
26
+
27
+ def initialize(root_dir = Dir.pwd)
28
+ @root_dir = root_dir
29
+ super(DefaultConfiguration::DEFAULTS)
30
+ load_from_config_file if config_file_exists?
31
+ end
32
+
33
+ # generates a file based on current settings
34
+ def generate
35
+ File.open(config_file, "w") do |f|
36
+ Psych.dump(to_h { |k, v| [k.to_s, v] }, f) # rubocop:disable Style/HashTransformKeys doesn't work
37
+ end
38
+ end
39
+
40
+ def config_file_exists?
41
+ File.exist?(config_file)
42
+ end
43
+
44
+ def config_file
45
+ File.join(config_dir, DefaultConfiguration::FILE_NAME)
46
+ end
47
+
48
+ # an ordered array of expected list names before the version and month names
49
+ def expected_list_names
50
+ @expected_list_names ||= initial_list_names + [todo_list_name,
51
+ doing_list_name] + done_list_names + [next_version_list_name]
52
+ end
53
+
54
+ def divider_list_name?(list_name)
55
+ divider_list_matcher.match?(list_name)
56
+ end
57
+
58
+ def divider_list_matcher
59
+ @divider_list_matcher ||= begin
60
+ pieces = divider_template.split(/(%s)/)
61
+ pieces = pieces.map { |piece| piece == "%s" ? ".+" : Regexp.escape(piece) }
62
+ Regexp.new("\\A#{pieces.join}\\Z")
63
+ end
64
+ end
65
+
66
+ def version_list_name?(list_name)
67
+ version_list_matcher.match?(list_name)
68
+ end
69
+
70
+ def version_list_matcher
71
+ @version_list_matcher ||= Regexp.new("\\A#{format(version_template, '\d+[.]\d+[.]\d+')}")
72
+ end
73
+
74
+ def month_template=(template)
75
+ self.divider_template = template
76
+ puts "DEPRECATED: use divider_template instead of month_template"
77
+ end
78
+
79
+ protected
80
+
81
+ def config_dir
82
+ @config_dir ||= find_config_dir
83
+ end
84
+
85
+ def find_config_dir
86
+ [
87
+ File.join(@root_dir, "config"),
88
+ @root_dir
89
+ ].each do |target|
90
+ return target if Dir.exist?(target)
91
+ end
92
+ end
93
+
94
+ def load_from_config_file
95
+ Psych.safe_load(File.read(config_file)).each do |key, value|
96
+ send("#{key}=", value)
97
+ end
98
+ self.initial_list_names ||= []
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TrelloTool
4
+ # Health analysis of a board
5
+ class Health
6
+ attr_reader :board, :configuration, :symbols_and_colours, :unexpected, :expected_lists
7
+
8
+ def initialize(board, configuration)
9
+ @board = board
10
+ @configuration = configuration
11
+ @symbols_and_colours = []
12
+ @unexpected = []
13
+ @expected_lists = {}
14
+ analyze
15
+ end
16
+
17
+ def each_issue_with_severity
18
+ unexpected.each do |list, index|
19
+ yield list.name.inspect, "Unexpected @ ##{index + 1}"
20
+ end
21
+ yield todo_list_issue if todo_list_issue
22
+ yield doing_list_issue if doing_list_issue
23
+ end
24
+
25
+ def each_expected_list_with_length
26
+ expected_lists.each do |name, value|
27
+ yield name, value[:length]
28
+ end
29
+ end
30
+
31
+ protected
32
+
33
+ def todo_list
34
+ expected_lists[configuration.todo_list_name]
35
+ end
36
+
37
+ def doing_list
38
+ expected_lists[configuration.doing_list_name]
39
+ end
40
+
41
+ def doing_list_issue
42
+ if !doing_list
43
+ ["No doing list (looking for #{configuration.doing_list_name.inspect})", "Unconfigured"]
44
+ elsif configuration.too_many_doing <= doing_list[:length]
45
+ ["Cards in #{configuration.doing_list_name.inspect} has #{doing_list[:length]} cards (> #{configuration.too_many_doing})", "Bad"]
46
+ end
47
+ end
48
+
49
+ def todo_list_issue
50
+ if !todo_list
51
+ ["No to do list (looking for #{configuration.todo_list_name.inspect})", "Unconfigured"]
52
+ elsif configuration.too_many_todo <= todo_list[:length]
53
+ ["Cards in #{configuration.todo_list_name.inspect} has #{todo_list[:length]} cards (> #{configuration.too_many_todo})", "Bad"]
54
+ end
55
+ end
56
+
57
+ def analyze
58
+ board.lists.each_with_index do |list, index|
59
+ if list.name == configuration.next_version_list_name
60
+ add_expected_list(list, "V", Thor::Shell::Color::BOLD)
61
+ elsif list.name == configuration.todo_list_name
62
+ add_expected_list(list, "+", Thor::Shell::Color::BOLD)
63
+ elsif list.name == configuration.doing_list_name
64
+ add_expected_list(list, "d", Thor::Shell::Color::BOLD)
65
+ elsif configuration.expected_list_names.include?(list.name)
66
+ add_expected_list(list, ".", Thor::Shell::Color::CYAN)
67
+ elsif configuration.divider_list_matcher.match?(list.name)
68
+ symbols_and_colours << ["|", Thor::Shell::Color::CYAN]
69
+ elsif configuration.version_list_matcher.match?(list.name)
70
+ symbols_and_colours << ["v", Thor::Shell::Color::CYAN]
71
+ else
72
+ add_unexpected_list(list, index)
73
+ end
74
+ end
75
+ end
76
+
77
+ def add_expected_list(list, symbol, colour)
78
+ expected_lists[list.name] = { length: list.cards.length }
79
+ symbols_and_colours << [symbol, colour]
80
+ end
81
+
82
+ def add_unexpected_list(list, index)
83
+ unexpected << [list, index]
84
+ symbols_and_colours << ["?", Thor::Shell::Color::RED]
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "trello"
4
+ require "trello_tool/util"
5
+
6
+ module TrelloTool
7
+ # Wrapped client for trello adapting it to things we need it to do
8
+ class TrelloClient < SimpleDelegator
9
+ include TrelloTool::Util
10
+ attr_reader :client, :configuration
11
+
12
+ # @param configuration[TrelloTool::Configuration]
13
+ def initialize(configuration)
14
+ @configuration = configuration
15
+ @client = Trello::Client.new(
16
+ developer_public_key: ENV["TRELLO_DEVELOPER_PUBLIC_KEY"],
17
+ member_token: ENV["TRELLO_MEMBER_TOKEN"]
18
+ )
19
+ super(@client)
20
+ end
21
+
22
+ def authorized(&block)
23
+ Trello.configure do |config|
24
+ config.developer_public_key = ENV["TRELLO_DEVELOPER_PUBLIC_KEY"]
25
+ config.member_token = ENV["TRELLO_MEMBER_TOKEN"]
26
+ end
27
+ block.call
28
+ Trello.configure do |config|
29
+ config.developer_public_key = nil
30
+ config.member_token = nil
31
+ end
32
+ end
33
+
34
+ def main_board
35
+ @main_board ||= client.find(:boards, extract_id_from_url(configuration.main_board_url))
36
+ end
37
+
38
+ def archive_board
39
+ @archive_board ||= client.find(:boards, extract_id_from_url(configuration.archive_board_url))
40
+ end
41
+
42
+ # @return [Array] of list names with left index, ordered from right
43
+ def archiveable_list_names_with_index
44
+ @archiveable_list_names_with_index ||= [].tap do |lists|
45
+ all_lists = main_board.lists
46
+ all_lists.reverse.each_with_index do |list, right_index|
47
+ if (divider_list?(list) && right_index.zero?) || version_list?(list) # rubocop:disable Style/GuardClause
48
+ left_index = all_lists.length - right_index - 1
49
+ lists << [list.name, left_index]
50
+ else
51
+ break
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ def next_version_list
58
+ @next_version_list ||= find_list_by_list_name(main_board, configuration.next_version_list_name)
59
+ end
60
+
61
+ protected
62
+
63
+ def divider_list?(list)
64
+ configuration.divider_list_name?(list.name)
65
+ end
66
+
67
+ def version_list?(list)
68
+ configuration.version_list_name?(list.name)
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "trello"
4
+
5
+ module TrelloTool
6
+ # small utility methods for handling trello urls
7
+ module Util
8
+ private
9
+
10
+ def extract_id_from_url(trello_board_url)
11
+ match_data = %r{https://trello.com/b/([a-zA-Z0-9]+)/?.*}.match(trello_board_url)
12
+ raise "Unexpectedly #{trello_board_url} doesn't match https://trelloc.om/b/ID/description" unless match_data
13
+
14
+ match_data[1]
15
+ end
16
+
17
+ # @param board [Trello::Board]
18
+ # @param list_name [String]
19
+ # @return [Trello::List]
20
+ def find_list_by_list_name(board, list_name)
21
+ list = board.lists.detect { |l| l.name == list_name }
22
+ return list if list
23
+
24
+ puts "couldn't find list called #{list_name.inspect}. found: #{board.lists.map(&:name).map(&:inspect).join(', ')}."
25
+ nil
26
+ end
27
+
28
+ def find_pos_before_list(board, target_list)
29
+ previous_list_pos = 0
30
+ board.lists.each do |this_list|
31
+ return previous_list_pos && ((target_list.pos + previous_list_pos) / 2) if this_list == target_list
32
+
33
+ previous_list_pos = this_list.pos
34
+ end
35
+
36
+ puts "couldn't find list"
37
+ nil
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TrelloTool
4
+ VERSION = "0.2.0"
5
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "trello_tool/version"
4
+
5
+ module TrelloTool
6
+ class Error < StandardError; end
7
+ # Your code goes here...
8
+ end
@@ -0,0 +1,171 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "thor"
4
+ require "trello_tool/configuration"
5
+ require "trello_tool/health"
6
+ require "trello_tool/trello_client"
7
+ require "trello_tool/util"
8
+
9
+ # The thor class
10
+ # rubocop:disable Metrics/ClassLength
11
+ class TrelloToolThor < Thor
12
+ include TrelloTool::Util
13
+
14
+ def self.configuration
15
+ @configuration ||= TrelloTool::Configuration.new
16
+ end
17
+
18
+ no_commands do
19
+ delegate :configuration, to: :class
20
+ end
21
+
22
+ namespace :trello_tool
23
+
24
+ desc "config", "generates default config file unless already present"
25
+
26
+ def config
27
+ if configuration.config_file_exists?
28
+ say("Configuration already exists at #{configuration.config_file}")
29
+ else
30
+ configuration.generate
31
+ say("Generated configuration at #{configuration.config_file}. You will need to specify trello urls")
32
+ end
33
+ end
34
+
35
+ desc "archive_last (N)",
36
+ "archives the last N lists from the end of #{configuration.main_board_url} to the beginning of #{configuration.archive_board_url}"
37
+
38
+ def archive_last(to_archive = "1")
39
+ number_to_archive = to_archive.to_i
40
+ say "archiving #{number_to_archive} lists:"
41
+ lists_reversed = client.main_board.lists.reverse
42
+ 0.upto(number_to_archive - 1).each do |index|
43
+ say(format("\r%<count>2s / %<total>s", count: index + 1, total: number_to_archive), Thor::Shell::Color::GREEN,
44
+ false)
45
+ list = lists_reversed[index]
46
+ break unless list
47
+
48
+ list.move_to_board(client.archive_board)
49
+ say "\r * #{list.name.inspect}#{' ' * 20}\n"
50
+ end
51
+ say
52
+ end
53
+
54
+ desc "archive", "archives one month's worth"
55
+
56
+ def archive
57
+ client.archiveable_list_names_with_index.each do |list, index|
58
+ say "* #{list.inspect} @##{index + 1}"
59
+ end
60
+ archive_last(client.archiveable_list_names_with_index.length) if yes?("archive them?")
61
+ end
62
+
63
+ desc "health", "checks whether main board is 'healthy'"
64
+
65
+ def health
66
+ health = TrelloTool::Health.new(client.main_board, configuration)
67
+ health.symbols_and_colours.each do |symbol, colour|
68
+ say(symbol, colour, false)
69
+ end
70
+ say
71
+ health.each_issue_with_severity do |issue, severity|
72
+ say(format("%-20s", "#{severity}:"), Thor::Shell::Color::RED, false)
73
+ say(issue)
74
+ end
75
+ health.each_expected_list_with_length do |list_name, length|
76
+ say(" * #{list_name} (#{length})")
77
+ end
78
+ end
79
+
80
+ desc "lists (BOARD_URL)", "prints out lists in a board (defaults to main board)"
81
+
82
+ def lists(url = configuration.main_board_url)
83
+ board = client.find(:boards, extract_id_from_url(url))
84
+ say board.name
85
+ say url
86
+ say
87
+ board.lists.each do |list|
88
+ say "* #{list.name}"
89
+ end
90
+ end
91
+
92
+ desc "release (VERSION)",
93
+ "rename next_version to VERSION and create next_version. If VERSION isn't specified use whatever is in ./.RELEASE_NEW_VERSION"
94
+
95
+ def release(version = nil)
96
+ version ||= File.exist?(".RELEASE_NEW_VERSION") && File.read(".RELEASE_NEW_VERSION").strip
97
+ unless version
98
+ say("Usage: release VERSION # or put version number in .RELEASE_NEW_VERSION")
99
+ return
100
+ end
101
+
102
+ next_version_list = client.next_version_list
103
+ next_version_list.name = version
104
+ next_version_list.save
105
+ client.authorized do
106
+ Trello::List.create(name: configuration.next_version_list_name, board_id: client.main_board.id,
107
+ pos: find_pos_before_list(client.main_board, next_version_list))
108
+ end
109
+ end
110
+
111
+ desc "summarize_as_md (LIST_NAME (BOARD_URL))",
112
+ "prints out markdown summarizing all cards in a list in a board (defaults to 'to do' list of main board)"
113
+
114
+ def summarize_as_md(list_name = configuration.todo_list_name, url = configuration.main_board_url)
115
+ board = client.find(:boards, extract_id_from_url(url))
116
+ list = find_list_by_list_name(board, list_name)
117
+ return unless list
118
+
119
+ cards = list.cards
120
+ say "\n# #{list.name} (#{cards.length} cards)\n\n"
121
+ list.cards.each do |card|
122
+ say "* [#{card.name}](#{card.url})"
123
+ end
124
+ say "\n"
125
+ end
126
+
127
+ desc "summarize_as_md_long (LIST_NAME (BOARD_URL))",
128
+ "prints out markdown summarizing all cards in a list in a board" \
129
+ "(defaults to 'to do' list of main board) -- includes attachment urls"
130
+
131
+ def summarize_as_md_long(list_name = configuration.todo_list_name, url = configuration.main_board_url)
132
+ board = client.find(:boards, extract_id_from_url(url))
133
+ list = find_list_by_list_name(board, list_name)
134
+ return unless list
135
+
136
+ cards = list.cards
137
+ say "\n# #{list.name} (#{cards.length} cards)\n\n"
138
+ list.cards.each do |card|
139
+ labels = card.labels.map { |label| "[#{label.name}]" }.join(" ")
140
+ say "* #{card.name} #{labels}\n #{card.url}"
141
+ card.attachments.each do |attachment|
142
+ next unless (url = attachment.url)
143
+ next if %w[pdf png jpg].include?(url.split(".").last&.downcase)
144
+
145
+ say " - #{url}"
146
+ end
147
+ end
148
+ say "\n"
149
+ end
150
+ desc "summarize_as_urls (LIST_NAME (BOARD_URL))",
151
+ "prints out urls summarizing all cards in a list in a board (defaults to 'to do' list of main board)"
152
+ def summarize_as_urls(list_name = configuration.todo_list_name, url = configuration.main_board_url)
153
+ board = client.find(:boards, extract_id_from_url(url))
154
+ list = find_list_by_list_name(board, list_name)
155
+ return unless list
156
+
157
+ cards = list.cards
158
+ say "\n#{list.name} (#{cards.length} cards)\n\n"
159
+ list.cards.each do |card|
160
+ say card.url
161
+ end
162
+ say "\n"
163
+ end
164
+
165
+ private
166
+
167
+ def client
168
+ TrelloTool::TrelloClient.new(configuration)
169
+ end
170
+ end
171
+ # rubocop:enable Metrics/ClassLength
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/trello_tool/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "trello_tool"
7
+ spec.version = TrelloTool::VERSION
8
+ spec.authors = ["Tim Diggins"]
9
+ spec.email = ["tim@red56.uk"]
10
+
11
+ spec.summary = "Tool for doing basic things to a dev trello using the api."
12
+ spec.homepage = "https://github.com/timdiggins/trello_tool"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = ">= 3.0.0"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = spec.homepage
18
+ spec.metadata["changelog_uri"] = "https://github.com/timdiggins/trello_tool/blob/main/CHANGELOG.md"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject do |f|
24
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
25
+ end
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_dependency "ruby-trello"
32
+ spec.add_dependency "thor"
33
+ spec.metadata["rubygems_mfa_required"] = "true"
34
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trello_tool
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Tim Diggins
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-09-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruby-trello
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: thor
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:
42
+ email:
43
+ - tim@red56.uk
44
+ executables:
45
+ - trello_tool
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".rspec"
50
+ - ".rubocop.yml"
51
+ - ".rubocop_todo.yml"
52
+ - CHANGELOG.md
53
+ - CODE_OF_CONDUCT.md
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - config/githooks/pre-commit
59
+ - exe/trello_tool
60
+ - lib/trello_tool.rb
61
+ - lib/trello_tool/configuration.rb
62
+ - lib/trello_tool/health.rb
63
+ - lib/trello_tool/trello_client.rb
64
+ - lib/trello_tool/util.rb
65
+ - lib/trello_tool/version.rb
66
+ - lib/trello_tool_thor.rb
67
+ - trello_tool.gemspec
68
+ homepage: https://github.com/timdiggins/trello_tool
69
+ licenses:
70
+ - MIT
71
+ metadata:
72
+ homepage_uri: https://github.com/timdiggins/trello_tool
73
+ source_code_uri: https://github.com/timdiggins/trello_tool
74
+ changelog_uri: https://github.com/timdiggins/trello_tool/blob/main/CHANGELOG.md
75
+ rubygems_mfa_required: 'true'
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 3.0.0
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubygems_version: 3.5.15
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Tool for doing basic things to a dev trello using the api.
95
+ test_files: []