-
-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make user_id foreign key for github team members #7027
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8fc1c82
Fix foreign key
ErikSchierboom 800dab0
Simplify model
ErikSchierboom dc8ce1a
Fix database
ErikSchierboom ca0f145
Simplify create and destroy
ErikSchierboom 8298f79
Fix syncing members
ErikSchierboom d7a210b
Fix tests
ErikSchierboom 85c1560
Fix missing group
ErikSchierboom 5f8612e
Don't destroy unnecessarily
ErikSchierboom 22ce993
Don't unnecessarily update team member maintainer check
ErikSchierboom f790640
Fix tests
ErikSchierboom bc9dd8a
Another test fix
ErikSchierboom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
class Github::TeamMember::Create | ||
include Mandate | ||
|
||
initialize_with :user_id, :team_name | ||
initialize_with :github_uid, :team_name | ||
|
||
def call | ||
::Github::TeamMember.find_create_or_find_by!(user_id:, team_name:).tap do | ||
User::UpdateMaintainer.(user) if user | ||
return unless user | ||
|
||
user.github_team_memberships.find_or_create_by!(team_name:).tap do |team_member| | ||
User::UpdateMaintainer.(user) if team_member.previously_new_record? | ||
end | ||
end | ||
|
||
memoize | ||
def user = User.find_by(uid: user_id) | ||
def user = User.find_by(uid: github_uid) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
class Github::TeamMember::Destroy | ||
include Mandate | ||
|
||
initialize_with :user_id, :team_name | ||
initialize_with :github_uid, :team_name | ||
|
||
def call | ||
::Github::TeamMember.where(user_id:, team_name:).destroy_all.tap do | ||
User::UpdateMaintainer.(user) if user | ||
end | ||
return unless user | ||
return unless team_member | ||
|
||
team_member.delete | ||
User::UpdateMaintainer.(user) | ||
end | ||
|
||
memoize | ||
def user = User.find_by(uid: user_id) | ||
def user = User.find_by(uid: github_uid) | ||
|
||
memoize | ||
def team_member = Github::TeamMember.find_by(user:, team_name:) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,3 @@ | ||
class Github::TeamMember < ApplicationRecord | ||
has_one :user, | ||
foreign_key: :uid, | ||
primary_key: :user_id, | ||
class_name: "User", | ||
inverse_of: :github_team_memberships, | ||
dependent: :destroy | ||
belongs_to :user | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
db/migrate/20240813125214_change_user_id_to_foreign_key_in_github_team_members.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class ChangeUserIdToForeignKeyInGithubTeamMembers < ActiveRecord::Migration[7.0] | ||
def change | ||
return if Rails.env.production? | ||
|
||
# We'll re-sync the data using Github::TeamMember::SyncMembers.() | ||
Github::TeamMember.delete_all | ||
|
||
remove_index :github_team_members, name: "index_github_team_members_on_user_id_and_team_name" | ||
remove_column :github_team_members, :user_id, :string | ||
|
||
add_reference :github_team_members, :user, null: false, foreign_key: { to_table: :users }, if_not_exists: true | ||
add_index :github_team_members, %i[user_id team_name], unique: true, if_not_exists: true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made it explicit that this is the GitHub UID.