Class: GitWebhook::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/git-webhook/repository.rb

Instance Method Summary collapse

Constructor Details

#initialize(path, options = {}) ⇒ Repository

Returns a new instance of Repository.



7
8
9
10
11
12
13
14
15
# File 'lib/git-webhook/repository.rb', line 7

def initialize(path, options = {})
  options.to_options!
  options.assert_valid_keys :url, :name, :description, :homepage, :watchers,
                            :forks, :private, :pledgie, :owner, :commit_url
  options[:owner].assert_valid_keys(:name, :email) unless options[:owner].nil?

  @repo = Grit::Repo.new(path)
  @options = options
end

Instance Method Details

#commits_between(old, new) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/git-webhook/repository.rb', line 21

def commits_between(old, new)
  commits = []
  @repo.commits_between(old, new).each do |commit|
    commit_data = {
      :id => commit.sha,
      :author => {
        :name => commit.author.name,
        :email => commit.author.email
      },
      :message => commit.message,
      :timestamp => commit.date.xmlschema
    }
    commit_data[:url] = @options[:commit_url] % commit.sha unless @options[:commit_url].blank?

    commit_data.merge! commit_stats(commit)

    commits << commit_data
  end
  commits
end

#infoObject



17
18
19
# File 'lib/git-webhook/repository.rb', line 17

def info
  @options.except(:commit_url)
end