Skip to content

Commit 6f457ff

Browse files
authored
Script to find upgradeable patterns (#534)
* Script to identify upgradeable patterns based on their number of Known Instances * Formatting changes to the 'Known Instances' section of some patterns. Allows for easier scanning of the new find_upgradeable_patterns.rb script
1 parent 69da445 commit 6f457ff

File tree

8 files changed

+101
-3
lines changed

8 files changed

+101
-3
lines changed

meta/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ The topics below cover information about how we define, operate, and upkeep this
1212
* [Style Guide](./pattern-style-guide.md) - Recommended conventions to use when writing patterns
1313
* [Glossary](./glossary.md) - Defines essential terms that are commonly used when writing new patterns.
1414
* [Board Reports](./boardreports) - The Patterns Working Group submits a report to the Board of the InnerSource Commons Foundation on a quarterly basis. This folder contains all reports that the Patterns Working Group has created.
15+
* [Scripts](./scripts) - Scripts that help us with the maintenance of our patterns.
1516

1617
## Unfinished documentation
1718

meta/scripts/Gemfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
source "https://rubygems.org"
4+
5+
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
6+
7+
gem 'commonmarker'
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
require 'rubygems'
2+
require 'bundler/setup'
3+
Bundler.require(:default)
4+
5+
require 'pp'
6+
7+
# ------------------------------------------------------------------------------------------------------------
8+
# This script scans all patterns in /patterns/1-initial and /patterns/2-structured.
9+
# Based on the number of Known Instances in the pattern, it suggests which patterns that might be ready to be leveled-up.
10+
#
11+
# The number of Known Instances are only one of the [requirement](https://github.com/InnerSourceCommons/InnerSourcePatterns/blob/main/meta/contributor-handbook.md#requirements-level-2---structured)
12+
# for our patterns to reach the next level. Therefore reading the pattern and the level requirements in detail is still required
13+
# to decide whether or not a pattern can be pushed to the next level.
14+
15+
# NOTE: This script and `/book/scripts/generate_toc.rb` have some overlap in how they are parsing markdown.
16+
# However the overlap seemed minimal, so I opted not to do any deduplication of code.
17+
# ------------------------------------------------------------------------------------------------------------
18+
19+
# Count Known Instances in a pattern
20+
# - return 0 if the section does not exist, or does not contain the expected list structure
21+
# - return <count of Known Instances>
22+
def count_known_instances(file)
23+
section_nodes = collect_section_nodes(file, "Known Instances")
24+
list_nodes = []
25+
# pick the first list in the "Known Instances" section, and return the number of elements in that list.
26+
# CAUTION: this assumes a certain structure across all patterns. Therefore fairly brittle.
27+
list_nodes = section_nodes.select {|n| n.type == :list}
28+
29+
known_instances_count = 0
30+
known_instances_count = list_nodes.first.count if !list_nodes.first.nil?
31+
32+
return known_instances_count
33+
end
34+
35+
def collect_section_nodes(file, section_title)
36+
markdown = open(file).readlines().join
37+
doc = CommonMarker.render_doc(markdown)
38+
39+
title_found = false
40+
section_nodes = []
41+
42+
doc.walk do |node|
43+
if node.type == :header
44+
if title_found == false
45+
node.each do |subnode|
46+
if subnode.type == :text and subnode.string_content == section_title
47+
title_found = true
48+
end
49+
end
50+
# stop the recursion once the next header is reached
51+
# TODO: is this correct, or should we check if this is another `##` header, rather than any header?
52+
else
53+
break
54+
end
55+
# once the title has been found, collect all nodes up to the next header
56+
elsif title_found == true
57+
section_nodes << node
58+
end
59+
end
60+
61+
return section_nodes
62+
end
63+
64+
65+
# Main block
66+
67+
puts "## Initial => Structured"
68+
puts "## 1-Initial patterns primed for upgrade to 2-Structured (based on Known Instances only)"
69+
l1_patterns = Dir["../../patterns/1-initial/*.md"]
70+
71+
l1_patterns.each do |file|
72+
known_instances_count = count_known_instances(file)
73+
puts "#{known_instances_count} | #{file}" if known_instances_count >= 1
74+
end
75+
76+
puts "\n"
77+
puts "## Structured => Validated"
78+
puts "## 2-Structured patterns primed for upgrade to 3-Validated (based on Known Instances only)"
79+
l2_patterns = Dir["../../patterns/2-structured/*.md", "../../patterns/2-structured/project-setup/*.md"]
80+
81+
l2_patterns.each do |file|
82+
known_instances_count = count_known_instances(file)
83+
puts "#{known_instances_count} | #{file}" if known_instances_count >= 3
84+
end

patterns/1-initial/governance-levels.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ Examples of promoting the model names (3) are:
8383

8484
## Known Instances
8585

86+
* Flutter Entertainment
87+
8688
![InnerSource Pyramid used by Flutter Entertainment](../../assets/img/flutter-pyramid.svg)
8789

8890
Flutter Entertainment define an [InnerSource Pyramid](https://innersource.flutter.com/how/) to describe 3 different InnerSource operating models: Readable Source, Guest Contributions and Maintainers in Multiple Teams. Each name is centrally documented. The use of these names is encouraged via repeated usage, direct training and categorisation of each InnerSource project.

patterns/1-initial/incubator-pipeline.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ This pattern was inspired by things like the Apache Software Foundation's incuba
6060

6161
## Known Instances
6262

63-
Being implemented at U.S. Bank.
63+
* Being implemented at **U.S. Bank**.
6464

6565
## Status
6666

patterns/1-initial/introducing-metrics-in-innersource.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Continued monitoring of these metrics will help middle management and developers
9292

9393
## Known Instances
9494

95-
Santander Bank
95+
* **Santander Bank**
9696

9797
## Status
9898

patterns/2-structured/dedicated-community-leader.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Having excellent and dedicated community leaders is a precondition for the succe
5858

5959
## Known Instances
6060

61-
_BIOS at Robert Bosch GmbH_. Note that InnerSource at Bosch was, for the majority, aimed at increasing innovation and to a large degree dealt with internal facing products. This pattern is currently not used at Bosch for lack of funding.
61+
* _BIOS at Robert Bosch GmbH_. Note that InnerSource at Bosch was, for the majority, aimed at increasing innovation and to a large degree dealt with internal facing products. This pattern is currently not used at Bosch for lack of funding.
6262

6363
## Alias
6464

patterns/2-structured/document-your-guiding-principles.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ All Trusted Committers of a project are published.
121121

122122
## Known Instances
123123

124+
* Europace AG
125+
* GitHub
126+
* Robert Bosch GmbH
127+
124128
### Europace AG
125129

126130
The InnerSource principles listed in the Solution above are mostly based on Europace's experience.

0 commit comments

Comments
 (0)