Batch Changes gives you a declarative structure for finding and modifying code across all of your repositories. With a simple UI, it is easy to track and manage all of your changesets through checks and code reviews until each change is merged.
Find all occurrences of code to change, programmatically define changes, and execute via a lightweight CLI. Track changeset lifecycle status across multiple code hosts via the Sourcegraph UI.
Jared Hodge
Senior Manager Developer Experience, Indeed
The ability to automate downstream changes that Sourcegraph Batch Changes provides is a key capability for reducing the hidden burden of updates pushed across teams and enabling us to increase our engineering velocity.
Trent Grover
Director of Architecture: Client Technologies, Workiva
Sourcegraph Batch Changes gives us the confidence we need to understand the total impact of large-scale code changes before we make them. This enables the entire team to make more impactful decisions more often.
Eliminate manual spreadsheet tracking. Automatically track changeset lifecycle status, like check state, reviews, and merge status via the Sourcegraph UI.
Quickly edit every CI, build, and other configuration files to make changes such as altering steps, migrating versions, or changing base images.
name: update-circle-ci-docker-user
description: Changes the Docker Hub username used for Circle CI
# Search for repositories containing a circle-ci.yml file with the old usename
on:
- repositoriesMatchingQuery: mydockerhub-user file:circle-ci.[yaml|yml]
# In each repository
steps:
# replace the old with the new username in the found files
- run: |
for file in “${{ join repository.search_results_paths “ “ }}”;
do
sed -i ‘s/mydockerhub-user/ci-dockerbhub-user/g;’ ;${file}
done
container: alpine:3
# Describe the changeset (e.g., Github pull request) you want for each repository.
changesetTemplate:
title: Use new Docker Hub username in Circle CI config
body: This change replaces the old Docker Hub user with the new, CI Specific user account.
branch: batches/update-ci-user
commit:
message: Update Docker user in CI
published: false
Use language-aware tooling of your choice to perform complex refactors like updating an API and its function calls or replacing libraries entirely.
name: sprintf-to-itoa
description: |
This campaign uses [Comby](https://comby.dev) to replace `fmt.Sprintf` calls
in Go code with the equivalent but clearer `strconv.Itoa` call.
on:
- repositoriesMatchingQuery: lang:go fmt.Sprintf("%d", :[v]) patterntype:structural
steps:
# Use Comby to replace `fmt.Sprintf` calls
- run: comby -in-place 'fmt.Sprintf(“%d”, :[v])’ ‘strconv.Itoa(“[v]’
${{ join repository.search_results_paths “ ” }}
container: comby/comby
# Run `goimports` over the just-modified files to import `fmt` if necessary
- run: goimports -w ${{ join previous_step.modified_files “ “ }}
container: unibeautify/goimports
changesetTemplate:
title: Replace fmt.Sprintf with equivalent strconv.Itoa
body: This batch change replaces `fmt.Sprintf` with `strconv.Itoa`
branch: batches/sprintf-to-itoa
commit:
message: Replacing fmt.Sprintf with strconv.Itoa
published: false
Refactor code to replace insecure functions, update vulnerable packages, or modify container configurations across hundreds of repositories.
name: pin-docker-base-images
description: Pin Docker images using the `:latest` tag to a specific image digest.
on:
# Find all repositories that contain Dockerfiles with a `:latest` tag in a base image.
- repositoriesMatchingQuery: ^FROM (\\w+\\)?\\w+:latest($|\\s) [file:Dockerfile]
patternType:regexp
# In each repository...
steps:
# Use dockerlint to pin the images in the Dockerfiles we found:
- run: |
for file in `${{ join repository.search_results_paths “ “ }}`;
do
dockerlint -w ${file}
done
container: sourcegraph/dockerlint-run:latest
# Describe the changeset (e.g., Github pull request) you want for each repository.
changesetTemplate:
title: Pin Docker `:latest` image tags to digest
body: |
The `:latest` tag changes, so future pulls of this image may retrieve a different image
with different (and possibly erroneous, unexpected, or dangerous) behavior.
Pin the image to an [image digest] (https://docs.docker.com/engine/reference/commandline/pull/#
pull-an-image-by-digest-immutable-identifier)
for deterministic behavior.
*See also: [Hadolint error DL3007](https://github.com/hadolint/hadolint/wiki/DL3007).*
branch: batches/pin-docker-images
commit:
message: Pin Docker `:latest` image tags to digest
published: false