Class: CollavreGithub::AccountsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/collavre_github/accounts_controller.rb

Instance Method Summary collapse

Instance Method Details

#organizationsObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/collavre_github/accounts_controller.rb', line 9

def organizations
  orgs = github_client.organizations.map do |org|
    {
      id: org[:id] || org["id"],
      login: org[:login] || org["login"],
      name: org[:name] || org["name"] || (org[:login] || org["login"]),
      type: org[:type] || org["type"]
    }
  end

  user_org = {
    id: Current.user..github_uid,
    login: Current.user..,
    name: Current.user..name.presence || Current.user..,
    type: "User"
  }

  render json: { organizations: [ user_org ] + orgs }
rescue Octokit::Unauthorized
  render json: { error: "unauthorized" }, status: :unauthorized
end

#repositoriesObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/collavre_github/accounts_controller.rb', line 31

def repositories
  organization = params[:organization]
  creative = params[:creative_id].present? ? Collavre::Creative.find_by(id: params[:creative_id]) : nil
  selected = if creative
    creative.github_repository_links.where(github_account: Current.user.)
            .pluck(:repository_full_name)
  else
    []
  end

  repos = fetch_repositories(organization).map do |repo|
    full_name = repo[:full_name] || repo["full_name"]
    {
      id: repo[:id] || repo["id"],
      name: repo[:name] || repo["name"],
      full_name: full_name,
      selected: selected.include?(full_name)
    }
  end

  render json: { repositories: repos }
rescue Octokit::NotFound
  render json: { error: "not_found" }, status: :not_found
end

#showObject



5
6
7
# File 'app/controllers/collavre_github/accounts_controller.rb', line 5

def show
  render json: (Current.user.)
end