Class: Kettle::Dev::ReadmeBackers
- Inherits:
-
Object
- Object
- Kettle::Dev::ReadmeBackers
- Defined in:
- lib/kettle/dev/readme_backers.rb
Defined Under Namespace
Classes: Backer
Constant Summary collapse
- DEFAULT_AVATAR =
"https://opencollective.com/static/images/default-avatar.png"
- README_PATH =
File.("../../../../README.md", __dir__)
- OC_YML_PATH =
File.("../../../../.opencollective.yml", __dir__)
- README_OSC_TAG_DEFAULT =
"OPENCOLLECTIVE"
- COMMIT_SUBJECT_DEFAULT =
"💸 Thanks 🙏 to our new backers 🎒 and subscribers 📜"
Instance Method Summary collapse
-
#initialize(handle: nil, readme_path: README_PATH) ⇒ ReadmeBackers
constructor
A new instance of ReadmeBackers.
-
#run! ⇒ Object
Constructor Details
#initialize(handle: nil, readme_path: README_PATH) ⇒ ReadmeBackers
Returns a new instance of ReadmeBackers.
43 44 45 46 |
# File 'lib/kettle/dev/readme_backers.rb', line 43 def initialize(handle: nil, readme_path: README_PATH) @handle = handle || resolve_handle @readme_path = readme_path end |
Instance Method Details
#run! ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/kettle/dev/readme_backers.rb', line 48 def run! readme = File.read(@readme_path) # Identify previous entries for diffing/mentions b_start, b_end = (readme) prev_backer_identities = extract_section_identities(readme, b_start, b_end) s_start_prev, s_end_prev = (readme) prev_sponsor_identities = extract_section_identities(readme, s_start_prev, s_end_prev) # Backers (individuals) backers = fetch_members("backers.json") backers_md = generate_markdown(backers, empty_message: "No backers yet. Be the first!", default_name: "Backer") updated = (readme, b_start, b_end, backers_md) case updated when :not_found updated_readme = readme backers_changed = false new_backers = [] when :no_change updated_readme = readme backers_changed = false new_backers = [] else updated_readme = updated backers_changed = true new_backers = compute_new_members(prev_backer_identities, backers) end # Sponsors (organizations) sponsors = fetch_members("sponsors.json") sponsors_md = generate_markdown(sponsors, empty_message: "No sponsors yet. Be the first!", default_name: "Sponsor") s_start, s_end = (updated_readme) updated2 = (updated_readme, s_start, s_end, sponsors_md) case updated2 when :not_found sponsors_changed = false final = updated_readme new_sponsors = [] when :no_change sponsors_changed = false final = updated_readme new_sponsors = [] else sponsors_changed = true final = updated2 new_sponsors = compute_new_members(prev_sponsor_identities, sponsors) end if !backers_changed && !sponsors_changed if b_start == :not_found && s_start == :not_found ts = tag_strings warn("No recognized Open Collective tags found in #{@readme_path}. Expected one or more of: " \ "#{ts[:generic_start]}/#{ts[:generic_end]}, #{ts[:individuals_start]}/#{ts[:individuals_end]}, #{ts[:orgs_start]}/#{ts[:orgs_end]}.") # Do not exit the process during tests or library use; just return. return end puts "No changes to backers or sponsors sections in #{@readme_path}." return end File.write(@readme_path, final) msgs = [] msgs << "backers" if backers_changed msgs << "sponsors" if sponsors_changed puts "Updated #{msgs.join(" and ")} section#{{true => "s", false => ""}[msgs.size > 1]} in #{@readme_path}." # Compose and perform commit with mentions if in a git repo perform_git_commit(new_backers, new_sponsors) if git_repo? && (backers_changed || sponsors_changed) end |