mirror of
https://github.com/czhu12/canine.git
synced 2025-12-21 10:49:49 -06:00
updates
This commit is contained in:
@@ -6,11 +6,10 @@ class Providers::CreateGithubProvider
|
||||
promises :provider
|
||||
|
||||
executed do |context|
|
||||
client_options = { access_token: context.provider.access_token }
|
||||
if context.provider.enterprise?
|
||||
client_options[:api_endpoint] = "#{context.provider.api_base_url}/api/v3/"
|
||||
end
|
||||
client = Octokit::Client.new(client_options)
|
||||
client = Git::Github::Client.build_client(
|
||||
access_token: context.provider.access_token,
|
||||
api_base_url: context.provider.api_base_url
|
||||
)
|
||||
username = client.user[:login]
|
||||
context.provider.auth = {
|
||||
info: {
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
class Integrations::Github::RepositoriesController < ApplicationController
|
||||
def index
|
||||
client = Octokit::Client.new(access_token: current_account.github_provider.access_token)
|
||||
provider = current_account.github_provider
|
||||
client = Git::Github::Client.build_client(
|
||||
access_token: provider.access_token,
|
||||
api_base_url: provider.api_base_url
|
||||
)
|
||||
if params[:q].present?
|
||||
client.auto_paginate = true
|
||||
@repositories = client.repos(current_account.github_username)
|
||||
|
||||
@@ -12,6 +12,14 @@ class Git::Github::Client < Git::Client
|
||||
)
|
||||
end
|
||||
|
||||
def self.build_client(access_token:, api_base_url: nil)
|
||||
client_options = { access_token: }
|
||||
if api_base_url && api_base_url != "https://api.github.com"
|
||||
client_options[:api_endpoint] = "#{api_base_url}/api/v3/"
|
||||
end
|
||||
Octokit::Client.new(client_options)
|
||||
end
|
||||
|
||||
def commits(branch)
|
||||
client.commits(repository_url, branch).map do |commit|
|
||||
Git::Common::Commit.new(
|
||||
@@ -29,11 +37,7 @@ class Git::Github::Client < Git::Client
|
||||
end
|
||||
|
||||
def initialize(access_token:, repository_url:, api_base_url: nil)
|
||||
client_options = { access_token: }
|
||||
if api_base_url && api_base_url != "https://api.github.com"
|
||||
client_options[:api_endpoint] = "#{api_base_url}/api/v3/"
|
||||
end
|
||||
@client = Octokit::Client.new(client_options)
|
||||
@client = self.class.build_client(access_token:, api_base_url:)
|
||||
@repository_url = repository_url
|
||||
end
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ RSpec.describe Providers::Create do
|
||||
let(:provider) { build(:provider, :github) }
|
||||
context 'when the access token is valid' do
|
||||
before do
|
||||
allow(Octokit::Client).to receive(:new).and_return(double(user: { login: 'test_user' }, scopes: [ 'repo', 'write:packages' ]))
|
||||
allow(Git::Github::Client).to receive(:build_client).and_return(double(user: { login: 'test_user' }, scopes: [ 'repo', 'write:packages' ]))
|
||||
end
|
||||
|
||||
it 'sets the provider auth info' do
|
||||
@@ -37,7 +37,7 @@ RSpec.describe Providers::Create do
|
||||
|
||||
context 'when the access token is invalid' do
|
||||
before do
|
||||
allow(Octokit::Client).to receive(:new).and_raise(Octokit::Unauthorized)
|
||||
allow(Git::Github::Client).to receive(:build_client).and_raise(Octokit::Unauthorized)
|
||||
end
|
||||
|
||||
it 'adds an error to the provider' do
|
||||
@@ -48,7 +48,7 @@ RSpec.describe Providers::Create do
|
||||
|
||||
context 'when the scopes are invalid' do
|
||||
before do
|
||||
allow(Octokit::Client).to receive(:new).and_return(double(user: { login: 'test_user' }, scopes: [ 'repo' ]))
|
||||
allow(Git::Github::Client).to receive(:build_client).and_return(double(user: { login: 'test_user' }, scopes: [ 'repo' ]))
|
||||
end
|
||||
|
||||
it 'fails the context with an invalid scopes message' do
|
||||
|
||||
Reference in New Issue
Block a user