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
Commit lock author #901
Commit lock author #901
Conversation
a570b23
to
5458ffe
Compare
@@ -76,6 +76,7 @@ | |||
t.string "pull_request_title", limit: 1024 | |||
t.integer "pull_request_id" | |||
t.boolean "locked", default: false, null: false | |||
t.integer "lock_author_id", limit: 4 |
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.
Done to match
shipit-engine/test/dummy/db/schema.rb
Line 206 in 5458ffe
t.integer "lock_author_id", limit: 4 |
Fixed the Rubocop violations |
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.
❤️
Wait, there is another code path, that might need change. |
@davidcornu Here the other path that would need author handling: shipit-engine/app/models/shipit/stack.rb Line 254 in f6b93d8
|
app/models/shipit/stack.rb
Outdated
@@ -239,7 +239,7 @@ def status | |||
:default | |||
end | |||
|
|||
def lock_reverted_commits! | |||
def lock_reverted_commits!(user = AnonymousUser.new) |
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.
There's another code path that uses this
shipit-engine/app/jobs/shipit/github_sync_job.rb
Lines 15 to 22 in 868398f
new_commits, shared_parent = fetch_missing_commits { @stack.github_commits } | |
@stack.transaction do | |
shared_parent&.detach_children! | |
appended_commits = new_commits.map do |gh_commit| | |
append_commit(gh_commit) | |
end | |
@stack.lock_reverted_commits! if appended_commits.any?(&:revert?) |
I left that one as commits being locked as a result of syncing with GH don't have an obvious lock author.
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.
syncing with GH don't have an obvious lock author.
I would have used the revert author, but both are fine.
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.
🤔 Given appended_commits.any?(&:revert?)
, there could be multiple no?
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.
In SyncJob yes, but here:
shipit-engine/app/models/shipit/stack.rb
Lines 248 to 249 in f6b93d8
if revert = backlog.shift | |
commits_to_lock += backlog.reverse.drop_while { |c| !revert.revert_of?(c) } |
It's not ambiguous.
5b945ec
to
be75dbe
Compare
@@ -240,21 +240,23 @@ def status | |||
end | |||
|
|||
def lock_reverted_commits! |
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.
@casperisfine thoughts on this change? I refactored the logic to lock in batches rather than all at once so the lock_author
can be set to the revert commit author.
Tests are gonna fail. Will fix after work.
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.
LGTM. I'd use affected_rows
rather than affected
though /nitpick.
@@ -729,5 +730,105 @@ def setup | |||
|
|||
@stack.async_refresh_deployed_revision | |||
end | |||
|
|||
test "#lock_reverted_commits! locks all commits between the original and reverted commits" do |
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.
Ended up adding a bunch of test coverage here as there's some in
shipit-engine/test/jobs/github_sync_job_test.rb
Lines 39 to 87 in 22403f4
test "#perform locks all commits leading to a revert" do | |
@stack.deploys_and_rollbacks.destroy_all | |
initial_queue = [ | |
["whoami", false], | |
["fix all the things", false], | |
["yoloshipit!", false], | |
["fix it!", false], | |
["sheep it!", false], | |
["lets go", false], | |
] | |
assert_equal initial_queue, @stack.undeployed_commits.map { |c| [c.title, c.locked?] } | |
author = stub( | |
id: 1234, | |
login: 'bob', | |
name: 'Bob the Builder', | |
email: 'bob@bob.com', | |
date: '2011-04-14T16:00:49Z', | |
) | |
@job.expects(:fetch_missing_commits).returns([ | |
[ | |
stub( | |
sha: '36514755579bfb5bc313f403b216f4347a027990', | |
author: author, | |
committer: author, | |
stats: nil, | |
commit: stub( | |
sha: '36514755579bfb5bc313f403b216f4347a027990', | |
message: 'Revert "fix it!"', | |
author: author, | |
committer: author, | |
), | |
), | |
], | |
shipit_commits(:fifth), | |
]) | |
@job.perform(stack_id: @stack.id) | |
final_queue = [ | |
['Revert "fix it!"', false], | |
["fix all the things", true], | |
["yoloshipit!", true], | |
["fix it!", true], | |
["sheep it!", false], | |
["lets go", false], | |
] | |
assert_equal final_queue, @stack.reload.undeployed_commits.map { |c| [c.title, c.locked?] } | |
end |
shipit-engine/test/models/rollbacks_test.rb
Lines 22 to 56 in 22403f4
test "when a rollback succeed reverted commits are locked" do | |
@stack.tasks.where.not(id: shipit_tasks(:shipit_complete).id).delete_all | |
deploy = @stack.deploys.success.last | |
reverted_commit = deploy.until_commit | |
@stack.commits.create!( | |
sha: '50ce7d4440fcd8c734f8b7b76c86f8db46706e4f', | |
message: %(Revert "#{reverted_commit.message_header}"), | |
author: reverted_commit.author, | |
committer: reverted_commit.committer, | |
authored_at: Time.zone.now, | |
committed_at: Time.zone.now, | |
) | |
expected = [ | |
['Revert "Merge pull request #7 from shipit-engine/yoloshipit"', false, nil], | |
["whoami", false, nil], | |
['fix all the things', false, nil], | |
] | |
assert_equal(expected, @stack.undeployed_commits.map { |c| [c.title, c.locked?, c.lock_author_id] }) | |
rollback = deploy.trigger_revert | |
rollback.run! | |
rollback.complete! | |
user_id = reverted_commit.author.id | |
expected = [ | |
['Revert "Merge pull request #7 from shipit-engine/yoloshipit"', false, nil], | |
["whoami", true, user_id], | |
['fix all the things', true, user_id], | |
['yoloshipit!', true, user_id], | |
] | |
assert_equal(expected, @stack.undeployed_commits.map { |c| [c.title, c.locked?, c.lock_author_id] }) | |
end |
I've also split the addition of these tests and the refactor into separate commits so it's more obvious what my changes actually did.
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.
This looks great, thanks for stepping up ✨
Implements #860.