Class: Policial::Commit

Inherits:
Object
  • Object
show all
Defined in:
lib/policial/commit.rb

Overview

Public: A Commit in a GitHub repo.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo, sha) ⇒ Commit

Returns a new instance of Commit.



6
7
8
9
# File 'lib/policial/commit.rb', line 6

def initialize(repo, sha)
  @repo = repo
  @sha  = sha
end

Instance Attribute Details

#repoObject (readonly)

Returns the value of attribute repo.



4
5
6
# File 'lib/policial/commit.rb', line 4

def repo
  @repo
end

#shaObject (readonly)

Returns the value of attribute sha.



4
5
6
# File 'lib/policial/commit.rb', line 4

def sha
  @sha
end

Instance Method Details

#file_content(filename) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/policial/commit.rb', line 11

def file_content(filename)
  contents = Policial.octokit.contents(@repo, path: filename, ref: @sha)

  if contents && contents.content
    Base64.decode64(contents.content).force_encoding('UTF-8')
  else
    ''
  end
rescue Octokit::NotFound
  ''
end