Class: GithubIntegration::TrackingIssue

Inherits:
Object
  • Object
show all
Defined in:
action/lib/github_integration.rb

Overview

Finds, creates, updates, and closes the single tracking issue used to report updates on runs without a pull request context.

Defined Under Namespace

Classes: LookupExhausted

Constant Summary collapse

ISSUE_IDENTIFIER =
"<!-- spm-version-updates-action:tracking-issue -->"
LABEL =
"spm-version-updates"
TITLE =
"Swift package dependency updates available"
PAGE_SIZE =
100
MAX_FIND_EXISTING_PAGES =
10

Instance Method Summary collapse

Constructor Details

#initialize(client, repository) ⇒ TrackingIssue

Returns a new instance of TrackingIssue.



33
34
35
36
# File 'action/lib/github_integration.rb', line 33

def initialize(client, repository)
  @client = client
  @repository = repository
end

Instance Method Details

#close(comment) ⇒ Object

Close the open tracking issue, leaving a resolution comment. No-op when no tracking issue exists.



52
53
54
55
56
57
58
59
60
61
# File 'action/lib/github_integration.rb', line 52

def close(comment)
  number = find_existing&.[](:number)
  return unless number

  @client.add_comment(@repository, number, comment)
  @client.close_issue(@repository, number)
  puts("Closed resolved tracking issue ##{number}")
rescue Octokit::Error, LookupExhausted => error
  puts("Error closing tracking issue: #{error.message}")
end

#upsert(body_content) ⇒ Hash?

Update the existing open tracking issue or create a new one.

Returns:

  • (Hash, nil)

    { number:, url: }, or nil when the API call failed



40
41
42
43
44
45
46
47
48
# File 'action/lib/github_integration.rb', line 40

def upsert(body_content)
  issue = upsert_issue(find_existing, "#{ISSUE_IDENTIFIER}\n#{body_content}")
  url = issue[:html_url]
  puts("Tracking issue: #{url}")
  { number: issue[:number], url: }
rescue Octokit::Error, LookupExhausted => error
  puts("Error upserting tracking issue: #{error.message}")
  nil
end