Class: CollavreGithub::AccountsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- CollavreGithub::AccountsController
- Defined in:
- app/controllers/collavre_github/accounts_controller.rb
Instance Method Summary collapse
Instance Method Details
#organizations ⇒ Object
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_account.github_uid, login: Current.user.github_account.login, name: Current.user.github_account.name.presence || Current.user.github_account.login, type: "User" } render json: { organizations: [ user_org ] + orgs } rescue Octokit::Unauthorized render json: { error: "unauthorized" }, status: :unauthorized end |
#repositories ⇒ Object
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.github_account) .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 |
#show ⇒ Object
5 6 7 |
# File 'app/controllers/collavre_github/accounts_controller.rb', line 5 def show render json: serialize_account(Current.user.github_account) end |