module Commands::Track::Helpers

Private Instance Methods

build_track(track) click to toggle source
# File lib/commands/track/helpers.rb, line 6
def build_track(track)
  LearningTrack.new(track['name']).tap do |learning_track|
    track['exercises'].each do |exercise|
      name, path = exercise.flatten.to_a
      learning_track.exercise(name: name, path: path)
    end

    learning_track.validate
  end
end
create_column(project_id, name) click to toggle source
# File lib/commands/track/helpers.rb, line 25
def create_column(project_id, name)
  github_client.create_project_column(project_id, name, default_projects_options)
end
create_columns(project_id, names) click to toggle source
# File lib/commands/track/helpers.rb, line 17
def create_columns(project_id, names)
  {}.tap do |columns|
    names.each do |name|
      columns[name] = create_column(project_id, name)
    end
  end
end
create_exercises(todo_column, track_name) click to toggle source
# File lib/commands/track/helpers.rb, line 29
def create_exercises(todo_column, track_name)
  exercises(track_name).each do |exercise|
    issue = github_client.create_issue(fork, exercise.name, exercise.detail, labels: '')

    options = default_projects_options.merge(content_id: issue.id, content_type: 'Issue')
    github_client.create_project_card(todo_column.id, options)
  end
end
create_project(board_name) click to toggle source
# File lib/commands/track/helpers.rb, line 38
def create_project(board_name)
  github_client.create_project(fork, board_name, default_projects_options)
end
default_projects_options() click to toggle source
# File lib/commands/track/helpers.rb, line 42
def default_projects_options
  { accept: 'application/vnd.github.inertia-preview+json' }
end
enable_issues() click to toggle source
# File lib/commands/track/helpers.rb, line 46
def enable_issues
  github_client.edit_repository(fork, has_issues: true)
end
exercises(track_name) click to toggle source
# File lib/commands/track/helpers.rb, line 50
def exercises(track_name)
  tracks[track_name].exercises.reverse
end
fork() click to toggle source
# File lib/commands/track/helpers.rb, line 54
def fork
  options[:fork]
end
github_client() click to toggle source
# File lib/commands/track/helpers.rb, line 58
def github_client
  @github_client ||= begin
    options = { netrc: true, api_endpoint: api_endpoint }
    Octokit::Client.new(options).tap do |client|
      raise NetrcMissingError unless File.exist?(client.netrc_file)

      host = URI(client.api_endpoint).host
      raise MissingCredentialsError, host unless Netrc.read(client.netrc_file)[host]
    end
  end
end
load_tracks(hash) click to toggle source
# File lib/commands/track/helpers.rb, line 70
def load_tracks(hash)
  {}.tap do |tracks|
    hash.each do |track|
      tracks[build_track(track).name] = build_track(track)
    end
  end
end
setup!(track_name) click to toggle source
# File lib/commands/track/helpers.rb, line 90
def setup!(track_name)
  raise TrackNotFoundError.new(track_name: track_name, track_names: track_names) unless track_exists?(track_name)

  repo = github_client.repo(fork)

  raise RepoIsNotForkError, fork unless repo['fork'] == true

  enable_issues
end
track_exists?(track_name) click to toggle source
# File lib/commands/track/helpers.rb, line 78
def track_exists?(track_name)
  tracks.key?(track_name)
end
track_names() click to toggle source
# File lib/commands/track/helpers.rb, line 82
def track_names
  tracks.keys
end
tracks_dir() click to toggle source
# File lib/commands/track/helpers.rb, line 86
def tracks_dir
  File.dirname(File.expand_path(tracks_yaml))
end