Class: Github::Client::Issues

Inherits:
API
  • Object
show all
Defined in:
lib/github_api/client/issues.rb

Defined Under Namespace

Classes: Assignees, Comments, Events, Labels, Milestones

Constant Summary collapse

VALID_ISSUE_PARAM_NAMES =
%w[
  assignee
  body
  creator
  direction
  filter
  labels
  milestone
  mentioned
  mime_type
  org
  resource
  since
  sort
  state
  title
].freeze
VALID_ISSUE_PARAM_VALUES =
{
  'filter'    => %w[ assigned created mentioned subscribed all ],
  'state'     => %w[ open closed all ],
  'sort'      => %w[ created updated comments ],
  'direction' => %w[ desc asc ],
  'since'     => %r{\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z}
}

Constants included from MimeType

MimeType::MEDIA_LOOKUP

Constants included from Github::Constants

Github::Constants::ACCEPT, Github::Constants::ACCEPTED_OAUTH_SCOPES, Github::Constants::ACCEPT_CHARSET, Github::Constants::CACHE_CONTROL, Github::Constants::CONTENT_LENGTH, Github::Constants::CONTENT_TYPE, Github::Constants::DATE, Github::Constants::ETAG, Github::Constants::HEADER_LAST, Github::Constants::HEADER_LINK, Github::Constants::HEADER_NEXT, Github::Constants::LOCATION, Github::Constants::META_FIRST, Github::Constants::META_LAST, Github::Constants::META_NEXT, Github::Constants::META_PREV, Github::Constants::META_REL, Github::Constants::OAUTH_SCOPES, Github::Constants::PARAM_PAGE, Github::Constants::PARAM_PER_PAGE, Github::Constants::PARAM_START_PAGE, Github::Constants::RATELIMIT_LIMIT, Github::Constants::RATELIMIT_REMAINING, Github::Constants::RATELIMIT_RESET, Github::Constants::SERVER, Github::Constants::USER_AGENT

Instance Attribute Summary

Attributes inherited from API

#current_options

Instance Method Summary collapse

Methods inherited from API

after_callbacks, after_request, #api_methods_in, #arguments, before_callbacks, before_request, clear_request_methods!, #execute, extend_with_actions, extra_methods, #extract_basic_auth, extract_class_name, #filter_callbacks, inherited, #initialize, internal_methods, method_added, #method_missing, #module_methods_in, namespace, request_methods, root!, #run_callbacks, #set, #yield_or_eval

Methods included from Github::ClassMethods

#configuration, #configure, #require_all

Methods included from RateLimit

#ratelimit, #ratelimit_remaining, #ratelimit_reset

Methods included from Request::Verbs

#delete_request, #get_request, #head_request, #options_request, #patch_request, #post_request, #put_request

Methods included from MimeType

#lookup_media, #parse

Methods included from Authorization

#auth_code, #authenticated?, #authentication, #authorize_url, #basic_authed?, #client, #get_token

Constructor Details

This class inherits a constructor from Github::API

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Github::API

Instance Method Details

#create(*args) ⇒ Object

Create an issue

Examples:

github = Github.new user: 'user-name', repo: 'repo-name'
github.issues.create
  title: "Found a bug",
  body: "I'm having a problem with this.",
  assignee: "octocat",
  milestone: 1,
  labels: [
    "Label1",
    "Label2"
  ]

198
199
200
201
202
203
204
205
# File 'lib/github_api/client/issues.rb', line 198

def create(*args)
  arguments(args, required: [:user, :repo]) do
    permit VALID_ISSUE_PARAM_NAMES
    assert_required %w[ title ]
  end

  post_request("/repos/#{arguments.user}/#{arguments.repo}/issues", arguments.params)
end

#edit(*args) ⇒ Object

Edit an issue

Examples:

github = Github.new
github.issues.edit 'user-name', 'repo-name', 'number'
  title: "Found a bug",
  body: "I'm having a problem with this.",
  assignee: "octocat",
  milestone: 1,
  labels": [
    "Label1",
    "Label2"
  ]

238
239
240
241
242
243
244
# File 'lib/github_api/client/issues.rb', line 238

def edit(*args)
  arguments(args, required: [:user, :repo, :number]) do
    permit VALID_ISSUE_PARAM_NAMES
  end

  patch_request("/repos/#{arguments.user}/#{arguments.repo}/issues/#{arguments.number}", arguments.params)
end

#get(*args) ⇒ Object Also known as: find

Get a single issue

Examples:

github = Github.new
github.issues.get 'user-name', 'repo-name', 'number'

159
160
161
162
163
# File 'lib/github_api/client/issues.rb', line 159

def get(*args)
  arguments(args, required: [:user, :repo, :number])

  get_request("/repos/#{arguments.user}/#{arguments.repo}/issues/#{arguments.number}", arguments.params)
end

#list(*args) ⇒ Object Also known as: all

List your issues

List all issues across all the authenticated user’s visible repositories including owned repositories, member repositories, and organization repositories.

List all issues across owned and member repositories for the authenticated user.

List all issues for a given organization for the authenticated user.

List issues for a repository

Examples:

github = Github.new oauth_token: '...'
github.issues.list
github = Github.new oauth_token: '...'
github.issues.list :user
github = Github.new oauth_token: '...'
github.issues.list org: 'org-name'
github = Github.new
github.issues.list user: 'user-name', repo: 'repo-name'
github = Github.new oauth_token: '...'
github.issues.list since: '2011-04-12T12:12:12Z',
  filter: 'created',
  state: 'open',
  labels: "bug,ui,bla",
  sort: 'comments',
  direction: 'asc'

123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/github_api/client/issues.rb', line 123

def list(*args)
  params = arguments(args) do
    assert_values VALID_ISSUE_PARAM_VALUES
  end.params

  response = if (org = params.delete('org'))
    get_request("/orgs/#{org}/issues", params)

  elsif (user_name = params.delete('user')) &&
        (repo_name = params.delete('repo'))

    list_repo user_name, repo_name
  elsif args.include? :user
    get_request("/user/issues", params)
  else
    get_request("/issues", params)
  end
  return response unless block_given?
  response.each { |el| yield el }
end