gist-sweep 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 190dac3c764ee0a30fb841eda89eb07f8b0c34b5
4
- data.tar.gz: da581f0650a029a5593fbc49a3c6c8a709c942e9
3
+ metadata.gz: 39cd272d2c8ac88559045864de4a73baa588f2b7
4
+ data.tar.gz: a106b28c6bfd51cb6da53f2a2ee3cceb239c3524
5
5
  SHA512:
6
- metadata.gz: 986a265af6830dfbf4a4aeddc6de6ce87af1575ba96c1361f5bae97e8ab20b20adfd30842f8a29a5bada7f20de357ca4111d66fb688fa05ade7577f2de4afb6e
7
- data.tar.gz: cda787957e508beb73c32fd23f9aee82cbf5ab0a6ab187f38e7c6c9e1ea5e5051d19382612b4b48d08389c55c94cb3048fc7d835bf505044af9c93752c58d9b3
6
+ metadata.gz: f430c3b6a3d847c25b523bded469581ce774b178e6ff5cb4444daf97cd2f3a13f0f05b1ce737bfa96bd3e844a410444334af2a9e55fca5dbb71673e1864f75ee
7
+ data.tar.gz: 6910f7eaa43f71cfa4b5b91f6d7ebad14f208e2ce847dc5b823bd866729781906db6b32a15d03c3bd1f2375e35b8b4a945976068ccd65cc1533e8f11377de34f
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # gist-sweep
2
2
 
3
+ A similar tool to [git-sweep](http://lab.arc90.com/2012/04/03/git-sweep/), but for [Github Gists](http://gist.github.com).
4
+
3
5
  ## Usage
4
6
 
5
7
  > gist-sweep -u adamdecaf
@@ -11,6 +13,7 @@ Usage: gist-sweep [options]
11
13
  -u Username to sweep gists on
12
14
  -d Days to keep
13
15
  -p Include public gists
16
+ [pattern] Optional pattern to match gist descriptions to
14
17
  ```
15
18
 
16
19
  ## Installation
@@ -28,3 +31,8 @@ And then execute:
28
31
  Or install it yourself as:
29
32
 
30
33
  $ gem install gist-sweep
34
+
35
+
36
+ ## Contributing
37
+
38
+ Submit a PR to me and I'll probably merge it.
data/bin/gist-sweep CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'gist/sweep'
3
+ raw_args = ARGV.to_a.clone
3
4
  sweep = GistSweep::Sweep.new
4
- sweep.sweep()
5
+ sweep.sweep(raw_args)
@@ -1,5 +1,5 @@
1
1
  module Gist
2
2
  module Sweep
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
data/lib/gist/sweep.rb CHANGED
@@ -25,11 +25,11 @@ module GistSweep
25
25
  options[:config_file] = c
26
26
  end
27
27
 
28
- opts.on("-u", "Username to sweep gists on") do |u|
28
+ opts.on("-u USERNAME", "Username to sweep gists on") do |u|
29
29
  options[:username] = u
30
30
  end
31
31
 
32
- opts.on("-d", "Days to keep", Integer) do |d|
32
+ opts.on("-d NUM", "Days to keep", Integer) do |d|
33
33
  options[:days] = d.to_i
34
34
  end
35
35
 
@@ -74,8 +74,11 @@ module GistSweep
74
74
  end
75
75
  end
76
76
 
77
- def promot_to_remove_gists(count)
78
- print "Remove #{count} gists? (y/n) "
77
+ def promot_to_remove_gists(gists)
78
+ gists.each { |g|
79
+ puts "#{g["id"]} -- #{g["description"]}"
80
+ }
81
+ print "Remove #{gists.size} gists? (y/n) "
79
82
  line = STDIN.gets.strip
80
83
  if line == 'y'
81
84
  true
@@ -90,22 +93,33 @@ module GistSweep
90
93
  end
91
94
  end
92
95
 
93
- def sweep()
96
+ def sweep(raw_args)
94
97
  args = parse_arguments()
95
98
  config = read_config_from_file(args[:config_file])
96
99
  github = load_github_api(config, args[:config_file])
97
100
 
101
+ # pattern will be the first item in ARGV after options are parsed
102
+ pattern = ARGV[0]
103
+
98
104
  if args[:username]
99
105
  min_age = DateTime.now - args[:days]
100
106
  verbose_log(args, "Removing gists older than #{min_age}")
107
+
108
+ pattern_matcher = Regexp.new(pattern || "")
109
+
101
110
  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)
111
+ keep_already = (!g["public"] or args[:public]) and (DateTime.parse(g["updated_at"]) < min_age)
112
+ if pattern
113
+ keep_already and pattern_matcher.match(g["description"])
114
+ else
115
+ keep_already
116
+ end
103
117
  }
104
118
 
105
119
  if gists_to_remove.empty?
106
120
  puts "No gists to remove"
107
121
  else
108
- if promot_to_remove_gists(gists_to_remove.size)
122
+ if promot_to_remove_gists(gists_to_remove)
109
123
  gists_to_remove.each { |g|
110
124
  verbose_log(args, "Deleting gist #{g["id"]}")
111
125
  github.gists.delete(g["id"])
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gist-sweep
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Shannon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-04 00:00:00.000000000 Z
11
+ date: 2015-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json