Module: Usps::Support::Models::GitHub

Defined in:
lib/usps/support/models/git_hub.rb

Overview

GitHub API

Constant Summary collapse

ORG =
'unitedstatespowersquadrons'
CLIENT_MUTEX =
Mutex.new

Class Method Summary collapse

Class Method Details

.check_runs(repo, check_suite_id) ⇒ Object



19
20
21
# File 'lib/usps/support/models/git_hub.rb', line 19

def check_runs(repo, check_suite_id)
  client.check_runs_for_check_suite("#{ORG}/#{repo}", check_suite_id).check_runs
end

.check_suites(repo, branch) ⇒ Object



11
12
13
# File 'lib/usps/support/models/git_hub.rb', line 11

def check_suites(repo, branch)
  client.check_suites_for_ref("#{ORG}/#{repo}", branch).check_suites
end

.expired?Boolean

Returns:

  • (Boolean)


43
# File 'lib/usps/support/models/git_hub.rb', line 43

def expired? = expires_at <= Time.zone.now

.expires_atObject



44
# File 'lib/usps/support/models/git_hub.rb', line 44

def expires_at = @auth[:expires_at]

.fetch_head_commit(repo, branch) ⇒ Object



23
24
25
26
# File 'lib/usps/support/models/git_hub.rb', line 23

def fetch_head_commit(repo, branch)
  sha = client.ref("#{ORG}/#{repo}", "heads/#{branch}").object.sha
  client.commit("#{ORG}/#{repo}", sha).commit
end

.graphql(query, variables = {}) ⇒ Object



15
16
17
# File 'lib/usps/support/models/git_hub.rb', line 15

def graphql(query, variables = {})
  client.post('/graphql', { query:, variables: }.to_json)
end

.latest_tag(repo, include_prereleases: false) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/usps/support/models/git_hub.rb', line 32

def latest_tag(repo, include_prereleases: false)
  client
    .tags("#{ORG}/#{repo}")
    .pluck(:name)
    .grep(/^v\d+\.\d+\.\d(?:-[\w\-.]+)?/)
    .index_with { Gem::Version.new(it.delete('v')) }
    .reject { |_, gv| gv.prerelease? unless include_prereleases }
    .max_by { |_, gv| gv }
    .first
end

.permissionsObject



45
# File 'lib/usps/support/models/git_hub.rb', line 45

def permissions = @auth[:permissions]

.repository_selectionObject



46
# File 'lib/usps/support/models/git_hub.rb', line 46

def repository_selection = @auth[:repository_selection]

.repository_workflow_runs(repo, head_sha:) ⇒ Object



28
29
30
# File 'lib/usps/support/models/git_hub.rb', line 28

def repository_workflow_runs(repo, head_sha:)
  client.repository_workflow_runs("#{ORG}/#{repo}", head_sha:).workflow_runs
end