fun_ci 2.4.0-x86_64-linux → 2.5.0-x86_64-linux

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.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +73 -0
  3. data/README.md +16 -7
  4. data/lib/fun_ci/agent/events.rb +15 -7
  5. data/lib/fun_ci/agent/job_events.rb +12 -5
  6. data/lib/fun_ci/agent/onward.rb +21 -0
  7. data/lib/fun_ci/agent/output.rb +7 -0
  8. data/lib/fun_ci/agent/reports.rb +3 -0
  9. data/lib/fun_ci/agent/snapshots.rb +25 -7
  10. data/lib/fun_ci/agent/status_text.rb +7 -3
  11. data/lib/fun_ci/agent/wait_command.rb +37 -5
  12. data/lib/fun_ci/console/board_data.rb +46 -11
  13. data/lib/fun_ci/console/branch_page.rb +9 -0
  14. data/lib/fun_ci/console/console_state.rb +22 -8
  15. data/lib/fun_ci/console/cursor.rb +22 -0
  16. data/lib/fun_ci/console/cursor_rows.rb +37 -0
  17. data/lib/fun_ci/console/job_message.rb +5 -4
  18. data/lib/fun_ci/console/job_order.rb +5 -3
  19. data/lib/fun_ci/console/job_row.rb +17 -0
  20. data/lib/fun_ci/console/job_rows.rb +14 -3
  21. data/lib/fun_ci/console/key_handler.rb +88 -51
  22. data/lib/fun_ci/console/question.rb +63 -0
  23. data/lib/fun_ci/console/run_message.rb +3 -3
  24. data/lib/fun_ci/console/view.rb +20 -6
  25. data/lib/fun_ci/jobs/job_run.rb +10 -9
  26. data/lib/fun_ci/persistence/active_runs.rb +47 -17
  27. data/lib/fun_ci/persistence/arrival.rb +18 -0
  28. data/lib/fun_ci/persistence/branch_visibility.rb +40 -0
  29. data/lib/fun_ci/persistence/database.rb +28 -2
  30. data/lib/fun_ci/persistence/hidden_row_tables.rb +24 -0
  31. data/lib/fun_ci/persistence/job_runs.rb +17 -7
  32. data/lib/fun_ci/persistence/job_visibility.rb +43 -0
  33. data/lib/fun_ci/persistence/null_recorder.rb +3 -0
  34. data/lib/fun_ci/persistence/pipeline_recorder.rb +22 -3
  35. data/lib/fun_ci/persistence/pipeline_run.rb +15 -4
  36. data/lib/fun_ci/persistence/stage_job.rb +13 -0
  37. data/lib/fun_ci/persistence/trunk_checks.rb +7 -6
  38. data/lib/fun_ci/pipeline/process_runner.rb +8 -7
  39. data/lib/fun_ci/pipeline/run_canceller.rb +1 -3
  40. data/lib/fun_ci/pipeline/slot.rb +12 -0
  41. data/lib/fun_ci/pipeline/slot_run.rb +20 -5
  42. data/lib/fun_ci/pipeline/slow_turns.rb +74 -0
  43. data/lib/fun_ci/pipeline/stale_pipeline_canceller.rb +1 -1
  44. data/lib/fun_ci/pipeline/trigger.rb +9 -1
  45. data/lib/fun_ci/pipeline/trigger_params.rb +7 -3
  46. data/lib/fun_ci/pipeline/turn_queue.rb +65 -0
  47. data/lib/fun_ci/pipeline/waiting_slots.rb +30 -0
  48. data/lib/fun_ci/pipeline/worktree_pool.rb +5 -2
  49. data/lib/fun_ci/pipeline/worktrees.rb +3 -0
  50. data/lib/fun_ci/trunk/check.rb +7 -2
  51. data/lib/fun_ci/version.rb +1 -1
  52. data/libexec/fun-ci-renderer +0 -0
  53. metadata +25 -10
@@ -7,7 +7,7 @@ require_relative "job_message"
7
7
  module FunCi
8
8
  module Console
9
9
  # What the console shows: the page of runs BoardData reads that the View
10
- # puts on screen, the daily and weekly jobs below it, and the clock's
10
+ # puts on screen, the daily and weekly jobs in view below it, and the clock's
11
11
  # time, as a protocol `board` message, after the `event`s for what changed
