Class: Tokite::RepositoriesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/tokite/repositories_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/tokite/repositories_controller.rb', line 22

def create
  if params[:names].nil?
    flash[:error] = "Error: No repository was selected"
  else
    github_repos = params[:names].map do |name|
      octokit_client.repository(name)
    end
    errors = github_repos.select(&:archived).map(&:full_name)
    if errors != []
      flash[:error] = %(Error: The following repositories have been archived: #{errors.join(", ")})
    else
      github_repos.each do |repo|
        Repository.hook!(octokit_client, repo)
      end
      flash[:info] = "Import repositories."
    end
  end
  redirect_to repositories_path
end

#destroyObject



42
43
44
45
46
47
# File 'app/controllers/tokite/repositories_controller.rb', line 42

def destroy
  repo = Repository.find(params[:id])
  repo.unhook!(octokit_client)
  flash[:info] = "Unhook repository #{repo.name}"
  redirect_to repositories_path
end

#indexObject



5
6
7
# File 'app/controllers/tokite/repositories_controller.rb', line 5

def index
  @repositories = Repository.all
end

#newObject



9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/tokite/repositories_controller.rb', line 9

def new
  github_repos = octokit_client.repositories.
    select{|r| r.permissions.admin }.
    delete_if(&:fork).
    delete_if(&:archived)
  @repositories = github_repos.map do |repo|
    Repository.new(name: repo.full_name, url: repo.html_url, private: repo.private)
  end
  Repository.all.pluck(:name).each do |existing_name|
    @repositories.delete_if {|repo| repo.name == existing_name }
  end
end