crm-stage-map-check 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +22 -0
- data/README.md +52 -0
- data/bin/crm-stage-map-check +25 -0
- data/lib/crm_stage_map_check.rb +118 -0
- metadata +62 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: c4caa136209f2c2e2ceb5fd050435f7eb54e210ed4e7c358cdf3c597a38d7546
|
|
4
|
+
data.tar.gz: acf60b7629b7d0975b6fdb1867109d1dbea5f9c27f6b270c42440cd3c7584862
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: dc5b019a7c3e2cac819e56c59165a47488bb691e9e383d8c76860cf82c43df046ccdb3e8e94c8ebe2f1484e01eb2663d242ce93aedb05b64ca1153355294d774
|
|
7
|
+
data.tar.gz: 2c130a38a8e85e367d7e8324c64e6a6284260f0986ed0298f84e1d5807268011fbcac878e431ca6a5a5e8b2b498db438e0f930af49c8606c823f27ac249f73a9
|
data/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 OneGTMLab
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
data/README.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# crm-stage-map-check
|
|
2
|
+
|
|
3
|
+
Ruby command line tool and library. Give it a CSV with one row per CRM record: the record id, its old stage and the new stage you have assigned (empty if you have not mapped it yet). It lists the records that are not mapped yet, shows where each old stage goes, flags old stages that go to more than one new stage (conflict) and new stages that are fed by more than one old stage (merge), and prints totals. It only counts and flags: it does not know your stages and does not judge your plan.
|
|
4
|
+
|
|
5
|
+
Part of the [OneGTMLab](https://www.onegtmlab.dev) free GTM tools. Background on the idea: [HubSpot vs Salesforce](https://www.onegtmlab.dev/tool-directory/compare/hubspot-vs-salesforce).
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
gem install crm-stage-map-check
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Use
|
|
14
|
+
|
|
15
|
+
CSV columns: record_id, old_stage, new_stage. Stages are trimmed and compared ignoring upper and lower case, and the first spelling seen is shown. An empty new_stage means the record is not mapped yet. Output: rows, mapped, unmapped (the first 10 record ids with their old stage, then "and N more"); per old stage (sorted by records, highest first, then by name) the records and the new stages they went to with counts, marked "conflict" when the same old stage goes to more than one new stage (records with no new stage yet are not counted as a second target); per new stage (same sort) its records and how many different old stages feed it, marked "merge" when more than one; then totals for old stages, new stages, conflicts and merges. A conflict or a merge is a flag for you to look at, not an error in your plan: you may have split or combined stages on purpose. Option --strict exits 1 (after printing the report) when anything is unmapped or in conflict; without it the exit code is 0. Exit code 2 means the input could not be used. A missing file, a missing column, an empty record_id or old_stage (the row is named), a duplicate record_id, a bad option or a CSV with no rows stops the run with an error message.
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
$ ruby bin/crm-stage-map-check sample.csv
|
|
19
|
+
rows: 10
|
|
20
|
+
mapped: 7
|
|
21
|
+
unmapped: 3
|
|
22
|
+
|
|
23
|
+
unmapped records
|
|
24
|
+
r7 (old stage Stage C)
|
|
25
|
+
r8 (old stage Stage D)
|
|
26
|
+
r9 (old stage Stage D)
|
|
27
|
+
|
|
28
|
+
per old stage
|
|
29
|
+
Stage A: 3 records -> Stage X 2, Stage Y 1 conflict
|
|
30
|
+
Stage B: 2 records -> Stage X 2
|
|
31
|
+
Stage C: 2 records -> Stage Z 1, not mapped yet 1
|
|
32
|
+
Stage D: 2 records -> not mapped yet 2
|
|
33
|
+
Stage E: 1 record -> Stage Z 1
|
|
34
|
+
|
|
35
|
+
per new stage
|
|
36
|
+
Stage X: 4 records from 2 old stages merge
|
|
37
|
+
Stage Z: 2 records from 2 old stages merge
|
|
38
|
+
Stage Y: 1 record from 1 old stage
|
|
39
|
+
|
|
40
|
+
old stages: 5
|
|
41
|
+
new stages: 3
|
|
42
|
+
conflicts: 1
|
|
43
|
+
merges: 2
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Test
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
ruby test/run.rb
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Offline, no network calls, no dependencies beyond the language runtime. MIT licensed.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative '../lib/crm_stage_map_check'
|
|
5
|
+
|
|
6
|
+
if ARGV.empty? || ARGV.include?('-h') || ARGV.include?('--help')
|
|
7
|
+
warn "usage: crm-stage-map-check stages.csv [--strict]\n" \
|
|
8
|
+
"CSV columns: record_id, old_stage, new_stage. Exit 1 with --strict when anything is unmapped or in conflict, 2 for bad input. " \
|
|
9
|
+
"More: https://www.onegtmlab.dev/tool-directory/compare/hubspot-vs-salesforce"
|
|
10
|
+
exit 2
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
begin
|
|
14
|
+
path, strict = CrmStageMapCheck.parse_args(ARGV)
|
|
15
|
+
result = CrmStageMapCheck.analyze(CrmStageMapCheck.from_csv(File.read(path)))
|
|
16
|
+
rescue ArgumentError, Errno::ENOENT, Errno::EISDIR, Errno::EACCES, CSV::MalformedCSVError => e
|
|
17
|
+
warn "error: #{e.message}"
|
|
18
|
+
exit 2
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
print CrmStageMapCheck.render(result)
|
|
22
|
+
if strict && CrmStageMapCheck.strict_failure?(result)
|
|
23
|
+
warn "strict: #{result[:unmapped]} unmapped, #{result[:conflicts]} conflict(s)"
|
|
24
|
+
exit 1
|
|
25
|
+
end
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'csv'
|
|
4
|
+
|
|
5
|
+
# Check a stage mapping you wrote for a CRM move: for every record, the old stage and the new stage you assigned.
|
|
6
|
+
# It counts and flags; it does not decide whether your mapping is right.
|
|
7
|
+
module CrmStageMapCheck
|
|
8
|
+
Row = Struct.new(:record_id, :old_stage, :new_stage, :line, keyword_init: true)
|
|
9
|
+
|
|
10
|
+
LIST_LIMIT = 10
|
|
11
|
+
|
|
12
|
+
# Returns the rows; raises ArgumentError on bad input.
|
|
13
|
+
def self.from_csv(text)
|
|
14
|
+
table = CSV.parse(text.sub(/\A/, ''), headers: true, header_converters: ->(h) { h.to_s.strip.downcase })
|
|
15
|
+
missing = %w[record_id old_stage new_stage] - table.headers.compact
|
|
16
|
+
raise ArgumentError, "missing column(s): #{missing.join(', ')}" unless missing.empty?
|
|
17
|
+
raise ArgumentError, 'no rows in the CSV' if table.empty?
|
|
18
|
+
|
|
19
|
+
seen = {}
|
|
20
|
+
table.each_with_index.map do |r, i|
|
|
21
|
+
line = i + 2
|
|
22
|
+
id = r['record_id'].to_s.strip
|
|
23
|
+
raise ArgumentError, "row #{line}: empty record_id" if id.empty?
|
|
24
|
+
|
|
25
|
+
old = r['old_stage'].to_s.strip
|
|
26
|
+
raise ArgumentError, "row #{line}: empty old_stage for record #{id.inspect}" if old.empty?
|
|
27
|
+
raise ArgumentError, "row #{line}: duplicate record_id #{id.inspect} (first seen in row #{seen[id]})" if seen.key?(id)
|
|
28
|
+
|
|
29
|
+
seen[id] = line
|
|
30
|
+
nw = r['new_stage'].to_s.strip
|
|
31
|
+
Row.new(record_id: id, old_stage: old, new_stage: nw.empty? ? nil : nw, line: line)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Stages are grouped trimmed and case-insensitive; the first spelling seen is displayed.
|
|
36
|
+
def self.analyze(rows)
|
|
37
|
+
olds = {}
|
|
38
|
+
news = {}
|
|
39
|
+
rows.each do |r|
|
|
40
|
+
o = (olds[r.old_stage.downcase] ||= { label: r.old_stage, records: 0, targets: {}, unmapped: 0 })
|
|
41
|
+
o[:records] += 1
|
|
42
|
+
if r.new_stage.nil?
|
|
43
|
+
o[:unmapped] += 1
|
|
44
|
+
next
|
|
45
|
+
end
|
|
46
|
+
key = r.new_stage.downcase
|
|
47
|
+
t = (o[:targets][key] ||= { label: r.new_stage, count: 0 })
|
|
48
|
+
t[:count] += 1
|
|
49
|
+
n = (news[key] ||= { label: r.new_stage, records: 0, from: [] })
|
|
50
|
+
n[:records] += 1
|
|
51
|
+
n[:from] << r.old_stage.downcase unless n[:from].include?(r.old_stage.downcase)
|
|
52
|
+
end
|
|
53
|
+
old_list = olds.values.map do |o|
|
|
54
|
+
goes = o[:targets].values.sort_by { |t| [-t[:count], t[:label].downcase, t[:label]] }
|
|
55
|
+
{ label: o[:label], records: o[:records], unmapped: o[:unmapped], goes_to: goes.map { |t| [t[:label], t[:count]] },
|
|
56
|
+
conflict: goes.size > 1 }
|
|
57
|
+
end
|
|
58
|
+
old_list.sort_by! { |o| [-o[:records], o[:label].downcase, o[:label]] }
|
|
59
|
+
new_list = news.values.map { |n| { label: n[:label], records: n[:records], old_stages: n[:from].size, merge: n[:from].size > 1 } }
|
|
60
|
+
new_list.sort_by! { |n| [-n[:records], n[:label].downcase, n[:label]] }
|
|
61
|
+
unmapped = rows.select { |r| r.new_stage.nil? }
|
|
62
|
+
{ rows: rows.size, mapped: rows.size - unmapped.size, unmapped: unmapped.size,
|
|
63
|
+
unmapped_list: unmapped.first(LIST_LIMIT).map { |r| [r.record_id, r.old_stage] },
|
|
64
|
+
unmapped_more: [unmapped.size - LIST_LIMIT, 0].max,
|
|
65
|
+
old_stages: old_list, new_stages: new_list,
|
|
66
|
+
conflicts: old_list.count { |o| o[:conflict] }, merges: new_list.count { |n| n[:merge] } }
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def self.plural(n, word)
|
|
70
|
+
"#{n} #{word}#{n == 1 ? '' : 's'}"
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def self.render(res)
|
|
74
|
+
out = +"rows: #{res[:rows]}\nmapped: #{res[:mapped]}\nunmapped: #{res[:unmapped]}\n"
|
|
75
|
+
unless res[:unmapped_list].empty?
|
|
76
|
+
out << "\nunmapped records\n"
|
|
77
|
+
res[:unmapped_list].each { |id, stage| out << " #{id} (old stage #{stage})\n" }
|
|
78
|
+
out << " and #{res[:unmapped_more]} more\n" if res[:unmapped_more].positive?
|
|
79
|
+
end
|
|
80
|
+
out << "\nper old stage\n"
|
|
81
|
+
res[:old_stages].each do |o|
|
|
82
|
+
parts = o[:goes_to].map { |label, n| "#{label} #{n}" }
|
|
83
|
+
parts << "not mapped yet #{o[:unmapped]}" if o[:unmapped].positive?
|
|
84
|
+
out << " #{o[:label]}: #{plural(o[:records], 'record')} -> #{parts.join(', ')}#{o[:conflict] ? ' conflict' : ''}\n"
|
|
85
|
+
end
|
|
86
|
+
out << "\nper new stage\n"
|
|
87
|
+
res[:new_stages].each do |n|
|
|
88
|
+
out << " #{n[:label]}: #{plural(n[:records], 'record')} from #{plural(n[:old_stages], 'old stage')}#{n[:merge] ? ' merge' : ''}\n"
|
|
89
|
+
end
|
|
90
|
+
out << "\nold stages: #{res[:old_stages].size}\nnew stages: #{res[:new_stages].size}\n"
|
|
91
|
+
out << "conflicts: #{res[:conflicts]}\nmerges: #{res[:merges]}\n"
|
|
92
|
+
out
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# True when --strict should fail the run.
|
|
96
|
+
def self.strict_failure?(res)
|
|
97
|
+
res[:unmapped].positive? || res[:conflicts].positive?
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# Returns [path, strict]; raises ArgumentError on bad input.
|
|
101
|
+
def self.parse_args(argv)
|
|
102
|
+
path = nil
|
|
103
|
+
strict = false
|
|
104
|
+
argv.each do |arg|
|
|
105
|
+
case arg
|
|
106
|
+
when '--strict' then strict = true
|
|
107
|
+
when /\A-/ then raise ArgumentError, "unknown option #{arg}"
|
|
108
|
+
else
|
|
109
|
+
raise ArgumentError, "unexpected extra argument #{arg.inspect}" if path
|
|
110
|
+
|
|
111
|
+
path = arg
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
raise ArgumentError, 'no CSV file given' unless path
|
|
115
|
+
|
|
116
|
+
[path, strict]
|
|
117
|
+
end
|
|
118
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: crm-stage-map-check
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- OneGTMLab
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: csv
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
-
|
|
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
|
+
- ">="
|
|
26
|
+
- !ruby/object:Gem::Version
|
|
27
|
+
version: "0"
|
|
28
|
+
description: "Ruby CLI and library: from a CSV of record ids with an old stage and the new stage you assigned, list unmapped records, flag old stages that go to more than one new stage, and flag new stages fed by more than one old stage. It only counts and flags. Offline."
|
|
29
|
+
executables:
|
|
30
|
+
- crm-stage-map-check
|
|
31
|
+
extensions: []
|
|
32
|
+
extra_rdoc_files: []
|
|
33
|
+
files:
|
|
34
|
+
- LICENSE
|
|
35
|
+
- README.md
|
|
36
|
+
- bin/crm-stage-map-check
|
|
37
|
+
- lib/crm_stage_map_check.rb
|
|
38
|
+
homepage: "https://www.onegtmlab.dev/tool-directory/compare/hubspot-vs-salesforce"
|
|
39
|
+
licenses:
|
|
40
|
+
- MIT
|
|
41
|
+
metadata:
|
|
42
|
+
source_code_uri: "https://github.com/jaizendra-netizen/crm-stage-map-check"
|
|
43
|
+
rdoc_options: []
|
|
44
|
+
require_paths:
|
|
45
|
+
- lib
|
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
47
|
+
requirements:
|
|
48
|
+
-
|
|
49
|
+
- ">="
|
|
50
|
+
- !ruby/object:Gem::Version
|
|
51
|
+
version: "2.7"
|
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
|
+
requirements:
|
|
54
|
+
-
|
|
55
|
+
- ">="
|
|
56
|
+
- !ruby/object:Gem::Version
|
|
57
|
+
version: "0"
|
|
58
|
+
requirements: []
|
|
59
|
+
rubygems_version: 4.1.0
|
|
60
|
+
specification_version: 4
|
|
61
|
+
summary: "Check a CRM stage mapping: unmapped records, conflicts and merges, from a CSV"
|
|
62
|
+
test_files: []
|