Module: PlanMyStuff::Pipeline::IssueLinker

Defined in:
lib/plan_my_stuff/pipeline/issue_linker.rb

Overview

Resolves linked issues from pull request payloads and finds their corresponding ProjectItems in the pipeline project.

Uses module_function pattern (matches MetadataParser, Pipeline).

Constant Summary collapse

CLOSING_KEYWORD_PATTERN =

Regex matching GitHub closing keywords in PR bodies. Matches all nine variants: close/closes/closed, fix/fixes/fixed, resolve/resolves/resolved (case-insensitive).

/\b(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?)\s+#(\d+)\b/i

Class Method Summary collapse

Class Method Details

.extract_issue_numbers(pr_payload, commit_messages: []) ⇒ Array<Integer>

Extracts issue numbers from a PR payload by parsing the PR body and commit messages for GitHub closing keywords (close/closes/closed, fix/fixes/fixed, resolve/resolves/resolved).

Parameters:

  • pr_payload (Hash)

    parsed PR webhook payload (expects :body or “body” key)

  • commit_messages (Array<String>) (defaults to: [])

    commit messages to scan (default: [])

Returns:

  • (Array<Integer>)

    referenced issue numbers (empty if none found)



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/plan_my_stuff/pipeline/issue_linker.rb', line 27

def extract_issue_numbers(pr_payload, commit_messages: [])
  texts = []

  body = pr_payload[:body] || pr_payload['body']
  texts << body if body.present?

  Array.wrap(commit_messages).each do |message|
    texts << message if message.present?
  end

  return [] if texts.empty?

  matches = texts.join("\n").scan(CLOSING_KEYWORD_PATTERN).flatten
  matches.map!(&:to_i)
  matches.uniq!
  matches
end

.find_project_item(issue_number, _repo: nil, project_number: nil) ⇒ PlanMyStuff::ProjectItem?

Finds the ProjectItem in the pipeline project that matches the given issue number. Loads the full project and iterates its items.

Parameters:

  • issue_number (Integer)

    issue number to find

  • repo (Symbol, String, nil)

    unused, reserved for future multi-repo support

  • project_number (Integer, nil) (defaults to: nil)

    pipeline project number

Returns:



54
55
56
57
58
59
# File 'lib/plan_my_stuff/pipeline/issue_linker.rb', line 54

def find_project_item(issue_number, _repo: nil, project_number: nil)
  number = PlanMyStuff::Pipeline.resolve_pipeline_project_number(project_number)
  project = PlanMyStuff::Project.find(number)

  project.items.find { |item| item.number == issue_number }
end