Sha256: 8eaf903e87527c4bf865fa8c1e5d3e7a6bc66ff103061cfde76794717bf94ef2

Contents?: true

Size: 1.18 KB

Versions: 3

Compression:

Stored size: 1.18 KB

Contents

require_relative "../github"
require_relative "user"

module Octopolo
  module GitHub
    class Commit
      attr_accessor :commit_data

      # Public: Instantiate a new Commit wrapper object
      #
      # commit_data - The GitHub API data about the commit
      def initialize commit_data
        self.commit_data = commit_data
      end

      # Public: Find commits for a given pull request
      #
      # pull_request - A PullRequest or other object responding to #repo_name
      #   and #number
      #
      # Returns an Array of Commit objects
      def self.for_pull_request pull_request
        GitHub.pull_request_commits(pull_request.repo_name, pull_request.number).map do |c|
          Commit.new c
        end
      end

      # Public: GitHub User that is the author of the commit
      #
      # Returns a Hashie::Mash object of the GitHub User
      def author
        GitHub::User.new(commit_data.author.login)
      rescue NoMethodError
        GitHub::User.new(GitHub::UNKNOWN_USER)
      end

      # Public: The name of the author of the commit
      #
      # Returns a String containing the author's name
      def author_name
        author.author_name
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
octopolo-0.1.0 lib/octopolo/github/commit.rb
octopolo-0.0.2 lib/octopolo/github/commit.rb
octopolo-0.0.1 lib/octopolo/github/commit.rb