repo
stringlengths 5
58
| path
stringlengths 9
168
| func_name
stringlengths 9
130
| original_string
stringlengths 66
10.5k
| language
stringclasses 1
value | code
stringlengths 66
10.5k
| code_tokens
sequence | docstring
stringlengths 8
16k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 94
266
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
mhenrixon/sidekiq-unique-jobs | lib/sidekiq_unique_jobs/locksmith.rb | SidekiqUniqueJobs.Locksmith.unlock! | def unlock!(token = nil)
token ||= jid
Scripts.call(
:unlock,
redis_pool,
keys: [exists_key, grabbed_key, available_key, version_key, UNIQUE_SET, unique_digest],
argv: [token, ttl, lock_type],
)
end | ruby | def unlock!(token = nil)
token ||= jid
Scripts.call(
:unlock,
redis_pool,
keys: [exists_key, grabbed_key, available_key, version_key, UNIQUE_SET, unique_digest],
argv: [token, ttl, lock_type],
)
end | [
"def",
"unlock!",
"(",
"token",
"=",
"nil",
")",
"token",
"||=",
"jid",
"Scripts",
".",
"call",
"(",
":unlock",
",",
"redis_pool",
",",
"keys",
":",
"[",
"exists_key",
",",
"grabbed_key",
",",
"available_key",
",",
"version_key",
",",
"UNIQUE_SET",
",",
"unique_digest",
"]",
",",
"argv",
":",
"[",
"token",
",",
"ttl",
",",
"lock_type",
"]",
",",
")",
"end"
] | Removes the lock keys from Redis
@param [String] token the token to unlock (defaults to jid)
@return [false] unless locked?
@return [String] Sidekiq job_id (jid) if successful | [
"Removes",
"the",
"lock",
"keys",
"from",
"Redis"
] | 2944b97c720528f53962ccfd17d43ac939a77f46 | https://github.com/mhenrixon/sidekiq-unique-jobs/blob/2944b97c720528f53962ccfd17d43ac939a77f46/lib/sidekiq_unique_jobs/locksmith.rb#L91-L100 | train |
mhenrixon/sidekiq-unique-jobs | lib/sidekiq_unique_jobs/connection.rb | SidekiqUniqueJobs.Connection.redis | def redis(redis_pool = nil)
if redis_pool
redis_pool.with { |conn| yield conn }
else
Sidekiq.redis { |conn| yield conn }
end
end | ruby | def redis(redis_pool = nil)
if redis_pool
redis_pool.with { |conn| yield conn }
else
Sidekiq.redis { |conn| yield conn }
end
end | [
"def",
"redis",
"(",
"redis_pool",
"=",
"nil",
")",
"if",
"redis_pool",
"redis_pool",
".",
"with",
"{",
"|",
"conn",
"|",
"yield",
"conn",
"}",
"else",
"Sidekiq",
".",
"redis",
"{",
"|",
"conn",
"|",
"yield",
"conn",
"}",
"end",
"end"
] | Creates a connection to redis
@return [Sidekiq::RedisConnection, ConnectionPool] a connection to redis | [
"Creates",
"a",
"connection",
"to",
"redis"
] | 2944b97c720528f53962ccfd17d43ac939a77f46 | https://github.com/mhenrixon/sidekiq-unique-jobs/blob/2944b97c720528f53962ccfd17d43ac939a77f46/lib/sidekiq_unique_jobs/connection.rb#L14-L20 | train |
mhenrixon/sidekiq-unique-jobs | lib/sidekiq_unique_jobs/digests.rb | SidekiqUniqueJobs.Digests.all | def all(pattern: SCAN_PATTERN, count: DEFAULT_COUNT)
redis { |conn| conn.sscan_each(UNIQUE_SET, match: pattern, count: count).to_a }
end | ruby | def all(pattern: SCAN_PATTERN, count: DEFAULT_COUNT)
redis { |conn| conn.sscan_each(UNIQUE_SET, match: pattern, count: count).to_a }
end | [
"def",
"all",
"(",
"pattern",
":",
"SCAN_PATTERN",
",",
"count",
":",
"DEFAULT_COUNT",
")",
"redis",
"{",
"|",
"conn",
"|",
"conn",
".",
"sscan_each",
"(",
"UNIQUE_SET",
",",
"match",
":",
"pattern",
",",
"count",
":",
"count",
")",
".",
"to_a",
"}",
"end"
] | Return unique digests matching pattern
@param [String] pattern a pattern to match with
@param [Integer] count the maximum number to match
@return [Array<String>] with unique digests | [
"Return",
"unique",
"digests",
"matching",
"pattern"
] | 2944b97c720528f53962ccfd17d43ac939a77f46 | https://github.com/mhenrixon/sidekiq-unique-jobs/blob/2944b97c720528f53962ccfd17d43ac939a77f46/lib/sidekiq_unique_jobs/digests.rb#L21-L23 | train |
mhenrixon/sidekiq-unique-jobs | lib/sidekiq_unique_jobs/digests.rb | SidekiqUniqueJobs.Digests.page | def page(pattern: SCAN_PATTERN, cursor: 0, page_size: 100)
redis do |conn|
total_size, digests = conn.multi do
conn.scard(UNIQUE_SET)
conn.sscan(UNIQUE_SET, cursor, match: pattern, count: page_size)
end
[total_size, digests[0], digests[1]]
end
end | ruby | def page(pattern: SCAN_PATTERN, cursor: 0, page_size: 100)
redis do |conn|
total_size, digests = conn.multi do
conn.scard(UNIQUE_SET)
conn.sscan(UNIQUE_SET, cursor, match: pattern, count: page_size)
end
[total_size, digests[0], digests[1]]
end
end | [
"def",
"page",
"(",
"pattern",
":",
"SCAN_PATTERN",
",",
"cursor",
":",
"0",
",",
"page_size",
":",
"100",
")",
"redis",
"do",
"|",
"conn",
"|",
"total_size",
",",
"digests",
"=",
"conn",
".",
"multi",
"do",
"conn",
".",
"scard",
"(",
"UNIQUE_SET",
")",
"conn",
".",
"sscan",
"(",
"UNIQUE_SET",
",",
"cursor",
",",
"match",
":",
"pattern",
",",
"count",
":",
"page_size",
")",
"end",
"[",
"total_size",
",",
"digests",
"[",
"0",
"]",
",",
"digests",
"[",
"1",
"]",
"]",
"end",
"end"
] | Paginate unique digests
@param [String] pattern a pattern to match with
@param [Integer] cursor the maximum number to match
@param [Integer] page_size the current cursor position
@return [Array<String>] with unique digests | [
"Paginate",
"unique",
"digests"
] | 2944b97c720528f53962ccfd17d43ac939a77f46 | https://github.com/mhenrixon/sidekiq-unique-jobs/blob/2944b97c720528f53962ccfd17d43ac939a77f46/lib/sidekiq_unique_jobs/digests.rb#L32-L41 | train |
mhenrixon/sidekiq-unique-jobs | lib/sidekiq_unique_jobs/digests.rb | SidekiqUniqueJobs.Digests.del | def del(digest: nil, pattern: nil, count: DEFAULT_COUNT)
return delete_by_pattern(pattern, count: count) if pattern
return delete_by_digest(digest) if digest
raise ArgumentError, "either digest or pattern need to be provided"
end | ruby | def del(digest: nil, pattern: nil, count: DEFAULT_COUNT)
return delete_by_pattern(pattern, count: count) if pattern
return delete_by_digest(digest) if digest
raise ArgumentError, "either digest or pattern need to be provided"
end | [
"def",
"del",
"(",
"digest",
":",
"nil",
",",
"pattern",
":",
"nil",
",",
"count",
":",
"DEFAULT_COUNT",
")",
"return",
"delete_by_pattern",
"(",
"pattern",
",",
"count",
":",
"count",
")",
"if",
"pattern",
"return",
"delete_by_digest",
"(",
"digest",
")",
"if",
"digest",
"raise",
"ArgumentError",
",",
"\"either digest or pattern need to be provided\"",
"end"
] | Deletes unique digest either by a digest or pattern
@param [String] digest the full digest to delete
@param [String] pattern a key pattern to match with
@param [Integer] count the maximum number
@raise [ArgumentError] when both pattern and digest are nil
@return [Array<String>] with unique digests | [
"Deletes",
"unique",
"digest",
"either",
"by",
"a",
"digest",
"or",
"pattern"
] | 2944b97c720528f53962ccfd17d43ac939a77f46 | https://github.com/mhenrixon/sidekiq-unique-jobs/blob/2944b97c720528f53962ccfd17d43ac939a77f46/lib/sidekiq_unique_jobs/digests.rb#L57-L62 | train |
mhenrixon/sidekiq-unique-jobs | lib/sidekiq_unique_jobs/digests.rb | SidekiqUniqueJobs.Digests.delete_by_pattern | def delete_by_pattern(pattern, count: DEFAULT_COUNT)
result, elapsed = timed do
digests = all(pattern: pattern, count: count)
batch_delete(digests)
digests.size
end
log_info("#{__method__}(#{pattern}, count: #{count}) completed in #{elapsed}ms")
result
end | ruby | def delete_by_pattern(pattern, count: DEFAULT_COUNT)
result, elapsed = timed do
digests = all(pattern: pattern, count: count)
batch_delete(digests)
digests.size
end
log_info("#{__method__}(#{pattern}, count: #{count}) completed in #{elapsed}ms")
result
end | [
"def",
"delete_by_pattern",
"(",
"pattern",
",",
"count",
":",
"DEFAULT_COUNT",
")",
"result",
",",
"elapsed",
"=",
"timed",
"do",
"digests",
"=",
"all",
"(",
"pattern",
":",
"pattern",
",",
"count",
":",
"count",
")",
"batch_delete",
"(",
"digests",
")",
"digests",
".",
"size",
"end",
"log_info",
"(",
"\"#{__method__}(#{pattern}, count: #{count}) completed in #{elapsed}ms\"",
")",
"result",
"end"
] | Deletes unique digests by pattern
@param [String] pattern a key pattern to match with
@param [Integer] count the maximum number
@return [Array<String>] with unique digests | [
"Deletes",
"unique",
"digests",
"by",
"pattern"
] | 2944b97c720528f53962ccfd17d43ac939a77f46 | https://github.com/mhenrixon/sidekiq-unique-jobs/blob/2944b97c720528f53962ccfd17d43ac939a77f46/lib/sidekiq_unique_jobs/digests.rb#L71-L81 | train |
mhenrixon/sidekiq-unique-jobs | lib/sidekiq_unique_jobs/digests.rb | SidekiqUniqueJobs.Digests.delete_by_digest | def delete_by_digest(digest)
result, elapsed = timed do
Scripts.call(:delete_by_digest, nil, keys: [UNIQUE_SET, digest])
count
end
log_info("#{__method__}(#{digest}) completed in #{elapsed}ms")
result
end | ruby | def delete_by_digest(digest)
result, elapsed = timed do
Scripts.call(:delete_by_digest, nil, keys: [UNIQUE_SET, digest])
count
end
log_info("#{__method__}(#{digest}) completed in #{elapsed}ms")
result
end | [
"def",
"delete_by_digest",
"(",
"digest",
")",
"result",
",",
"elapsed",
"=",
"timed",
"do",
"Scripts",
".",
"call",
"(",
":delete_by_digest",
",",
"nil",
",",
"keys",
":",
"[",
"UNIQUE_SET",
",",
"digest",
"]",
")",
"count",
"end",
"log_info",
"(",
"\"#{__method__}(#{digest}) completed in #{elapsed}ms\"",
")",
"result",
"end"
] | Get a total count of unique digests
@param [String] digest a key pattern to match with | [
"Get",
"a",
"total",
"count",
"of",
"unique",
"digests"
] | 2944b97c720528f53962ccfd17d43ac939a77f46 | https://github.com/mhenrixon/sidekiq-unique-jobs/blob/2944b97c720528f53962ccfd17d43ac939a77f46/lib/sidekiq_unique_jobs/digests.rb#L86-L95 | train |
mhenrixon/sidekiq-unique-jobs | lib/sidekiq_unique_jobs/sidekiq_worker_methods.rb | SidekiqUniqueJobs.SidekiqWorkerMethods.worker_class_constantize | def worker_class_constantize(klazz = @worker_class)
return klazz unless klazz.is_a?(String)
Object.const_get(klazz)
rescue NameError => ex
case ex.message
when /uninitialized constant/
klazz
else
raise
end
end | ruby | def worker_class_constantize(klazz = @worker_class)
return klazz unless klazz.is_a?(String)
Object.const_get(klazz)
rescue NameError => ex
case ex.message
when /uninitialized constant/
klazz
else
raise
end
end | [
"def",
"worker_class_constantize",
"(",
"klazz",
"=",
"@worker_class",
")",
"return",
"klazz",
"unless",
"klazz",
".",
"is_a?",
"(",
"String",
")",
"Object",
".",
"const_get",
"(",
"klazz",
")",
"rescue",
"NameError",
"=>",
"ex",
"case",
"ex",
".",
"message",
"when",
"/",
"/",
"klazz",
"else",
"raise",
"end",
"end"
] | Attempt to constantize a string worker_class argument, always
failing back to the original argument when the constant can't be found
@return [Sidekiq::Worker] | [
"Attempt",
"to",
"constantize",
"a",
"string",
"worker_class",
"argument",
"always",
"failing",
"back",
"to",
"the",
"original",
"argument",
"when",
"the",
"constant",
"can",
"t",
"be",
"found"
] | 2944b97c720528f53962ccfd17d43ac939a77f46 | https://github.com/mhenrixon/sidekiq-unique-jobs/blob/2944b97c720528f53962ccfd17d43ac939a77f46/lib/sidekiq_unique_jobs/sidekiq_worker_methods.rb#L45-L56 | train |
mhenrixon/sidekiq-unique-jobs | lib/sidekiq_unique_jobs/config.rb | SidekiqUniqueJobs.Config.add_lock | def add_lock(name, klass)
raise ArgumentError, "Lock #{name} already defined, please use another name" if locks.key?(name.to_sym)
new_locks = locks.dup.merge(name.to_sym => klass).freeze
self.locks = new_locks
end | ruby | def add_lock(name, klass)
raise ArgumentError, "Lock #{name} already defined, please use another name" if locks.key?(name.to_sym)
new_locks = locks.dup.merge(name.to_sym => klass).freeze
self.locks = new_locks
end | [
"def",
"add_lock",
"(",
"name",
",",
"klass",
")",
"raise",
"ArgumentError",
",",
"\"Lock #{name} already defined, please use another name\"",
"if",
"locks",
".",
"key?",
"(",
"name",
".",
"to_sym",
")",
"new_locks",
"=",
"locks",
".",
"dup",
".",
"merge",
"(",
"name",
".",
"to_sym",
"=>",
"klass",
")",
".",
"freeze",
"self",
".",
"locks",
"=",
"new_locks",
"end"
] | Adds a lock type to the configuration. It will raise if the lock exists already
@param [String] name the name of the lock
@param [Class] klass the class describing the lock | [
"Adds",
"a",
"lock",
"type",
"to",
"the",
"configuration",
".",
"It",
"will",
"raise",
"if",
"the",
"lock",
"exists",
"already"
] | 2944b97c720528f53962ccfd17d43ac939a77f46 | https://github.com/mhenrixon/sidekiq-unique-jobs/blob/2944b97c720528f53962ccfd17d43ac939a77f46/lib/sidekiq_unique_jobs/config.rb#L50-L55 | train |
mhenrixon/sidekiq-unique-jobs | lib/sidekiq_unique_jobs/config.rb | SidekiqUniqueJobs.Config.add_strategy | def add_strategy(name, klass)
raise ArgumentError, "strategy #{name} already defined, please use another name" if strategies.key?(name.to_sym)
new_strategies = strategies.dup.merge(name.to_sym => klass).freeze
self.strategies = new_strategies
end | ruby | def add_strategy(name, klass)
raise ArgumentError, "strategy #{name} already defined, please use another name" if strategies.key?(name.to_sym)
new_strategies = strategies.dup.merge(name.to_sym => klass).freeze
self.strategies = new_strategies
end | [
"def",
"add_strategy",
"(",
"name",
",",
"klass",
")",
"raise",
"ArgumentError",
",",
"\"strategy #{name} already defined, please use another name\"",
"if",
"strategies",
".",
"key?",
"(",
"name",
".",
"to_sym",
")",
"new_strategies",
"=",
"strategies",
".",
"dup",
".",
"merge",
"(",
"name",
".",
"to_sym",
"=>",
"klass",
")",
".",
"freeze",
"self",
".",
"strategies",
"=",
"new_strategies",
"end"
] | Adds an on_conflict strategy to the configuration.
It will raise if the strategy exists already
@param [String] name the name of the custom strategy
@param [Class] klass the class describing the strategy | [
"Adds",
"an",
"on_conflict",
"strategy",
"to",
"the",
"configuration",
".",
"It",
"will",
"raise",
"if",
"the",
"strategy",
"exists",
"already"
] | 2944b97c720528f53962ccfd17d43ac939a77f46 | https://github.com/mhenrixon/sidekiq-unique-jobs/blob/2944b97c720528f53962ccfd17d43ac939a77f46/lib/sidekiq_unique_jobs/config.rb#L62-L67 | train |
mhenrixon/sidekiq-unique-jobs | lib/sidekiq_unique_jobs/unique_args.rb | SidekiqUniqueJobs.UniqueArgs.digestable_hash | def digestable_hash
@item.slice(CLASS_KEY, QUEUE_KEY, UNIQUE_ARGS_KEY).tap do |hash|
hash.delete(QUEUE_KEY) if unique_across_queues?
hash.delete(CLASS_KEY) if unique_across_workers?
end
end | ruby | def digestable_hash
@item.slice(CLASS_KEY, QUEUE_KEY, UNIQUE_ARGS_KEY).tap do |hash|
hash.delete(QUEUE_KEY) if unique_across_queues?
hash.delete(CLASS_KEY) if unique_across_workers?
end
end | [
"def",
"digestable_hash",
"@item",
".",
"slice",
"(",
"CLASS_KEY",
",",
"QUEUE_KEY",
",",
"UNIQUE_ARGS_KEY",
")",
".",
"tap",
"do",
"|",
"hash",
"|",
"hash",
".",
"delete",
"(",
"QUEUE_KEY",
")",
"if",
"unique_across_queues?",
"hash",
".",
"delete",
"(",
"CLASS_KEY",
")",
"if",
"unique_across_workers?",
"end",
"end"
] | Filter a hash to use for digest
@return [Hash] to use for digest | [
"Filter",
"a",
"hash",
"to",
"use",
"for",
"digest"
] | 2944b97c720528f53962ccfd17d43ac939a77f46 | https://github.com/mhenrixon/sidekiq-unique-jobs/blob/2944b97c720528f53962ccfd17d43ac939a77f46/lib/sidekiq_unique_jobs/unique_args.rb#L62-L67 | train |
mhenrixon/sidekiq-unique-jobs | lib/sidekiq_unique_jobs/unique_args.rb | SidekiqUniqueJobs.UniqueArgs.filtered_args | def filtered_args(args)
return args if args.empty?
json_args = Normalizer.jsonify(args)
case unique_args_method
when Proc
filter_by_proc(json_args)
when Symbol
filter_by_symbol(json_args)
else
log_debug("#{__method__} arguments not filtered (using all arguments for uniqueness)")
json_args
end
end | ruby | def filtered_args(args)
return args if args.empty?
json_args = Normalizer.jsonify(args)
case unique_args_method
when Proc
filter_by_proc(json_args)
when Symbol
filter_by_symbol(json_args)
else
log_debug("#{__method__} arguments not filtered (using all arguments for uniqueness)")
json_args
end
end | [
"def",
"filtered_args",
"(",
"args",
")",
"return",
"args",
"if",
"args",
".",
"empty?",
"json_args",
"=",
"Normalizer",
".",
"jsonify",
"(",
"args",
")",
"case",
"unique_args_method",
"when",
"Proc",
"filter_by_proc",
"(",
"json_args",
")",
"when",
"Symbol",
"filter_by_symbol",
"(",
"json_args",
")",
"else",
"log_debug",
"(",
"\"#{__method__} arguments not filtered (using all arguments for uniqueness)\"",
")",
"json_args",
"end",
"end"
] | Filters unique arguments by proc or symbol
@param [Array] args the arguments passed to the sidekiq worker
@return [Array] {#filter_by_proc} when {#unique_args_method} is a Proc
@return [Array] {#filter_by_symbol} when {#unique_args_method} is a Symbol
@return [Array] args unfiltered when neither of the above | [
"Filters",
"unique",
"arguments",
"by",
"proc",
"or",
"symbol"
] | 2944b97c720528f53962ccfd17d43ac939a77f46 | https://github.com/mhenrixon/sidekiq-unique-jobs/blob/2944b97c720528f53962ccfd17d43ac939a77f46/lib/sidekiq_unique_jobs/unique_args.rb#L101-L115 | train |
mhenrixon/sidekiq-unique-jobs | lib/sidekiq_unique_jobs/unique_args.rb | SidekiqUniqueJobs.UniqueArgs.filter_by_symbol | def filter_by_symbol(args)
return args unless worker_method_defined?(unique_args_method)
worker_class.send(unique_args_method, args)
rescue ArgumentError => ex
log_fatal(ex)
args
end | ruby | def filter_by_symbol(args)
return args unless worker_method_defined?(unique_args_method)
worker_class.send(unique_args_method, args)
rescue ArgumentError => ex
log_fatal(ex)
args
end | [
"def",
"filter_by_symbol",
"(",
"args",
")",
"return",
"args",
"unless",
"worker_method_defined?",
"(",
"unique_args_method",
")",
"worker_class",
".",
"send",
"(",
"unique_args_method",
",",
"args",
")",
"rescue",
"ArgumentError",
"=>",
"ex",
"log_fatal",
"(",
"ex",
")",
"args",
"end"
] | Filters unique arguments by method configured in the sidekiq worker
@param [Array] args the arguments passed to the sidekiq worker
@return [Array] unfiltered unless {#worker_method_defined?}
@return [Array] with the filtered arguments | [
"Filters",
"unique",
"arguments",
"by",
"method",
"configured",
"in",
"the",
"sidekiq",
"worker"
] | 2944b97c720528f53962ccfd17d43ac939a77f46 | https://github.com/mhenrixon/sidekiq-unique-jobs/blob/2944b97c720528f53962ccfd17d43ac939a77f46/lib/sidekiq_unique_jobs/unique_args.rb#L128-L135 | train |
k1LoW/awspec | lib/awspec/helper/client_wrap.rb | Awspec::Helper.ClientWrap.method_missing | def method_missing(m, *args, &block)
begin
results = client.send(m, *args, &block)
rescue Exception => e # rubocop:disable Lint/RescueException
raise unless e.class.to_s == symbol.to_s && backoff < backoff_limit
@backoff = backoff + (iteration * iteration * 0.5)
@iteration += 1
sleep backoff
results = self.send(m, *args, &block)
end
reset_backoff
results
end | ruby | def method_missing(m, *args, &block)
begin
results = client.send(m, *args, &block)
rescue Exception => e # rubocop:disable Lint/RescueException
raise unless e.class.to_s == symbol.to_s && backoff < backoff_limit
@backoff = backoff + (iteration * iteration * 0.5)
@iteration += 1
sleep backoff
results = self.send(m, *args, &block)
end
reset_backoff
results
end | [
"def",
"method_missing",
"(",
"m",
",",
"*",
"args",
",",
"&",
"block",
")",
"begin",
"results",
"=",
"client",
".",
"send",
"(",
"m",
",",
"args",
",",
"block",
")",
"rescue",
"Exception",
"=>",
"e",
"# rubocop:disable Lint/RescueException",
"raise",
"unless",
"e",
".",
"class",
".",
"to_s",
"==",
"symbol",
".",
"to_s",
"&&",
"backoff",
"<",
"backoff_limit",
"@backoff",
"=",
"backoff",
"+",
"(",
"iteration",
"*",
"iteration",
"*",
"0.5",
")",
"@iteration",
"+=",
"1",
"sleep",
"backoff",
"results",
"=",
"self",
".",
"send",
"(",
"m",
",",
"args",
",",
"block",
")",
"end",
"reset_backoff",
"results",
"end"
] | used to capture only the "RequestLimitExceeded" error from an aws
client api call. In the case of matching it we want to try again,
backing off successively each time, until the backoff_limit is reached or
exceeded, in which case, the error will be re-raised and it should fail
as expected. | [
"used",
"to",
"capture",
"only",
"the",
"RequestLimitExceeded",
"error",
"from",
"an",
"aws",
"client",
"api",
"call",
".",
"In",
"the",
"case",
"of",
"matching",
"it",
"we",
"want",
"to",
"try",
"again",
"backing",
"off",
"successively",
"each",
"time",
"until",
"the",
"backoff_limit",
"is",
"reached",
"or",
"exceeded",
"in",
"which",
"case",
"the",
"error",
"will",
"be",
"re",
"-",
"raised",
"and",
"it",
"should",
"fail",
"as",
"expected",
"."
] | d33365040c42c79fa4c8233451d7fe8f24f2c503 | https://github.com/k1LoW/awspec/blob/d33365040c42c79fa4c8233451d7fe8f24f2c503/lib/awspec/helper/client_wrap.rb#L24-L39 | train |
palkan/logidze | lib/logidze/history.rb | Logidze.History.changes_to | def changes_to(time: nil, version: nil, data: {}, from: 0)
raise ArgumentError, "Time or version must be specified" if time.nil? && version.nil?
filter = time.nil? ? method(:version_filter) : method(:time_filter)
versions.each_with_object(data.dup) do |v, acc|
next if v.version < from
break acc if filter.call(v, version, time)
acc.merge!(v.changes)
end
end | ruby | def changes_to(time: nil, version: nil, data: {}, from: 0)
raise ArgumentError, "Time or version must be specified" if time.nil? && version.nil?
filter = time.nil? ? method(:version_filter) : method(:time_filter)
versions.each_with_object(data.dup) do |v, acc|
next if v.version < from
break acc if filter.call(v, version, time)
acc.merge!(v.changes)
end
end | [
"def",
"changes_to",
"(",
"time",
":",
"nil",
",",
"version",
":",
"nil",
",",
"data",
":",
"{",
"}",
",",
"from",
":",
"0",
")",
"raise",
"ArgumentError",
",",
"\"Time or version must be specified\"",
"if",
"time",
".",
"nil?",
"&&",
"version",
".",
"nil?",
"filter",
"=",
"time",
".",
"nil?",
"?",
"method",
"(",
":version_filter",
")",
":",
"method",
"(",
":time_filter",
")",
"versions",
".",
"each_with_object",
"(",
"data",
".",
"dup",
")",
"do",
"|",
"v",
",",
"acc",
"|",
"next",
"if",
"v",
".",
"version",
"<",
"from",
"break",
"acc",
"if",
"filter",
".",
"call",
"(",
"v",
",",
"version",
",",
"time",
")",
"acc",
".",
"merge!",
"(",
"v",
".",
"changes",
")",
"end",
"end"
] | Return diff from the initial state to specified time or version.
Optional `data` paramater can be used as initial diff state. | [
"Return",
"diff",
"from",
"the",
"initial",
"state",
"to",
"specified",
"time",
"or",
"version",
".",
"Optional",
"data",
"paramater",
"can",
"be",
"used",
"as",
"initial",
"diff",
"state",
"."
] | ffa0f793cb9c6fab96fa67a285341ca9aaa7ded8 | https://github.com/palkan/logidze/blob/ffa0f793cb9c6fab96fa67a285341ca9aaa7ded8/lib/logidze/history.rb#L60-L70 | train |
palkan/logidze | lib/logidze/history.rb | Logidze.History.diff_from | def diff_from(time: nil, version: nil)
raise ArgumentError, "Time or version must be specified" if time.nil? && version.nil?
from_version = version.nil? ? find_by_time(time) : find_by_version(version)
from_version ||= versions.first
base = changes_to(version: from_version.version)
diff = changes_to(version: self.version, data: base, from: from_version.version + 1)
build_changes(base, diff)
end | ruby | def diff_from(time: nil, version: nil)
raise ArgumentError, "Time or version must be specified" if time.nil? && version.nil?
from_version = version.nil? ? find_by_time(time) : find_by_version(version)
from_version ||= versions.first
base = changes_to(version: from_version.version)
diff = changes_to(version: self.version, data: base, from: from_version.version + 1)
build_changes(base, diff)
end | [
"def",
"diff_from",
"(",
"time",
":",
"nil",
",",
"version",
":",
"nil",
")",
"raise",
"ArgumentError",
",",
"\"Time or version must be specified\"",
"if",
"time",
".",
"nil?",
"&&",
"version",
".",
"nil?",
"from_version",
"=",
"version",
".",
"nil?",
"?",
"find_by_time",
"(",
"time",
")",
":",
"find_by_version",
"(",
"version",
")",
"from_version",
"||=",
"versions",
".",
"first",
"base",
"=",
"changes_to",
"(",
"version",
":",
"from_version",
".",
"version",
")",
"diff",
"=",
"changes_to",
"(",
"version",
":",
"self",
".",
"version",
",",
"data",
":",
"base",
",",
"from",
":",
"from_version",
".",
"version",
"+",
"1",
")",
"build_changes",
"(",
"base",
",",
"diff",
")",
"end"
] | Return diff object representing changes since specified time or version.
@example
diff_from(time: 2.days.ago)
#=> { "id" => 1, "changes" => { "title" => { "old" => "Hello!", "new" => "World" } } }
rubocop:disable Metrics/AbcSize | [
"Return",
"diff",
"object",
"representing",
"changes",
"since",
"specified",
"time",
"or",
"version",
"."
] | ffa0f793cb9c6fab96fa67a285341ca9aaa7ded8 | https://github.com/palkan/logidze/blob/ffa0f793cb9c6fab96fa67a285341ca9aaa7ded8/lib/logidze/history.rb#L79-L89 | train |
palkan/logidze | lib/logidze/history.rb | Logidze.History.current_ts? | def current_ts?(time)
(current_version.time <= time) &&
(next_version.nil? || (next_version.time < time))
end | ruby | def current_ts?(time)
(current_version.time <= time) &&
(next_version.nil? || (next_version.time < time))
end | [
"def",
"current_ts?",
"(",
"time",
")",
"(",
"current_version",
".",
"time",
"<=",
"time",
")",
"&&",
"(",
"next_version",
".",
"nil?",
"||",
"(",
"next_version",
".",
"time",
"<",
"time",
")",
")",
"end"
] | Return true iff time corresponds to current version | [
"Return",
"true",
"iff",
"time",
"corresponds",
"to",
"current",
"version"
] | ffa0f793cb9c6fab96fa67a285341ca9aaa7ded8 | https://github.com/palkan/logidze/blob/ffa0f793cb9c6fab96fa67a285341ca9aaa7ded8/lib/logidze/history.rb#L98-L101 | train |
palkan/logidze | lib/logidze/model.rb | Logidze.Model.at_version | def at_version(version)
return self if log_data.version == version
log_entry = log_data.find_by_version(version)
return nil unless log_entry
build_dup(log_entry)
end | ruby | def at_version(version)
return self if log_data.version == version
log_entry = log_data.find_by_version(version)
return nil unless log_entry
build_dup(log_entry)
end | [
"def",
"at_version",
"(",
"version",
")",
"return",
"self",
"if",
"log_data",
".",
"version",
"==",
"version",
"log_entry",
"=",
"log_data",
".",
"find_by_version",
"(",
"version",
")",
"return",
"nil",
"unless",
"log_entry",
"build_dup",
"(",
"log_entry",
")",
"end"
] | Return a dirty copy of specified version of record | [
"Return",
"a",
"dirty",
"copy",
"of",
"specified",
"version",
"of",
"record"
] | ffa0f793cb9c6fab96fa67a285341ca9aaa7ded8 | https://github.com/palkan/logidze/blob/ffa0f793cb9c6fab96fa67a285341ca9aaa7ded8/lib/logidze/model.rb#L111-L118 | train |
palkan/logidze | lib/logidze/model.rb | Logidze.Model.diff_from | def diff_from(ts = nil, version: nil, time: nil)
Deprecations.show_ts_deprecation_for("#diff_from") if ts
time ||= ts
time = parse_time(time) if time
changes = log_data.diff_from(time: time, version: version).tap do |v|
deserialize_changes!(v)
end
changes.delete_if { |k, _v| deleted_column?(k) }
{ "id" => id, "changes" => changes }
end | ruby | def diff_from(ts = nil, version: nil, time: nil)
Deprecations.show_ts_deprecation_for("#diff_from") if ts
time ||= ts
time = parse_time(time) if time
changes = log_data.diff_from(time: time, version: version).tap do |v|
deserialize_changes!(v)
end
changes.delete_if { |k, _v| deleted_column?(k) }
{ "id" => id, "changes" => changes }
end | [
"def",
"diff_from",
"(",
"ts",
"=",
"nil",
",",
"version",
":",
"nil",
",",
"time",
":",
"nil",
")",
"Deprecations",
".",
"show_ts_deprecation_for",
"(",
"\"#diff_from\"",
")",
"if",
"ts",
"time",
"||=",
"ts",
"time",
"=",
"parse_time",
"(",
"time",
")",
"if",
"time",
"changes",
"=",
"log_data",
".",
"diff_from",
"(",
"time",
":",
"time",
",",
"version",
":",
"version",
")",
".",
"tap",
"do",
"|",
"v",
"|",
"deserialize_changes!",
"(",
"v",
")",
"end",
"changes",
".",
"delete_if",
"{",
"|",
"k",
",",
"_v",
"|",
"deleted_column?",
"(",
"k",
")",
"}",
"{",
"\"id\"",
"=>",
"id",
",",
"\"changes\"",
"=>",
"changes",
"}",
"end"
] | Return diff object representing changes since specified time.
@example
post.diff_from(time: 2.days.ago) # or post.diff_from(version: 2)
#=> { "id" => 1, "changes" => { "title" => { "old" => "Hello!", "new" => "World" } } } | [
"Return",
"diff",
"object",
"representing",
"changes",
"since",
"specified",
"time",
"."
] | ffa0f793cb9c6fab96fa67a285341ca9aaa7ded8 | https://github.com/palkan/logidze/blob/ffa0f793cb9c6fab96fa67a285341ca9aaa7ded8/lib/logidze/model.rb#L134-L145 | train |
palkan/logidze | lib/logidze/model.rb | Logidze.Model.undo! | def undo!(append: Logidze.append_on_undo)
version = log_data.previous_version
return false if version.nil?
switch_to!(version.version, append: append)
end | ruby | def undo!(append: Logidze.append_on_undo)
version = log_data.previous_version
return false if version.nil?
switch_to!(version.version, append: append)
end | [
"def",
"undo!",
"(",
"append",
":",
"Logidze",
".",
"append_on_undo",
")",
"version",
"=",
"log_data",
".",
"previous_version",
"return",
"false",
"if",
"version",
".",
"nil?",
"switch_to!",
"(",
"version",
".",
"version",
",",
"append",
":",
"append",
")",
"end"
] | Restore record to the previous version.
Return false if no previous version found, otherwise return updated record. | [
"Restore",
"record",
"to",
"the",
"previous",
"version",
".",
"Return",
"false",
"if",
"no",
"previous",
"version",
"found",
"otherwise",
"return",
"updated",
"record",
"."
] | ffa0f793cb9c6fab96fa67a285341ca9aaa7ded8 | https://github.com/palkan/logidze/blob/ffa0f793cb9c6fab96fa67a285341ca9aaa7ded8/lib/logidze/model.rb#L149-L154 | train |
palkan/logidze | lib/logidze/model.rb | Logidze.Model.switch_to! | def switch_to!(version, append: Logidze.append_on_undo)
return false unless at_version(version)
if append && version < log_version
update!(log_data.changes_to(version: version))
else
at_version!(version)
self.class.without_logging { save! }
end
end | ruby | def switch_to!(version, append: Logidze.append_on_undo)
return false unless at_version(version)
if append && version < log_version
update!(log_data.changes_to(version: version))
else
at_version!(version)
self.class.without_logging { save! }
end
end | [
"def",
"switch_to!",
"(",
"version",
",",
"append",
":",
"Logidze",
".",
"append_on_undo",
")",
"return",
"false",
"unless",
"at_version",
"(",
"version",
")",
"if",
"append",
"&&",
"version",
"<",
"log_version",
"update!",
"(",
"log_data",
".",
"changes_to",
"(",
"version",
":",
"version",
")",
")",
"else",
"at_version!",
"(",
"version",
")",
"self",
".",
"class",
".",
"without_logging",
"{",
"save!",
"}",
"end",
"end"
] | Restore record to the specified version.
Return false if version is unknown. | [
"Restore",
"record",
"to",
"the",
"specified",
"version",
".",
"Return",
"false",
"if",
"version",
"is",
"unknown",
"."
] | ffa0f793cb9c6fab96fa67a285341ca9aaa7ded8 | https://github.com/palkan/logidze/blob/ffa0f793cb9c6fab96fa67a285341ca9aaa7ded8/lib/logidze/model.rb#L167-L176 | train |
markdownlint/markdownlint | lib/mdl/doc.rb | MarkdownLint.Doc.find_type | def find_type(type, nested=true)
find_type_elements(type, nested).map { |e| e.options }
end | ruby | def find_type(type, nested=true)
find_type_elements(type, nested).map { |e| e.options }
end | [
"def",
"find_type",
"(",
"type",
",",
"nested",
"=",
"true",
")",
"find_type_elements",
"(",
"type",
",",
"nested",
")",
".",
"map",
"{",
"|",
"e",
"|",
"e",
".",
"options",
"}",
"end"
] | Find all elements of a given type, returning their options hash. The
options hash has most of the useful data about an element and often you
can just use this in your rules.
# Returns [ { :location => 1, :element_level => 2 }, ... ]
elements = find_type(:li)
If +nested+ is set to false, this returns only top level elements of a
given type. | [
"Find",
"all",
"elements",
"of",
"a",
"given",
"type",
"returning",
"their",
"options",
"hash",
".",
"The",
"options",
"hash",
"has",
"most",
"of",
"the",
"useful",
"data",
"about",
"an",
"element",
"and",
"often",
"you",
"can",
"just",
"use",
"this",
"in",
"your",
"rules",
"."
] | a9e80fcf3989d73b654b00bb2225a00be53983e8 | https://github.com/markdownlint/markdownlint/blob/a9e80fcf3989d73b654b00bb2225a00be53983e8/lib/mdl/doc.rb#L72-L74 | train |
markdownlint/markdownlint | lib/mdl/doc.rb | MarkdownLint.Doc.find_type_elements | def find_type_elements(type, nested=true, elements=@elements)
results = []
if type.class == Symbol
type = [type]
end
elements.each do |e|
results.push(e) if type.include?(e.type)
if nested and not e.children.empty?
results.concat(find_type_elements(type, nested, e.children))
end
end
results
end | ruby | def find_type_elements(type, nested=true, elements=@elements)
results = []
if type.class == Symbol
type = [type]
end
elements.each do |e|
results.push(e) if type.include?(e.type)
if nested and not e.children.empty?
results.concat(find_type_elements(type, nested, e.children))
end
end
results
end | [
"def",
"find_type_elements",
"(",
"type",
",",
"nested",
"=",
"true",
",",
"elements",
"=",
"@elements",
")",
"results",
"=",
"[",
"]",
"if",
"type",
".",
"class",
"==",
"Symbol",
"type",
"=",
"[",
"type",
"]",
"end",
"elements",
".",
"each",
"do",
"|",
"e",
"|",
"results",
".",
"push",
"(",
"e",
")",
"if",
"type",
".",
"include?",
"(",
"e",
".",
"type",
")",
"if",
"nested",
"and",
"not",
"e",
".",
"children",
".",
"empty?",
"results",
".",
"concat",
"(",
"find_type_elements",
"(",
"type",
",",
"nested",
",",
"e",
".",
"children",
")",
")",
"end",
"end",
"results",
"end"
] | Find all elements of a given type, returning a list of the element
objects themselves.
Instead of a single type, a list of types can be provided instead to
find all types.
If +nested+ is set to false, this returns only top level elements of a
given type. | [
"Find",
"all",
"elements",
"of",
"a",
"given",
"type",
"returning",
"a",
"list",
"of",
"the",
"element",
"objects",
"themselves",
"."
] | a9e80fcf3989d73b654b00bb2225a00be53983e8 | https://github.com/markdownlint/markdownlint/blob/a9e80fcf3989d73b654b00bb2225a00be53983e8/lib/mdl/doc.rb#L86-L98 | train |
markdownlint/markdownlint | lib/mdl/doc.rb | MarkdownLint.Doc.find_type_elements_except | def find_type_elements_except(type, nested_except=[], elements=@elements)
results = []
if type.class == Symbol
type = [type]
end
if nested_except.class == Symbol
nested_except = [nested_except]
end
elements.each do |e|
results.push(e) if type.include?(e.type)
unless nested_except.include?(e.type) or e.children.empty?
results.concat(find_type_elements_except(type, nested_except, e.children))
end
end
results
end | ruby | def find_type_elements_except(type, nested_except=[], elements=@elements)
results = []
if type.class == Symbol
type = [type]
end
if nested_except.class == Symbol
nested_except = [nested_except]
end
elements.each do |e|
results.push(e) if type.include?(e.type)
unless nested_except.include?(e.type) or e.children.empty?
results.concat(find_type_elements_except(type, nested_except, e.children))
end
end
results
end | [
"def",
"find_type_elements_except",
"(",
"type",
",",
"nested_except",
"=",
"[",
"]",
",",
"elements",
"=",
"@elements",
")",
"results",
"=",
"[",
"]",
"if",
"type",
".",
"class",
"==",
"Symbol",
"type",
"=",
"[",
"type",
"]",
"end",
"if",
"nested_except",
".",
"class",
"==",
"Symbol",
"nested_except",
"=",
"[",
"nested_except",
"]",
"end",
"elements",
".",
"each",
"do",
"|",
"e",
"|",
"results",
".",
"push",
"(",
"e",
")",
"if",
"type",
".",
"include?",
"(",
"e",
".",
"type",
")",
"unless",
"nested_except",
".",
"include?",
"(",
"e",
".",
"type",
")",
"or",
"e",
".",
"children",
".",
"empty?",
"results",
".",
"concat",
"(",
"find_type_elements_except",
"(",
"type",
",",
"nested_except",
",",
"e",
".",
"children",
")",
")",
"end",
"end",
"results",
"end"
] | A variation on find_type_elements that allows you to skip drilling down
into children of specific element types.
Instead of a single type, a list of types can be provided instead to
find all types.
Unlike find_type_elements, this method will always search for nested
elements, and skip the element types given to nested_except. | [
"A",
"variation",
"on",
"find_type_elements",
"that",
"allows",
"you",
"to",
"skip",
"drilling",
"down",
"into",
"children",
"of",
"specific",
"element",
"types",
"."
] | a9e80fcf3989d73b654b00bb2225a00be53983e8 | https://github.com/markdownlint/markdownlint/blob/a9e80fcf3989d73b654b00bb2225a00be53983e8/lib/mdl/doc.rb#L110-L125 | train |
markdownlint/markdownlint | lib/mdl/doc.rb | MarkdownLint.Doc.element_linenumber | def element_linenumber(element)
element = element.options if element.is_a?(Kramdown::Element)
element[:location]
end | ruby | def element_linenumber(element)
element = element.options if element.is_a?(Kramdown::Element)
element[:location]
end | [
"def",
"element_linenumber",
"(",
"element",
")",
"element",
"=",
"element",
".",
"options",
"if",
"element",
".",
"is_a?",
"(",
"Kramdown",
"::",
"Element",
")",
"element",
"[",
":location",
"]",
"end"
] | Returns the line number a given element is located on in the source
file. You can pass in either an element object or an options hash here. | [
"Returns",
"the",
"line",
"number",
"a",
"given",
"element",
"is",
"located",
"on",
"in",
"the",
"source",
"file",
".",
"You",
"can",
"pass",
"in",
"either",
"an",
"element",
"object",
"or",
"an",
"options",
"hash",
"here",
"."
] | a9e80fcf3989d73b654b00bb2225a00be53983e8 | https://github.com/markdownlint/markdownlint/blob/a9e80fcf3989d73b654b00bb2225a00be53983e8/lib/mdl/doc.rb#L131-L134 | train |
markdownlint/markdownlint | lib/mdl/doc.rb | MarkdownLint.Doc.matching_lines | def matching_lines(re)
@lines.each_with_index.select{|text, linenum| re.match(text)}.map{
|i| i[1]+1}
end | ruby | def matching_lines(re)
@lines.each_with_index.select{|text, linenum| re.match(text)}.map{
|i| i[1]+1}
end | [
"def",
"matching_lines",
"(",
"re",
")",
"@lines",
".",
"each_with_index",
".",
"select",
"{",
"|",
"text",
",",
"linenum",
"|",
"re",
".",
"match",
"(",
"text",
")",
"}",
".",
"map",
"{",
"|",
"i",
"|",
"i",
"[",
"1",
"]",
"+",
"1",
"}",
"end"
] | Returns line numbers for lines that match the given regular expression | [
"Returns",
"line",
"numbers",
"for",
"lines",
"that",
"match",
"the",
"given",
"regular",
"expression"
] | a9e80fcf3989d73b654b00bb2225a00be53983e8 | https://github.com/markdownlint/markdownlint/blob/a9e80fcf3989d73b654b00bb2225a00be53983e8/lib/mdl/doc.rb#L220-L223 | train |
markdownlint/markdownlint | lib/mdl/doc.rb | MarkdownLint.Doc.extract_text | 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 | 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 | [
"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"
] | Extracts the text from an element whose children consist of text
elements and other things | [
"Extracts",
"the",
"text",
"from",
"an",
"element",
"whose",
"children",
"consist",
"of",
"text",
"elements",
"and",
"other",
"things"
] | a9e80fcf3989d73b654b00bb2225a00be53983e8 | https://github.com/markdownlint/markdownlint/blob/a9e80fcf3989d73b654b00bb2225a00be53983e8/lib/mdl/doc.rb#L249-L275 | train |
markdownlint/markdownlint | lib/mdl/doc.rb | MarkdownLint.Doc.add_levels | def add_levels(elements, level=1)
elements.each do |e|
e.options[:element_level] = level
add_levels(e.children, level+1)
end
end | ruby | def add_levels(elements, level=1)
elements.each do |e|
e.options[:element_level] = level
add_levels(e.children, level+1)
end
end | [
"def",
"add_levels",
"(",
"elements",
",",
"level",
"=",
"1",
")",
"elements",
".",
"each",
"do",
"|",
"e",
"|",
"e",
".",
"options",
"[",
":element_level",
"]",
"=",
"level",
"add_levels",
"(",
"e",
".",
"children",
",",
"level",
"+",
"1",
")",
"end",
"end"
] | Adds a 'level' option to all elements to show how nested they are | [
"Adds",
"a",
"level",
"option",
"to",
"all",
"elements",
"to",
"show",
"how",
"nested",
"they",
"are"
] | a9e80fcf3989d73b654b00bb2225a00be53983e8 | https://github.com/markdownlint/markdownlint/blob/a9e80fcf3989d73b654b00bb2225a00be53983e8/lib/mdl/doc.rb#L282-L287 | train |
mojombo/chronic | lib/chronic/parser.rb | Chronic.Parser.guess | 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 | 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 | [
"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"
] | Guess a specific time within the given span.
span - The Chronic::Span object to calcuate a guess from.
Returns a new Time object. | [
"Guess",
"a",
"specific",
"time",
"within",
"the",
"given",
"span",
"."
] | 2b1eae7ec440d767c09e0b1a7f0e9bcf30ce1d6c | https://github.com/mojombo/chronic/blob/2b1eae7ec440d767c09e0b1a7f0e9bcf30ce1d6c/lib/chronic/parser.rb#L152-L157 | train |
mojombo/chronic | lib/chronic/dictionary.rb | Chronic.Dictionary.definitions | 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 | 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 | [
"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"
] | returns a hash of each word's Definitions | [
"returns",
"a",
"hash",
"of",
"each",
"word",
"s",
"Definitions"
] | 2b1eae7ec440d767c09e0b1a7f0e9bcf30ce1d6c | https://github.com/mojombo/chronic/blob/2b1eae7ec440d767c09e0b1a7f0e9bcf30ce1d6c/lib/chronic/dictionary.rb#L14-L19 | train |
mojombo/chronic | lib/chronic/handlers.rb | Chronic.Handlers.handle_od_rm | 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 | 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 | [
"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"
] | Handle ordinal this month | [
"Handle",
"ordinal",
"this",
"month"
] | 2b1eae7ec440d767c09e0b1a7f0e9bcf30ce1d6c | https://github.com/mojombo/chronic/blob/2b1eae7ec440d767c09e0b1a7f0e9bcf30ce1d6c/lib/chronic/handlers.rb#L54-L58 | train |
mojombo/chronic | lib/chronic/handlers.rb | Chronic.Handlers.handle_r | def handle_r(tokens, options)
dd_tokens = dealias_and_disambiguate_times(tokens, options)
get_anchor(dd_tokens, options)
end | ruby | def handle_r(tokens, options)
dd_tokens = dealias_and_disambiguate_times(tokens, options)
get_anchor(dd_tokens, options)
end | [
"def",
"handle_r",
"(",
"tokens",
",",
"options",
")",
"dd_tokens",
"=",
"dealias_and_disambiguate_times",
"(",
"tokens",
",",
"options",
")",
"get_anchor",
"(",
"dd_tokens",
",",
"options",
")",
"end"
] | anchors
Handle repeaters | [
"anchors",
"Handle",
"repeaters"
] | 2b1eae7ec440d767c09e0b1a7f0e9bcf30ce1d6c | https://github.com/mojombo/chronic/blob/2b1eae7ec440d767c09e0b1a7f0e9bcf30ce1d6c/lib/chronic/handlers.rb#L432-L435 | train |
mojombo/chronic | lib/chronic/handlers.rb | Chronic.Handlers.handle_orr | 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 | 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 | [
"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"
] | narrows
Handle oridinal repeaters | [
"narrows",
"Handle",
"oridinal",
"repeaters"
] | 2b1eae7ec440d767c09e0b1a7f0e9bcf30ce1d6c | https://github.com/mojombo/chronic/blob/2b1eae7ec440d767c09e0b1a7f0e9bcf30ce1d6c/lib/chronic/handlers.rb#L488-L504 | train |
mojombo/chronic | lib/chronic/handlers.rb | Chronic.Handlers.find_within | 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 | 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 | [
"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"
] | Recursively finds repeaters within other repeaters.
Returns a Span representing the innermost time span
or nil if no repeater union could be found | [
"Recursively",
"finds",
"repeaters",
"within",
"other",
"repeaters",
".",
"Returns",
"a",
"Span",
"representing",
"the",
"innermost",
"time",
"span",
"or",
"nil",
"if",
"no",
"repeater",
"union",
"could",
"be",
"found"
] | 2b1eae7ec440d767c09e0b1a7f0e9bcf30ce1d6c | https://github.com/mojombo/chronic/blob/2b1eae7ec440d767c09e0b1a7f0e9bcf30ce1d6c/lib/chronic/handlers.rb#L584-L595 | train |
mojombo/chronic | lib/chronic/handler.rb | Chronic.Handler.match | 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 | 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 | [
"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"
] | pattern - An Array of patterns to match tokens against.
handler_method - A Symbol representing the method to be invoked
when a pattern matches.
tokens - An Array of tokens to process.
definitions - A Hash of definitions to check against.
Returns true if a match is found. | [
"pattern",
"-",
"An",
"Array",
"of",
"patterns",
"to",
"match",
"tokens",
"against",
".",
"handler_method",
"-",
"A",
"Symbol",
"representing",
"the",
"method",
"to",
"be",
"invoked",
"when",
"a",
"pattern",
"matches",
".",
"tokens",
"-",
"An",
"Array",
"of",
"tokens",
"to",
"process",
".",
"definitions",
"-",
"A",
"Hash",
"of",
"definitions",
"to",
"check",
"against",
"."
] | 2b1eae7ec440d767c09e0b1a7f0e9bcf30ce1d6c | https://github.com/mojombo/chronic/blob/2b1eae7ec440d767c09e0b1a7f0e9bcf30ce1d6c/lib/chronic/handler.rb#L20-L68 | train |
piotrmurach/github | lib/github_api/client/repos.rb | Github.Client::Repos.create | 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 | 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 | [
"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"
] | Create a new repository for the authenticated user.
@param [Hash] params
@option params [String] :name
Required string
@option params [String] :description
Optional string
@option params [String] :homepage
Optional string
@option params [Boolean] :private
Optional boolean - true to create a private repository,
false to create a public one.
@option params [Boolean] :has_issues
Optional boolean - true to enable issues for this repository,
false to disable them
@option params [Boolean] :has_wiki
Optional boolean - true to enable the wiki for this repository,
false to disable it. Default is true
@option params [Boolean] :has_downloads
Optional boolean - true to enable downloads for this repository
@option params [String] :org
Optional string - The organisation in which this
repository will be created
@option params [Numeric] :team_id
Optional number - The id of the team that will be granted
access to this repository. This is only valid when creating
a repo in an organization
@option params [Boolean] :auto_init
Optional boolean - true to create an initial commit with
empty README. Default is false.
@option params [String] :gitignore_template
Optional string - Desired language or platform .gitignore
template to apply. Use the name of the template without
the extension. For example, “Haskell” Ignored if
auto_init parameter is not provided.
@example
github = Github.new
github.repos.create "name": 'repo-name'
"description": "This is your first repo",
"homepage": "https://github.com",
"private": false,
"has_issues": true,
"has_wiki": true,
"has_downloads": true
Create a new repository in this organisation. The authenticated user
must be a member of this organisation
@example
github = Github.new oauth_token: '...'
github.repos.create name: 'repo-name', org: 'organisation-name'
@example | [
"Create",
"a",
"new",
"repository",
"for",
"the",
"authenticated",
"user",
"."
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/repos.rb#L240-L252 | train |
piotrmurach/github | lib/github_api/client/users.rb | Github.Client::Users.get | 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 | 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 | [
"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"
] | Get a single unauthenticated user
@example
github = Github.new
github.users.get user: 'user-name'
Get the authenticated user
@example
github = Github.new oauth_token: '...'
github.users.get
@api public | [
"Get",
"a",
"single",
"unauthenticated",
"user"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/users.rb#L68-L76 | train |
piotrmurach/github | lib/github_api/client/pull_requests/reviews.rb | Github.Client::PullRequests::Reviews.create | 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 | 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 | [
"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"
] | Create a pull request review
@param [Hash] params
@option params [String] :event
Required string - The review action (event) to perform; can be one of
APPROVE, REQUEST_CHANGES, or COMMENT. If left blank, the API returns
HTTP 422 (Unrecognizable entity) and the review is left PENDING
@option params [String] :body
Optional string. The text of the review.
@option params [Array] :comments
Optional array of draft review comment objects. An array of comments
part of the review.
@example
github = Github.new
github.pull_requests.reviews.create 'user-name', 'repo-name', 'number',
body: "Nice change",
event: "APPROVE",
comments: [
{
path: 'path/to/file/commented/on',
position: 10,
body: 'This looks good.'
}
]
@api public | [
"Create",
"a",
"pull",
"request",
"review"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/pull_requests/reviews.rb#L86-L93 | train |
piotrmurach/github | lib/github_api/client/pull_requests/reviews.rb | Github.Client::PullRequests::Reviews.update | 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 | 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 | [
"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"
] | Update a pull request review
@param [Hash] params
@option params [String] :state
Required string - The review action (event) to perform; can be one of
APPROVE, REQUEST_CHANGES, or COMMENT. If left blank, the API returns
HTTP 422 (Unrecognizable entity) and the review is left PENDING
@optoin params [String] :body
Optional string
@example
github = Github.new oauth_token: '...'
github.pull_requests.reviews.update 'user-name', 'repo-name', 'number', 'review-id'
body: "Update body",
event: "APPROVE"
@api public | [
"Update",
"a",
"pull",
"request",
"review"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/pull_requests/reviews.rb#L112-L119 | train |
piotrmurach/github | lib/github_api/client/activity/feeds.rb | Github.Client::Activity::Feeds.get | 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 | 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 | [
"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"
] | Get all the items for a named timeline
@see https://developer.github.com/v3/activity/feeds/#list-feeds
@example
github = Github.new
github.activity.feeds.get "timeline"
@param [String] name
the name of the timeline resource
@api public | [
"Get",
"all",
"the",
"items",
"for",
"a",
"named",
"timeline"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/activity/feeds.rb#L37-L47 | train |
piotrmurach/github | lib/github_api/client/projects/cards.rb | Github.Client::Projects::Cards.list | 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 | 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 | [
"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"
] | List project cards for a column
@example
github = Github.new
github.projects.cards.list :column_id
@see https://developer.github.com/v3/projects/cards/#list-project-cards
@api public | [
"List",
"project",
"cards",
"for",
"a",
"column"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/projects/cards.rb#L19-L29 | train |
piotrmurach/github | lib/github_api/client/projects/cards.rb | Github.Client::Projects::Cards.create | 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 | 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 | [
"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"
] | Create a project card for a column
@param [Hash] params
@option params [String] :note
The card's note content. Only valid for cards without another type of
content, so this must be omitted if content_id and content_type are
specified.
@option params [Integer] :content_id
The id of the Issue to associate with this card.
@option params [String] :content_type
The type of content to associate with this card. Can only be "Issue" at
this time.
@example
github = Github.new
github.projects.cards.create :column_id, note: 'Card Note'
@example
github = Github.new
github.projects.cards.create :column_id, content_id: <content-id>, content_type: 'content-type'
@see https://developer.github.com/v3/projects/cards/#create-a-project-card
@api public | [
"Create",
"a",
"project",
"card",
"for",
"a",
"column"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/projects/cards.rb#L75-L82 | train |
piotrmurach/github | lib/github_api/client/projects/cards.rb | Github.Client::Projects::Cards.update | 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 | 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 | [
"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"
] | Update a project card
@param [Hash] params
@option params [String] :note
The card's note content. Only valid for cards without another type of
content, so this cannot be specified if the card already has a
content_id and content_type.
@example
github = Github.new
github.projects.cards.update :card_id, note: 'New card note'
@see https://developer.github.com/v3/projects/cards/#update-a-project-card
@api public | [
"Update",
"a",
"project",
"card"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/projects/cards.rb#L99-L106 | train |
piotrmurach/github | lib/github_api/client/projects/cards.rb | Github.Client::Projects::Cards.delete | 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 | 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 | [
"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"
] | Delete a project card
@example
github = Github.new
github.projects.cards.delete :card_id
@see https://developer.github.com/v3/projects/cards/#delete-a-project-card
@api public | [
"Delete",
"a",
"project",
"card"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/projects/cards.rb#L118-L125 | train |
piotrmurach/github | lib/github_api/client/projects/cards.rb | Github.Client::Projects::Cards.move | 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 | 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 | [
"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"
] | Move a project card
@param [Hash] params
@option params [String] :position
Required. Required. Can be one of 'first', 'last', or
'after:<column-id>', where <column-id> is the id value of a column in
the same project.
@example
github = Github.new
github.projects.cards.move :card_id, position: 'bottom'
@example
github = Github.new
github.projects.cards.move :card_id, position: 'after:<card-id>', column_id: <column-id>
@see https://developer.github.com/v3/projects/cards/#move-a-project-card
@api public | [
"Move",
"a",
"project",
"card"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/projects/cards.rb#L147-L156 | train |
piotrmurach/github | lib/github_api/client/issues.rb | Github.Client::Issues.list | 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 | 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 | [
"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"
] | List your issues
List all issues across all the authenticated user’s visible repositories
including owned repositories, member repositories,
and organization repositories.
@example
github = Github.new oauth_token: '...'
github.issues.list
List all issues across owned and member repositories for the
authenticated user.
@example
github = Github.new oauth_token: '...'
github.issues.list :user
List all issues for a given organization for the authenticated user.
@example
github = Github.new oauth_token: '...'
github.issues.list org: 'org-name'
List issues for a repository
@example
github = Github.new
github.issues.list user: 'user-name', repo: 'repo-name'
@param [Hash] params
@option params [String] :filter
* assigned Issues assigned to you (default)
* created Issues created by you
* mentioned Issues mentioning you
* subscribed Issues you've subscribed to updates for
* all All issues the user can see
@option params [String] :milestone
* Integer Milestone number
* none for Issues with no Milestone.
* * for Issues with any Milestone
@option params [String] :state
open, closed, default: open
@option params [String] :labels
String list of comma separated Label names. Example: bug,ui,@high
@option params [String] :assignee
* String User login
* <tt>none</tt> for Issues with no assigned User.
* <tt>*</tt> for Issues with any assigned User.
@option params [String] :creator
String User login
@option params [String] :mentioned
String User login
@option params [String] :sort
created, updated, comments, default: <tt>created</tt>
@option params [String] :direction
asc, desc, default: desc
@option params [String] :since
Optional string of a timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ
@example
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'
@api public | [
"List",
"your",
"issues"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/issues.rb#L125-L144 | train |
piotrmurach/github | lib/github_api/client/repos/releases/assets.rb | Github.Client::Repos::Releases::Assets.upload | 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 | 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 | [
"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"
] | Upload a release asset
@param [Hash] params
@input params [String] :name
Required string. The file name of the asset
@input params [String] :content_type
Required string. The content type of the asset.
Example: “application/zip”.
@example
github = Github.new
github.repos.releases.assets.upload 'owner', 'repo', 'id', 'file-path'
name: "batman.jpg",
content_type: "application/octet-stream"
@api public | [
"Upload",
"a",
"release",
"asset"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/repos/releases/assets.rb#L62-L84 | train |
piotrmurach/github | lib/github_api/client/repos/releases/assets.rb | Github.Client::Repos::Releases::Assets.infer_media | 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 | 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 | [
"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"
] | Infer media type of the asset | [
"Infer",
"media",
"type",
"of",
"the",
"asset"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/repos/releases/assets.rb#L88-L94 | train |
piotrmurach/github | lib/github_api/client/repos/releases/assets.rb | Github.Client::Repos::Releases::Assets.edit | 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 | 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 | [
"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"
] | Edit a release asset
Users with push access to the repository can edit a release asset.
@param [Hash] params
@input params [String] :name
Required. The file name of the asset.
@input params [String] :label
An alternate short description of the asset.
Used in place of the filename.
@example
github = Github.new
github.repos.releases.assets.edit 'owner', 'repo', 'id',
name: "foo-1.0.0-osx.zip",
label: "Mac binary"
@api public | [
"Edit",
"a",
"release",
"asset"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/repos/releases/assets.rb#L114-L120 | train |
piotrmurach/github | lib/github_api/client/markdown.rb | Github.Client::Markdown.render | def render(*args)
arguments(args) do
assert_required ['text']
end
params = arguments.params
params['raw'] = true
post_request("markdown", arguments.params)
end | ruby | def render(*args)
arguments(args) do
assert_required ['text']
end
params = arguments.params
params['raw'] = true
post_request("markdown", arguments.params)
end | [
"def",
"render",
"(",
"*",
"args",
")",
"arguments",
"(",
"args",
")",
"do",
"assert_required",
"[",
"'text'",
"]",
"end",
"params",
"=",
"arguments",
".",
"params",
"params",
"[",
"'raw'",
"]",
"=",
"true",
"post_request",
"(",
"\"markdown\"",
",",
"arguments",
".",
"params",
")",
"end"
] | Render an arbitrary Markdown document
= Parameters
<tt>:text</tt> - Required string - The Markdown text to render
<tt>:mode<tt> - Optional string - The rendering mode
* <tt>markdown</tt> to render a document as plain Markdown, just
like README files are rendered.
* <tt>gfm</tt> to render a document as user-content, e.g. like user
comments or issues are rendered. In GFM mode, hard line breaks are
always taken into account, and issue and user mentions are
linked accordingly.
<tt>:context<tt> - Optional string - The repository context, only taken
into account when rendering as <tt>gfm</tt>
= Examples
github = Github.new
github.markdown.render
"text": "Hello world github/linguist#1 **cool**, and #1!",
"mode": "gfm",
"context": "github/gollum" | [
"Render",
"an",
"arbitrary",
"Markdown",
"document"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/markdown.rb#L29-L37 | train |
piotrmurach/github | lib/github_api/client/markdown.rb | Github.Client::Markdown.render_raw | 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 | 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 | [
"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"
] | Render a Markdown document in raw mode
= Input
The raw API it not JSON-based. It takes a Markdown document as plaintext
<tt>text/plain</tt> or <tt>text/x-markdown</tt> and renders it as plain
Markdown without a repository context (just like a README.md file is
rendered – this is the simplest way to preview a readme online)
= Examples
github = Github.new
github.markdown.render_raw "Hello github/linguist#1 **cool**, and #1!",
"accept": "text/plain", | [
"Render",
"a",
"Markdown",
"document",
"in",
"raw",
"mode"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/markdown.rb#L52-L59 | train |
piotrmurach/github | lib/github_api/client/repos/statuses.rb | Github.Client::Repos::Statuses.create | 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 | 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 | [
"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"
] | Create a status
@param [Hash] params
@input params [String] :state
Required. The state of the status. Can be one of pending,
success, error, or failure.
@input params [String] :target_url
The target URL to associate with this status. This URL will
be linked from the GitHub UI to allow users to easily see
the ‘source’ of the Status.
For example, if your Continuous Integration system is posting
build status, you would want to provide the deep link for
the build output for this specific SHA:
http://ci.example.com/user/repo/build/sha.
@input params [String] :description
A short description of the status
@input params [String] :context
A string label to differentiate this status from the
status of other systems. Default: "default"
@example
github = Github.new
github.repos.statuses.create 'user-name', 'repo-name', 'sha',
state: "success",
target_url: "http://ci.example.com/johndoe/my-repo/builds/sha",
description: "Successful build #3 from origin/master"
@api public | [
"Create",
"a",
"status"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/repos/statuses.rb#L82-L89 | train |
piotrmurach/github | lib/github_api/client/activity/starring.rb | Github.Client::Activity::Starring.starring? | 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 | 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 | [
"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"
] | Check if you are starring a repository
@see https://developer.github.com/v3/activity/starring/#check-if-you-are-starring-a-repository
@example
github = Github.new
github.activity.starring.starring? 'user-name', 'repo-name'
@example
github.activity.starring.starring? user: 'user-name', repo: 'repo-name'
@return [Boolean]
Returns true if this repo is starred by you, false otherwise.
@api public | [
"Check",
"if",
"you",
"are",
"starring",
"a",
"repository"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/activity/starring.rb#L81-L88 | train |
piotrmurach/github | lib/github_api/client/gitignore.rb | Github.Client::Gitignore.list | def list(*args)
arguments(args)
response = get_request("/gitignore/templates", arguments.params)
return response unless block_given?
response.each { |el| yield el }
end | ruby | def list(*args)
arguments(args)
response = get_request("/gitignore/templates", arguments.params)
return response unless block_given?
response.each { |el| yield el }
end | [
"def",
"list",
"(",
"*",
"args",
")",
"arguments",
"(",
"args",
")",
"response",
"=",
"get_request",
"(",
"\"/gitignore/templates\"",
",",
"arguments",
".",
"params",
")",
"return",
"response",
"unless",
"block_given?",
"response",
".",
"each",
"{",
"|",
"el",
"|",
"yield",
"el",
"}",
"end"
] | List all templates available to pass as an option
when creating a repository.
@see https://developer.github.com/v3/gitignore/#listing-available-templates
@example
github = Github.new
github.gitignore.list
github.gitignore.list { |template| ... }
@api public | [
"List",
"all",
"templates",
"available",
"to",
"pass",
"as",
"an",
"option",
"when",
"creating",
"a",
"repository",
"."
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/gitignore.rb#L20-L26 | train |
piotrmurach/github | lib/github_api/client/gitignore.rb | Github.Client::Gitignore.get | 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 | 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 | [
"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"
] | Get a single template
@see https://developer.github.com/v3/gitignore/#get-a-single-template
@example
github = Github.new
github.gitignore.get "template-name"
Use the raw media type to get the raw contents.
@examples
github = Github.new
github.gitignore.get "template-name", accept: 'applicatin/vnd.github.raw'
@api public | [
"Get",
"a",
"single",
"template"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/gitignore.rb#L44-L54 | train |
piotrmurach/github | lib/github_api/client/issues/labels.rb | Github.Client::Issues::Labels.get | 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 | 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 | [
"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"
] | Get a single label
@example
github = Github.new
github.issues.labels.find 'user-name', 'repo-name', 'label-name'
@example
github = Github.new user: 'user-name', repo: 'repo-name'
github.issues.labels.get label_name: 'bug'
@api public | [
"Get",
"a",
"single",
"label"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/issues/labels.rb#L59-L64 | train |
piotrmurach/github | lib/github_api/client/issues/labels.rb | Github.Client::Issues::Labels.create | 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 | 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 | [
"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"
] | Create a label
@param [Hash] params
@option params [String] :name
Required string
@option params [String] :color
Required string - 6 character hex code, without leading
@example
github = Github.new user: 'user-name', repo: 'repo-name'
github.issues.labels.create name: 'API', color: 'FFFFFF'
@api public | [
"Create",
"a",
"label"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/issues/labels.rb#L80-L87 | train |
piotrmurach/github | lib/github_api/client/issues/labels.rb | Github.Client::Issues::Labels.update | 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 | 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 | [
"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"
] | Update a label
@param [Hash] params
@option params [String] :name
Required string
@option params [String] :color
Required string - 6 character hex code, without leading
@example
github = Github.new
github.issues.labels.update 'user-name', 'repo-name', 'label-name',
name: 'API', color: "FFFFFF"
@api public | [
"Update",
"a",
"label"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/issues/labels.rb#L103-L110 | train |
piotrmurach/github | lib/github_api/client/issues/labels.rb | Github.Client::Issues::Labels.remove | 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 | 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 | [
"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"
] | Remove a label from an issue
@example
github = Github.new
github.issues.labels.remove 'user-name', 'repo-name', 'issue-number',
label_name: 'label-name'
Remove all labels from an issue
@example
github = Github.new
github.issues.labels.remove 'user-name', 'repo-name', 'issue-number'
@api public | [
"Remove",
"a",
"label",
"from",
"an",
"issue"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/issues/labels.rb#L157-L169 | train |
piotrmurach/github | lib/github_api/client/issues/labels.rb | Github.Client::Issues::Labels.replace | 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 | 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 | [
"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"
] | Replace all labels for an issue
Sending an empty array ([]) will remove all Labels from the Issue.
@example
github = Github.new
github.issues.labels.replace 'user-name', 'repo-name', 'issue-number',
'label1', 'label2', ...
@api public | [
"Replace",
"all",
"labels",
"for",
"an",
"issue"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/issues/labels.rb#L181-L187 | train |
piotrmurach/github | lib/github_api/page_iterator.rb | Github.PageIterator.parse_page_params | 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 | 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 | [
"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"
] | Extracts query string parameter for given name | [
"Extracts",
"query",
"string",
"parameter",
"for",
"given",
"name"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/page_iterator.rb#L113-L128 | train |
piotrmurach/github | lib/github_api/client/scopes.rb | Github.Client::Scopes.list | 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 | 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 | [
"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"
] | Check what OAuth scopes you have.
@see https://developer.github.com/v3/oauth/#scopes
@example
github = Github.new oauth_token: 'e72e16c7e42f292c6912e7710c838347ae17'
github.scopes.all
@example
github = Github.new
github.scopes.list 'e72e16c7e42f292c6912e7710c838347ae17'
@example
github = Github.new
github.scopes.list token: 'e72e16c7e42f292c6912e7710c838347ae17'
@api public | [
"Check",
"what",
"OAuth",
"scopes",
"you",
"have",
"."
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/scopes.rb#L24-L43 | train |
piotrmurach/github | lib/github_api/client/activity/events.rb | Github.Client::Activity::Events.received | 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 | 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 | [
"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"
] | List all events that a user has received
@see https://developer.github.com/v3/activity/events/#list-events-that-a-user-has-received
These are events that you’ve received by watching repos
and following users. If you are authenticated as the given user,
you will see private events. Otherwise, you’ll only see public events.
@example
github = Github.new
github.activity.events.received 'user-name'
github.activity.events.received 'user-name' { |event| ... }
List all public events that a user has received
@see https://developer.github.com/v3/activity/events/#list-public-events-that-a-user-has-received
@example
github = Github.new
github.activity.events.received 'user-name', public: true
github.activity.events.received 'user-name', public: true { |event| ... }
@api public | [
"List",
"all",
"events",
"that",
"a",
"user",
"has",
"received"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/activity/events.rb#L150-L162 | train |
piotrmurach/github | lib/github_api/pagination.rb | Github.Pagination.auto_paginate | 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 | 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 | [
"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"
] | Iterate over results set pages by automatically calling `next_page`
until all pages are exhausted. Caution needs to be exercised when
using this feature - 100 pages iteration will perform 100 API calls.
By default this is off. You can set it on the client, individual API
instances or just per given request. | [
"Iterate",
"over",
"results",
"set",
"pages",
"by",
"automatically",
"calling",
"next_page",
"until",
"all",
"pages",
"are",
"exhausted",
".",
"Caution",
"needs",
"to",
"be",
"exercised",
"when",
"using",
"this",
"feature",
"-",
"100",
"pages",
"iteration",
"will",
"perform",
"100",
"API",
"calls",
".",
"By",
"default",
"this",
"is",
"off",
".",
"You",
"can",
"set",
"it",
"on",
"the",
"client",
"individual",
"API",
"instances",
"or",
"just",
"per",
"given",
"request",
"."
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/pagination.rb#L28-L35 | train |
piotrmurach/github | lib/github_api/client/projects/columns.rb | Github.Client::Projects::Columns.get | 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 | 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 | [
"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"
] | Get a project columns
@example
github = Github.new
github.projects.columns.get :column_id
@see https://developer.github.com/v3/projects/columns/#get-a-project-column
@api public | [
"Get",
"a",
"project",
"columns"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/projects/columns.rb#L42-L49 | train |
piotrmurach/github | lib/github_api/client/git_data/trees.rb | Github.Client::GitData::Trees.get | 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 | 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 | [
"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"
] | Get a tree
@example
github = Github.new
github.git_data.trees.get 'user-name', 'repo-name', 'sha'
github.git_data.trees.get 'user-name', 'repo-name', 'sha' do |file|
file.path
end
Get a tree recursively
@example
github = Github.new
github.git_data.trees.get 'user-name', 'repo-name', 'sha', recursive: true
@api public | [
"Get",
"a",
"tree"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/git_data/trees.rb#L40-L55 | train |
piotrmurach/github | lib/github_api/client/git_data/trees.rb | Github.Client::GitData::Trees.create | 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 | 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 | [
"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"
] | Create a tree
The tree creation API will take nested entries as well.
If both a tree and a nested path modifying that tree are specified,
it will overwrite the contents of that tree with the new path contents
and write a new tree out.
@param [Hash] params
@input params [String] :base_tree
The SHA1 of the tree you want to update with new data
@input params [Array[Hash]] :tree
Required. Objects (of path, mode, type, and sha)
specifying a tree structure
The tree parameter takes the following keys:
@input tree [String] :path
The file referenced in the tree
@input tree [String] :mode
The file mode; one of 100644 for file (blob), 100755 for
executable (blob), 040000 for subdirectory (tree), 160000 for
submodule (commit), or 120000 for a blob that specifies
the path of a symlink
@input tree [String] :type
Either blob, tree, or commit
@input tree [String] :sha
The SHA1 checksum ID of the object in the tree
@input tree [String] :content
The content you want this file to have - GitHub will write
this blob out and use the SHA for this entry.
Use either this or <tt>tree.sha</tt>
@example
github = Github.new
github.git_data.trees.create 'user-name', 'repo-name',
tree: [
{
path: "file.rb",
mode: "100644",
type: "blob",
sha: "44b4fc6d56897b048c772eb4087f854f46256132"
},
...
]
@api public | [
"Create",
"a",
"tree"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/git_data/trees.rb#L103-L111 | train |
piotrmurach/github | lib/github_api/client/git_data/commits.rb | Github.Client::GitData::Commits.create | 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 | 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 | [
"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"
] | Create a commit
@param [Hash] params
@input params [String] :message
The commit message
@input params [String] :tree
String of the SHA of the tree object this commit points to
@input params [Array[String]] :parents
Array of the SHAs of the commits that were the parents of this commit.
If omitted or empty, the commit will be written as a root commit.
For a single parent, an array of one SHA should be provided,
for a merge commit, an array of more than one should be provided.
Optional Parameters
You can provide an additional commiter parameter, which is a hash
containing information about the committer. Or, you can provide an author
parameter, which is a hash containing information about the author.
The committer section is optional and will be filled with the author
data if omitted. If the author section is omitted, it will be filled
in with the authenticated users information and the current date.
Both the author and commiter parameters have the same keys:
@input params [String] :name
String of the name of the author (or commiter) of the commit
@input params [String] :email
String of the email of the author (or commiter) of the commit
@input params [Timestamp] :date
Indicates when this commit was authored (or committed).
This is a timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ.
@example
github = Github.new
github.git_data.commits.create 'user-name', 'repo-name',
message: "my commit message",
author: {
name: "Scott Chacon",
email: "[email protected]",
date: "2008-07-09T16:13:30+12:00"
},
parents: [
"7d1b31e74ee336d15cbd21741bc88a537ed063a0"
],
tree: "827efc6d56897b048c772eb4087f854f46256132"]
@api public | [
"Create",
"a",
"commit"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/git_data/commits.rb#L92-L99 | train |
piotrmurach/github | lib/github_api/client/issues/assignees.rb | Github.Client::Issues::Assignees.remove | 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 | 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 | [
"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"
] | Remove a assignees from an issue
@example
github = Github.new
github.issues.assignees.remove 'user', 'repo', 'issue-number',
'hubot', 'other_assignee'
@api public | [
"Remove",
"a",
"assignees",
"from",
"an",
"issue"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/issues/assignees.rb#L69-L75 | train |
piotrmurach/github | lib/github_api/api.rb | Github.API.filter_callbacks | 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 | def filter_callbacks(kind, action_name)
self.class.send("#{kind}_callbacks").select do |callback|
callback[:only].nil? || callback[:only].include?(action_name)
end
end | [
"def",
"filter_callbacks",
"(",
"kind",
",",
"action_name",
")",
"self",
".",
"class",
".",
"send",
"(",
"\"#{kind}_callbacks\"",
")",
".",
"select",
"do",
"|",
"callback",
"|",
"callback",
"[",
":only",
"]",
".",
"nil?",
"||",
"callback",
"[",
":only",
"]",
".",
"include?",
"(",
"action_name",
")",
"end",
"end"
] | Filter callbacks based on kind
@param [Symbol] kind
one of :before or :after
@return [Array[Hash]]
@api private | [
"Filter",
"callbacks",
"based",
"on",
"kind"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/api.rb#L224-L228 | train |
piotrmurach/github | lib/github_api/api.rb | Github.API.run_callbacks | 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 | 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 | [
"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"
] | Run all callbacks associated with this action
@apram [Symbol] action_name
@api private | [
"Run",
"all",
"callbacks",
"associated",
"with",
"this",
"action"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/api.rb#L235-L239 | train |
piotrmurach/github | lib/github_api/api.rb | Github.API.set | 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 | 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 | [
"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"
] | Set a configuration option for a given namespace
@param [String] option
@param [Object] value
@param [Boolean] ignore_setter
@return [self]
@api public | [
"Set",
"a",
"configuration",
"option",
"for",
"a",
"given",
"namespace"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/api.rb#L294-L309 | train |
piotrmurach/github | lib/github_api/api.rb | Github.API.set_options | 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 | def set_options(options)
unless options.respond_to?(:each)
raise ArgumentError, 'cannot iterate over value'
end
options.each { |key, value| set(key, value) }
end | [
"def",
"set_options",
"(",
"options",
")",
"unless",
"options",
".",
"respond_to?",
"(",
":each",
")",
"raise",
"ArgumentError",
",",
"'cannot iterate over value'",
"end",
"options",
".",
"each",
"{",
"|",
"key",
",",
"value",
"|",
"set",
"(",
"key",
",",
"value",
")",
"}",
"end"
] | Set multiple options
@api private | [
"Set",
"multiple",
"options"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/api.rb#L366-L371 | train |
piotrmurach/github | lib/github_api/api.rb | Github.API.define_accessors | 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 | 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 | [
"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"
] | Define setters and getters
@api private | [
"Define",
"setters",
"and",
"getters"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/api.rb#L376-L382 | train |
piotrmurach/github | lib/github_api/api.rb | Github.API.define_singleton_method | 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 | 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 | [
"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"
] | Dynamically define a method for setting request option
@api private | [
"Dynamically",
"define",
"a",
"method",
"for",
"setting",
"request",
"option"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/api.rb#L387-L396 | train |
piotrmurach/github | lib/github_api/client/git_data/tags.rb | Github.Client::GitData::Tags.create | 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 | 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 | [
"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"
] | Create a tag object
Note that creating a tag object does not create the reference that
makes a tag in Git. If you want to create an annotated tag in Git,
you have to do this call to create the tag object, and then create
the refs/tags/[tag] reference. If you want to create a lightweight
tag, you simply have to create the reference -
this call would be unnecessary.
@param [Hash] params
@input params [String] :tag
The tag
@input params [String] :message
The tag message
@input params [String] :object
The SHA of the git object this is tagging
@input params [String] :type
The type of the object we're tagging.
Normally this is a commit but it can also be a tree or a blob
@input params [Hash] :tagger
A hash with information about the individual creating the tag.
The tagger hash contains the following keys:
@input tagger [String] :name
The name of the author of the tag
@input tagger [String] :email
The email of the author of the tag
@input tagger [String] :date
When this object was tagged. This is a timestamp in ISO 8601
format: YYYY-MM-DDTHH:MM:SSZ.
@xample
github = Github.new
github.git_data.tags.create 'user-name', 'repo-name',
tag: "v0.0.1",
message: "initial version\n",
type: "commit",
object: "c3d0be41ecbe669545ee3e94d31ed9a4bc91ee3c",
tagger: {
name: "Scott Chacon",
email: "[email protected]",
date: "2011-06-17T14:53:3"
}
@api public | [
"Create",
"a",
"tag",
"object"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/git_data/tags.rb#L86-L93 | train |
piotrmurach/github | lib/github_api/client/users/followers.rb | Github.Client::Users::Followers.list | 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 | 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 | [
"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"
] | List a user's followers
@example
github = Github.new
github.users.followers.list 'user-name'
github.users.followers.list 'user-name' { |user| ... }
List the authenticated user's followers
@example
github = Github.new oauth_token: '...'
github.users.followers
github.users.followers { |user| ... }
@api public | [
"List",
"a",
"user",
"s",
"followers"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/users/followers.rb#L23-L33 | train |
piotrmurach/github | lib/github_api/client/users/followers.rb | Github.Client::Users::Followers.following? | 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 | 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 | [
"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"
] | Check if you are following a user
@example
github = Github.new oauth_token: '...'
github.users.followers.following? 'user-name'
github.users.followers.following? username: 'user-name'
Check if one user follows another
@example
github = Github.new oauth_token: '...'
github.users.followers.following? username: 'user-name',
target_user: 'target-user-name'
@api public | [
"Check",
"if",
"you",
"are",
"following",
"a",
"user"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/users/followers.rb#L77-L88 | train |
piotrmurach/github | lib/github_api/client/activity/watching.rb | Github.Client::Activity::Watching.watched | 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 | 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 | [
"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"
] | List repos being watched by a user
@see https://developer.github.com/v3/activity/watching/#list-repositories-being-watched
@example
github = Github.new
github.activity.watching.watched user: 'user-name'
List repos being watched by the authenticated user
@example
github = Github.new oauth_token: '...'
github.activity.watching.watched
@api public | [
"List",
"repos",
"being",
"watched",
"by",
"a",
"user"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/activity/watching.rb#L43-L54 | train |
piotrmurach/github | lib/github_api/client/orgs/members.rb | Github.Client::Orgs::Members.member? | 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 | 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 | [
"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"
] | Check if user is, publicly or privately, a member of an organization
@example
github = Github.new
github.orgs.members.member? 'org-name', 'member-name'
Check if a user is a public member of an organization
@example
github = Github.new
github.orgs.members.member? 'org-name', 'member-name', public: true
@api public | [
"Check",
"if",
"user",
"is",
"publicly",
"or",
"privately",
"a",
"member",
"of",
"an",
"organization"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/orgs/members.rb#L75-L88 | train |
piotrmurach/github | lib/github_api/client/repos/branches/protections.rb | Github.Client::Repos::Branches::Protections.edit | 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 | 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 | [
"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"
] | Edit a branch protection
Users with push access to the repository can edit a branch protection.
@param [Hash] params
@input params [String] :required_status_checks
Required.
@input params [String] :enforce_admins
Required.
@input params [String] :restrictions
Required.
@input params [String] :required_pull_request_reviews
Required.
Look to the branch protection API to see how to use these
https://developer.github.com/v3/repos/branches/#update-branch-protection
@example
github = Github.new
github.repos.branches.protections.edit 'user', 'repo', 'branch',
required_pull_request_reviews: {dismiss_stale_reviews: false}
@api public | [
"Edit",
"a",
"branch",
"protection"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/repos/branches/protections.rb#L52-L58 | train |
piotrmurach/github | lib/github_api/parameter_filter.rb | Github.ParameterFilter.filter! | 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 | 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 | [
"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"
] | Removes any keys from nested hashes that don't match predefiend keys | [
"Removes",
"any",
"keys",
"from",
"nested",
"hashes",
"that",
"don",
"t",
"match",
"predefiend",
"keys"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/parameter_filter.rb#L14-L32 | train |
piotrmurach/github | lib/github_api/client/orgs/teams.rb | Github.Client::Orgs::Teams.team_repo? | 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 | 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 | [
"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"
] | Check if a repository belongs to a team
@see https://developer.github.com/v3/orgs/teams/#get-team-repo
@example
github = Github.new oauth_token: '...'
github.orgs.teams.team_repo? 'team-id', 'user-name', 'repo-name'
@api public | [
"Check",
"if",
"a",
"repository",
"belongs",
"to",
"a",
"team"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/orgs/teams.rb#L356-L363 | train |
piotrmurach/github | lib/github_api/response/raise_error.rb | Github.Response::RaiseError.on_complete | 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 | 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 | [
"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"
] | Check if status code requires raising a ServiceError
@api private | [
"Check",
"if",
"status",
"code",
"requires",
"raising",
"a",
"ServiceError"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/response/raise_error.rb#L12-L20 | train |
piotrmurach/github | lib/github_api/client/repos/deployments.rb | Github.Client::Repos::Deployments.create | 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 | 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 | [
"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"
] | Create a deployment
@param [Hash] params
@option params [String] :ref
Required string. The ref to deploy. This can be a branch, tag, or sha.
@option params [Boolean] :auto_merge
Optional boolean. Merge the default branch into the requested.
@option params [Array] :required_contexts
Optional array of status contexts verified against commit status checks.
If this parameter is omitted from the parameters then all unique
contexts will be verified before a deployment is created. To bypass
checking entirely pass an empty array. Defaults to all unique contexts.
@option params [String] :payload
Optional JSON payload with extra information about the deployment.
Default: ""
@option params [String] :payload
Optional String. Name for the target deployment environment (e.g.,
production, staging, qa). Default: "production"
@option params [String] :description
Optional string. Optional short description.
@example
github = Github.new
github.repos.deployments.create 'user-name', 'repo-name', ref: '...'
github.repos.deployments.create
'user-name',
'repo-name',
ref: '...',
description: 'New deploy',
force: true
@api public | [
"Create",
"a",
"deployment"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/repos/deployments.rb#L76-L85 | train |
piotrmurach/github | lib/github_api/client/repos/deployments.rb | Github.Client::Repos::Deployments.statuses | 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 | 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 | [
"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"
] | List the statuses of a deployment.
@param [Hash] params
@option params [String] :id
Required string. Id of the deployment being queried.
@example
github = Github.new
github.repos.deployments.statuses 'user-name', 'repo-name', DEPLOYMENT_ID
github.repos.deployments.statuses 'user-name', 'repo-name', DEPLOYMENT_ID { |status| ... }
@api public | [
"List",
"the",
"statuses",
"of",
"a",
"deployment",
"."
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/repos/deployments.rb#L99-L107 | train |
piotrmurach/github | lib/github_api/client/repos/deployments.rb | Github.Client::Repos::Deployments.create_status | 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 | 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 | [
"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"
] | Create a deployment status
@param [Hash] params
@option params [String] :id
Required string. Id of the deployment being referenced.
@option params [String] :state
Required string. State of the deployment. Can be one of:
pending, success, error, or failure.
@option params [String] :target_url
Optional string. The URL associated with the status.
@option params [String] :description
Optional string. A short description of the status.
@example
github = Github.new
github.repos.deployments.create_status 'user-name', 'repo-name', DEPLOYMENT_ID, state: '...'
@api public | [
"Create",
"a",
"deployment",
"status"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/repos/deployments.rb#L127-L136 | train |
piotrmurach/github | lib/github_api/params_hash.rb | Github.ParamsHash.options | 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 | 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 | [
"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"
] | Configuration options from request
@return [Hash]
@api public | [
"Configuration",
"options",
"from",
"request"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/params_hash.rb#L71-L80 | train |
piotrmurach/github | lib/github_api/params_hash.rb | Github.ParamsHash.merge_default | 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 | def merge_default(defaults)
if defaults && !defaults.empty?
defaults.each do |key, value|
self[key] = value unless self.key?(key)
end
end
self
end | [
"def",
"merge_default",
"(",
"defaults",
")",
"if",
"defaults",
"&&",
"!",
"defaults",
".",
"empty?",
"defaults",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"self",
"[",
"key",
"]",
"=",
"value",
"unless",
"self",
".",
"key?",
"(",
"key",
")",
"end",
"end",
"self",
"end"
] | Update hash with default parameters for non existing keys | [
"Update",
"hash",
"with",
"default",
"parameters",
"for",
"non",
"existing",
"keys"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/params_hash.rb#L84-L91 | train |
piotrmurach/github | lib/github_api/params_hash.rb | Github.ParamsHash.strict_encode64 | 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 | 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 | [
"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"
] | Base64 encode string removing newline characters
@api public | [
"Base64",
"encode",
"string",
"removing",
"newline",
"characters"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/params_hash.rb#L96-L104 | train |
piotrmurach/github | lib/github_api/client/repos/comments.rb | Github.Client::Repos::Comments.create | 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 | 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 | [
"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"
] | Creates a commit comment
@param [Hash] params
@option params [String] :body
Required. The contents of the comment.
@option params [String] :path
Required. Relative path of the file to comment on.
@option params [Number] :position
Required number - Line index in the diff to comment on.
@option params [Number] :line
Required number - Line number in the file to comment on.
@example
github = Github.new
github.repos.comments.create 'user-name', 'repo-name', 'sha-key',
body: "Nice change",
position: 4,
line: 1,
path: "file1.txt"
@api public | [
"Creates",
"a",
"commit",
"comment"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/repos/comments.rb#L84-L90 | train |
piotrmurach/github | lib/github_api/client/repos/comments.rb | Github.Client::Repos::Comments.update | 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 | 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 | [
"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"
] | Update a commit comment
@param [Hash] params
@option params [String] :body
Required. The contents of the comment.
@example
github = Github.new
github.repos.comments.update 'user-name', 'repo-name', 'id',
body: "Nice change"
@api public | [
"Update",
"a",
"commit",
"comment"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/repos/comments.rb#L104-L110 | train |
piotrmurach/github | lib/github_api/client/repos/contents.rb | Github.Client::Repos::Contents.create | 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 | 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 | [
"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"
] | Create a file
This method creates a new file in a repository
@param [Hash] params
@option params [String] :path
Required string. The content path
@option params [String]
@option params [String] :message
Required string. The commit message.
@option params [String] :content
Required string. The new file content, which will be Base64 encoded
@option params [String] :branch
The branch name. If not provided, uses the repository’s
default branch (usually master)
Optional Parameters
The :author section is optional and is filled in with the
:committer information if omitted. If the :committer
information is omitted, the authenticated user’s information is used.
You must provide values for both :name and :email, whether
you choose to use :author or :committer. Otherwise, you’ll
receive a 500 status code.
Both the author and commiter parameters have the same keys:
@option params [String] :name
The name of the author (or commiter) of the commit
@option params [String] :email
The email of the author (or commiter) of the commit
@example
github = Github.new
github.repos.contents.create 'user-name', 'repo-name', 'path',
path: 'hello.rb',
content: "puts 'hello ruby'",
message: "my commit message"
@api public | [
"Create",
"a",
"file"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/repos/contents.rb#L104-L112 | train |
piotrmurach/github | lib/github_api/client/repos/contents.rb | Github.Client::Repos::Contents.delete | 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 | 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 | [
"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"
] | Delete a file
This method deletes a file in a repository
@param [Hash] params
@option params [String] :path
Requried string. The content path
@option params [String]
@option params [String] :message
Requried string. The commit message.
@option params [String] :sha
Required string. The blob SHA of the file being replaced.
@option params [String] :branch
The branch name. If not provided, uses the repository’s
default branch (usually master)
Optional Parameters
The :author section is optional and is filled in with the
:committer information if omitted. If the :committer
information is omitted, the authenticated user’s information is used.
You must provide values for both :name and :email, whether
you choose to use :author or :committer. Otherwise, you’ll
receive a 500 status code.
Both the author and commiter parameters have the same keys:
@option params [String] :name
The name of the author (or commiter) of the commit
@option params [String] :email
The email of the author (or commiter) of the commit
@example
github = Github.new
github.repos.contents.delete 'user-name', 'repo-name', 'path',
path: 'hello.rb',
message: "delete hello.rb file",
sha: "329688480d39049927147c162b9d2deaf885005f" | [
"Delete",
"a",
"file"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/repos/contents.rb#L202-L208 | train |
piotrmurach/github | lib/github_api/client/repos/contents.rb | Github.Client::Repos::Contents.archive | 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 | 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 | [
"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"
] | Get archive link
This method will return a 302 to a URL to download a tarball or zipball
archive for a repository. Please make sure your HTTP framework is configured
to follow redirects or you will need to use the Location header to make
a second GET request.
@note
For private repositories, these links are temporary and expire quickly.
@param [Hash] params
@input params [String] :archive_format
Required string. Either tarball or zipball. Default: tarball
@input params [String] :ref
Optional string. A valid Git reference.
Default: the repository’s default branch (usually master)
@example
github = Github.new
github.repos.contents.archive 'user-name', 'repo-name',
archive_format: "tarball",
ref: "master"
@api public | [
"Get",
"archive",
"link"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/repos/contents.rb#L234-L244 | train |
piotrmurach/github | lib/github_api/normalizer.rb | Github.Normalizer.normalize! | 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 | 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 | [
"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"
] | Turns any keys from nested hashes including nested arrays into strings | [
"Turns",
"any",
"keys",
"from",
"nested",
"hashes",
"including",
"nested",
"arrays",
"into",
"strings"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/normalizer.rb#L8-L21 | train |
piotrmurach/github | lib/github_api/client/authorizations/app.rb | Github.Client::Authorizations::App.create | 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 | 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 | [
"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"
] | Get-or-create an authorization for a specific app
@see https://developer.github.com/v3/oauth_authorizations/#get-or-create-an-authorization-for-a-specific-app
@param [Hash] params
@option params [String] client_secret
The 40 character OAuth app client secret associated with the client
ID specified in the URL.
@option params [Array] :scopes
Optional array - A list of scopes that this authorization is in.
@option params [String] :note
Optional string - A note to remind you what the OAuth token is for.
@option params [String] :note_url
Optional string - A URL to remind you what the OAuth token is for.
@example
github = Github.new
github.oauth.app.create 'client-id', client_secret: '...'
@api public | [
"Get",
"-",
"or",
"-",
"create",
"an",
"authorization",
"for",
"a",
"specific",
"app"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/authorizations/app.rb#L27-L36 | train |
piotrmurach/github | lib/github_api/client/authorizations/app.rb | Github.Client::Authorizations::App.check | 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 | 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 | [
"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"
] | Check if an access token is a valid authorization for an application
@example
github = Github.new basic_auth: "client_id:client_secret"
github.oauth.app.check 'client_id', 'access-token'
@api public | [
"Check",
"if",
"an",
"access",
"token",
"is",
"a",
"valid",
"authorization",
"for",
"an",
"application"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/authorizations/app.rb#L45-L58 | train |
piotrmurach/github | lib/github_api/client/authorizations/app.rb | Github.Client::Authorizations::App.delete | 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 | 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 | [
"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"
] | Revoke all authorizations for an application
@example
github = Github.new basic_auth: "client_id:client_secret"
github.oauth.app.delete 'client-id'
Revoke an authorization for an application
@example
github = Github.new basic_auth: "client_id:client_secret"
github.oauth.app.delete 'client-id', 'access-token'
@api public | [
"Revoke",
"all",
"authorizations",
"for",
"an",
"application"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/authorizations/app.rb#L73-L87 | train |
piotrmurach/github | lib/github_api/client/projects.rb | Github.Client::Projects.edit | def edit(*args)
arguments(args, required: [:id])
params = arguments.params
params["accept"] ||= PREVIEW_MEDIA
patch_request("/projects/#{arguments.id}", params)
end | ruby | def edit(*args)
arguments(args, required: [:id])
params = arguments.params
params["accept"] ||= PREVIEW_MEDIA
patch_request("/projects/#{arguments.id}", params)
end | [
"def",
"edit",
"(",
"*",
"args",
")",
"arguments",
"(",
"args",
",",
"required",
":",
"[",
":id",
"]",
")",
"params",
"=",
"arguments",
".",
"params",
"params",
"[",
"\"accept\"",
"]",
"||=",
"PREVIEW_MEDIA",
"patch_request",
"(",
"\"/projects/#{arguments.id}\"",
",",
"params",
")",
"end"
] | Edit a project
@param [Hash] params
@option params [String] :name
Optional string
@option params [String] :body
Optional string
@option params [String] :state
Optional string
@example
github = Github.new
github.projects.edit 1002604,
name: "Outcomes Tracker",
body: "The board to track work for the Outcomes application."
@api public | [
"Edit",
"a",
"project"
] | 8702452c66bea33c9388550aed9e9974f76aaef1 | https://github.com/piotrmurach/github/blob/8702452c66bea33c9388550aed9e9974f76aaef1/lib/github_api/client/projects.rb#L57-L64 | train |
Subsets and Splits