Skip to content

Commit

Permalink
downcase github handle (#639)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienpoly authored Feb 19, 2025
1 parent 96b206f commit 0859de4
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
2 changes: 2 additions & 0 deletions app/models/connected_account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ class ConnectedAccount < ApplicationRecord
belongs_to :user

encrypts :access_token

normalizes :username, with: ->(value) { value.strip.downcase }
end
4 changes: 3 additions & 1 deletion app/models/speaker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ class Speaker < ApplicationRecord
scope :not_canonical, -> { where.not(canonical_id: nil) }

# normalizes
normalizes :github, with: ->(value) { value.gsub(/^(?:https?:\/\/)?(?:www\.)?github\.com\//, "").gsub(/^@/, "") }
normalizes :github, with: ->(value) {
value.gsub(/^(?:https?:\/\/)?(?:www\.)?github\.com\//, "").gsub(/^@/, "").downcase
}
normalizes :twitter, with: ->(value) { value.gsub(%r{https?://(?:www\.)?(?:x\.com|twitter\.com)/}, "").gsub(/@/, "") }
normalizes :bsky, with: ->(value) {
value.gsub(%r{https?://(?:www\.)?(?:x\.com|bsky\.app/profile)/}, "").gsub(/@/, "")
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def self.normalize_github_handle(value)
value
.gsub(GITHUB_URL_PATTERN, "")
.delete("@")
.strip
.strip.downcase
end

after_update if: :password_digest_previously_changed? do
Expand Down
18 changes: 18 additions & 0 deletions db/migrate/20250218073648_normalize_github_handle.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class NormalizeGitHubHandle < ActiveRecord::Migration[8.0]
def change
User.all.each do |u|
next if u.github_handle.blank?
u.update_column(:github_handle, u.github_handle.strip.downcase)
end

ConnectedAccount.all.each do |ca|
next if ca.username.blank?

ca.update_column(:username, ca.username.strip.downcase)
end

Speaker.where.not(github: [nil, ""]).each do |s|
s.update_column(:github, s.github.strip.downcase)
end
end
end
2 changes: 1 addition & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0859de4

Please sign in to comment.