Class: Agentilda::Resync::Prs

Inherits:
Object
  • Object
show all
Defined in:
lib/agentilda/resync.rb

Overview

resync prs — puts an [NNN.MM] prefix on every pull request title that lacks one, and [DEV.00] on the ones that implement no plan.

The resolution order is the branch name first, then the diff, and only when the diff touches exactly one plan. Anything else is reported for a human and never edited: pull-requests.md is generated from these titles, and a wrong number files work under a plan that did not do it, leaving the plan that did looking untouched.

Defined Under Namespace

Classes: Change

Constant Summary collapse

STALE =

The marker this tool used to write, now replaced. A title wearing it is rewritten in place: the assertion it makes — "this belongs to no specification" — is still true and still somebody's deliberate call, so it is restamped rather than re-resolved.

/\A\[#{Regexp.escape(Agentilda::STALE_NO_PLAN_PREFIX)}\]\s*/
PREFIXED =

Titles that already carry a prefix — a plan number, the no-plan marker, or the legacy [XXX].

/\A\[(?:\d{3}(?:\.\d{2})?|#{Agentilda::NO_PLAN_PREFIX}|XXX)\](?:\([A-Z]\))?\s/
BRANCH_PATTERN =

Finds a plan number in a branch name: kig/018.01-verify, 002-slug.

%r{(?:\A|[/\-_])(\d{3}(?:\.\d{2})?)(?:\z|[-_])}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tree:, github: GitHub.new, adopt: true, root: nil) ⇒ Prs

Returns a new instance of Prs.

Parameters:

  • tree (Agentilda::Tree)
  • github (Agentilda::GitHub) (defaults to: GitHub.new)
  • adopt (Boolean) (defaults to: true)

    give a plan folder to every pull request that resolves to none, rather than flagging it and moving on

  • root (String, nil) (defaults to: nil)

    repository root, for reading branches



184
185
186
187
188
189
# File 'lib/agentilda/resync.rb', line 184

def initialize(tree:, github: GitHub.new, adopt: true, root: nil)
  @tree = tree
  @github = github
  @adopt = adopt
  @root = root
end

Instance Attribute Details

#githubAgentilda::GitHub (readonly)

Returns:



198
199
200
# File 'lib/agentilda/resync.rb', line 198

def github
  @github
end

#treeAgentilda::Tree (readonly)

Returns:



195
196
197
# File 'lib/agentilda/resync.rb', line 195

def tree
  @tree
end

Instance Method Details

#adopt?Boolean

Returns:

  • (Boolean)


192
# File 'lib/agentilda/resync.rb', line 192

def adopt? = @adopt

#adoptionArray<Agentilda::Adoption>

Returns the adopter, memoized.

Returns:



224
# File 'lib/agentilda/resync.rb', line 224

def adoption = @adoption ||= Adoption.new(tree:, github:, root: @root)

#call(commit: false) ⇒ Array<Agentilda::Resync::Prs::Change>

Returns what was proposed.

Parameters:

  • commit (Boolean) (defaults to: false)

    actually retitle, and mint the folders

Returns:



212
213
214
215
216
217
218
219
220
221
# File 'lib/agentilda/resync.rb', line 212

def call(commit: false)
  changes = resolve(candidates)
  return restamps + (adopt? ? with_adoptions(changes) : changes) unless commit

  changes = with_adoptions(changes, create: true) if adopt?
  changes = restamps + changes
  applicable = changes.select(&:applicable?)
  UI.stepping(applicable, "Retitling") { |c| github.retitle(number: c.number, title: c.new_title) }
  changes
end

#planArray<Agentilda::Resync::Prs::Change>

What would change, without changing anything.

Returns:



203
204
205
# File 'lib/agentilda/resync.rb', line 203

def plan
  restamps + resolve(candidates).then { |changes| adopt? ? with_adoptions(changes) : changes }
end

#restampsArray<Agentilda::Resync::Prs::Change>

Returns:



208
# File 'lib/agentilda/resync.rb', line 208

def restamps = stale.map { |pull| restamped(pull) }