Skip to content

Instantly share code, notes, and snippets.

@RageCage64
Last active February 22, 2021 22:02
Show Gist options
  • Save RageCage64/b5aa2d49c0ca44382f997078be6bb8f0 to your computer and use it in GitHub Desktop.
Save RageCage64/b5aa2d49c0ca44382f997078be6bb8f0 to your computer and use it in GitHub Desktop.
Apply all dependabot PRs in a single branch
tmp_dir_name="dbot_patches"
mkdir -p $tmp_dir_name
base_branch=$1
if [ -z "$base_branch" ] ; then
base_branch="master"
fi
dependabot_branches=( `git branch -r | grep origin/dependabot/` )
today=$(date +'%d%m%Y')
git checkout -b dependabot_$today
for branch in "${dependabot_branches[@]}"
do
echo "$branch"
patch_file_name=$(echo "$branch" | sed "s/\///g")
patch_file_name="$patch_file_name.patch"
git diff $base_branch $branch > $tmp_dir_name/$patch_file_name
git apply --reject --whitespace=fix $tmp_dir_name/$patch_file_name
done
rm -rf $tmp_dir_name
@RageCage64
Copy link
Author

This script will apply all Dependabot branches from the remote into a single branch. It makes two assumptions:

  • All dependabot branches found on remote are from open PRs (i.e. old dependabot branches are deleted)
  • It is running in the root of the repository

This script was written to avoid the pain caused by applying Dependabot PRs one at a time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment