Class: Middleman::GithubApi::Extension

Inherits:
Extension
  • Object
show all
Defined in:
lib/middleman-github_api/extension.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, options_hash = {}, &block) ⇒ Extension

Returns a new instance of Extension.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# 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

Instance Method Details

#after_configurationObject



46
47
48
# File 'lib/middleman-github_api/extension.rb', line 46

def after_configuration
  # Do something
end