12
12
  # since the last one.
13
13
  class ConsoleState
@@ -26,23 +26,37 @@ module FunCi
26
26
  # Pages for a terminal of `rows`.
27
27
  def resize(rows) = @board_data.resize(@view.resize(rows))
28
28
 
29
+ # The events of the branches in view, hidden or not shown, so `a` plays no scene; then the board.
29
30
  def updates
30
31
  @board_data.record_dead_slow_suites
31
32
  @board_data.record_dead_jobs
32
- runs = @board_data.runs
33
- [*@events.since_last(runs), board(runs, @board_data.jobs(runs))]
33
+ branches = @board_data.branch_page
34
+ runs = branches.runs
35
+ [*@events.since_last(runs.reject { |run| run[:hidden] }), board(branches, @board_data.jobs(runs))]
34
36
  end
35
37
 
36
38
  private
37
39
 
38
- def board(runs, jobs)
39
- page = @view.page(runs, more: @board_data.more?, jobs: jobs)
40
+ def board(branches, job_rows)
41
+ runs = branches.runs
42
+ shown = @view.shown(job_rows)
43
+ page = @view.page(@view.shown_runs(runs), more: branches.more, jobs: shown)
40
44
  { t: "board", now: @clock.call.to_i, streak: @board_data.streak, **page,
41
- runs: page[:runs].map { |run| RunMessage.from(run) }, **job_section(jobs), **stale_trunks(runs) }
45
+ runs: page[:runs].map { |run| RunMessage.from(run) }, **job_section(shown),
46
+ **hidden_rows(runs, job_rows), **stale_trunks(runs) }
42
47
  end
43
48
 
44
- # Only when there are jobs, as the protocol lets a board leave them out.
45
- def job_section(jobs) = jobs.empty? ? {} : { jobs: jobs.map { |job| JobMessage.from(job) } }
49
+ # Only when there are jobs in view, as the protocol lets a board leave them out.
50
+ def job_section(rows)
51
+ rows.empty? ? {} : { jobs: rows.map { |row| JobMessage.from(row.standing, hidden: row.hidden) } }
52
+ end
53
+
54
+ # How many branches and jobs the user hid, in view or not; only when some
55
+ # are, as the protocol lets a board leave it out.
56
+ def hidden_rows(runs, job_rows)
57
+ count = runs.count { |run| run[:hidden] } + job_rows.count(&:hidden)
58
+ count.zero? ? {} : { hidden_rows: count }
59
+ end
46
60
 
47
61
  # Only when a trunk is stale, as the protocol lets a board leave it out.
48
62
  def stale_trunks(runs)
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FunCi
4
+ module Console
5
+ # Where the cursor is among CursorRows: its row's index, and which row
6
+ # that is (CursorRows#key_at), so it stays on that row when the rows move
7
+ # under it.
8
+ Cursor = Data.define(:index, :on)
9
+
10
+ class Cursor
11
+ # The cursor on the row at `index`, or on the last row when `index` is
12
+ # past it; none when there is no row.
13
+ def self.at(rows, index)
14
+ within = rows.within(index)
15
+ within && new(within, rows.key_at(within))
16
+ end
17
+
18
+ # The cursor on its row where `rows` hold it, or at its index when that row left them.
19
+ def within(rows) = Cursor.at(rows, rows.index_of(on) || index)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FunCi
4
+ module Console
5
+ # The rows the cursor moves through: the runs loaded, then the job rows in view.
6
+ CursorRows = Data.define(:runs, :jobs)
7
+
8
+ class CursorRows
9
+ # The last row's index; negative when there is no row.
10
+ def last = runs.length + jobs.length - 1
11
+
12
+ # [:run, the run] or [:job, the job's row] at `index`; none without one.
13
+ def at(index)
14
+ return [] unless index
15
+ return [:run, runs[index]] if index < runs.length
16
+
17
+ [:job, jobs[index - runs.length]]
18
+ end
19
+
20
+ # `index`, or the last row's when it is past it; nil when there is no row.
21
+ def within(index) = index && !last.negative? ? [index, last].min : nil
22
+
23
+ # Which row `row` is, of `kind` (:run or :job): a branch of a project, or a job of one.
24
+ def self.key(kind, row) = kind == :run ? [:run, row[:project_path], row[:branch]] : [:job, row.project, row.name]
25
+
26
+ # Which row is at `index`.
27
+ def key_at(index) = keys[index]
28
+
29
+ # The index of the row `key` names; nil when it is none of these.
30
+ def index_of(key) = keys.index(key)
31
+
32
+ private
33
+
34
+ def keys = runs.map { |run| CursorRows.key(:run, run) } + jobs.map { |job| CursorRows.key(:job, job) }
35
+ end
36
+ end
37
+ end
@@ -5,17 +5,18 @@ require "time"
5
5
  module FunCi
