_id stringlengths 2 6 | title stringlengths 9 130 | partition stringclasses 3 values | text stringlengths 66 10.5k | language stringclasses 1 value | meta_information dict |
|---|---|---|---|---|---|
q12500 | MarkdownLint.Doc.extract_text | train | def extract_text(element, prefix="", restore_whitespace = true)
quotes = {
:rdquo => '"',
:ldquo => '"',
:lsquo => "'",
:rsquo => "'"
}
# If anything goes amiss here, e.g. unknown type, then nil will be
# returned and we'll just not catch that part of the text, which seems
# like a sensible failure mode.
lines = element.children.map { |e|
if e.type == :text
e.value
elsif [:strong, :em, :p, :codespan].include?(e.type)
extract_text(e, prefix, restore_whitespace).join("\n")
elsif e.type == :smart_quote
quotes[e.value]
end
}.join.split("\n")
# Text blocks have whitespace stripped, so we need to add it back in at
# the beginning. Because this might be in something like a blockquote,
# we optionally strip off a prefix given to the function.
if restore_whitespace
lines[0] = element_line(element).sub(prefix, "")
end
lines
end | ruby | {
"resource": ""
} |
q12501 | MarkdownLint.Doc.add_levels | train | def add_levels(elements, level=1)
elements.each do |e|
e.options[:element_level] = level
add_levels(e.children, level+1)
end
end | ruby | {
"resource": ""
} |
q12502 | Chronic.Parser.guess | train | def guess(span, mode = :middle)
return span if not mode
return span.begin + span.width / 2 if span.width > 1 and (mode == true or mode == :middle)
return span.end if mode == :end
span.begin
end | ruby | {
"resource": ""
} |
q12503 | Chronic.Dictionary.definitions | train | def definitions
defined_items.each_with_object({}) do |word, defs|
word_type = "#{word.capitalize.to_s + 'Definitions'}"
defs[word] = Chronic.const_get(word_type).new(options).definitions
end
end | ruby | {
"resource": ""
} |
q12504 | Chronic.Handlers.handle_od_rm | train | def handle_od_rm(tokens, options)
day = tokens[0].get_tag(OrdinalDay).type
month = tokens[2].get_tag(RepeaterMonth)
handle_m_d(month, day, tokens[3..tokens.size], options)
end | ruby | {
"resource": ""
} |
q12505 | Chronic.Handlers.handle_r | train | def handle_r(tokens, options)
dd_tokens = dealias_and_disambiguate_times(tokens, options)
get_anchor(dd_tokens, options)
end | ruby | {
"resource": ""
} |
q12506 | Chronic.Handlers.handle_orr | train | def handle_orr(tokens, outer_span, options)
repeater = tokens[1].get_tag(Repeater)
repeater.start = outer_span.begin - 1
ordinal = tokens[0].get_tag(Ordinal).type
span = nil
ordinal.times do
span = repeater.next(:future)
if span.begin >= outer_span.end
span = nil
break
end
end
span
end | ruby | {
"resource": ""
} |
q12507 | Chronic.Handlers.find_within | train | def find_within(tags, span, pointer)
puts "--#{span}" if Chronic.debug
return span if tags.empty?
head = tags.shift
head.start = (pointer == :future ? span.begin : span.end)
h = head.this(:none)
if span.cover?(h.begin) || span.cover?(h.end)
find_within(tags, h, pointer)
end
end | ruby | {
"resource": ""
} |
q12508 | Chronic.Handler.match | train | def match(tokens, definitions)
token_index = 0
@pattern.each do |elements|
was_optional = false
elements = [elements] unless elements.is_a?(Array)
elements.each_index do |i|
name = elements[i].to_s
optional = name[-1, 1] == '?'
name = name.chop if optional
case elements[i]
when Symbol
if tags_match?(name, tokens, token_index)
token_index += 1
break
else
if optional
was_optional = true
next
elsif i + 1 < elements.count
next
else
return false unless was_optional
end
end
when String
return true if optional && token_index == tokens.size
if definitions.key?(name.to_sym)
sub_handlers = definitions[name.to_sym]
else
raise "Invalid subset #{name} specified"
end
sub_handlers.each do |sub_handler|
return true if sub_handler.match(tokens[token_index..tokens.size], definitions)
end
else
raise "Invalid match type: #{elements[i].class}"
end
end
end
return false if token_index != tokens.size
return true
end | ruby | {
"resource": ""
} |
q12509 | Github.Client::Repos.create | train | def create(*args)
arguments(args) do
assert_required %w[ name ]
end
params = arguments.params
# Requires authenticated user
if (org = params.delete('org') || org)
post_request("/orgs/#{org}/repos", params)
else
post_request("/user/repos", params)
end
end | ruby | {
"resource": ""
} |
q12510 | Github.Client::Users.get | train | def get(*args)
params = arguments(args).params
if user_name = params.delete('user')
get_request("/users/#{user_name}", params)
else
get_request("/user", params)
end
end | ruby | {
"resource": ""
} |
q12511 | Github.Client::PullRequests::Reviews.create | train | def create(*args)
arguments(args, required: [:user, :repo, :number])
params = arguments.params
params["accept"] ||= PREVIEW_MEDIA
post_request("/repos/#{arguments.user}/#{arguments.repo}/pulls/#{arguments.number}/reviews", params)
end | ruby | {
"resource": ""
} |
q12512 | Github.Client::PullRequests::Reviews.update | train | def update(*args)
arguments(args, required: [:user, :repo, :number, :id])
params = arguments.params
params["accept"] ||= PREVIEW_MEDIA
post_request("/repos/#{arguments.user}/#{arguments.repo}/pulls/#{arguments.number}/reviews/#{arguments.id}/events", params)
end | ruby | {
"resource": ""
} |
q12513 | Github.Client::Activity::Feeds.get | train | def get(*args)
arguments(args, required: [:name])
name = arguments.name
response = list.body._links[name]
if response
params = arguments.params
params['accept'] = response.type
get_request(response.href, params)
end
end | ruby | {
"resource": ""
} |
q12514 | Github.Client::Projects::Cards.list | train | def list(*args)
arguments(args, required: [:column_id])
params = arguments.params
params["accept"] ||= ::Github::Client::Projects::PREVIEW_MEDIA
response = get_request("/projects/columns/#{arguments.column_id}/cards", params)
return response unless block_given?
response.each { |el| yield el }
end | ruby | {
"resource": ""
} |
q12515 | Github.Client::Projects::Cards.create | train | def create(*args)
arguments(args, required: [:column_id])
params = arguments.params
params["accept"] ||= ::Github::Client::Projects::PREVIEW_MEDIA
post_request("/projects/columns/#{arguments.column_id}/cards", params)
end | ruby | {
"resource": ""
} |
q12516 | Github.Client::Projects::Cards.update | train | def update(*args)
arguments(args, required: [:card_id])
params = arguments.params
params["accept"] ||= ::Github::Client::Projects::PREVIEW_MEDIA
patch_request("/projects/columns/cards/#{arguments.card_id}", params)
end | ruby | {
"resource": ""
} |
q12517 | Github.Client::Projects::Cards.delete | train | def delete(*args)
arguments(args, required: [:card_id])
params = arguments.params
params["accept"] ||= ::Github::Client::Projects::PREVIEW_MEDIA
delete_request("/projects/columns/cards/#{arguments.card_id}", params)
end | ruby | {
"resource": ""
} |
q12518 | Github.Client::Projects::Cards.move | train | def move(*args)
arguments(args, required: [:card_id]) do
assert_required REQUIRED_MOVE_CARD_PARAMS
end
params = arguments.params
params["accept"] ||= ::Github::Client::Projects::PREVIEW_MEDIA
post_request("/projects/columns/cards/#{arguments.card_id}/moves", params)
end | ruby | {
"resource": ""
} |
q12519 | Github.Client::Issues.list | train | 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 | ruby | {
"resource": ""
} |
q12520 | Github.Client::Repos::Releases::Assets.upload | train | def upload(*args)
arguments(args, required: [:owner, :repo, :id, :filepath]) do
permit VALID_ASSET_PARAM_NAMES
end
params = arguments.params
unless type = params['content_type']
type = infer_media(arguments.filepath)
end
file = Faraday::UploadIO.new(arguments.filepath, type)
options = {
headers: { content_type: type },
endpoint: upload_endpoint,
query: {'name' => params['name']}
}
params['data'] = file.read
params['options'] = options
post_request("/repos/#{arguments.owner}/#{arguments.repo}/releases/#{arguments.id}/assets", params)
ensure
file.close if file
end | ruby | {
"resource": ""
} |
q12521 | Github.Client::Repos::Releases::Assets.infer_media | train | def infer_media(filepath)
require 'mime/types'
types = MIME::Types.type_for(filepath)
types.empty? ? 'application/octet-stream' : types.first
rescue LoadError
raise Github::Error::UnknownMedia.new(filepath)
end | ruby | {
"resource": ""
} |
q12522 | Github.Client::Repos::Releases::Assets.edit | train | def edit(*args)
arguments(args, required: [:owner, :repo, :id]) do
permit VALID_ASSET_PARAM_NAMES
end
patch_request("/repos/#{arguments.owner}/#{arguments.repo}/releases/assets/#{arguments.id}", arguments.params)
end | ruby | {
"resource": ""
} |
q12523 | Github.Client::Markdown.render | train | def render(*args)
arguments(args) do
assert_required ['text']
end
params = arguments.params
params['raw'] = true
post_request("markdown", arguments.params)
end | ruby | {
"resource": ""
} |
q12524 | Github.Client::Markdown.render_raw | train | def render_raw(*args)
params = arguments(args).params
params['data'] = args.shift
params['raw'] = true
params['accept'] = params.fetch('accept') { 'text/plain' }
post_request("markdown/raw", params)
end | ruby | {
"resource": ""
} |
q12525 | Github.Client::Repos::Statuses.create | train | def create(*args)
arguments(args, required: [:user, :repo, :sha]) do
permit VALID_STATUS_PARAM_NAMES, recursive: false
assert_required REQUIRED_PARAMS
end
post_request("/repos/#{arguments.user}/#{arguments.repo}/statuses/#{arguments.sha}", arguments.params)
end | ruby | {
"resource": ""
} |
q12526 | Github.Client::Activity::Starring.starring? | train | def starring?(*args)
arguments(args, required: [:user, :repo])
get_request("/user/starred/#{arguments.user}/#{arguments.repo}", arguments.params)
true
rescue Github::Error::NotFound
false
end | ruby | {
"resource": ""
} |
q12527 | Github.Client::Gitignore.list | train | def list(*args)
arguments(args)
response = get_request("/gitignore/templates", arguments.params)
return response unless block_given?
response.each { |el| yield el }
end | ruby | {
"resource": ""
} |
q12528 | Github.Client::Gitignore.get | train | def get(*args)
arguments(args, required: [:name])
params = arguments.params
if (media = params.delete('accept'))
params['accept'] = media
params['raw'] = true
end
get_request("/gitignore/templates/#{arguments.name}", params)
end | ruby | {
"resource": ""
} |
q12529 | Github.Client::Issues::Labels.get | train | def get(*args)
arguments(args, required: [:user, :repo, :label_name])
params = arguments.params
get_request("/repos/#{arguments.user}/#{arguments.repo}/labels/#{arguments.label_name}", params)
end | ruby | {
"resource": ""
} |
q12530 | Github.Client::Issues::Labels.create | train | def create(*args)
arguments(args, required: [:user, :repo]) do
permit VALID_LABEL_INPUTS
assert_required VALID_LABEL_INPUTS
end
post_request("/repos/#{arguments.user}/#{arguments.repo}/labels", arguments.params)
end | ruby | {
"resource": ""
} |
q12531 | Github.Client::Issues::Labels.update | train | def update(*args)
arguments(args, required: [:user, :repo, :label_name]) do
permit VALID_LABEL_INPUTS
assert_required VALID_LABEL_INPUTS
end
patch_request("/repos/#{arguments.user}/#{arguments.repo}/labels/#{arguments.label_name}", arguments.params)
end | ruby | {
"resource": ""
} |
q12532 | Github.Client::Issues::Labels.remove | train | def remove(*args)
arguments(args, required: [:user, :repo, :number])
params = arguments.params
user = arguments.user
repo = arguments.repo
number = arguments.number
if (label_name = params.delete('label_name'))
delete_request("/repos/#{user}/#{repo}/issues/#{number}/labels/#{label_name}", params)
else
delete_request("/repos/#{user}/#{repo}/issues/#{number}/labels", params)
end
end | ruby | {
"resource": ""
} |
q12533 | Github.Client::Issues::Labels.replace | train | def replace(*args)
arguments(args, required: [:user, :repo, :number])
params = arguments.params
params['data'] = arguments.remaining unless arguments.remaining.empty?
put_request("/repos/#{arguments.user}/#{arguments.repo}/issues/#{arguments.number}/labels", params)
end | ruby | {
"resource": ""
} |
q12534 | Github.PageIterator.parse_page_params | train | def parse_page_params(uri, attr) # :nodoc:
return -1 if uri.nil? || uri.empty?
parsed = nil
begin
parsed = URI.parse(uri)
rescue URI::Error
return -1
end
param = parse_query_for_param(parsed.query, attr)
return -1 if param.nil? || param.empty?
begin
return param.to_i
rescue ArgumentError
return -1
end
end | ruby | {
"resource": ""
} |
q12535 | Github.Client::Scopes.list | train | def list(*args)
arguments(args)
params = arguments.params
token = args.shift
if token.is_a?(Hash) && !params['token'].nil?
token = params.delete('token')
elsif token.nil?
token = oauth_token
end
if token.nil?
raise ArgumentError, 'Access token required'
end
headers = { 'Authorization' => "token #{token}" }
params['headers'] = headers
response = get_request("/user", params)
response.headers.oauth_scopes.split(',').map(&:strip)
end | ruby | {
"resource": ""
} |
q12536 | Github.Client::Activity::Events.received | train | def received(*args)
arguments(args, required: [:user])
params = arguments.params
public_events = if params['public']
params.delete('public')
'/public'
end
response = get_request("/users/#{arguments.user}/received_events#{public_events}", params)
return response unless block_given?
response.each { |el| yield el }
end | ruby | {
"resource": ""
} |
q12537 | Github.Pagination.auto_paginate | train | def auto_paginate(auto=false)
if (current_api.auto_pagination? || auto) && self.body.is_a?(Array)
resources_bodies = []
each_page { |resource| resources_bodies += resource.body }
self.body = resources_bodies
end
self
end | ruby | {
"resource": ""
} |
q12538 | Github.Client::Projects::Columns.get | train | def get(*args)
arguments(args, required: [:column_id])
params = arguments.params
params["accept"] ||= ::Github::Client::Projects::PREVIEW_MEDIA
get_request("/projects/columns/#{arguments.column_id}", params)
end | ruby | {
"resource": ""
} |
q12539 | Github.Client::GitData::Trees.get | train | def get(*args)
arguments(args, required: [:user, :repo, :sha])
user = arguments.user
repo = arguments.repo
sha = arguments.sha
params = arguments.params
response = if params['recursive']
params['recursive'] = 1
get_request("/repos/#{user}/#{repo}/git/trees/#{sha}", params)
else
get_request("/repos/#{user}/#{repo}/git/trees/#{sha.to_s}", params)
end
return response unless block_given?
response.tree.each { |el| yield el }
end | ruby | {
"resource": ""
} |
q12540 | Github.Client::GitData::Trees.create | train | def create(*args)
arguments(args, required: [:user, :repo]) do
assert_required %w[ tree ]
permit VALID_TREE_PARAM_NAMES, 'tree', { recursive: true }
assert_values VALID_TREE_PARAM_VALUES, 'tree'
end
post_request("/repos/#{arguments.user}/#{arguments.repo}/git/trees", arguments.params)
end | ruby | {
"resource": ""
} |
q12541 | Github.Client::GitData::Commits.create | train | def create(*args)
arguments(args, required: [:user, :repo]) do
permit VALID_COMMIT_PARAM_NAMES
assert_required REQUIRED_COMMIT_PARAMS
end
post_request("/repos/#{arguments.user}/#{arguments.repo}/git/commits", arguments.params)
end | ruby | {
"resource": ""
} |
q12542 | Github.Client::Issues::Assignees.remove | train | def remove(*args)
arguments(args, required: [:user, :repo, :number])
params = arguments.params
params['data'] = { 'assignees' => arguments.remaining } unless arguments.remaining.empty?
delete_request("/repos/#{arguments.user}/#{arguments.repo}/issues/#{arguments.number}/assignees", params)
end | ruby | {
"resource": ""
} |
q12543 | Github.API.filter_callbacks | train | def filter_callbacks(kind, action_name)
self.class.send("#{kind}_callbacks").select do |callback|
callback[:only].nil? || callback[:only].include?(action_name)
end
end | ruby | {
"resource": ""
} |
q12544 | Github.API.run_callbacks | train | def run_callbacks(action_name, &block)
filter_callbacks(:before, action_name).each { |hook| send hook[:callback] }
yield if block_given?
filter_callbacks(:after, action_name).each { |hook| send hook[:callback] }
end | ruby | {
"resource": ""
} |
q12545 | Github.API.set | train | def set(option, value=(not_set=true), ignore_setter=false, &block)
raise ArgumentError, 'value not set' if block and !not_set
return self if !not_set and value.nil?
if not_set
set_options option
return self
end
if respond_to?("#{option}=") and not ignore_setter
return __send__("#{option}=", value)
end
define_accessors option, value
self
end | ruby | {
"resource": ""
} |
q12546 | Github.API.set_options | train | def set_options(options)
unless options.respond_to?(:each)
raise ArgumentError, 'cannot iterate over value'
end
options.each { |key, value| set(key, value) }
end | ruby | {
"resource": ""
} |
q12547 | Github.API.define_accessors | train | def define_accessors(option, value)
setter = proc { |val| set option, val, true }
getter = proc { value }
define_singleton_method("#{option}=", setter) if setter
define_singleton_method(option, getter) if getter
end | ruby | {
"resource": ""
} |
q12548 | Github.API.define_singleton_method | train | def define_singleton_method(method_name, content=Proc.new)
(class << self; self; end).class_eval do
undef_method(method_name) if method_defined?(method_name)
if String === content
class_eval("def #{method_name}() #{content}; end")
else
define_method(method_name, &content)
end
end
end | ruby | {
"resource": ""
} |
q12549 | Github.Client::GitData::Tags.create | train | def create(*args)
arguments(args, required: [:user, :repo]) do
permit VALID_TAG_PARAM_NAMES
assert_values VALID_TAG_PARAM_VALUES
end
post_request("/repos/#{arguments.user}/#{arguments.repo}/git/tags", arguments.params)
end | ruby | {
"resource": ""
} |
q12550 | Github.Client::Users::Followers.list | train | def list(*args)
params = arguments(args).params
response = if user_name = arguments.remaining.first
get_request("/users/#{user_name}/followers", params)
else
get_request("/user/followers", params)
end
return response unless block_given?
response.each { |el| yield el }
end | ruby | {
"resource": ""
} |
q12551 | Github.Client::Users::Followers.following? | train | def following?(*args)
arguments(args, required: [:username])
params = arguments.params
if target_user = params.delete('target_user')
get_request("/users/#{arguments.username}/following/#{target_user}", params)
else
get_request("/user/following/#{arguments.username}", params)
end
true
rescue Github::Error::NotFound
false
end | ruby | {
"resource": ""
} |
q12552 | Github.Client::Activity::Watching.watched | train | def watched(*args)
arguments(args)
params = arguments.params
response = if (user_name = params.delete('user'))
get_request("/users/#{user_name}/subscriptions", params)
else
get_request('/user/subscriptions', params)
end
return response unless block_given?
response.each { |el| yield el }
end | ruby | {
"resource": ""
} |
q12553 | Github.Client::Orgs::Members.member? | train | def member?(*args)
params = arguments(args, required: [:org_name, :user]).params
org_name = arguments.org_name
user = arguments.user
response = if params.delete('public')
get_request("/orgs/#{org_name}/public_members/#{user}", params)
else
get_request("/orgs/#{org_name}/members/#{user}", params)
end
response.status == 204
rescue Github::Error::NotFound
false
end | ruby | {
"resource": ""
} |
q12554 | Github.Client::Repos::Branches::Protections.edit | train | def edit(*args)
arguments(args, required: [:user, :repo, :branch]) do
permit VALID_PROTECTION_PARAM_NAMES
end
put_request("/repos/#{arguments.user}/#{arguments.repo}/branches/#{arguments.branch}/protection", arguments.params)
end | ruby | {
"resource": ""
} |
q12555 | Github.ParameterFilter.filter! | train | def filter!(keys, params, options={:recursive => true}) # :nodoc:
case params
when Hash, ParamsHash
params.keys.each do |k, v|
unless (keys.include?(k) or Github::Validations::VALID_API_KEYS.include?(k))
params.delete(k)
else
filter!(keys, params[k]) if options[:recursive]
end
end
when Array
params.map! do |el|
filter!(keys, el) if options[:recursive]
end
else
params
end
return params
end | ruby | {
"resource": ""
} |
q12556 | Github.Client::Orgs::Teams.team_repo? | train | def team_repo?(*args)
arguments(args, required: [:id, :user, :repo])
response = get_request("/teams/#{arguments.id}/repos/#{arguments.user}/#{arguments.repo}", arguments.params)
response.status == 204
rescue Github::Error::NotFound
false
end | ruby | {
"resource": ""
} |
q12557 | Github.Response::RaiseError.on_complete | train | def on_complete(env)
status_code = env[:status].to_i
service_error = Github::Error::ServiceError
error_class = service_error.error_mapping[status_code]
if !error_class and (400...600) === status_code
error_class = service_error
end
raise error_class.new(env) if error_class
end | ruby | {
"resource": ""
} |
q12558 | Github.Client::Repos::Deployments.create | train | def create(*args)
arguments(args, required: [:user, :repo]) do
permit VALID_DEPLOYMENTS_OPTIONS
assert_required %w[ ref ]
end
params = arguments.params
params['accept'] ||= PREVIEW_MEDIA
post_request("repos/#{arguments.user}/#{arguments.repo}/deployments", arguments.params)
end | ruby | {
"resource": ""
} |
q12559 | Github.Client::Repos::Deployments.statuses | train | def statuses(*args)
arguments(args, required: [:user, :repo, :id])
params = arguments.params
params['accept'] ||= PREVIEW_MEDIA
statuses = get_request("repos/#{arguments.user}/#{arguments.repo}/deployments/#{arguments.id}/statuses", params)
return statuses unless block_given?
statuses.each { |status| yield status }
end | ruby | {
"resource": ""
} |
q12560 | Github.Client::Repos::Deployments.create_status | train | def create_status(*args)
arguments(args, required: [:user, :repo, :id]) do
assert_required %w[ state ]
permit VALID_STATUS_OPTIONS
end
params = arguments.params
params['accept'] ||= PREVIEW_MEDIA
post_request("repos/#{arguments.user}/#{arguments.repo}/deployments/#{arguments.id}/statuses", params)
end | ruby | {
"resource": ""
} |
q12561 | Github.ParamsHash.options | train | def options
opts = fetch('options', {})
headers = fetch('headers', {})
if value = accept
headers[:accept] = value
end
opts[:raw] = key?('raw') ? self['raw'] : false
opts[:headers] = headers unless headers.empty?
opts
end | ruby | {
"resource": ""
} |
q12562 | Github.ParamsHash.merge_default | train | def merge_default(defaults)
if defaults && !defaults.empty?
defaults.each do |key, value|
self[key] = value unless self.key?(key)
end
end
self
end | ruby | {
"resource": ""
} |
q12563 | Github.ParamsHash.strict_encode64 | train | def strict_encode64(key)
value = self[key]
encoded = if Base64.respond_to?(:strict_encode64)
Base64.strict_encode64(value)
else
[value].pack('m0')
end
self[key] = encoded.delete("\n\r")
end | ruby | {
"resource": ""
} |
q12564 | Github.Client::Repos::Comments.create | train | def create(*args)
arguments(args, required: [:user, :repo, :sha]) do
assert_required REQUIRED_COMMENT_OPTIONS
end
post_request("/repos/#{arguments.user}/#{arguments.repo}/commits/#{arguments.sha}/comments", arguments.params)
end | ruby | {
"resource": ""
} |
q12565 | Github.Client::Repos::Comments.update | train | def update(*args)
arguments(args, required: [:user, :repo, :id]) do
assert_required REQUIRED_COMMENT_OPTIONS
end
patch_request("/repos/#{arguments.user}/#{arguments.repo}/comments/#{arguments.id}", arguments.params)
end | ruby | {
"resource": ""
} |
q12566 | Github.Client::Repos::Contents.create | train | def create(*args)
arguments(args, required: [:user, :repo, :path]) do
assert_required REQUIRED_CONTENT_OPTIONS
end
params = arguments.params
params.strict_encode64('content')
put_request("/repos/#{arguments.user}/#{arguments.repo}/contents/#{arguments.path}", params)
end | ruby | {
"resource": ""
} |
q12567 | Github.Client::Repos::Contents.delete | train | def delete(*args)
arguments(args, required: [:user, :repo, :path]) do
assert_required %w[ path message sha ]
end
delete_request("/repos/#{arguments.user}/#{arguments.repo}/contents/#{arguments.path}", arguments.params)
end | ruby | {
"resource": ""
} |
q12568 | Github.Client::Repos::Contents.archive | train | def archive(*args)
arguments(args, required: [:user, :repo])
params = arguments.params
archive_format = params.delete('archive_format') || 'tarball'
ref = params.delete('ref') || 'master'
disable_redirects do
response = get_request("/repos/#{arguments.user}/#{arguments.repo}/#{archive_format}/#{ref}", params)
response.headers.location
end
end | ruby | {
"resource": ""
} |
q12569 | Github.Normalizer.normalize! | train | def normalize!(params)
case params
when Hash
params.keys.each do |k|
params[k.to_s] = params.delete(k)
normalize!(params[k.to_s])
end
when Array
params.map! do |el|
normalize!(el)
end
end
params
end | ruby | {
"resource": ""
} |
q12570 | Github.Client::Authorizations::App.create | train | def create(*args)
raise_authentication_error unless authenticated?
arguments(args, required: [:client_id])
if arguments.client_id
put_request("/authorizations/clients/#{arguments.client_id}", arguments.params)
else
raise raise_app_authentication_error
end
end | ruby | {
"resource": ""
} |
q12571 | Github.Client::Authorizations::App.check | train | def check(*args)
raise_authentication_error unless authenticated?
params = arguments(args, required: [:client_id, :access_token]).params
if arguments.client_id
begin
get_request("/applications/#{arguments.client_id}/tokens/#{arguments.access_token}", params)
rescue Github::Error::NotFound
nil
end
else
raise raise_app_authentication_error
end
end | ruby | {
"resource": ""
} |
q12572 | Github.Client::Authorizations::App.delete | train | def delete(*args)
raise_authentication_error unless authenticated?
params = arguments(args, required: [:client_id]).params
if arguments.client_id
if access_token = (params.delete('access_token') || args[1])
delete_request("/applications/#{arguments.client_id}/tokens/#{access_token}", params)
else
# Revokes all tokens
delete_request("/applications/#{arguments.client_id}/tokens", params)
end
else
raise raise_app_authentication_error
end
end | ruby | {
"resource": ""
} |
q12573 | Github.Client::Projects.edit | train | def edit(*args)
arguments(args, required: [:id])
params = arguments.params
params["accept"] ||= PREVIEW_MEDIA
patch_request("/projects/#{arguments.id}", params)
end | ruby | {
"resource": ""
} |
q12574 | Github.Client::Gists.list | train | def list(*args)
params = arguments(args).params
response = if (user = params.delete('user'))
get_request("/users/#{user}/gists", params)
elsif args.map(&:to_s).include?('public')
get_request("/gists/public", params)
else
get_request("/gists", params)
end
return response unless block_given?
response.each { |el| yield el }
end | ruby | {
"resource": ""
} |
q12575 | Github.Client::Gists.get | train | def get(*args)
arguments(args, required: [:id])
if (sha = arguments.params.delete('sha'))
get_request("/gists/#{arguments.id}/#{sha}")
else
get_request("/gists/#{arguments.id}", arguments.params)
end
end | ruby | {
"resource": ""
} |
q12576 | Github.Authorization.client | train | def client
@client ||= ::OAuth2::Client.new(client_id, client_secret,
{
:site => current_options.fetch(:site) { Github.site },
:authorize_url => 'login/oauth/authorize',
:token_url => 'login/oauth/access_token',
:ssl => { :verify => false }
}
)
end | ruby | {
"resource": ""
} |
q12577 | Github.Client::Orgs::Projects.create | train | def create(*args)
arguments(args, required: [:org_name]) do
assert_required %w[ name ]
end
params = arguments.params
params["accept"] ||= PREVIEW_MEDIA
post_request("/orgs/#{arguments.org_name}/projects", params)
end | ruby | {
"resource": ""
} |
q12578 | Github.Request.call | train | def call(current_options, params)
unless HTTP_METHODS.include?(action)
raise ArgumentError, "unknown http method: #{method}"
end
puts "EXECUTED: #{action} - #{path} with PARAMS: #{params.request_params}" if ENV['DEBUG']
request_options = params.options
connection_options = current_options.merge(request_options)
conn = connection(api, connection_options)
self.path = Utils::Url.normalize(self.path)
if conn.path_prefix != '/' && self.path.index(conn.path_prefix) != 0
self.path = (conn.path_prefix + self.path).gsub(/\/(\/)*/, '/')
end
response = conn.send(action) do |request|
case action.to_sym
when *(HTTP_METHODS - METHODS_WITH_BODIES)
request.body = params.data if params.key?('data')
if params.key?('encoder')
request.params.params_encoder(params.encoder)
end
request.url(self.path, params.request_params)
when *METHODS_WITH_BODIES
request.url(self.path, connection_options[:query] || {})
request.body = params.data unless params.empty?
end
end
ResponseWrapper.new(response, api)
end | ruby | {
"resource": ""
} |
q12579 | Github.Client::Authorizations.get | train | def get(*args)
raise_authentication_error unless authenticated?
arguments(args, required: [:id])
get_request("/authorizations/#{arguments.id}", arguments.params)
end | ruby | {
"resource": ""
} |
q12580 | Github.Client::Authorizations.create | train | def create(*args)
raise_authentication_error unless authenticated?
arguments(args) do
assert_required :note, :scopes
end
post_request('/authorizations', arguments.params)
end | ruby | {
"resource": ""
} |
q12581 | Github.Client::Authorizations.update | train | def update(*args)
raise_authentication_error unless authenticated?
arguments(args, required: [:id])
patch_request("/authorizations/#{arguments.id}", arguments.params)
end | ruby | {
"resource": ""
} |
q12582 | Github.Client::Authorizations.delete | train | def delete(*args)
raise_authentication_error unless authenticated?
arguments(args, required: [:id])
delete_request("/authorizations/#{arguments.id}", arguments.params)
end | ruby | {
"resource": ""
} |
q12583 | Github.Client::Activity::Notifications.list | train | def list(*args)
arguments(args)
params = arguments.params
response = if ( (user_name = params.delete('user')) &&
(repo_name = params.delete('repo')) )
get_request("/repos/#{user_name}/#{repo_name}/notifications", params)
else
get_request('/notifications', params)
end
return response unless block_given?
response.each { |el| yield el }
end | ruby | {
"resource": ""
} |
q12584 | Github.Client::Activity::Notifications.mark | train | def mark(*args)
arguments(args)
params = arguments.params
if ( (user_name = params.delete('user')) &&
(repo_name = params.delete('repo')) )
put_request("/repos/#{user_name}/#{repo_name}/notifications", params)
elsif (thread_id = params.delete("id"))
patch_request("/notifications/threads/#{thread_id}", params)
else
put_request('/notifications', params)
end
end | ruby | {
"resource": ""
} |
q12585 | Github.PagedRequest.page_request | train | def page_request(path, params={})
if params[PARAM_PER_PAGE] == NOT_FOUND
params[PARAM_PER_PAGE] = default_page_size
end
if params[PARAM_PAGE] && params[PARAM_PAGE] == NOT_FOUND
params[PARAM_PAGE] = default_page
end
current_api.get_request(path, ParamsHash.new(params))
end | ruby | {
"resource": ""
} |
q12586 | Github.Client::Say.say | train | def say(*args)
params = arguments(*args).params
params[:s] = args.shift unless args.empty?
params['raw'] = true
get_request('/octocat', params)
end | ruby | {
"resource": ""
} |
q12587 | Github.ResponseWrapper.each | train | def each
body_parts = self.body.respond_to?(:each) ? self.body : [self.body]
return body_parts.to_enum unless block_given?
body_parts.each { |part| yield(part) }
end | ruby | {
"resource": ""
} |
q12588 | Github.API.api_methods_in | train | def api_methods_in(klass)
methods = klass.send(:instance_methods, false) - [:actions]
methods.sort.each_with_object([]) do |method_name, accumulator|
unless method_name.to_s.include?('with') ||
method_name.to_s.include?('without')
accumulator << method_name
end
accumulator
end
end | ruby | {
"resource": ""
} |
q12589 | Github.Connection.default_options | train | def default_options(options = {})
headers = default_headers.merge(options[:headers] || {})
headers.merge!({USER_AGENT => options[:user_agent]})
{
headers: headers,
ssl: options[:ssl],
url: options[:endpoint]
}
end | ruby | {
"resource": ""
} |
q12590 | Github.Connection.connection | train | def connection(api, options = {})
connection_options = default_options(options)
connection_options.merge!(builder: stack(options.merge!(api: api)))
if options[:connection_options]
connection_options.deep_merge!(options[:connection_options])
end
if ENV['DEBUG']
p "Connection options : \n"
pp connection_options
end
Faraday.new(connection_options)
end | ruby | {
"resource": ""
} |
q12591 | Github.Client::Users::Keys.update | train | def update(*args)
arguments(args, required: [:id]) do
permit VALID_KEY_PARAM_NAMES
end
patch_request("/user/keys/#{arguments.id}", arguments.params)
end | ruby | {
"resource": ""
} |
q12592 | Github.MimeType.parse | train | def parse(media)
version = 'v3'
media.sub!(/^[.]*|[.]*$/,"")
media = media.include?('+') ? media.split('+')[0] : media
version, media = media.split('.') if media.include?('.')
media_type = lookup_media(media)
"application/vnd.github.#{version}.#{media_type}"
end | ruby | {
"resource": ""
} |
q12593 | Github.Client::Orgs::Hooks.create | train | def create(*args)
arguments(args, required: [:org_name]) do
assert_required REQUIRED_PARAMS
end
post_request("/orgs/#{arguments.org_name}/hooks", arguments.params)
end | ruby | {
"resource": ""
} |
q12594 | Github.Client::Issues::Milestones.create | train | def create(*args)
arguments(args, required: [:user, :repo]) do
permit VALID_MILESTONE_INPUTS
assert_required %w[ title ]
end
post_request("/repos/#{arguments.user}/#{arguments.repo}/milestones", arguments.params)
end | ruby | {
"resource": ""
} |
q12595 | Github.Client::GitData::References.get | train | def get(*args)
arguments(args, required: [:user, :repo, :ref])
validate_reference arguments.ref
params = arguments.params
get_request("/repos/#{arguments.user}/#{arguments.repo}/git/refs/#{arguments.ref}", params)
end | ruby | {
"resource": ""
} |
q12596 | Github.Client::GitData::References.create | train | def create(*args)
arguments(args, required: [:user, :repo]) do
permit VALID_REF_PARAM_NAMES
assert_required REQUIRED_REF_PARAMS
end
params = arguments.params
validate_reference params['ref']
post_request("/repos/#{arguments.user}/#{arguments.repo}/git/refs", params)
end | ruby | {
"resource": ""
} |
q12597 | Github.Client::GitData::References.update | train | def update(*args)
arguments(args, required: [:user, :repo, :ref]) do
permit VALID_REF_PARAM_NAMES
assert_required %w[ sha ]
end
patch_request("/repos/#{arguments.user}/#{arguments.repo}/git/refs/#{arguments.ref}", arguments.params)
end | ruby | {
"resource": ""
} |
q12598 | Github.Client::GitData::References.delete | train | def delete(*args)
arguments(args, required: [:user, :repo, :ref])
params = arguments.params
delete_request("/repos/#{arguments.user}/#{arguments.repo}/git/refs/#{arguments.ref}", params)
end | ruby | {
"resource": ""
} |
q12599 | I18n.Config.available_locales_set | train | def available_locales_set #:nodoc:
@@available_locales_set ||= available_locales.inject(Set.new) do |set, locale|
set << locale.to_s << locale.to_sym
end
end | ruby | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.