ratatui_ruby 0.8.0 → 0.9.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 +4 -4
- data/.builds/ruby-3.2.yml +2 -2
- data/.builds/ruby-3.3.yml +2 -2
- data/.builds/ruby-3.4.yml +2 -2
- data/.builds/ruby-4.0.0.yml +2 -2
- data/.pre-commit-config.yaml +1 -1
- data/AGENTS.md +3 -3
- data/CHANGELOG.md +53 -1
- data/LICENSES/LGPL-3.0-or-later.txt +304 -0
- data/LICENSES/MIT-0.txt +16 -0
- data/README.md +33 -5
- data/Rakefile +1 -1
- data/doc/concepts/application_architecture.md +44 -3
- data/doc/concepts/application_testing.md +43 -1
- data/doc/concepts/async.md +32 -2
- data/doc/concepts/custom_widgets.md +247 -0
- data/doc/concepts/event_handling.md +32 -3
- data/doc/concepts/interactive_design.md +32 -2
- data/doc/contributors/auditing/parity.md +7 -1
- data/doc/contributors/design/ruby_frontend.md +85 -1
- data/doc/contributors/design/rust_backend.md +67 -1
- data/doc/contributors/developing_examples.md +56 -2
- data/doc/contributors/documentation_style.md +20 -3
- data/doc/contributors/future_work.md +169 -0
- data/doc/contributors/index.md +1 -1
- data/doc/contributors/v1.0.0_blockers.md +15 -175
- data/doc/getting_started/quickstart.md +22 -4
- data/doc/getting_started/why.md +1 -1
- data/doc/index.md +2 -1
- data/doc/troubleshooting/debugging.md +32 -2
- data/doc/troubleshooting/terminal_limitations.md +8 -2
- data/doc/troubleshooting/tui_output.md +42 -0
- data/examples/app_all_events/README.md +14 -2
- data/examples/app_all_events/app.rb +1 -1
- data/examples/app_all_events/model/app_model.rb +1 -1
- data/examples/app_all_events/model/event_color_cycle.rb +1 -1
- data/examples/app_all_events/model/event_entry.rb +1 -1
- data/examples/app_all_events/model/msg.rb +1 -1
- data/examples/app_all_events/model/timestamp.rb +1 -1
- data/examples/app_all_events/update.rb +1 -1
- data/examples/app_all_events/view/app_view.rb +1 -1
- data/examples/app_all_events/view/controls_view.rb +1 -1
- data/examples/app_all_events/view/counts_view.rb +1 -1
- data/examples/app_all_events/view/live_view.rb +1 -1
- data/examples/app_all_events/view/log_view.rb +1 -1
- data/examples/app_all_events/view.rb +1 -1
- data/examples/app_color_picker/README.md +20 -2
- data/examples/app_color_picker/app.rb +1 -1
- data/examples/app_color_picker/clipboard.rb +1 -1
- data/examples/app_color_picker/color.rb +1 -1
- data/examples/app_color_picker/controls.rb +1 -1
- data/examples/app_color_picker/copy_dialog.rb +1 -1
- data/examples/app_color_picker/export_pane.rb +1 -1
- data/examples/app_color_picker/harmony.rb +1 -1
- data/examples/app_color_picker/input.rb +1 -1
- data/examples/app_color_picker/main_container.rb +1 -1
- data/examples/app_color_picker/palette.rb +1 -1
- data/examples/app_login_form/README.md +8 -2
- data/examples/app_login_form/app.rb +1 -1
- data/examples/app_stateful_interaction/README.md +2 -2
- data/examples/app_stateful_interaction/app.rb +71 -17
- data/examples/timeout_demo.rb +1 -1
- data/examples/verify_quickstart_dsl/README.md +6 -0
- data/examples/verify_quickstart_dsl/app.rb +3 -3
- data/examples/verify_quickstart_layout/README.md +6 -0
- data/examples/verify_quickstart_layout/app.rb +3 -3
- data/examples/verify_quickstart_lifecycle/README.md +6 -0
- data/examples/verify_quickstart_lifecycle/app.rb +3 -3
- data/examples/verify_readme_usage/README.md +6 -0
- data/examples/verify_readme_usage/app.rb +3 -3
- data/examples/widget_barchart/README.md +6 -0
- data/examples/widget_barchart/app.rb +2 -2
- data/examples/widget_block/README.md +7 -1
- data/examples/widget_block/app.rb +2 -2
- data/examples/widget_box/README.md +6 -0
- data/examples/widget_box/app.rb +9 -6
- data/examples/widget_calendar/README.md +6 -0
- data/examples/widget_calendar/app.rb +2 -2
- data/examples/widget_canvas/README.md +4 -0
- data/examples/widget_canvas/app.rb +2 -2
- data/examples/widget_cell/README.md +6 -0
- data/examples/widget_cell/app.rb +2 -3
- data/examples/widget_center/README.md +4 -0
- data/examples/widget_center/app.rb +2 -2
- data/examples/widget_chart/README.md +6 -0
- data/examples/widget_chart/app.rb +2 -2
- data/examples/widget_gauge/README.md +6 -0
- data/examples/widget_gauge/app.rb +2 -2
- data/examples/widget_layout_split/README.md +6 -0
- data/examples/widget_layout_split/app.rb +3 -3
- data/examples/widget_line_gauge/README.md +6 -0
- data/examples/widget_line_gauge/app.rb +2 -2
- data/examples/widget_list/README.md +6 -0
- data/examples/widget_list/app.rb +2 -2
- data/examples/widget_map/README.md +8 -2
- data/examples/widget_map/app.rb +2 -2
- data/examples/widget_overlay/README.md +7 -1
- data/examples/widget_overlay/app.rb +2 -2
- data/examples/widget_popup/README.md +6 -0
- data/examples/widget_popup/app.rb +2 -2
- data/examples/widget_ratatui_logo/README.md +6 -0
- data/examples/widget_ratatui_logo/app.rb +2 -3
- data/examples/widget_ratatui_mascot/README.md +6 -0
- data/examples/widget_ratatui_mascot/app.rb +2 -2
- data/examples/widget_rect/README.md +12 -0
- data/examples/widget_rect/app.rb +40 -26
- data/examples/widget_render/README.md +6 -0
- data/examples/widget_render/app.rb +2 -2
- data/examples/widget_render/app.rbs +41 -0
- data/examples/widget_rich_text/README.md +6 -0
- data/examples/widget_rich_text/app.rb +2 -2
- data/examples/widget_scroll_text/README.md +6 -0
- data/examples/widget_scroll_text/app.rb +2 -2
- data/examples/widget_scrollbar/README.md +6 -0
- data/examples/widget_scrollbar/app.rb +2 -2
- data/examples/widget_sparkline/README.md +6 -0
- data/examples/widget_sparkline/app.rb +2 -2
- data/examples/widget_style_colors/README.md +6 -0
- data/examples/widget_style_colors/app.rb +2 -2
- data/examples/widget_table/README.md +8 -2
- data/examples/widget_table/app.rb +2 -2
- data/examples/widget_tabs/README.md +6 -0
- data/examples/widget_tabs/app.rb +2 -2
- data/examples/widget_text_width/README.md +6 -0
- data/examples/widget_text_width/app.rb +4 -4
- data/ext/ratatui_ruby/Cargo.lock +1 -1
- data/ext/ratatui_ruby/Cargo.toml +1 -1
- data/ext/ratatui_ruby/extconf.rb +2 -2
- data/ext/ratatui_ruby/src/rendering.rs +1 -1
- data/ext/ratatui_ruby/src/style.rs +0 -8
- data/ext/ratatui_ruby/src/widgets/chart.rs +0 -118
- data/ext/ratatui_ruby/src/widgets/list_state.rs +36 -0
- data/lib/ratatui_ruby/buffer/cell.rb +34 -2
- data/lib/ratatui_ruby/buffer.rb +2 -2
- data/lib/ratatui_ruby/cell.rb +34 -2
- data/lib/ratatui_ruby/event/focus_gained.rb +26 -2
- data/lib/ratatui_ruby/event/focus_lost.rb +26 -2
- data/lib/ratatui_ruby/event/key/character.rb +18 -2
- data/lib/ratatui_ruby/event/key/media.rb +2 -2
- data/lib/ratatui_ruby/event/key/modifier.rb +10 -2
- data/lib/ratatui_ruby/event/key/navigation.rb +2 -2
- data/lib/ratatui_ruby/event/key/system.rb +2 -2
- data/lib/ratatui_ruby/event/key.rb +114 -2
- data/lib/ratatui_ruby/event/mouse.rb +42 -2
- data/lib/ratatui_ruby/event/none.rb +10 -2
- data/lib/ratatui_ruby/event/paste.rb +34 -2
- data/lib/ratatui_ruby/event/resize.rb +34 -2
- data/lib/ratatui_ruby/event.rb +26 -2
- data/lib/ratatui_ruby/frame.rb +74 -2
- data/lib/ratatui_ruby/layout/constraint.rb +58 -2
- data/lib/ratatui_ruby/layout/layout.rb +47 -2
- data/lib/ratatui_ruby/layout/rect.rb +403 -2
- data/lib/ratatui_ruby/layout.rb +2 -2
- data/lib/ratatui_ruby/list_state.rb +113 -2
- data/lib/ratatui_ruby/output_guard.rb +26 -3
- data/lib/ratatui_ruby/schema/bar_chart/bar.rb +2 -2
- data/lib/ratatui_ruby/schema/bar_chart/bar_group.rb +2 -2
- data/lib/ratatui_ruby/schema/bar_chart.rb +50 -2
- data/lib/ratatui_ruby/schema/block.rb +21 -15
- data/lib/ratatui_ruby/schema/calendar.rb +2 -2
- data/lib/ratatui_ruby/schema/canvas.rb +10 -2
- data/lib/ratatui_ruby/schema/center.rb +10 -2
- data/lib/ratatui_ruby/schema/chart.rb +2 -28
- data/lib/ratatui_ruby/schema/clear.rb +10 -2
- data/lib/ratatui_ruby/schema/constraint.rb +58 -2
- data/lib/ratatui_ruby/schema/cursor.rb +10 -2
- data/lib/ratatui_ruby/schema/draw.rb +10 -2
- data/lib/ratatui_ruby/schema/gauge.rb +2 -2
- data/lib/ratatui_ruby/schema/layout.rb +18 -2
- data/lib/ratatui_ruby/schema/line_gauge.rb +2 -2
- data/lib/ratatui_ruby/schema/list.rb +10 -2
- data/lib/ratatui_ruby/schema/list_item.rb +10 -2
- data/lib/ratatui_ruby/schema/overlay.rb +10 -2
- data/lib/ratatui_ruby/schema/paragraph.rb +10 -2
- data/lib/ratatui_ruby/schema/ratatui_logo.rb +2 -2
- data/lib/ratatui_ruby/schema/ratatui_mascot.rb +2 -2
- data/lib/ratatui_ruby/schema/rect.rb +58 -2
- data/lib/ratatui_ruby/schema/row.rb +10 -2
- data/lib/ratatui_ruby/schema/scrollbar.rb +2 -2
- data/lib/ratatui_ruby/schema/shape/label.rb +10 -2
- data/lib/ratatui_ruby/schema/sparkline.rb +10 -2
- data/lib/ratatui_ruby/schema/style.rb +18 -2
- data/lib/ratatui_ruby/schema/table.rb +2 -2
- data/lib/ratatui_ruby/schema/tabs.rb +2 -2
- data/lib/ratatui_ruby/schema/text.rb +34 -2
- data/lib/ratatui_ruby/scrollbar_state.rb +10 -2
- data/lib/ratatui_ruby/style/style.rb +18 -2
- data/lib/ratatui_ruby/style.rb +2 -2
- data/lib/ratatui_ruby/table_state.rb +10 -2
- data/lib/ratatui_ruby/terminal_lifecycle.rb +18 -3
- data/lib/ratatui_ruby/test_helper/event_injection.rb +34 -2
- data/lib/ratatui_ruby/test_helper/snapshot.rb +74 -9
- data/lib/ratatui_ruby/test_helper/style_assertions.rb +98 -2
- data/lib/ratatui_ruby/test_helper/terminal.rb +50 -2
- data/lib/ratatui_ruby/test_helper/test_doubles.rb +18 -2
- data/lib/ratatui_ruby/test_helper.rb +10 -2
- data/lib/ratatui_ruby/tui/buffer_factories.rb +2 -2
- data/lib/ratatui_ruby/tui/canvas_factories.rb +2 -2
- data/lib/ratatui_ruby/tui/core.rb +2 -2
- data/lib/ratatui_ruby/tui/layout_factories.rb +32 -2
- data/lib/ratatui_ruby/tui/state_factories.rb +2 -2
- data/lib/ratatui_ruby/tui/style_factories.rb +2 -2
- data/lib/ratatui_ruby/tui/text_factories.rb +2 -2
- data/lib/ratatui_ruby/tui/widget_factories.rb +2 -2
- data/lib/ratatui_ruby/tui.rb +11 -3
- data/lib/ratatui_ruby/version.rb +3 -3
- data/lib/ratatui_ruby/widgets/bar_chart/bar.rb +2 -2
- data/lib/ratatui_ruby/widgets/bar_chart/bar_group.rb +2 -2
- data/lib/ratatui_ruby/widgets/bar_chart.rb +58 -2
- data/lib/ratatui_ruby/widgets/block.rb +37 -15
- data/lib/ratatui_ruby/widgets/calendar.rb +2 -2
- data/lib/ratatui_ruby/widgets/canvas.rb +10 -2
- data/lib/ratatui_ruby/widgets/cell.rb +10 -2
- data/lib/ratatui_ruby/widgets/center.rb +10 -2
- data/lib/ratatui_ruby/widgets/chart.rb +2 -28
- data/lib/ratatui_ruby/widgets/clear.rb +10 -2
- data/lib/ratatui_ruby/widgets/cursor.rb +10 -2
- data/lib/ratatui_ruby/widgets/gauge.rb +16 -2
- data/lib/ratatui_ruby/widgets/line_gauge.rb +16 -2
- data/lib/ratatui_ruby/widgets/list.rb +41 -2
- data/lib/ratatui_ruby/widgets/list_item.rb +10 -2
- data/lib/ratatui_ruby/widgets/overlay.rb +10 -2
- data/lib/ratatui_ruby/widgets/paragraph.rb +10 -2
- data/lib/ratatui_ruby/widgets/ratatui_logo.rb +2 -2
- data/lib/ratatui_ruby/widgets/ratatui_mascot.rb +2 -2
- data/lib/ratatui_ruby/widgets/row.rb +10 -2
- data/lib/ratatui_ruby/widgets/scrollbar.rb +2 -2
- data/lib/ratatui_ruby/widgets/shape/label.rb +10 -2
- data/lib/ratatui_ruby/widgets/sparkline.rb +10 -2
- data/lib/ratatui_ruby/widgets/table.rb +62 -2
- data/lib/ratatui_ruby/widgets/tabs.rb +2 -2
- data/lib/ratatui_ruby/widgets.rb +2 -2
- data/lib/ratatui_ruby.rb +90 -2
- data/sig/examples/app_all_events/view.rbs +7 -1
- data/sig/examples/app_all_events/view_state.rbs +7 -1
- data/sig/examples/app_color_picker/app.rbs +5 -0
- data/sig/examples/app_stateful_interaction/app.rbs +7 -1
- data/sig/examples/verify_quickstart_dsl/app.rbs +7 -1
- data/sig/examples/verify_quickstart_lifecycle/app.rbs +7 -1
- data/sig/examples/verify_readme_usage/app.rbs +7 -1
- data/sig/examples/widget_block_demo/app.rbs +6 -0
- data/sig/examples/widget_box_demo/app.rbs +7 -1
- data/sig/examples/widget_calendar_demo/app.rbs +7 -1
- data/sig/examples/widget_cell_demo/app.rbs +7 -1
- data/sig/examples/widget_chart_demo/app.rbs +7 -1
- data/sig/examples/widget_gauge_demo/app.rbs +7 -1
- data/sig/examples/widget_layout_split/app.rbs +7 -1
- data/sig/examples/widget_line_gauge_demo/app.rbs +7 -1
- data/sig/examples/widget_list_demo/app.rbs +5 -0
- data/sig/examples/widget_map_demo/app.rbs +7 -1
- data/sig/examples/widget_popup_demo/app.rbs +7 -1
- data/sig/examples/widget_ratatui_logo_demo/app.rbs +7 -1
- data/sig/examples/widget_ratatui_mascot_demo/app.rbs +7 -1
- data/sig/examples/widget_rect/app.rbs +7 -1
- data/sig/examples/widget_render/app.rbs +7 -1
- data/sig/examples/widget_rich_text/app.rbs +7 -1
- data/sig/examples/widget_scroll_text/app.rbs +7 -1
- data/sig/examples/widget_scrollbar_demo/app.rbs +7 -1
- data/sig/examples/widget_sparkline_demo/app.rbs +7 -1
- data/sig/examples/widget_style_colors/app.rbs +7 -1
- data/sig/examples/widget_table_demo/app.rbs +7 -1
- data/sig/examples/widget_text_width/app.rbs +7 -1
- data/sig/ratatui_ruby/event.rbs +7 -1
- data/sig/ratatui_ruby/frame.rbs +15 -3
- data/sig/ratatui_ruby/list_state.rbs +11 -1
- data/sig/ratatui_ruby/ratatui_ruby.rbs +8 -2
- data/sig/ratatui_ruby/schema/bar_chart/bar.rbs +7 -1
- data/sig/ratatui_ruby/schema/bar_chart/bar_group.rbs +6 -0
- data/sig/ratatui_ruby/schema/bar_chart.rbs +6 -0
- data/sig/ratatui_ruby/schema/block.rbs +7 -1
- data/sig/ratatui_ruby/schema/calendar.rbs +6 -0
- data/sig/ratatui_ruby/schema/canvas.rbs +6 -0
- data/sig/ratatui_ruby/schema/center.rbs +6 -0
- data/sig/ratatui_ruby/schema/chart.rbs +6 -9
- data/sig/ratatui_ruby/schema/constraint.rbs +6 -0
- data/sig/ratatui_ruby/schema/cursor.rbs +6 -0
- data/sig/ratatui_ruby/schema/draw.rbs +6 -0
- data/sig/ratatui_ruby/schema/gauge.rbs +9 -1
- data/sig/ratatui_ruby/schema/layout.rbs +6 -0
- data/sig/ratatui_ruby/schema/line_gauge.rbs +9 -1
- data/sig/ratatui_ruby/schema/list.rbs +9 -1
- data/sig/ratatui_ruby/schema/list_item.rbs +7 -1
- data/sig/ratatui_ruby/schema/overlay.rbs +6 -0
- data/sig/ratatui_ruby/schema/paragraph.rbs +6 -0
- data/sig/ratatui_ruby/schema/ratatui_logo.rbs +6 -0
- data/sig/ratatui_ruby/schema/ratatui_mascot.rbs +5 -0
- data/sig/ratatui_ruby/schema/rect.rbs +30 -0
- data/sig/ratatui_ruby/schema/row.rbs +7 -1
- data/sig/ratatui_ruby/schema/scrollbar.rbs +6 -0
- data/sig/ratatui_ruby/schema/sparkline.rbs +6 -0
- data/sig/ratatui_ruby/schema/style.rbs +7 -1
- data/sig/ratatui_ruby/schema/table.rbs +11 -1
- data/sig/ratatui_ruby/schema/tabs.rbs +6 -0
- data/sig/ratatui_ruby/schema/text.rbs +7 -1
- data/sig/ratatui_ruby/scrollbar_state.rbs +7 -1
- data/sig/ratatui_ruby/session.rbs +7 -1
- data/sig/ratatui_ruby/table_state.rbs +7 -1
- data/sig/ratatui_ruby/test_helper/event_injection.rbs +7 -1
- data/sig/ratatui_ruby/test_helper/snapshot.rbs +7 -1
- data/sig/ratatui_ruby/test_helper/style_assertions.rbs +7 -1
- data/sig/ratatui_ruby/test_helper/terminal.rbs +7 -1
- data/sig/ratatui_ruby/test_helper/test_doubles.rbs +7 -1
- data/sig/ratatui_ruby/test_helper.rbs +7 -1
- data/sig/ratatui_ruby/tui/buffer_factories.rbs +7 -1
- data/sig/ratatui_ruby/tui/canvas_factories.rbs +7 -1
- data/sig/ratatui_ruby/tui/core.rbs +7 -1
- data/sig/ratatui_ruby/tui/layout_factories.rbs +7 -1
- data/sig/ratatui_ruby/tui/state_factories.rbs +7 -1
- data/sig/ratatui_ruby/tui/style_factories.rbs +7 -1
- data/sig/ratatui_ruby/tui/text_factories.rbs +7 -1
- data/sig/ratatui_ruby/tui/widget_factories.rbs +7 -1
- data/sig/ratatui_ruby/tui.rbs +7 -1
- data/sig/ratatui_ruby/version.rbs +6 -0
- data/tasks/autodoc/examples.rb +1 -1
- data/tasks/autodoc/member.rb +1 -1
- data/tasks/autodoc/name.rb +1 -1
- data/tasks/bump/cargo_lockfile.rb +1 -1
- data/tasks/bump/changelog.rb +1 -1
- data/tasks/bump/header.rb +1 -1
- data/tasks/bump/history.rb +1 -1
- data/tasks/bump/links.rb +1 -1
- data/tasks/bump/manifest.rb +1 -1
- data/tasks/bump/ruby_gem.rb +1 -1
- data/tasks/bump/sem_ver.rb +1 -1
- data/tasks/bump/unreleased_section.rb +1 -1
- data/tasks/license/headers_md.rb +223 -0
- data/tasks/license/headers_rb.rb +210 -0
- data/tasks/license/license_utils.rb +130 -0
- data/tasks/license/snippets_md.rb +315 -0
- data/tasks/license/snippets_rdoc.rb +150 -0
- data/tasks/license.rake +91 -0
- data/tasks/rdoc_config.rb +1 -1
- data/tasks/resources/build.yml.erb +13 -7
- data/tasks/sourcehut.rake +3 -1
- data/tasks/terminal_preview/app_screenshot.rb +1 -1
- data/tasks/terminal_preview/crash_report.rb +1 -1
- data/tasks/terminal_preview/example_app.rb +1 -1
- data/tasks/terminal_preview/launcher_script.rb +1 -1
- data/tasks/terminal_preview/preview_collection.rb +1 -1
- data/tasks/terminal_preview/preview_timing.rb +1 -1
- data/tasks/terminal_preview/safety_confirmation.rb +1 -1
- data/tasks/terminal_preview/saved_screenshot.rb +1 -1
- data/tasks/terminal_preview/system_appearance.rb +1 -1
- data/tasks/terminal_preview/terminal_window.rb +1 -1
- data/tasks/terminal_preview/window_id.rb +1 -1
- data/tasks/website/index_page.rb +1 -1
- data/tasks/website/version.rb +1 -1
- data/tasks/website/version_menu.rb +1 -1
- data/tasks/website/versioned_documentation.rb +1 -1
- data/tasks/website/website.rb +1 -1
- metadata +13 -3
- data/doc/migration/v0_7_0.md +0 -236
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
#--
|
|
4
|
+
# SPDX-FileCopyrightText: 2026 Kerrick Long <me@kerricklong.com>
|
|
5
|
+
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
6
|
+
#++
|
|
7
|
+
|
|
8
|
+
# Script to ensure markdown files have correct SPDX file headers (CC-BY-SA-4.0).
|
|
9
|
+
#
|
|
10
|
+
# Usage: ruby tasks/license/headers_md.rb [path...]
|
|
11
|
+
#
|
|
12
|
+
# If no paths are given, processes all .md files via git ls-files.
|
|
13
|
+
#
|
|
14
|
+
# Rules:
|
|
15
|
+
# - Ensures file has CC-BY-SA-4.0 license header with YOUR copyright
|
|
16
|
+
# - Updates years for EXISTING contributors based on git blame + Co-Authored-By
|
|
17
|
+
# - Does NOT add new contributors from git history - only updates existing ones
|
|
18
|
+
# - Uses non-code-block lines for year calculation
|
|
19
|
+
# - Adds header with YOUR copyright if missing
|
|
20
|
+
|
|
21
|
+
require_relative "license_utils"
|
|
22
|
+
|
|
23
|
+
YOUR_NAME = "Kerrick Long"
|
|
24
|
+
YOUR_EMAIL = "me@kerricklong.com"
|
|
25
|
+
YOUR_IDENTIFIERS = [YOUR_NAME, YOUR_EMAIL].freeze
|
|
26
|
+
YOUR_COPYRIGHT = "#{YOUR_NAME} <#{YOUR_EMAIL}>"
|
|
27
|
+
LICENSE = "CC-BY-SA-4.0"
|
|
28
|
+
|
|
29
|
+
def find_code_blocks(lines)
|
|
30
|
+
blocks = []
|
|
31
|
+
i = 0
|
|
32
|
+
|
|
33
|
+
while i < lines.length
|
|
34
|
+
line = lines[i]
|
|
35
|
+
|
|
36
|
+
if line =~ /^(````*)(\w*)$/
|
|
37
|
+
fence_marker = $1
|
|
38
|
+
fence_start = i
|
|
39
|
+
re_end = /^#{Regexp.escape(fence_marker)}$/
|
|
40
|
+
|
|
41
|
+
j = i + 1
|
|
42
|
+
while j < lines.length
|
|
43
|
+
if lines[j] =~ re_end
|
|
44
|
+
blocks << { start: fence_start, end: j }
|
|
45
|
+
i = j
|
|
46
|
+
break
|
|
47
|
+
end
|
|
48
|
+
j += 1
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
i += 1
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
blocks
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def get_non_code_line_ranges(lines)
|
|
59
|
+
header_end = 0
|
|
60
|
+
if lines[0]&.include?("<!--")
|
|
61
|
+
(0...(lines.length)).each do |i|
|
|
62
|
+
if lines[i].include?("-->")
|
|
63
|
+
header_end = i + 1
|
|
64
|
+
break
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
code_blocks = find_code_blocks(lines)
|
|
70
|
+
non_code_ranges = []
|
|
71
|
+
current_line = header_end
|
|
72
|
+
|
|
73
|
+
code_blocks.each do |block|
|
|
74
|
+
if current_line < block[:start]
|
|
75
|
+
non_code_ranges << [current_line + 1, block[:start]]
|
|
76
|
+
end
|
|
77
|
+
current_line = block[:end] + 1
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
if current_line < lines.length
|
|
81
|
+
non_code_ranges << [current_line + 1, lines.length]
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
non_code_ranges
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def parse_existing_header(lines)
|
|
88
|
+
return nil unless lines[0]&.include?("<!--")
|
|
89
|
+
|
|
90
|
+
header_end = nil
|
|
91
|
+
copyrights = []
|
|
92
|
+
license = nil
|
|
93
|
+
|
|
94
|
+
(0...(lines.length)).each do |i|
|
|
95
|
+
line = lines[i]
|
|
96
|
+
|
|
97
|
+
if line =~ /SPDX-FileCopyrightText:\s*(\d{4})\s+(.+)$/
|
|
98
|
+
copyrights << { year: $1.to_i, holder: $2.strip }
|
|
99
|
+
# REUSE-IgnoreStart
|
|
100
|
+
elsif line =~ /SPDX-License-Identifier:\s*(.+)$/
|
|
101
|
+
# REUSE-IgnoreEnd
|
|
102
|
+
license = $1.strip
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
if line.include?("-->")
|
|
106
|
+
header_end = i
|
|
107
|
+
break
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
return nil if header_end.nil?
|
|
112
|
+
return nil if copyrights.empty? && license.nil?
|
|
113
|
+
|
|
114
|
+
{ end_line: header_end, copyrights:, license: }
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def process_file(filepath)
|
|
118
|
+
content = File.read(filepath)
|
|
119
|
+
lines = content.lines
|
|
120
|
+
|
|
121
|
+
non_code_ranges = get_non_code_line_ranges(lines)
|
|
122
|
+
|
|
123
|
+
# Get contributors from non-code lines for year lookups
|
|
124
|
+
all_contributors = {}
|
|
125
|
+
non_code_ranges.each do |start_line, end_line|
|
|
126
|
+
range_contributors = LicenseUtils.get_contributors_for_lines(filepath, start_line, end_line)
|
|
127
|
+
range_contributors.each do |contributor, year|
|
|
128
|
+
all_contributors[contributor] = [all_contributors[contributor] || 0, year].max
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
your_year = nil
|
|
133
|
+
all_contributors.each do |contributor, year|
|
|
134
|
+
if YOUR_IDENTIFIERS.any? { |id| contributor.include?(id) }
|
|
135
|
+
your_year = [your_year || 0, year].max
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
your_year ||= Date.today.year
|
|
139
|
+
|
|
140
|
+
existing = parse_existing_header(lines)
|
|
141
|
+
|
|
142
|
+
if existing
|
|
143
|
+
# Only update years for EXISTING contributors
|
|
144
|
+
needs_update = false
|
|
145
|
+
updated_copyrights = []
|
|
146
|
+
|
|
147
|
+
existing[:copyrights].each do |c|
|
|
148
|
+
git_year = nil
|
|
149
|
+
all_contributors.each do |contributor, year|
|
|
150
|
+
if c[:holder].split.any? { |word| contributor.include?(word) }
|
|
151
|
+
git_year = [git_year || 0, year].max
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
if git_year && git_year != c[:year]
|
|
156
|
+
puts " Updated #{c[:holder].split.first}'s copyright year: #{c[:year]} -> #{git_year}"
|
|
157
|
+
updated_copyrights << { year: git_year, holder: c[:holder] }
|
|
158
|
+
needs_update = true
|
|
159
|
+
else
|
|
160
|
+
updated_copyrights << c
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
# Check if YOUR year needs updating
|
|
165
|
+
your_existing = updated_copyrights.find { |c| YOUR_IDENTIFIERS.any? { |id| c[:holder].include?(id) } }
|
|
166
|
+
if your_existing.nil?
|
|
167
|
+
puts " Adding your copyright"
|
|
168
|
+
updated_copyrights << { year: your_year, holder: YOUR_COPYRIGHT }
|
|
169
|
+
needs_update = true
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
if existing[:license] != LICENSE
|
|
173
|
+
puts " Fixing license: #{existing[:license]} -> #{LICENSE}"
|
|
174
|
+
needs_update = true
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
if needs_update
|
|
178
|
+
# REUSE-IgnoreStart
|
|
179
|
+
header_lines = ["<!--\n"]
|
|
180
|
+
updated_copyrights.each do |c|
|
|
181
|
+
header_lines << " SPDX-FileCopyrightText: #{c[:year]} #{c[:holder]}\n"
|
|
182
|
+
end
|
|
183
|
+
header_lines << " SPDX-License-Identifier: #{LICENSE}\n"
|
|
184
|
+
header_lines << "-->\n"
|
|
185
|
+
# REUSE-IgnoreEnd
|
|
186
|
+
|
|
187
|
+
remaining = lines[(existing[:end_line] + 1)..]
|
|
188
|
+
File.write(filepath, header_lines.join + remaining.join)
|
|
189
|
+
puts "Updated: #{filepath}"
|
|
190
|
+
end
|
|
191
|
+
else
|
|
192
|
+
# No header - add one with YOUR copyright only
|
|
193
|
+
# REUSE-IgnoreStart
|
|
194
|
+
header = "<!--\n SPDX-FileCopyrightText: #{your_year} #{YOUR_COPYRIGHT}\n SPDX-License-Identifier: #{LICENSE}\n-->\n"
|
|
195
|
+
# REUSE-IgnoreEnd
|
|
196
|
+
|
|
197
|
+
File.write(filepath, header + content)
|
|
198
|
+
puts "Added header: #{filepath}"
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
def find_md_files(paths)
|
|
203
|
+
if paths.empty?
|
|
204
|
+
`git ls-files '*.md'`.split("\n")
|
|
205
|
+
else
|
|
206
|
+
paths.flat_map do |path|
|
|
207
|
+
if File.directory?(path)
|
|
208
|
+
`git ls-files '#{path}/**/*.md'`.split("\n")
|
|
209
|
+
else
|
|
210
|
+
path
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
if __FILE__ == $0
|
|
217
|
+
paths = ARGV.empty? ? [] : ARGV
|
|
218
|
+
files = find_md_files(paths)
|
|
219
|
+
|
|
220
|
+
files.each do |file|
|
|
221
|
+
process_file(file)
|
|
222
|
+
end
|
|
223
|
+
end
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
#--
|
|
4
|
+
# SPDX-FileCopyrightText: 2026 Kerrick Long <me@kerricklong.com>
|
|
5
|
+
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
6
|
+
#++
|
|
7
|
+
|
|
8
|
+
# Script to ensure Ruby files have correct SPDX file headers.
|
|
9
|
+
#
|
|
10
|
+
# Usage: ruby tasks/license/headers_rb.rb [path...]
|
|
11
|
+
#
|
|
12
|
+
# If no paths are given, processes lib/, ext/, test/, examples/, tasks/, bin/.
|
|
13
|
+
#
|
|
14
|
+
# License selection by directory:
|
|
15
|
+
# - lib/, ext/, test/ → LGPL-3.0-or-later
|
|
16
|
+
# - examples/widget_*, examples/verify_* → MIT-0
|
|
17
|
+
# - examples/app_*, tasks/, bin/ → AGPL-3.0-or-later
|
|
18
|
+
|
|
19
|
+
require_relative "license_utils"
|
|
20
|
+
|
|
21
|
+
YOUR_NAME = "Kerrick Long"
|
|
22
|
+
YOUR_EMAIL = "me@kerricklong.com"
|
|
23
|
+
YOUR_IDENTIFIERS = [YOUR_NAME, YOUR_EMAIL].freeze
|
|
24
|
+
YOUR_COPYRIGHT = "#{YOUR_NAME} <#{YOUR_EMAIL}>"
|
|
25
|
+
|
|
26
|
+
def license_for_file(filepath)
|
|
27
|
+
case filepath
|
|
28
|
+
when %r{^(lib|sig/ratatui_ruby|ext|test)/}
|
|
29
|
+
"LGPL-3.0-or-later"
|
|
30
|
+
when %r{^(examples|sig/examples)/(widget_|verify_)}
|
|
31
|
+
"MIT-0"
|
|
32
|
+
else
|
|
33
|
+
"AGPL-3.0-or-later"
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def parse_existing_header(lines)
|
|
38
|
+
# Returns { end_line:, copyrights: [{year:, holder:}], license: }
|
|
39
|
+
# REUSE-IgnoreStart
|
|
40
|
+
# Ruby files typically have:
|
|
41
|
+
# # frozen_string_literal: true
|
|
42
|
+
# (blank line)
|
|
43
|
+
# #--
|
|
44
|
+
# # SPDX-FileCopyrightText: YYYY Name
|
|
45
|
+
# # SPDX-License-Identifier: LICENSE
|
|
46
|
+
# #++
|
|
47
|
+
# REUSE-IgnoreEnd
|
|
48
|
+
|
|
49
|
+
copyrights = []
|
|
50
|
+
license = nil
|
|
51
|
+
header_end = nil
|
|
52
|
+
found_spdx = false
|
|
53
|
+
|
|
54
|
+
lines.each_with_index do |line, i|
|
|
55
|
+
if line =~ /^#\s*SPDX-FileCopyrightText:\s*(\d{4})\s+(.+)$/
|
|
56
|
+
copyrights << { year: $1.to_i, holder: $2.strip }
|
|
57
|
+
found_spdx = true
|
|
58
|
+
# REUSE-IgnoreStart
|
|
59
|
+
elsif line =~ /^#\s*SPDX-License-Identifier:\s*(.+)$/
|
|
60
|
+
# REUSE-IgnoreEnd
|
|
61
|
+
license = $1.strip
|
|
62
|
+
found_spdx = true
|
|
63
|
+
elsif line =~ /^#\+\+\s*$/ && found_spdx
|
|
64
|
+
header_end = i
|
|
65
|
+
break
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
return nil if copyrights.empty? && license.nil?
|
|
70
|
+
|
|
71
|
+
{ end_line: header_end || 0, copyrights:, license: }
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def process_file(filepath)
|
|
75
|
+
content = File.read(filepath)
|
|
76
|
+
lines = content.lines
|
|
77
|
+
|
|
78
|
+
target_license = license_for_file(filepath)
|
|
79
|
+
|
|
80
|
+
# Get contributors from git for year lookups
|
|
81
|
+
all_contributors = LicenseUtils.get_contributors_for_lines(filepath)
|
|
82
|
+
your_year = LicenseUtils.get_your_latest_year(filepath, YOUR_IDENTIFIERS)
|
|
83
|
+
|
|
84
|
+
existing = parse_existing_header(lines)
|
|
85
|
+
|
|
86
|
+
if existing
|
|
87
|
+
# File has existing header - only update years for EXISTING contributors
|
|
88
|
+
needs_update = false
|
|
89
|
+
updated_copyrights = []
|
|
90
|
+
|
|
91
|
+
existing[:copyrights].each do |c|
|
|
92
|
+
# Find this contributor's latest year from git
|
|
93
|
+
git_year = nil
|
|
94
|
+
all_contributors.each do |contributor, year|
|
|
95
|
+
if c[:holder].split.any? { |word| contributor.include?(word) }
|
|
96
|
+
git_year = [git_year || 0, year].max
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
if git_year && git_year != c[:year]
|
|
101
|
+
puts " Updated #{c[:holder].split.first}'s copyright year: #{c[:year]} -> #{git_year}"
|
|
102
|
+
updated_copyrights << { year: git_year, holder: c[:holder] }
|
|
103
|
+
needs_update = true
|
|
104
|
+
else
|
|
105
|
+
updated_copyrights << c
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# Check if YOUR year needs updating (if you're a contributor)
|
|
110
|
+
your_existing = updated_copyrights.find { |c| YOUR_IDENTIFIERS.any? { |id| c[:holder].include?(id) } }
|
|
111
|
+
if your_existing.nil?
|
|
112
|
+
puts " Adding your copyright"
|
|
113
|
+
updated_copyrights << { year: your_year, holder: YOUR_COPYRIGHT }
|
|
114
|
+
needs_update = true
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# Check license
|
|
118
|
+
if existing[:license] != target_license
|
|
119
|
+
puts " Fixing license: #{existing[:license]} -> #{target_license}"
|
|
120
|
+
needs_update = true
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
if needs_update
|
|
124
|
+
frozen_string = lines[0].include?("frozen_string_literal") ? lines[0] : nil
|
|
125
|
+
|
|
126
|
+
header_lines = []
|
|
127
|
+
header_lines << "# frozen_string_literal: true\n" unless frozen_string
|
|
128
|
+
header_lines << "\n" if frozen_string.nil? && !lines[0].strip.empty?
|
|
129
|
+
header_lines << "#--\n"
|
|
130
|
+
|
|
131
|
+
# REUSE-IgnoreStart
|
|
132
|
+
updated_copyrights.each do |c|
|
|
133
|
+
header_lines << "# SPDX-FileCopyrightText: #{c[:year]} #{c[:holder]}\n"
|
|
134
|
+
end
|
|
135
|
+
header_lines << "# SPDX-License-Identifier: #{target_license}\n"
|
|
136
|
+
# REUSE-IgnoreEnd
|
|
137
|
+
header_lines << "#++\n"
|
|
138
|
+
|
|
139
|
+
content_start = existing[:end_line] + 1
|
|
140
|
+
while content_start < lines.length && lines[content_start].strip.empty?
|
|
141
|
+
content_start += 1
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
remaining = lines[content_start..]
|
|
145
|
+
|
|
146
|
+
new_content = if frozen_string
|
|
147
|
+
"#{frozen_string}\n#{header_lines.join}\n#{remaining.join}"
|
|
148
|
+
else
|
|
149
|
+
"#{header_lines.join}\n#{remaining.join}"
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
File.write(filepath, new_content)
|
|
153
|
+
puts "Updated: #{filepath}"
|
|
154
|
+
end
|
|
155
|
+
else
|
|
156
|
+
# No header - add one with YOUR copyright only
|
|
157
|
+
frozen_line = lines[0]&.include?("frozen_string_literal") ? lines.shift : nil
|
|
158
|
+
|
|
159
|
+
header = []
|
|
160
|
+
header << "# frozen_string_literal: true\n\n" unless frozen_line
|
|
161
|
+
header << "#--\n"
|
|
162
|
+
# REUSE-IgnoreStart
|
|
163
|
+
header << "# SPDX-FileCopyrightText: #{your_year} #{YOUR_COPYRIGHT}\n"
|
|
164
|
+
header << "# SPDX-License-Identifier: #{target_license}\n"
|
|
165
|
+
# REUSE-IgnoreEnd
|
|
166
|
+
header << "#++\n\n"
|
|
167
|
+
|
|
168
|
+
if frozen_line
|
|
169
|
+
File.write(filepath, "#{frozen_line}\n#{header.join}#{lines.join}")
|
|
170
|
+
else
|
|
171
|
+
File.write(filepath, header.join + lines.join)
|
|
172
|
+
end
|
|
173
|
+
puts "Added header: #{filepath}"
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
def find_rb_files(paths)
|
|
178
|
+
if paths.empty?
|
|
179
|
+
# Process all relevant directories
|
|
180
|
+
dirs = %w[lib ext test examples tasks bin sig]
|
|
181
|
+
files = dirs.flat_map do |dir|
|
|
182
|
+
# Include both root files and subdirectory files, for both .rb and .rbs
|
|
183
|
+
%w[rb rbs].flat_map do |ext|
|
|
184
|
+
root_files = `git ls-files '#{dir}/*.#{ext}' 2>/dev/null`.split("\n")
|
|
185
|
+
sub_files = `git ls-files '#{dir}/**/*.#{ext}' 2>/dev/null`.split("\n")
|
|
186
|
+
root_files + sub_files
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
files.uniq
|
|
190
|
+
else
|
|
191
|
+
paths.flat_map do |path|
|
|
192
|
+
if File.directory?(path)
|
|
193
|
+
rb_files = `git ls-files '#{path}/**/*.rb'`.split("\n")
|
|
194
|
+
rbs_files = `git ls-files '#{path}/**/*.rbs'`.split("\n")
|
|
195
|
+
rb_files + rbs_files
|
|
196
|
+
else
|
|
197
|
+
path
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
if __FILE__ == $0
|
|
204
|
+
paths = ARGV.empty? ? [] : ARGV
|
|
205
|
+
files = find_rb_files(paths)
|
|
206
|
+
|
|
207
|
+
files.each do |file|
|
|
208
|
+
process_file(file)
|
|
209
|
+
end
|
|
210
|
+
end
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
#--
|
|
4
|
+
# SPDX-FileCopyrightText: 2026 Kerrick Long <me@kerricklong.com>
|
|
5
|
+
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
6
|
+
#++
|
|
7
|
+
|
|
8
|
+
# Shared utility for detecting contributors from git blame and Co-Authored-By trailers.
|
|
9
|
+
#
|
|
10
|
+
# This module provides methods to:
|
|
11
|
+
# - Get all contributors (authors and co-authors) who touched specific lines
|
|
12
|
+
# - Track the latest year each contributor touched those lines
|
|
13
|
+
# - Parse Co-Authored-By trailers from commit messages
|
|
14
|
+
|
|
15
|
+
require "open3"
|
|
16
|
+
require "date"
|
|
17
|
+
|
|
18
|
+
module LicenseUtils
|
|
19
|
+
# Represents a contributor with their latest year of contribution
|
|
20
|
+
Contributor = Data.define(:name, :email, :year)
|
|
21
|
+
|
|
22
|
+
class << self
|
|
23
|
+
# Get all contributors who touched lines in a file (or range of lines).
|
|
24
|
+
# Returns a Hash of { "Name <email>" => year } mapping each contributor to their latest year.
|
|
25
|
+
#
|
|
26
|
+
# This considers both the commit author AND any Co-Authored-By trailers in commit messages.
|
|
27
|
+
def get_contributors_for_lines(filepath, start_line = nil, end_line = nil)
|
|
28
|
+
blame_cmd = if start_line && end_line
|
|
29
|
+
%W[git blame -L #{start_line},#{end_line} --porcelain -- #{filepath}]
|
|
30
|
+
else
|
|
31
|
+
%W[git blame --porcelain -- #{filepath}]
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
output, _status = Open3.capture2(*blame_cmd)
|
|
35
|
+
|
|
36
|
+
contributors = {} # "Name <email>" => year
|
|
37
|
+
commit_cache = {} # commit_hash => { year:, author:, co_authors: [] }
|
|
38
|
+
|
|
39
|
+
current_commit = nil
|
|
40
|
+
|
|
41
|
+
output.each_line do |line|
|
|
42
|
+
if line =~ /^([a-f0-9]{40})/
|
|
43
|
+
current_commit = $1
|
|
44
|
+
elsif line =~ /^author (.+)$/
|
|
45
|
+
commit_cache[current_commit] ||= {}
|
|
46
|
+
commit_cache[current_commit][:author_name] = $1
|
|
47
|
+
elsif line =~ /^author-mail <(.+)>$/
|
|
48
|
+
commit_cache[current_commit] ||= {}
|
|
49
|
+
commit_cache[current_commit][:author_email] = $1
|
|
50
|
+
elsif line =~ /^author-time (\d+)$/
|
|
51
|
+
commit_cache[current_commit] ||= {}
|
|
52
|
+
timestamp = $1.to_i
|
|
53
|
+
commit_cache[current_commit][:year] = Time.at(timestamp).year
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Now fetch co-authors for each unique commit
|
|
58
|
+
commit_cache.each do |commit_hash, data|
|
|
59
|
+
next if commit_hash == "0" * 40 # Skip uncommitted lines
|
|
60
|
+
|
|
61
|
+
# Get commit message for Co-Authored-By parsing
|
|
62
|
+
msg_output, _status = Open3.capture2("git", "log", "-1", "--format=%B", commit_hash)
|
|
63
|
+
co_authors = parse_co_authors(msg_output)
|
|
64
|
+
data[:co_authors] = co_authors
|
|
65
|
+
|
|
66
|
+
# Add author
|
|
67
|
+
if data[:author_name] && data[:author_email]
|
|
68
|
+
key = "#{data[:author_name]} <#{data[:author_email]}>"
|
|
69
|
+
year = data[:year] || Date.today.year
|
|
70
|
+
contributors[key] = [contributors[key] || 0, year].max
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Add co-authors with same year as commit
|
|
74
|
+
co_authors.each do |ca|
|
|
75
|
+
key = "#{ca[:name]} <#{ca[:email]}>"
|
|
76
|
+
year = data[:year] || Date.today.year
|
|
77
|
+
contributors[key] = [contributors[key] || 0, year].max
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
contributors
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Get YOUR latest year contribution to the file/lines.
|
|
85
|
+
# your_identifiers should be an array of strings that identify you (name, email fragments).
|
|
86
|
+
def get_your_latest_year(filepath, your_identifiers, start_line = nil, end_line = nil)
|
|
87
|
+
contributors = get_contributors_for_lines(filepath, start_line, end_line)
|
|
88
|
+
|
|
89
|
+
your_year = nil
|
|
90
|
+
contributors.each do |contributor, year|
|
|
91
|
+
if your_identifiers.any? { |id| contributor.include?(id) }
|
|
92
|
+
your_year = [your_year || 0, year].max
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
your_year || Date.today.year
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# Get all contributors EXCEPT you, with their latest years.
|
|
100
|
+
# Returns array of { name:, email:, year: }
|
|
101
|
+
def get_other_contributors(filepath, your_identifiers, start_line = nil, end_line = nil)
|
|
102
|
+
contributors = get_contributors_for_lines(filepath, start_line, end_line)
|
|
103
|
+
|
|
104
|
+
others = []
|
|
105
|
+
contributors.each do |contributor, year|
|
|
106
|
+
next if your_identifiers.any? { |id| contributor.include?(id) }
|
|
107
|
+
|
|
108
|
+
# Parse "Name <email>" format
|
|
109
|
+
if contributor =~ /^(.+?)\s*<(.+)>$/
|
|
110
|
+
others << { name: $1.strip, email: $2.strip, year: }
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
others
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
private def parse_co_authors(message)
|
|
118
|
+
co_authors = []
|
|
119
|
+
|
|
120
|
+
message.each_line do |line|
|
|
121
|
+
# Match "Co-Authored-By: Name <email>" (case insensitive)
|
|
122
|
+
if line =~ /^Co-Authored-By:\s*(.+?)\s*<(.+?)>\s*$/i
|
|
123
|
+
co_authors << { name: $1.strip, email: $2.strip }
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
co_authors
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|