gist-sweep 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1378ff400ad3109f7a1e72b02b4c2025096bc251
4
+ data.tar.gz: e4d59540ccd2bda3e4649de2b0c80d5854e363d2
5
+ SHA512:
6
+ metadata.gz: fb5f3858fe50faf9cedf81f03a15dfe1329900e0ce07290ecb95d7053bbd9da02c512b16e958a431099d0e0600416a124e772f69f56414838a748375b5535821
7
+ data.tar.gz: 21f2057ab61ba21357759f4054b6e2aab189c056be09431101f89db7bec941c08bcac55aaf3a1a2302fc1ecb8f0723193af2c5fadc674a91addc543de7dfc28f
data/.gitignore ADDED
@@ -0,0 +1,48 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ *.gem
16
+ *.rbc
17
+ /.config
18
+ /coverage/
19
+ /InstalledFiles
20
+ /pkg/
21
+ /spec/reports/
22
+ /test/tmp/
23
+ /test/version_tmp/
24
+ /tmp/
25
+
26
+ ## Specific to RubyMotion:
27
+ .dat*
28
+ .repl_history
29
+ build/
30
+
31
+ ## Documentation cache and generated files:
32
+ /.yardoc/
33
+ /_yardoc/
34
+ /doc/
35
+ /rdoc/
36
+
37
+ ## Environment normalisation:
38
+ /.bundle/
39
+ /lib/bundler/man/
40
+
41
+ # for a library or gem, you might want to ignore these files since the code is
42
+ # intended to run in multiple environments; otherwise, check them in:
43
+ # Gemfile.lock
44
+ # .ruby-version
45
+ # .ruby-gemset
46
+
47
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
48
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gist-sweep.gemspec
4
+ gemspec
5
+ gem 'json'
6
+ gem "github_api"
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Adam Shannon
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Gist::Sweep
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'gist-sweep'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install gist-sweep
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/gist-sweep/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/gist-sweep ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'gist/sweep'
3
+ sweep = GistSweep::Sweep.new
4
+ sweep.sweep()
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "gist/sweep/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "gist-sweep"
7
+ s.version = Gist::Sweep::VERSION
8
+ s.authors = ["Adam Shannon"]
9
+ s.email = ["adam@ashannon.us"]
10
+ s.homepage = "https://github.com/adamdecaf/gist-sweep"
11
+ s.summary = "sweep gists"
12
+ s.description = "Clear our old github gists"
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ s.licenses = ["MIT"]
20
+
21
+ s.add_runtime_dependency "json", "~> 1.7"
22
+ s.add_runtime_dependency "github_api", "~> 0.12"
23
+
24
+ s.add_development_dependency "bundler", "~> 1.7"
25
+ s.add_development_dependency "rake", "~> 10.0"
26
+ end
@@ -0,0 +1,5 @@
1
+ module Gist
2
+ module Sweep
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
data/lib/gist/sweep.rb ADDED
@@ -0,0 +1,121 @@
1
+ require "gist/sweep/version"
2
+ require 'date'
3
+ require 'json'
4
+ require 'github_api'
5
+ require 'optparse'
6
+
7
+ module GistSweep
8
+ class Sweep
9
+ def parse_arguments()
10
+ options = {
11
+ :verbose => false,
12
+ :config_file => "~/.gist-sweep",
13
+ :public => false,
14
+ :days => 90
15
+ }
16
+
17
+ OptionParser.new do |opts|
18
+ opts.banner = "Usage: gist-sweep [options]"
19
+
20
+ opts.on("-v", "-s", "Print verbose messages") do |v|
21
+ options[:verbose] = v
22
+ end
23
+
24
+ opts.on("-c", "Read config from a different file") do |c|
25
+ options[:config_file] = c
26
+ end
27
+
28
+ opts.on("-u", "Username to sweep gists on") do |u|
29
+ options[:username] = u
30
+ end
31
+
32
+ opts.on("-d", "Days to keep", Integer) do |d|
33
+ options[:days] = d.to_i
34
+ end
35
+
36
+ opts.on("-p", "Include public gists") do |p|
37
+ options[:public] = p
38
+ end
39
+
40
+ end.parse!
41
+
42
+ options
43
+ end
44
+
45
+ def read_config_from_file(path)
46
+ expanded_path = File.expand_path(path)
47
+ if File.exists?(expanded_path)
48
+ contents = File.read(expanded_path)
49
+ if contents.chomp.empty?
50
+ {}
51
+ else
52
+ JSON.parse(contents)
53
+ end
54
+ else
55
+ {}
56
+ end
57
+ end
58
+
59
+ def write_config_file(oauth_token, path)
60
+ expanded_path = File.expand_path(path)
61
+ File.write(expanded_path, JSON.generate({:oauth_token => oauth_token}))
62
+ FileUtils.chmod(0400, expanded_path)
63
+ end
64
+
65
+ def load_github_api(config, file_path)
66
+ if config["oauth_token"] and !config["oauth_token"].empty?
67
+ Github.new(:oauth_token => config["oauth_token"], :auto_pagination => true)
68
+ else
69
+ puts "You need to setup a 'Personal Access Token' to use with gist-sweep"
70
+ puts "I'll wait for you to paste one in: "
71
+ code = STDIN.gets.strip
72
+ write_config_file(code, file_path)
73
+ Github.new(:oauth_token => code, :auto_pagination => true)
74
+ end
75
+ end
76
+
77
+ def promot_to_remove_gists(count)
78
+ puts "Remove #{count} gists? (y/n)"
79
+ line = STDIN.gets.strip
80
+ if line == 'y'
81
+ true
82
+ else
83
+ false
84
+ end
85
+ end
86
+
87
+ def verbose_log(args, msg)
88
+ if args[:verbose]
89
+ puts msg
90
+ end
91
+ end
92
+
93
+ def sweep()
94
+ args = parse_arguments()
95
+ config = read_config_from_file(args[:config_file])
96
+ github = load_github_api(config, args[:config_file])
97
+
98
+ if args[:username]
99
+ min_age = DateTime.now - args[:days]
100
+ verbose_log(args, "Removing gists older than #{min_age}")
101
+ gists_to_remove = github.gists.list(args[:username]).body.select{ |g|
102
+ (!g["public"] or args[:public]) and (DateTime.parse(g["updated_at"]) < min_age)
103
+ }
104
+
105
+ if gists_to_remove.empty?
106
+ puts "No gists to remove"
107
+ else
108
+ if promot_to_remove_gists(gists_to_remove.size)
109
+ gists_to_remove.each { |g|
110
+ verbose_log(args, "Deleting gist #{g["id"]}")
111
+ github.gists.delete(g["id"])
112
+ }
113
+ puts "Swept gists."
114
+ end
115
+ end
116
+ else
117
+ abort "No username defined (with -u flag)."
118
+ end
119
+ end
120
+ end
121
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gist-sweep
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Adam Shannon
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: github_api
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.12'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: Clear our old github gists
70
+ email:
71
+ - adam@ashannon.us
72
+ executables:
73
+ - gist-sweep
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/gist-sweep
83
+ - gist-sweep.gemspec
84
+ - lib/gist/sweep.rb
85
+ - lib/gist/sweep/version.rb
86
+ homepage: https://github.com/adamdecaf/gist-sweep
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.2.2
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: sweep gists
110
+ test_files: []