6
6
  module Console
7
7
  # Where a job stands (Jobs::Standing) as the protocol's `board` carries it
8
- # under `jobs`: protocol status names and epoch seconds. Formatting them
9
- # is the renderer's job.
8
+ # under `jobs`: protocol status names and epoch seconds, and how the user
9
+ # hid it, for a hidden job the board shows. Formatting them is the
10
+ # renderer's job.
10
11
  module JobMessage
11
12
  # The protocol's word for a Jobs::State, where it has one of its own:
12
13
  # a cancelled job is due again, and one it can't read is shown due.
13
14
  STATUS = { "over_budget" => "timeout", "cancelled" => "due", "unknown" => "due" }.freeze
14
15
 
15
- def self.from(standing)
16
+ def self.from(standing, hidden: nil)
16
17
  { project: standing.project, name: standing.name, cadence: standing.cadence,
17
18
  status: STATUS.fetch(standing.state, standing.state), **run(standing.run, standing.starts_at),
18
- due_at: standing.due_at&.to_i }.compact
19
+ due_at: standing.due_at&.to_i, hidden: hidden }.compact
19
20
  end
20
21
 
21
22
  # What the latest run says: which, on what, and when; a run waiting its
@@ -5,8 +5,9 @@ module FunCi
5
5
  # The order of the job section's rows (design.md, The console): what
6
6
  # needs you first, then running, waiting its turn to (Jobs::Schedule),
7
7
  # due and passed; among equals, the
8
- # board's projects in its order, then each project's jobs by name. Rows
9
- # answer #state (Jobs::State), #project and #name.
8
+ # board's projects in its order, then each project's jobs by name. A
9
+ # hidden job, shown because the user asked, comes after every job in
10
+ # view. Rows answer #state (Jobs::State), #project, #name and #hidden.
10
11
  module JobOrder
11
12
  URGENCY = { "failed" => 0, "lost" => 0, "over_budget" => 1, "running" => 2, "scheduled" => 3, "due" => 4,
12
13
  "cancelled" => 4, "passed" => 5 }.freeze
@@ -15,7 +16,8 @@ module FunCi
15
16
 
16
17
  def self.of(rows, projects:)
17
18
  rows.sort_by do |row|
18
- [URGENCY.fetch(row.state, UNKNOWN), projects.index(row.project) || projects.size, row.name]
19
+ [row.hidden ? 1 : 0, URGENCY.fetch(row.state, UNKNOWN), projects.index(row.project) || projects.size,
20
+ row.name]
19
21
  end
20
22
  end
21
23
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FunCi
4
+ module Console
5
+ # A job as the job section holds it: where it stands (Jobs::Standing),
6
+ # and how the user hid it, `snoozed` or `ignored` (Persistence::JobVisibility);
7
+ # nil while it is in view.
8
+ JobRow = Data.define(:standing, :hidden)
9
+
10
+ class JobRow
11
+ def name = standing.name
12
+ def project = standing.project
13
+ def state = standing.state
14
+ def run = standing.run
15
+ end
16
+ end
17
+ end
@@ -1,20 +1,31 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "job_order"
4
+ require_relative "job_row"
4
5
  require_relative "../jobs/standings"
6
+ require_relative "../persistence/job_visibility"
5
7
 
6
8
  module FunCi
7
9
  module Console
8
10
  # The job section's rows (design.md, The console): where each daily and
9
- # weekly job of the board's projects stands (Jobs::Standing), in JobOrder.
11
+ # weekly job of the board's projects stands (Jobs::Standing) and how the
12
+ # user hid it, if they did (Persistence::JobVisibility), in JobOrder.
10
13
  class JobRows
