1
0
Fork 0
mirror of https://github.com/Luzifer/github-masswatch.git synced 2024-12-22 11:01:16 +00:00

Initial version

This commit is contained in:
Knut Ahlers 2015-06-02 18:52:56 +02:00
commit cc710435cb
5 changed files with 153 additions and 0 deletions

5
Gemfile Normal file
View file

@ -0,0 +1,5 @@
source 'https://rubygems.org'
ruby '2.1.6'
gem "octokit", "~> 3.0"
gem 'thor', '0.19.1'

20
Gemfile.lock Normal file
View file

@ -0,0 +1,20 @@
GEM
remote: https://rubygems.org/
specs:
addressable (2.3.6)
faraday (0.9.0)
multipart-post (>= 1.2, < 3)
multipart-post (1.2.0)
octokit (3.8.0)
sawyer (~> 0.6.0, >= 0.5.3)
sawyer (0.6.0)
addressable (~> 2.3.5)
faraday (~> 0.8, < 0.10)
thor (0.19.1)
PLATFORMS
ruby
DEPENDENCIES
octokit (~> 3.0)
thor (= 0.19.1)

13
LICENSE Normal file
View file

@ -0,0 +1,13 @@
Copyright 2015 Knut Ahlers <knut@ahlers.me>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

38
README.md Normal file
View file

@ -0,0 +1,38 @@
# Luzifer / github-masswatch
[![License: Apache 2.0](http://badge.luzifer.io/v1/badge?color=5d79b5&title=license&text=Apache%202.0)](LICENSE)
This project is a small helper for mass-watching / unwatching in GitHub repositories. If you are in a bigger organization like me you might have switched off auto-watching for new repositories as your mailbox gets flooded with stuff you don't even like to see. So after turning off the automatic watching you will not notice new repositories and you have to subscribe them one by one. To make this a bit more easy and have a chance to do this with a Jenkins job or similar I wrote this little tool.
## Features
- List all repositories you have access to
- List all repositories you are currently subscribed to
- Test a RegExp against that repository list
- Watch and unwatch repositories by providing a RegExp
## Simple usage example
```bash
# bundle install
[...]
# ruby watch.rb list --token=<mytoken>
Luzifer/alarmclock
Luzifer/alfred-fold
Luzifer/alfred-pwdgen
Luzifer/AMZWishlist
Luzifer/awsenv
[...]
# ruby watch.rb watch '^Luzifer/.*' --token=<mytoken>
Subscribing to Luzifer/blog.knut.me...
Subscribing to Luzifer/go-selfupdate...
Subscribing to Luzifer/golang-builder...
Subscribing to Luzifer/habitrpg...
Subscribing to Luzifer/homebrew...
Subscribing to Luzifer/homebrew-tools...
Subscribing to Luzifer/license...
Subscribing to Luzifer/radiopi...
Subscribing to Luzifer/simpleproxy...
```

77
watch.rb Executable file
View file

@ -0,0 +1,77 @@
#!/usr/bin/env ruby
require "Octokit"
require "thor"
class WatchCLI < Thor
class_option :token, :type => :string
desc "list <regex>", "lists all repos, useful to test your watch regex"
def list(regex='.*')
get_repos().each do |repo|
puts repo.full_name if /#{regex}/.match(repo.full_name)
end
end
desc "watched <regex>", "show all watched repos, useful to test your unwatch regex"
def watched(regex='.*')
get_subscriptions().each do |repo|
puts repo if /#{regex}/.match(repo)
end
end
desc "watch <regex>", "watch all repos matching your regex"
def watch(regex)
subscriptions = get_subscriptions()
get_repos().each do |repo|
if !subscriptions.include?(repo.full_name) and /#{regex}/.match(repo.full_name)
puts "Subscribing to #{repo.full_name}..."
get_octokit().update_subscription(repo.full_name, {subscribed: true})
end
end
end
desc "unwatch <regex>", "unwatch all repos matching your regex"
def unwatch(regex)
subscriptions = get_subscriptions()
get_repos().each do |repo|
puts "Unsubscribing from #{repo.full_name}..."
get_octokit().update_subscription(repo.full_name, {subscribed: false}) if subscriptions.include?(repo.full_name) and /#{regex}/.match(repo.full_name)
end
end
no_commands {
def get_octokit
if !options[:token]
puts "Please specify --token"
exit(1)
end
client = Octokit::Client.new(:access_token => options[:token])
client.auto_paginate = true
return client
end
def get_repos
client = get_octokit
repos = client.repositories(client.user.login)
orgs = client.organizations()
orgs.each do |org|
client.organization_repositories(org.login).each do |repo|
repos << repo
end
end
return repos
end
def get_subscriptions
client = get_octokit
return client.subscriptions(client.user.login).map { |repo| repo.full_name }
end
}
end
WatchCLI.start(ARGV)