Skip to content

Instantly share code, notes, and snippets.

@fnando
Created September 16, 2021 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fnando/81062395cbd8e0c8885020bd1d249f82 to your computer and use it in GitHub Desktop.
Save fnando/81062395cbd8e0c8885020bd1d249f82 to your computer and use it in GitHub Desktop.
Script to remove all travis-ci hooks from Github repos
  1. Make sure you run bundle install.
  2. Make sure you have a GITHUB_TRAVIS_CLEANUP_TOKEN personal token with admin:repo_hook scope.
  3. Run ruby script.rb
# frozen_string_literal: true
source "https://rubygems.org"
gem "octokit"
gem "pry-meta"
# frozen_string_literal: true
require "bundler/setup"
require "octokit"
client = Octokit::Client.new(
access_token: ENV.fetch("GITHUB_TRAVIS_CLEANUP_TOKEN")
)
client.auto_paginate = true
repos = client.repos({}, query: {type: "owner", sort: "asc"})
repos.each do |repo|
hooks = client.hooks(repo.id)
next if hooks.empty?
hooks.each do |hook|
next unless hook.config.url.include?("travis-ci")
puts "-> removing #{hook.config.url} (#{hook.id}) from #{repo.name}"
client.remove_hook(repo.id, hook.id)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment