Skip to content

Commit

Permalink
Merge branch 'main' into fixes/vanilla-error
Browse files Browse the repository at this point in the history
  • Loading branch information
gazayas committed Aug 9, 2023
2 parents 7f552af + 93570a0 commit 8165d5d
Show file tree
Hide file tree
Showing 237 changed files with 1,945 additions and 1,173 deletions.
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ orbs:
browser-tools: circleci/[email protected]
aliases:
- &ruby_node_browsers_docker_image
- image: cimg/ruby:3.2.1-browsers
- image: cimg/ruby:3.2.2-browsers
environment:
PGHOST: localhost
PGUSER: untitled_application
Expand All @@ -29,7 +29,7 @@ jobs:
steps:
- checkout
- browser-tools/install-browser-tools:
firefox-version: 108.0.1
firefox-version: "112.0"

- ruby/install-deps:
clean-bundle: true
Expand Down Expand Up @@ -62,7 +62,7 @@ jobs:
- checkout:
path: ~/project
- browser-tools/install-browser-tools:
firefox-version: 108.0.1
firefox-version: "112.0"

# TODO: This is a workaround to get `git clone` working, but it shouldn't be here.
# https://github.com/CircleCI-Public/browser-tools-orb/issues/62
Expand Down Expand Up @@ -114,7 +114,7 @@ jobs:
- checkout:
path: ~/project
- browser-tools/install-browser-tools:
firefox-version: 108.0.1
firefox-version: "112.0"

# TODO: This is a workaround to get `git clone` working, but it shouldn't be here.
# https://github.com/CircleCI-Public/browser-tools-orb/issues/62
Expand Down
8 changes: 0 additions & 8 deletions .standard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,5 @@ ignore:
- Lint/RescueException # TODO would it be okay to rescue `StandardError`?
- '*/lib/scaffolding/transformer.rb':
- Layout/EndAlignment
# TODO Fix these files up for Standard Ruby.
- '*/lib/bullet_train/super_scaffolding/scaffolders/oauth_provider_scaffolder.rb'
- '*/lib/tasks/bullet_train/themes/light_tasks.rake':
- Style/CommandLiteral
- '*/config/routes.rb':
- Lint/UselessAssignment
- '*/app/helpers/theme_helper.rb':
- Style/GlobalVars
- '*/app/models/concerns/webhooks/outgoing/uri_filtering.rb':
- Lint/ShadowedException
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby "3.2.1"
ruby "3.2.2"

gem "standard"
4 changes: 3 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ GEM
PLATFORMS
arm64-darwin-20
arm64-darwin-21
arm64-darwin-22
ruby
x86_64-linux

DEPENDENCIES
standard

RUBY VERSION
ruby 3.2.1p31
ruby 3.2.2p53

BUNDLED WITH
2.3.8
12 changes: 9 additions & 3 deletions bin/checkout-and-link-starter-repo
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@ STARTER_REPO_BRANCH="main"

# Look for a matching branch on the starter repository when running tests on CircleCI.
CI_BRANCH=$CIRCLE_BRANCH
if [[ -v CI_BRANCH ]]; then
BRANCH_RESPONSE=$(curl --head -H "Accept: application.vnd.github+json" https://api.github.com/repos/bullet-train-co/bullet_train/branches/$CI_BRANCH)
if [[ -v CI_BRANCH ]]
then
BRANCH_RESPONSE=$(curl --verbose -H "Accept: application.vnd.github+json" https://api.github.com/repos/bullet-train-co/bullet_train/branches/$CI_BRANCH)

if echo $BRANCH_RESPONSE | grep "200"; then
echo "Branch response ===================="
echo $BRANCH_RESPONSE

# If the branch is missing in the repo the response will not contain the branch name
if echo $BRANCH_RESPONSE | grep "$CIRCLE_BRANCH"; then
STARTER_REPO_BRANCH=$CI_BRANCH
fi
fi

echo "Cloning from ${STARTER_REPO_BRANCH}..."
git clone -b $STARTER_REPO_BRANCH --depth 1 https://github.com/bullet-train-co/bullet_train.git .

# TODO: Maybe generate this list automatically based on the subdirectories in core that contain a .gemspec?
packages=(
"bullet_train"
"bullet_train-api"
Expand Down
2 changes: 1 addition & 1 deletion bullet_train-api/.circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ aliases:
paths:
- node_modules
- &ruby_node_browsers_docker_image
- image: cimg/ruby:3.1.2-browsers
- image: cimg/ruby:3.2.2-browsers
environment:
PGHOST: localhost
PGUSER: untitled_application
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def destroy
include strong_parameters_from_api

def process_params(strong_params)
assign_date_and_time(strong_params, :last_used_at)
# 🚅 super scaffolding will insert processing for new fields above this line.
end
end
125 changes: 1 addition & 124 deletions bullet_train-api/app/controllers/api/open_api_controller.rb
Original file line number Diff line number Diff line change
@@ -1,128 +1,5 @@
module OpenApiHelper
def indent(string, count)
lines = string.lines
first_line = lines.shift
lines = lines.map { |line| (" " * count).to_s + line }
lines.unshift(first_line).join.html_safe
end

# TODO: Remove this method? It's not being used anywhere
def components_for(model)
for_model model do
indent(render("api/#{@version}/open_api/#{model.name.underscore.pluralize}/components"), 2)
end
end

def current_model
@model_stack.last
end

def for_model(model)
@model_stack ||= []
@model_stack << model
result = yield
@model_stack.pop
result
end

def gem_paths
@gem_paths ||= `bundle show --paths`.lines.map { |gem_path| gem_path.chomp }
end

def automatic_paths_for(model, parent, except: [])
output = render("api/#{@version}/open_api/shared/paths", except: except)
output = Scaffolding::Transformer.new(model.name, [parent&.name]).transform_string(output).html_safe
indent(output, 1)
end

def automatic_components_for(model, locals: {})
path = "app/views/api/#{@version}"
paths = ([path] + gem_paths.map { |gem_path| "#{gem_path}/#{path}" })
jbuilder = Jbuilder::Schema.renderer(paths, locals: {
# If we ever get to the point where we need a real model here, we should implement an example team in seeds that we can source it from.
model.name.underscore.split("/").last.to_sym => model.new,
# Same here, if we ever need this to be a real object, this should be `[email protected]` with an `SecureRandom.hex` password.
:current_user => User.new
}.merge(locals))

schema_json = jbuilder.json(
model.new,
title: I18n.t("#{model.name.underscore.pluralize}.label"),
# TODO Improve this. We don't have a generic description for models we can use here.
description: I18n.t("#{model.name.underscore.pluralize}.label"),
)

attributes_output = JSON.parse(schema_json)

# Rails attachments aren't technically attributes in a model,
# so we add the attributes manually to make them available in the API.
if model.attachment_reflections.any?
model.attachment_reflections.each do |reflection|
attribute_name = reflection.first

attributes_output["properties"][attribute_name] = {
"type" => "object",
"description" => attribute_name.titleize.to_s
}

attributes_output["example"].merge!({attribute_name.to_s => nil})
end
end

if has_strong_parameters?("Api::#{@version.upcase}::#{model.name.pluralize}Controller".constantize)
strong_params_module = "Api::#{@version.upcase}::#{model.name.pluralize}Controller::StrongParameters".constantize
strong_parameter_keys = BulletTrain::Api::StrongParametersReporter.new(model, strong_params_module).report
if strong_parameter_keys.last.is_a?(Hash)
strong_parameter_keys += strong_parameter_keys.pop.keys
end

parameters_output = JSON.parse(schema_json)
parameters_output["required"].select! { |key| strong_parameter_keys.include?(key.to_sym) }
parameters_output["properties"].select! { |key, value| strong_parameter_keys.include?(key.to_sym) }

(
indent(attributes_output.to_yaml.gsub("---", "#{model.name.gsub("::", "")}Attributes:"), 3) +
indent(" " + parameters_output.to_yaml.gsub("---", "#{model.name.gsub("::", "")}Parameters:"), 3)
).html_safe
else

indent(attributes_output.to_yaml.gsub("---", "#{model.name.gsub("::", "")}Attributes:"), 3)
.html_safe
end
end

def paths_for(model)
for_model model do
indent(render("api/#{@version}/open_api/#{model.name.underscore.pluralize}/paths"), 1)
end
end

def attribute(attribute)
heading = t("#{current_model.name.underscore.pluralize}.fields.#{attribute}.heading")
attribute_data = current_model.columns_hash[attribute.to_s]

# Default to `string` when the type returns nil.
type = attribute_data.nil? ? "string" : attribute_data.type

attribute_block = <<~YAML
#{attribute}:
description: "#{heading}"
type: #{type}
YAML
indent(attribute_block.chomp, 2)
end
alias_method :parameter, :attribute

private

def has_strong_parameters?(controller)
methods = controller.action_methods
methods.include?("create") || methods.include?("update")
end
end

class Api::OpenApiController < ApplicationController
helper :open_api
helper "api/open_api"

def set_default_response_format
request.format = :yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ def current_user
end

# TODO Remove this rescue once workspace clusters can write to this column on the identity server.
# TODO Make this logic configurable so that downstream developers can write different methods for this column getting updated.
if doorkeeper_token
begin
doorkeeper_token.update(last_used_at: Time.zone.now)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def user_params
:first_name,
:last_name,
:time_zone,
:locale
:locale,
:profile_photo_id
]

selected_fields = if params.is_a?(BulletTrain::Api::StrongParametersReporter)
Expand Down
Loading

0 comments on commit 8165d5d

Please sign in to comment.