class Middleman::GithubApi::Extension

Public Class Methods

new(app, options_hash={}, &block) click to toggle source
Calls superclass method
# File lib/middleman-github_api/extension.rb, line 5
def initialize(app, options_hash={}, &block)
  # Call super to build options from the options_hash
  super
  @app = app.inst

  repository = options_hash[:repo]
  unless repository
    $stderr.puts("middleman-github_api: repository option is missing")
    return
  end

  hash = {
    repository: repository,
  }

  require "octokit"
  access_token = ENV["MIDDLEMAN_GITHUB_API_ACCESS_TOKEN"]
  unless access_token
    $stderr.puts("middleman-github_api: GitHub access token is missing")
    $stderr.puts("Set token to MIDDLEMAN_GITHUB_API_ACCESS_TOKEN of environment variables")
    $stderr.puts("e.g.: $ export MIDDLEMAN_GITHUB_API_ACCESS_TOKEN=xxx")
    hash[:commits] = []
    @app.data.store(:github_api, hash)
    return
  end

  client = Octokit::Client.new(access_token: access_token)
  date = Time.now.strftime("%Y-%m-%d")
  raw_commits = client.commits_on(repository, date)
  commits = []
  raw_commits.each do |commit|
    commits << client.commit(repository, commit.sha)
  end
  hash[:commits] = commits

  @app.data.store(:github_api, hash)

  # set up your extension
  # puts options.my_option
end

Public Instance Methods

after_configuration() click to toggle source
# File lib/middleman-github_api/extension.rb, line 46
def after_configuration
  # Do something
end