| 1 | # frozen_string_literal: true |
| 2 | |
| 3 | # Creates issues. All issue creation — web UI or MCP — goes through here so |
| 4 | # per-repo numbering (shared with pull requests) behaves identically across |
| 5 | # callers. |
| 6 | class IssueService |
| 7 | class Error < StandardError; end |
| 8 | |
| 9 | # Opens an issue on +repository+ authored by +author+. Anyone who can read a |
| 10 | # repository may open an issue on it, so read access is enforced by the |
| 11 | # caller (the MCP layer only resolves repos the user can read), as with |
| 12 | # comments. Raises ActiveRecord::RecordInvalid on validation failure. |
| 13 | def self.create(repository:, author:, title:, body: nil) |
| 14 | repository.with_lock do |
| 15 | repository.issues.create!( |
| 16 | user: author, |
| 17 | number: repository.next_issue_number, |
| 18 | title: title, |
| 19 | body: body.to_s, |
| 20 | state: "open" |
| 21 | ) |
| 22 | end |
| 23 | end |
| 24 | end |