Sha256: 8040e14f0de2f836d25a88bb98c2f1446b046ce02310cefa5aed70e6a96ca2be

Contents?: true

Size: 1.85 KB

Versions: 5

Compression:

Stored size: 1.85 KB

Contents

require_relative "issue"
require_relative "../week"
require "octokit"

module Octopolo
  module GitHub
    class PullRequest < Issue

      # Public: All closed pull requests for a given repo
      #
      # repo_name - Full name ("account/repo") of the repo in question
      #
      # Returns an Array of PullRequest objects
      def self.closed repo_name
        GitHub.pull_requests(repo_name, "closed").map do |data|
          new repo_name, data.number, data
        end
      end

      # Public: Create a pull request for the given repo
      #
      # repo_name - Full name ("account/repo") of the repo in question
      # options - Hash of pull request information
      #   title: Title of the pull request
      #   description: Brief description of the pull request
      #   release: Boolean indicating if the pull request is for Release
      #   destination_branch: Which branch to merge into
      #   source_branch: Which branch to be merged
      #
      # Returns a PullRequest instance
      def self.create repo_name, options
        # create via the API
        creator = PullRequestCreator.perform(repo_name, options)
        # wrap in our class
        new repo_name, creator.number, creator.data
      end

      def data
        @data ||= GitHub.pull_request(repo_name, number)
      rescue Octokit::NotFound
        raise NotFound
      end

      def branch
        data.head.ref
      end

      def mergeable?
        data.mergeable
      end

      def week
        Week.parse data.closed_at
      end

      def commenter_names
        exclude_octopolo_user (comments.map{ |comment| GitHub::User.new(comment.user.login).author_name }.uniq - author_names)
      end

      def author_names
        exclude_octopolo_user commits.map(&:author_name).uniq
      end

      def commits
        @commits ||= Commit.for_pull_request self
      end

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
octopolo-1.0.2 lib/octopolo/github/pull_request.rb
octopolo-1.0.1 lib/octopolo/github/pull_request.rb
octopolo-1.0.0 lib/octopolo/github/pull_request.rb
octopolo-0.4.1 lib/octopolo/github/pull_request.rb
octopolo-0.4.0 lib/octopolo/github/pull_request.rb