Class: Commenter::GitHubSync
- Inherits:
-
GitHubIssueCreator
- Object
- GitHubIssueCreator
- Commenter::GitHubSync
- Defined in:
- lib/commenter/github_sync.rb
Overview
Synchronizes the comment YAML with GitHub issues, treating the YAML as the source of truth: comments without an issue get one, issue content is refreshed from the YAML (per the conflict policy), and issues whose comment has a recorded disposition can be closed.
Class Method Summary collapse
-
.reconcile_actions(issue:, rendered:, disposition:, conflict: "yaml", close_on_disposition: true) ⇒ Object
Returns the sync actions for one comment by comparing the rendered issue content against the issue's current state.
Instance Method Summary collapse
Methods inherited from GitHubIssueCreator
#create_issues_from_yaml, #initialize
Constructor Details
This class inherits a constructor from Commenter::GitHubIssueCreator
Class Method Details
.reconcile_actions(issue:, rendered:, disposition:, conflict: "yaml", close_on_disposition: true) ⇒ Object
Returns the sync actions for one comment by comparing the rendered issue content against the issue's current state. Pure — no network — so the conflict matrix is directly specifiable.
conflict policy:
yaml - re-render title/body over the issue (YAML wins)
github - leave differing issue content untouched (GitHub wins)
skip - take no action on differing content, report the conflict
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/commenter/github_sync.rb', line 17 def self.reconcile_actions(issue:, rendered:, disposition:, conflict: "yaml", close_on_disposition: true) actions = [] differing = [rendered[:title].to_s.strip, rendered[:body].to_s.strip] != [issue[:title].to_s.strip, issue[:body].to_s.strip] if differing case conflict when "yaml" then actions << :update_content when "github" then actions << :keep_github_content when "skip" then actions << :conflict end end actions << :close if close_on_disposition && issue[:state] == "open" && disposition && !disposition.strip.empty? actions end |
Instance Method Details
#sync(yaml_file, options = {}) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/commenter/github_sync.rb', line 36 def sync(yaml_file, = {}) comment_sheet = CommentSheet.from_yaml(File.read(yaml_file)) comment_sheet.stage = [:stage] if [:stage] results = comment_sheet.comments.map do |comment| [:dry_run] ? plan(comment, ) : reconcile(comment, comment_sheet, ) end update_yaml_with_github_info(yaml_file, comment_sheet, results, ) unless [:dry_run] results end |