11
14
  def initialize(db)
12
15
  @db = db
13
16
  end
14
17
 
15
18
  def of(projects, now:)
16
- standings = projects.flat_map { |project| Jobs::Standings.new(@db, project, now: now).all }
17
- JobOrder.of(standings, projects: projects)
19
+ JobOrder.of(projects.flat_map { |project| rows_of(project, now) }, projects: projects)
20
+ end
21
+
22
+ private
23
+
24
+ def rows_of(project, now)
25
+ hidden = Persistence::JobVisibility.new(@db).hidden(project)
26
+ Jobs::Standings.new(@db, project, now: now).all.map do |standing|
27
+ JobRow.new(standing: standing, hidden: hidden[standing.name])
28
+ end
18
29
  end
19
30
  end
20
31
  end
@@ -1,94 +1,131 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "cursor"
4
+ require_relative "cursor_rows"
5
+ require_relative "question"
6
+
3
7
  module FunCi
4
8
  module Console
5
9
  # What a key means for the runs BoardData loads, and the daily and weekly
6
- # jobs after them: moving the cursor through both, quitting, and
7
- # cancelling the run or job under the cursor (a running one after the
8
- # user confirms with `y`).
10
+ # jobs after them: moving the cursor through both, quitting, cancelling
11
+ # the run or job under the cursor (a running one after the user confirms
12
+ # with `y`), hiding the branch or job under it (`h`, then `s` to snooze it
13
+ # or `i` to ignore it), and showing the hidden ones (`a`), where `h` brings one back.
14
+ # The cursor stays on its row as the rows move, and a question ends when
15
+ # the row it asks about is no longer under the cursor as it was.
9
16
  class KeyHandler
10
- CONFIRMATION_ANSWERS = ["y", "n", :escape].freeze
11
-
12
- attr_reader :cursor_index
13
-
14
17
  def initialize(board_data:)
15
18
  @board_data = board_data
16
- @confirm_cancel = nil
19
+ @question = nil
20
+ @revealed = false
17
21
  end
18
22
 
23
+ # The index of the row under the cursor among the runs and the job rows in view; nil without a cursor.
24
+ def cursor_index = @cursor&.index
25
+
19
26
  # :quit when the key ends the session.
20
27
  def handle_key(key)
21
- return confirm(key) if @confirm_cancel
22
28
  return :quit if key == "q"
23
29
 
24
- act(key)
30
+ rows = self.rows
31
+ follow(rows.runs, rows.jobs)
32
+ return answer(key) if @question
33
+
34
+ act(key, rows)
25
35
  end
26
36
 
27
- def confirming?
28
- !@confirm_cancel.nil?
37
+ # Puts the cursor back on its row among `runs` and the job rows in view,
38
+ # `jobs`; on the first of them, `from_the_first`, while it is on none.
39
+ def follow(runs, jobs, from_the_first: false)
40
+ rows = CursorRows.new(runs, jobs)
41
+ @cursor = @cursor ? @cursor.within(rows) : (Cursor.at(rows, 0) if from_the_first)
42
+ @question = nil unless @question&.about?(rows.at(cursor_index))
29
43
  end
30
44
 
45
+ # What the footer asks, :cancel or :hide; nil while it asks nothing.
46
+ def asking = @question&.asks
47
+
48
+ def confirming? = asking == :cancel
49
+
50
+ # The job rows in view: not the hidden ones, unless `a` asked for them.
51
+ def shown(job_rows) = @revealed ? job_rows : job_rows.reject(&:hidden)
52
+
53
+ # The branches' runs in view: not those of the hidden branches, unless `a` asked for them.
54
+ def shown_runs(runs) = @revealed ? runs : runs.reject { |run| run[:hidden] }
55
+
31
56
  private
32
57
 
33
- def act(key)
58
+ def act(key, rows)
34
59
  case key
35
- when "j", :down then move_cursor_down
36
- when "k", :up then move_cursor_up
37
- when "c" then initiate_cancel
60
+ when "j", :down then move_cursor_down(rows)
61
+ when "k", :up then move_cursor_up(rows)
62
+ when "c" then initiate_cancel(rows)
63
+ when "h" then hide_or_show(rows)
64
+ when "a" then settle(revealed: !@revealed)
38
65
  end
