| Server IP : 188.151.22.197 / Your IP : 216.73.217.74 Web Server : Apache/2.4.62 (Rocky Linux) OpenSSL/3.5.5 System : Linux wsten.se 5.14.0-687.30.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Mon Jul 27 13:09:21 UTC 2026 x86_64 User : apache ( 48) PHP Version : 8.1.32 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /opt/gitlab/embedded/service/gitlab-rails/scripts/ |
Upload File : |
#!/usr/bin/env ruby
# frozen_string_literal: true
# This script uses the glab cli to check if any of your local branches have
# been merged and then deletes any that have.
#
# This needs the glab cli to function
# https://gitlab.com/gitlab-org/cli/#installation
require 'json'
require 'rainbow/refinement'
using Rainbow
if `git rev-parse --abbrev-ref HEAD`.strip != 'master'
puts 'Please checkout the '.white + 'master'.blue + ' branch before continuing'.white
exit
end
branches = `git branch --format='%(refname:short)'`.split("\n").filter_map do |b|
stripped = b.strip
stripped unless stripped.empty? || stripped == 'master'
end
deleted = 0
branches.each do |branch|
puts 'Checking 👀:'.white + " #{branch}".blue
output = `glab mr list -s #{branch} -F=json -M 2>/dev/null`
if $?.exitstatus != 0
puts 'API Error:'.red + " #{output.inspect}".white
next
end
begin
result = JSON.parse(output)
if result.empty?
puts 'Skipping ⛔️:'.white + " #{branch}".green
next
end
`git branch -D #{branch} 2>&1`
if $?.exitstatus == 0
puts 'Deleting ✅:'.white + " #{branch}".red
deleted += 1
end
rescue JSON::ParserError
puts "Warning: Failed to parse JSON for branch '#{branch}'"
next
end
end
puts ('-' * 80).white
puts 'Deleted '.blue + deleted.to_s.red + " branch#{'es' unless deleted == 1}".blue
puts ('-' * 80).white