Class: Vx::ServiceConnector::Github::Repos

Inherits:
Struct
  • Object
show all
Defined in:
lib/vx/service_connector/github/repos.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#sessionObject

Returns the value of attribute session

Returns:

  • (Object)

    the current value of session



4
5
6
# File 'lib/vx/service_connector/github/repos.rb', line 4

def session
  @session
end

Instance Method Details

#organization_repositoriesObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/vx/service_connector/github/repos.rb', line 18

def organization_repositories
  organizations.map do |org|
    Thread.new do
      begin
        session
          .organization_repositories(org)
          .select { |repo| repo.permissions && repo.permissions.admin }
          .map { |repo| repo_to_model repo }
      rescue Octokit::Unauthorized
        []
      end
    end.tap do |th|
      th.abort_on_exception = true
    end
  end.map(&:value).flatten
end

#organizationsObject



10
11
12
13
14
15
16
# File 'lib/vx/service_connector/github/repos.rb', line 10

def organizations
  begin
    session.organizations.map(&:login) || []
  rescue Octokit::Unauthorized
    []
  end
end

#repo_to_model(repo) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/vx/service_connector/github/repos.rb', line 45

def repo_to_model(repo)
  Model::Repo.new(
    repo.id,
    repo.full_name,
    repo.private,
    repo.rels[:ssh].href,
    repo.rels[:html].href,
    repo.description,
    repo.language
  )
end

#to_aObject



6
7
8
# File 'lib/vx/service_connector/github/repos.rb', line 6

def to_a
  @repos ||= (user_repositories + organization_repositories)
end

#user_repositoriesObject



35
36
37
38
39
40
41
42
43
# File 'lib/vx/service_connector/github/repos.rb', line 35

def user_repositories
  begin
    session.repositories
      .select { |repo| repo.permissions && repo.permissions.admin }
      .map { |repo| repo_to_model repo }
  rescue Octokit::Unauthorized
    []
  end
end