Replace need for GitHub ENV vars on bootup (#10372)
* Un-eagerload dev mode * Change approach * Fix for_user * Fix spec? * Fix spec? * Fix spec? * Fix spec? * Fix spec?
This commit is contained in:
parent
3be3fcf5d0
commit
1a531bca0e
7 changed files with 13 additions and 38 deletions
|
|
@ -82,7 +82,7 @@ module BadgeRewarder
|
|||
return unless badge
|
||||
|
||||
REPOSITORIES.each do |repo|
|
||||
commits = Github::Client.commits(repo, since: since.utc.iso8601)
|
||||
commits = Github::OauthClient.new.commits(repo, since: since.utc.iso8601)
|
||||
|
||||
authors_uids = commits.map { |commit| commit.author.id }
|
||||
Identity.github.where(uid: authors_uids).find_each do |i|
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ class GithubTag
|
|||
end
|
||||
|
||||
def render
|
||||
content = Github::Client.repository(repository_path)
|
||||
content = Github::OauthClient.new.repository(repository_path)
|
||||
|
||||
if show_readme?
|
||||
readme_html = fetch_readme(repository_path)
|
||||
|
|
@ -59,8 +59,8 @@ class GithubTag
|
|||
end
|
||||
|
||||
def fetch_readme(repository_path)
|
||||
readme_html = Github::Client.readme(repository_path, accept: "application/vnd.github.html")
|
||||
readme = Github::Client.readme(repository_path)
|
||||
readme_html = Github::OauthClient.new.readme(repository_path, accept: "application/vnd.github.html")
|
||||
readme = Github::OauthClient.new.readme(repository_path)
|
||||
clean_relative_path!(readme_html, readme.download_url)
|
||||
rescue Github::Errors::NotFound
|
||||
nil
|
||||
|
|
|
|||
|
|
@ -31,17 +31,17 @@ class GithubIssue < ApplicationRecord
|
|||
|
||||
if PATH_COMMENT_REGEXP.match?(url)
|
||||
repo, issue_id = comment_repo_and_issue_id(url)
|
||||
issue.issue_serialized = Github::Client.issue_comment(repo, issue_id).to_h
|
||||
issue.issue_serialized = Github::OauthClient.new.issue_comment(repo, issue_id).to_h
|
||||
issue.category = "issue_comment"
|
||||
else
|
||||
repo, issue_id = issue_or_pull_repo_and_issue_id(url)
|
||||
issue.issue_serialized = Github::Client.issue(repo, issue_id).to_h
|
||||
issue.issue_serialized = Github::OauthClient.new.issue(repo, issue_id).to_h
|
||||
issue.category = "issue"
|
||||
end
|
||||
|
||||
# despite the counter intuitive name `.markdown` returns HTML rendered
|
||||
# from the original markdown
|
||||
issue.processed_html = Github::Client.markdown(issue.issue_serialized[:body])
|
||||
issue.processed_html = Github::OauthClient.new.markdown(issue.issue_serialized[:body])
|
||||
|
||||
issue.save!
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +0,0 @@
|
|||
module Github
|
||||
# Github client with Application Authentication (uses ocktokit.rb as a backend)
|
||||
Client = OauthClient.new(
|
||||
client_id: ApplicationConfig["GITHUB_KEY"],
|
||||
client_secret: ApplicationConfig["GITHUB_SECRET"],
|
||||
)
|
||||
end
|
||||
|
|
@ -5,7 +5,11 @@ module Github
|
|||
APP_AUTH_CREDENTIALS_PRESENT = proc { |key, value| APP_AUTH_CREDENTIALS.include?(key) && value.present? }.freeze
|
||||
|
||||
# @param credentials [Hash] the OAuth credentials, {client_id:, client_secret:} or {access_token:}
|
||||
def initialize(credentials)
|
||||
def initialize(credentials = nil)
|
||||
credentials ||= {
|
||||
client_id: SiteConfig.github_key,
|
||||
client_secret: SiteConfig.github_secret
|
||||
}
|
||||
@credentials = check_credentials!(credentials)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ RSpec.describe GithubTag::GithubReadmeTag, type: :liquid_tag, vcr: true do
|
|||
end
|
||||
|
||||
it "renders a repository with a missing README" do
|
||||
allow(Github::Client).to receive(:readme).and_raise(Github::Errors::NotFound)
|
||||
allow_any_instance_of(Github::OauthClient).to receive(:readme).and_raise(Github::Errors::NotFound)
|
||||
|
||||
VCR.use_cassette("github_client_repository") do
|
||||
template = generate_tag(url_repository).render
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe Github::Client, type: :service, vcr: true do
|
||||
let(:repo) { "thepracticaldev/dev.to" }
|
||||
|
||||
describe ".issue" do
|
||||
it "returns a an issue" do
|
||||
VCR.use_cassette("github_client_issue") do
|
||||
issue = described_class.issue(repo, 7434)
|
||||
expect(issue.title).to be_present
|
||||
end
|
||||
end
|
||||
|
||||
it "raises NotFound if the issue does not exist" do
|
||||
VCR.use_cassette("github_client_issue_not_found") do
|
||||
expect do
|
||||
described_class.issue(repo, 0)
|
||||
end.to raise_error(Github::Errors::NotFound)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Reference in a new issue