Sha256: 98e23cf8fc6bc3aa034bd98cb3c7fe43445e7dd166ca88fc3f2da36a61a7bda6

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

require 'octokit'
require 'sinatra_auth_github'
require 'dotenv'
require_relative 'add-to-org/server'

Dotenv.load

module AddToOrg
  class App < Sinatra::Base

    set :github_options, {
      :scopes    => "user,user:email",
      :secret    => ENV['GITHUB_CLIENT_SECRET'],
      :client_id => ENV['GITHUB_CLIENT_ID']
    }

    def user
      env['warden'].user
    end

   # user client
    def client
      @client ||= Octokit::Client.new :access_token => user.token
    end

     # new org admin client
    def sudo_client
      @sudo_client ||= Octokit::Client.new :access_token => ENV['GITHUB_TOKEN']
    end

    # query api for the user's verified emails
    def verified_emails
      emails = client.emails :accept => 'application/vnd.github.v3'
      emails.select { |email| email.verified }
    end

     # true if user is already a member of the org
    def member?
      client.organization_member? org_id, user.login
    end

    def valid?
      raise "You must define a custom valid? method to determine eligibility"
    end

    def team_id
      ENV['GITHUB_TEAM_ID']
    end

    def org_id
      ENV['GITHUB_ORG_ID']
    end

    # the main event...
    def add
      sudo_client.add_team_member team_id, user.login
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
add-to-org-0.0.1 lib/add-to-org.rb