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

fix timeouts caused by stashing large failed changes #11309

Merged
merged 3 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions common/lib/dependabot/workspace/change_attempt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ module Workspace
class ChangeAttempt
extend T::Sig

sig { returns(T.nilable(String)) }
attr_reader :diff

sig { returns(T.nilable(StandardError)) }
attr_reader :error

Expand All @@ -28,15 +25,13 @@ class ChangeAttempt
workspace: Dependabot::Workspace::Base,
id: String,
memo: T.nilable(String),
diff: T.nilable(String),
error: T.nilable(StandardError)
).void
end
def initialize(workspace, id:, memo:, diff: nil, error: nil)
def initialize(workspace, id:, memo:, error: nil)
@workspace = workspace
@id = id
@memo = memo
@diff = diff
@error = error
end

Expand Down
23 changes: 8 additions & 15 deletions common/lib/dependabot/workspace/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ def store_change(memo = nil)
return nil if changed_files(ignored_mode: "no").empty?

debug("store_change - before: #{current_commit}")
sha, diff = commit(memo)
sha = commit(memo)

change_attempts << ChangeAttempt.new(self, id: sha, memo: memo, diff: diff)
change_attempts << ChangeAttempt.new(self, id: sha, memo: memo)
ensure
debug("store_change - after: #{current_commit}")
end
Expand All @@ -73,8 +73,8 @@ def store_change(memo = nil)
def capture_failed_change_attempt(memo = nil, error = nil)
return nil if changed_files(ignored_mode: "matching").empty? && error.nil?

sha, diff = stash(memo)
change_attempts << ChangeAttempt.new(self, id: sha, memo: memo, diff: diff, error: error)
sha = stash(memo)
change_attempts << ChangeAttempt.new(self, id: sha, memo: memo, error: error)
end

private
Expand Down Expand Up @@ -112,7 +112,7 @@ def changed_files(ignored_mode: "traditional")
).strip
end

sig { params(memo: T.nilable(String)).returns([String, String]) }
sig { params(memo: T.nilable(String)).returns(String) }
def stash(memo = nil)
msg = memo || "workspace change attempt"
run_shell_command("git add --all --force .")
Expand All @@ -122,19 +122,12 @@ def stash(memo = nil)
allow_unsafe_shell_command: true
)

sha = last_stash_sha
diff = run_shell_command(
"git stash show --patch #{sha}",
fingerprint: "git stash show --patch <sha>"
)

[sha, diff]
last_stash_sha
end

sig { params(memo: T.nilable(String)).returns([String, String]) }
sig { params(memo: T.nilable(String)).returns(String) }
def commit(memo = nil)
run_shell_command("git add #{path}")
diff = run_shell_command("git diff --cached .")

msg = memo || "workspace change"
run_shell_command(
Expand All @@ -143,7 +136,7 @@ def commit(memo = nil)
allow_unsafe_shell_command: true
)

[head_sha, diff]
head_sha
end

sig { params(sha: String).returns(String) }
Expand Down
33 changes: 0 additions & 33 deletions common/spec/dependabot/workspace/git_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,6 @@
workspace.store_change("rspec")
end

it "returns the diff of all changes" do
expect(workspace.changes.size).to eq(2)
expect(workspace.to_patch).to end_with(
<<~DIFF
gem "activesupport", ">= 6.0.0"
+gem "rspec", "~> 3.12.0", group: :test
+gem "timecop", "~> 0.9.6", group: :test
DIFF
)
end

context "when there are failed change attempts" do
before do
workspace.change("fail") do
Expand Down Expand Up @@ -123,12 +112,6 @@
expect(workspace.failed_change_attempts.size).to eq(1)
expect(workspace.change_attempts.size).to eq(1)
expect(workspace.change_attempts.first.id).to eq(`git rev-parse refs/stash`.strip)
expect(workspace.change_attempts.first.diff).to end_with(
<<~DIFF
gem "activesupport", ">= 6.0.0"
+gem "timecop", "~> 0.9.6", group: :test
DIFF
)
expect(workspace.change_attempts.first.memo).to eq("timecop")
expect(workspace.change_attempts.first.error).not_to be_nil
expect(workspace.change_attempts.first.error.message).to eq("uh oh")
Expand All @@ -152,16 +135,6 @@

it "captures the untracked/ignored files" do
expect(workspace.failed_change_attempts.size).to eq(1)
expect(workspace.failed_change_attempts.first.diff).to include(
<<~DIFF
gem "activesupport", ">= 6.0.0"
+gem "fail"
DIFF
)
expect(workspace.failed_change_attempts.first.diff).to include(
"diff --git a/ignored-file.txt b/ignored-file.txt",
"diff --git a/untracked-file.txt b/untracked-file.txt"
)
end
end
end
Expand Down Expand Up @@ -253,12 +226,6 @@
expect(workspace).to be_changed
expect(workspace.change_attempts.size).to eq(1)
expect(workspace.change_attempts.first.id).to eq(`git rev-parse HEAD`.strip)
expect(workspace.change_attempts.first.diff).to end_with(
<<~DIFF
gem "activesupport", ">= 6.0.0"
+gem "timecop", "~> 0.9.6", group: :test
DIFF
)
expect(workspace.change_attempts.first.memo).to eq("Update timecop")
expect(workspace.change_attempts.first.error).to be_nil
expect(workspace.change_attempts.first).not_to be_error
Expand Down
Loading