39
66
  end
40
67
 
41
- # Onto the last run loaded, which loads the next page, then into the jobs.
42
- def move_cursor_down
43
- runs = @board_data.runs
44
- last = runs.length + @board_data.jobs(runs).length - 1
45
- return if last.negative?
46
- return @cursor_index = 0 if @cursor_index.nil?
47
- return unless @cursor_index < last
68
+ def answer(key)
69
+ @question.take(key)
70
+ return unless @question.ended_by?(key)
48
71
 
49
- @cursor_index += 1
50
- @board_data.load_more if @cursor_index == runs.length - 1
72
+ @question = nil
73
+ settle
51
74
  end
52
75
 
53
- def move_cursor_up
54
- @cursor_index -= 1 if @cursor_index&.positive?
76
+ # After job rows left the view or came into it: hidden jobs are shown
77
+ # only while some job is hidden, and the cursor stays on a row.
78
+ def settle(revealed: @revealed)
79
+ runs = @board_data.runs
80
+ jobs = @board_data.jobs(runs)
81
+ @revealed = revealed && (jobs.any?(&:hidden) || runs.any? { |run| run[:hidden] })
82
+ follow(shown_runs(runs), shown(jobs))
55
83
  end
56
84
 
57
- def initiate_cancel
58
- kind, row = under_cursor
59
- return unless row
60
-
61
- kind == :job ? offer_job_cancel(row) : offer_run_cancel(row)
85
+ def rows
86
+ runs = @board_data.runs
87
+ CursorRows.new(shown_runs(runs), shown(@board_data.jobs(runs)))
62
88
  end
63
89
 
64
- # A run waiting to start is cancelled at once; a running one once the user confirms.
65
- def offer_run_cancel(run)
66
- @board_data.cancel_run(run[:id]) if run[:status] == "scheduled"
67
- @confirm_cancel = [:run, run] if run[:status] == "running"
90
+ # Onto the last run loaded, which loads the next page, then into the jobs.
91
+ def move_cursor_down(rows)
92
+ return @cursor = Cursor.at(rows, 0) unless @cursor
93
+ return unless cursor_index < rows.last
94
+
95
+ @cursor = Cursor.at(rows, cursor_index + 1)
96
+ @board_data.load_more if cursor_index == rows.runs.length - 1
68
97
  end
69
98
 
70
- # A job (a Jobs::Standing) waiting its turn is cancelled at once; a
71
- # running one once the user confirms.
72
- def offer_job_cancel(job)
73
- cancel(:job, job) if job.state == "scheduled"
74
- @confirm_cancel = [:job, job] if job.state == "running"
99
+ def move_cursor_up(rows)
100
+ @cursor = Cursor.at(rows, cursor_index - 1) if cursor_index&.positive?
75
101
  end
76
102
 
77
- # [:run, the run] or [:job, the job row] under the cursor, or none.
78
- def under_cursor
79
- runs = @board_data.runs
80
- return [] unless @cursor_index
81
- return [:run, runs[@cursor_index]] if @cursor_index < runs.length
103
+ def initiate_cancel(rows)
104
+ kind, row = rows.at(cursor_index)
105
+ return unless row
106
+
107
+ kind == :job ? offer_cancel(kind, row, row.state) : offer_cancel(kind, row, row[:status])
108
+ end
82
109
 
83
- [:job, @board_data.jobs(runs)[@cursor_index - runs.length]]
110
+ # A run or job waiting to start is cancelled at once, nothing of it
111
+ # having run; a running one once the user confirms.
112
+ def offer_cancel(kind, row, status)
113
+ cancel = Question::Cancel.new(@board_data, kind, row)
114
+ cancel.carry_out if status == "scheduled"
115
+ @question = cancel if status == "running"
84
116
  end
85
117
 
86
- def confirm(key)
87
- cancel(*@confirm_cancel) if key == "y"
88
- @confirm_cancel = nil if CONFIRMATION_ANSWERS.include?(key)
118
+ # Asks how to hide the branch or job under the cursor; one already hidden comes back at once.
119
+ def hide_or_show(rows)
120
+ kind, row = rows.at(cursor_index)
121
+ return unless row
122
+ return @question = Question::Hide.new(@board_data, kind, row) unless hidden?(kind, row)
123
+
124
+ kind == :job ? @board_data.show_job(row) : @board_data.show_run(row)
125
+ settle
89
126
  end
90
127
 
91
- def cancel(kind, row) = kind == :job ? @board_data.cancel_job(row.run[:id]) : @board_data.cancel_run(row[:id])
128
+ def hidden?(kind, row) = kind == :job ? row.hidden : row[:hidden]
92
129
  end
93
130
  end
94
131
  end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "cursor_rows"
4
+
5
+ module FunCi
6
+ module Console
7
+ # What the footer asks about the row under the cursor before a key acts
8
+ # on it (design.md, The console). Each says what it `asks`, does what a
9
+ # key it is given answers (`take`), and says whether that key ends it.
10
+ module Question
11
+ # What each question holds, the board it acts on and the row it asks
12
+ # about, and which keys end it: its class's ENDS.
13
+ module Asked
14
+ # kind: :run or :job; row: the branch's run, or the job's row.
15
+ def initialize(board_data, kind, row)
16
+ @board_data = board_data
17
+ @kind = kind
18
+ @row = row
19
+ end
20
+
21
+ def ended_by?(key) = self.class::ENDS.include?(key)
22
+ end
23
+
24
+ # Whether to cancel a running run or job, whose processes get killed: `y` does.
25
+ class Cancel
26
+ include Asked
27
+
28
+ ENDS = ["y", "n", :escape].freeze
29
+
30
+ def asks = :cancel
31
+
32
+ def take(key) = key == "y" && carry_out
33
+
34
+ def carry_out = @kind == :job ? @board_data.cancel_job(@row.run[:id]) : @board_data.cancel_run(@row[:id])
35
+
36
+ # Whether `place`, [kind, row] under the cursor now, is still the run asked about, running.
37
+ def about?(place) = place.first == @kind && Cancel.target(*place) == Cancel.target(@kind, @row)
38
+
39
+ # A run's id and status, or a job's latest run's id and its state.
40
+ def self.target(kind, row) = kind == :job ? [row.run&.dig(:id), row.state] : row.values_at(:id, :status)
41
+ end
42
+
43
+ # How to hide a branch or a job: `s` snoozes it, until its next run; `i` ignores it, until shown again.
44
+ class Hide
45
+ include Asked
46
+
47
+ KINDS = { "s" => "snoozed", "i" => "ignored" }.freeze
48
+ ENDS = [*KINDS.keys, "n", :escape].freeze
49
+
50
+ def asks = :hide
51
+
52
+ def take(key) = KINDS.key?(key) && hide(KINDS[key])
53
+
54
+ # Whether `place`, [kind, row] under the cursor now, is still the branch or job asked about.
55
+ def about?(place) = place.first == @kind && CursorRows.key(*place) == CursorRows.key(@kind, @row)
56
+
57
+ private
58
+
59
+ def hide(how) = @kind == :job ? @board_data.hide_job(@row, how) : @board_data.hide_run(@row, how)
60
+ end
61
+ end
62
+ end
63
+ end
@@ -16,9 +16,9 @@ module FunCi
16
16
  stages: run[:stages].map { |stage| stage(stage) }, **marks(run) }.compact
17
17
  end
18
18
 
19
- # What the row marks beyond the run itself: a conflict with the trunk, and
20
- # how many cancelled runs it stands for.
21
- def self.marks(run) = { trunk: conflict(run[:trunk]), folded: run[:folded] }
19
+ # What the row marks beyond the run itself: a conflict with the trunk,
20
+ # how many cancelled runs it stands for, and how the user hid its branch.
21
+ def self.marks(run) = { trunk: conflict(run[:trunk]), folded: run[:folded], hidden: run[:hidden] }
22
22
 
23
23
  # The branch's standing against the trunk, sent only where the row shows it: a conflict.
24
24
  def self.conflict(trunk) = trunk && trunk[:branch_state] == "conflicts" ? trunk : nil
@@ -2,8 +2,8 @@
2
2
 
3
3
  module FunCi
4
4
  module Console
