Skip to content
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

Merged
merged 9 commits into from May 8, 2019
Merged

Commit lock author #901

merged 9 commits into from May 8, 2019

Conversation

davidcornu
Copy link
Contributor

@davidcornu davidcornu commented May 2, 2019

Implements #860.

image

@davidcornu davidcornu self-assigned this May 2, 2019
@davidcornu davidcornu changed the title [WIP] Lock author [WIP] Commit lock author May 2, 2019
@davidcornu davidcornu force-pushed the lock-author branch 2 times, most recently from a570b23 to 5458ffe Compare May 2, 2019 14:57
@@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done to match

t.integer "lock_author_id", limit: 4

@davidcornu davidcornu changed the title [WIP] Commit lock author Commit lock author May 2, 2019
@davidcornu
Copy link
Contributor Author

Fixed the Rubocop violations

Copy link
Contributor

@casperisfine casperisfine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

@casperisfine
Copy link
Contributor

Wait, there is another code path, that might need change.

@casperisfine
Copy link
Contributor

@davidcornu Here the other path that would need author handling:

if commits.where(id: commits_to_lock.map(&:id).uniq).update_all(locked: true) > 1

@@ -239,7 +239,7 @@ def status
:default
end

def lock_reverted_commits!
def lock_reverted_commits!(user = AnonymousUser.new)
Copy link
Contributor Author

@davidcornu davidcornu May 3, 2019

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

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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:

if revert = backlog.shift
commits_to_lock += backlog.reverse.drop_while { |c| !revert.revert_of?(c) }

It's not ambiguous.

@davidcornu davidcornu force-pushed the lock-author branch 2 times, most recently from 5b945ec to be75dbe Compare May 3, 2019 12:13
@@ -240,21 +240,23 @@ def status
end

def lock_reverted_commits!
Copy link
Contributor Author

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.

Copy link
Contributor

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
Copy link
Contributor Author

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

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
and
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
but not enough to convince me that I wasn't breaking anything with the refactor.

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.

@davidcornu davidcornu requested a review from DazWorrall May 7, 2019 16:03
Copy link
Member

@DazWorrall DazWorrall left a 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 ✨

@davidcornu davidcornu merged commit 033ea77 into master May 8, 2019
@davidcornu davidcornu deleted the lock-author branch May 8, 2019 11:01
@casperisfine casperisfine temporarily deployed to rubygems July 19, 2019 09:47 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants