class Ossy::Github::Client
Constants
- BASE_URL
Public Instance Methods
get(path, opts = {})
click to toggle source
# File lib/ossy/github/client.rb, line 68 def get(path, opts = {}) request(:get, path, params: opts) end
headers()
click to toggle source
# File lib/ossy/github/client.rb, line 82 def headers { "Content-Type" => "application/json", "Accept" => "application/vnd.github.everest-preview+json" } end
http()
click to toggle source
# File lib/ossy/github/client.rb, line 76 def http @http ||= Faraday.new(url: BASE_URL, headers: headers) do |conn| conn.basic_auth(settings.github_login, settings.github_token) end end
member(name, org:)
click to toggle source
# File lib/ossy/github/client.rb, line 44 def member(name, org:) path = "orgs/#{org}/members" resp = get(path) return nil unless resp.status.equal?(200) JSON.parse(resp.body) .map { |member| user(member["login"]) } .detect { |user| user["name"].eql?(name) } end
membership?(username, org:, team:)
click to toggle source
# File lib/ossy/github/client.rb, line 15 def membership?(username, org:, team:) path = "orgs/#{org}/teams/#{team}/memberships/#{username}" resp = get(path) return false unless resp.status.equal?(200) json = JSON.parse(resp.body) json["state"].eql?("active") end
post(path, input)
click to toggle source
# File lib/ossy/github/client.rb, line 72 def post(path, input) request(:post, path, JSON.dump(input)) end
request(meth, path, opts = {})
click to toggle source
# File lib/ossy/github/client.rb, line 64 def request(meth, path, opts = {}) http.public_send(meth, path, opts) end
tagger(repo:, tag:)
click to toggle source
# File lib/ossy/github/client.rb, line 26 def tagger(repo:, tag:) path = "repos/#{repo}/git/ref/tags/#{tag}" resp = get(path) return false unless resp.status.equal?(200) sha = JSON.parse(resp.body)["object"]["sha"] path = "repos/#{repo}/git/tags/#{sha}" resp = get(path) return false unless resp.status.equal?(200) json = JSON.parse(resp.body) { tagger: json["tagger"], verified: json["verification"]["verified"] } end
user(login)
click to toggle source
# File lib/ossy/github/client.rb, line 55 def user(login) path = "users/#{login}" resp = get(path) return nil unless resp.status.equal?(200) JSON.parse(resp.body) end