5
- # What the user sees of the rows and does with them: KeyHandler's cursor
6
- # and cancel confirmation, and one page of rows, one per branch, as many as
5
+ # What the user sees of the rows and does with them: KeyHandler's cursor,
6
+ # what it asks and which job rows it keeps in view, and one page of rows, one per branch, as many as
7
7
  # the terminal fits, scrolled so the row under the cursor is on it
8
8
  # (renderer-protocol.md, `board`).
9
9
  class View
@@ -19,25 +19,39 @@ module FunCi
19
19
  @page_size = 0
20
20
  end
21
21
 
22
+ # The least a page holds: the renderer fits what it can of a run, and
23
+ # a page of none would read as no runs at all.
24
+ LEAST = 1
25
+
22
26
  # The number of runs a terminal of `rows` fits.
23
27
  def resize(rows)
24
- @page_size = [rows - CHROME_ROWS, 0].max
28
+ @page_size = [rows - CHROME_ROWS, LEAST].max
25
29
  end
26
30
 
27
31
  # :quit when the key ends the session.
28
32
  def press(key) = @key_handler.handle_key(key)
29
33
 
34
+ # The job rows in view: not the hidden ones, unless the user asked for them.
35
+ def shown(job_rows) = @key_handler.shown(job_rows)
36
+
37
+ # The branches' runs in view: not those of hidden branches, unless the user asked for them.
38
+ def shown_runs(runs) = @key_handler.shown_runs(runs)
39
+
30
40
  # `more`: whether the store holds runs beyond `runs`. `jobs`: the job
31
- # section's rows, below the page, which the cursor reaches after the runs.
41
+ # section's rows in view, below the page, which the cursor reaches after the runs.
32
42
  def page(runs, more:, jobs: [])
33
- size = jobs.empty? ? @page_size : [@page_size - JOB_LINES, 0].max
43
+ @key_handler.follow(runs, jobs, from_the_first: true)
44
+ size = jobs.empty? ? @page_size : [@page_size - JOB_LINES, LEAST].max
34
45
  first = first_shown(runs.size, size)
35
- { cursor: cursor_on_page(first, size), confirming: @key_handler.confirming?,
46
+ { cursor: cursor_on_page(first, size), confirming: @key_handler.confirming?, **hiding,
36
47
  has_more: more || first + size < runs.size, runs: runs[first, size] || [] }
37
48
  end
38
49
 
39
50
  private
40
51
 
52
+ # Only while the footer asks how to hide a branch or a job, as the protocol lets a board leave it out.
53
+ def hiding = @key_handler.asking == :hide ? { hiding: true } : {}
54
+
41
55
  # The last page of runs while the cursor is on a job.
42
56
  def first_shown(count, size)
43
57
  cursor = @key_handler.cursor_index
@@ -44,22 +44,23 @@ module FunCi
44
44
 
45
45
  def claimed(slot, at)
46
46
  runs.died(@job.name)
47
- id = runs.claim(@job, commit: @commit.to_h, lock_file: slot.lock_file, now: @site.clock.call)
48
- id && (turn_came?(id, at) ? execute(slot, id) : id)
47
+ now = @site.clock.call
48
+ waits = at > now
49
+ id = runs.claim(@job, commit: @commit.to_h, lock_file: slot.lock_file, now: now) do |run|
50
+ scheduled(run, at) if waits
51
+ end
52
+ id && (!waits || turn_came?(id, at - now) ? execute(slot, id) : id)
49
53
  end
50
54
 
51
- # Waits, scheduled, for the run's turn, the lock held; false when it was
55
+ # Waits `seconds` for the run's turn, the lock held; false when it was
52
56
  # cancelled meanwhile.
53
- def turn_came?(id, at)
54
- seconds = at - @site.clock.call
55
- return true unless seconds.positive?
56
-
57
- scheduled(id, at)
57
+ def turn_came?(id, seconds)
58
58
  @site.wait.call(seconds)
59
59
  runs.start_turn(id, @site.clock.call).positive?
60
60
  end
61
61
 
62
- # This process is recorded, so a cancel stops it while it waits.
62
+ # Scheduled from the moment it is claimed, and this process recorded, so
63
+ # a cancel stops it while it waits.
63
64
  def scheduled(id, at)
64
65
  recorder.started_by(id, Process.pid, budget: budget)
65
66
  runs.wait_until(id, at)