# encoding: utf-8
module Github
class Issues < API
extend AutoloadHelper
autoload_all 'github_api/issues',
:Comments => 'comments',
:Events => 'events',
:Labels => 'labels',
:Milestones => 'milestones'
include Github::Issues::Comments
include Github::Issues::Events
include Github::Issues::Labels
include Github::Issues::Milestones
VALID_ISSUE_PARAM_NAMES = %w[
filter
state
labels
sort
direction
since
milestone
assignee
mentioned
title
body
]
VALID_ISSUE_PARAM_VALUES = {
'filter' => %w[ assigned created mentioned subscribed ],
'state' => %w[ open closed ],
'sort' => %w[ created updated comments ],
'direction' => %w[ desc asc ],
'since' => %r{\d{4}-\d{2}-\d{5}:\d{2}:\d{3}}
}
# Creates new Issues API
def initialize(options = {})
super(options)
end
# List your issues
#
# = Parameters
# :filter
# * assigned: Issues assigned to you (default)
# * created: Issues assigned to you (default)
# * mentioned: Issues assigned to you (default)
# * subscribed: Issues assigned to you (default)
# :state - open, closed, default: open
# :labels - String list of comma separated Label names. Example: bug,ui,@high
# :sort - created, updated, comments, default: created
# :direction - asc, desc, default: desc
# :since - Optional string of a timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ
#
# = Examples
# @github = Github.new :oauth_token => '...'
# @github.issues.issues :since => '2011-04-12312:12:121',
# :filter => 'created',
# :state => 'open',
# :labels => "bug,ui,bla",
# :sort => 'comments',
# :direction => 'asc'
#
def issues(params={})
_normalize_params_keys(params)
_filter_params_keys(VALID_ISSUE_PARAM_NAMES, params)
_validate_params_values(VALID_ISSUE_PARAM_VALUES, params)
response = get("/issues", params)
return response unless block_given?
response.each { |el| yield el }
end
# List issues for a repository
#
# = Parameters
# :milestone
# * Integer Milestone number
# * none for Issues with no Milestone.
# * * for Issues with any Milestone
# :state - open, closed, default: open
# :assignee
# * String User login
# * none for Issues with no assigned User.
# * * for Issues with any assigned User.
# :mentioned String User login
# :labels - String list of comma separated Label names. Example: bug,ui,@high
# :sort - created, updated, comments, default: created
# :direction - asc, desc, default: desc
# :since - Optional string of a timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ
# , default: due_date
# :direction - asc, desc, default: desc
#
# = Examples
# @github = Github.new :user => 'user-name', :repo => 'repo-name'
# @github.issues.repo_issues :milestone => 1,
# :state => 'open',
# :assignee => '*',
# :mentioned => 'octocat',
# :labels => "bug,ui,bla",
# :sort => 'comments',
# :direction => 'asc'
#
def repo_issues(user_name=nil, repo_name=nil, params={})
_update_user_repo_params(user_name, repo_name)
_validate_user_repo_params(user, repo) unless user? && repo?
_normalize_params_keys(params)
_filter_params_keys(VALID_ISSUE_PARAM_NAMES, params)
_validate_params_values(VALID_ISSUE_PARAM_VALUES, params)
response = get("/repos/#{user}/#{repo}/issues", params)
return response unless block_given?
response.each { |el| yield el }
end
# Get a single issue
#
# = Examples
# @github = Github.new
# @github.issues.get_issue 'user-name', 'repo-name', 'issue-id'
#
def get_issue(user_name, repo_name, issue_id, params={})
_update_user_repo_params(user_name, repo_name)
_validate_user_repo_params(user, repo) unless user? && repo?
_normalize_params_keys(params)
get("/repos/#{user}/#{repo}/issues/#{issue_id}")
end
# Create an issue
#
# = Inputs
# :title - Required string
# :body - Optional string
# :assignee - Optional string - Login for the user that this issue should be assigned to.
# :milestone - Optional number - Milestone to associate this issue with
# :labels - Optional array of strings - Labels to associate with this issue
# = Examples
# @github = Github.new :user => 'user-name', :repo => 'repo-name'
# @github.issues.create_issue
# "title" => "Found a bug",
# "body" => "I'm having a problem with this.",
# "assignee" => "octocat",
# "milestone" => 1,
# "labels" => [
# "Label1",
# "Label2"
# ]
#
def create_issue(user_name=nil, repo_name=nil, params={})
_update_user_repo_params(user_name, repo_name)
_validate_user_repo_params(user, repo) unless user? && repo?
_normalize_params_keys(params)
_filter_params_keys(VALID_MILESTONE_INPUTS, params)
raise ArgumentError, "Required params are: :title" unless _validate_inputs(%w[ title ], params)
post("/repos/#{user}/#{repo}/issues", params)
end
# Edit an issue
#
# = Inputs
# :title - Optional string
# :body - Optional string
# :assignee - Optional string - Login for the user that this issue should be assigned to.
# :state - Optional string - State of the issue:open or closed
# :milestone - Optional number - Milestone to associate this issue with
# :labels - Optional array of strings - Labels to associate with this issue. Pass one or more Labels to replace the set of Labels on this Issue. Send an empty array ([]) to clear all Labels from the Issue.
#
# = Examples
# @github = Github.new
# @github.issues.create_issue 'user-name', 'repo-name', 'issue-id'
# "title" => "Found a bug",
# "body" => "I'm having a problem with this.",
# "assignee" => "octocat",
# "milestone" => 1,
# "labels" => [
# "Label1",
# "Label2"
# ]
#
def edit_issue(user_name, repo_name, issue_id, params={})
_update_user_repo_params(user_name, repo_name)
_validate_user_repo_params(user, repo) unless user? && repo?
_validate_presence_of issue_id
_normalize_params_keys(params)
_filter_params_keys(VALID_MILESTONE_INPUTS, params)
patch("/repos/#{user}/#{repo}/issues/#{issue_id}", params)
end
end # Issues
end # Github