Skip to content

Commit

Permalink
Allow changes to yarn.lock files
Browse files Browse the repository at this point in the history
This will allow Javascript dependencies to be automatically merged.

Example of PR that would be affected by this change: alphagov/travel-advice-publisher#1890

I have not added `Gemfile` and `package.json` to the allowed files list because in some cases we may have
legitimate reasons to keep dependencies pinned to specific versions and we don't want Dependabot to change that.
  • Loading branch information
MuriloDalRi committed May 7, 2024
1 parent 167f427 commit f881060
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/pull_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ def validate_single_commit
end

def validate_files_changed
allowed_files = ["yarn.lock", "Gemfile.lock"]
commit = GitHubClient.instance.commit("alphagov/#{@api_response.base.repo.name}", @api_response.head.sha)
files_changed = commit.files.map(&:filename)
# TODO: support other package managers too (e.g. NPM)
files_changed == ["Gemfile.lock"]
(files_changed - allowed_files).empty?
end

def validate_ci_workflow_exists
Expand Down
8 changes: 8 additions & 0 deletions spec/lib/pull_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ def create_pull_request_instance
expect(pr.validate_files_changed).to eq(true)
end

it "returns true if PR only changes yarn.lock" do
head_commit_api_response[:files][0][:filename] = "yarn.lock"
stub_remote_commit(head_commit_api_response)

pr = PullRequest.new(pull_request_api_response)
expect(pr.validate_files_changed).to eq(true)
end

it "returns false if PR changes anything else" do
head_commit_api_response[:files][0][:filename] = "something_else.rb"
stub_remote_commit(head_commit_api_response)
Expand Down

0 comments on commit f881060

Please sign in to comment.