gist_cleaner 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/README.md +34 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/gist_cleaner +5 -0
- data/bin/setup +8 -0
- data/gist_cleaner.gemspec +34 -0
- data/lib/gist_cleaner.rb +111 -0
- data/lib/gist_cleaner/version.rb +3 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5e08aaf5a05b8ba09e450bc93fea4750ba33a514
|
4
|
+
data.tar.gz: 97815974f38989f1123fae9195cb2fe022f57658
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7ef7f6c02f3905e6061d14844f836ce06d0b0dfbd8d5bf6095769c2180c4f4586b9351b29660ce79e9db6489d7239c5594435531219157302419d9957310c14e
|
7
|
+
data.tar.gz: 840d93162b9991196c77d3d9ba3469fb01d4fb2fc072682cc8a7cc9778c1e8af6dba957f0a4dd9e6d395bcce0b971397b2bb8de869794684276375c015681fcd
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at yhlssdone@gmail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# GistCleaner
|
2
|
+
|
3
|
+
Clean gist private, public, or both of them, with two-factor authentication or basic login
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'gist_cleaner'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install gist_cleaner
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Clean gist private, public, or both of them, with two-factor authentication or basic login
|
24
|
+
|
25
|
+
## Development
|
26
|
+
|
27
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
28
|
+
|
29
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/HongliYu/gist_cleaner. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
34
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "gist_cleaner"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/gist_cleaner
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'gist_cleaner/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "gist_cleaner"
|
8
|
+
spec.version = GistCleaner::VERSION
|
9
|
+
spec.authors = ["HongliYu"]
|
10
|
+
spec.email = ["yhlssdone@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{clean all private gist}
|
13
|
+
spec.description = %q{clean all private gist}
|
14
|
+
spec.homepage = "https://github.com/HongliYu/gist_cleaner"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
17
|
+
# delete this section to allow pushing this gem to any host.
|
18
|
+
# if spec.respond_to?(:metadata)
|
19
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
20
|
+
# else
|
21
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
22
|
+
# end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
# spec.bindir = "exe"
|
26
|
+
# spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.executables = ["gist_cleaner"]
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_runtime_dependency "httparty", "~>0.13.7"
|
31
|
+
spec.required_ruby_version = '>= 2.0.0'
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
34
|
+
end
|
data/lib/gist_cleaner.rb
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
require "gist_cleaner/version"
|
2
|
+
require 'httparty'
|
3
|
+
|
4
|
+
module GistCleaner
|
5
|
+
def initialize()
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.run()
|
9
|
+
puts "input username"
|
10
|
+
username = gets.chomp
|
11
|
+
if username.empty?
|
12
|
+
puts "invalid username"
|
13
|
+
return
|
14
|
+
end
|
15
|
+
puts "input password"
|
16
|
+
password = gets.chomp
|
17
|
+
if password.empty?
|
18
|
+
puts "invalid password"
|
19
|
+
return
|
20
|
+
end
|
21
|
+
|
22
|
+
puts 'enabled two-factor authentication? input optcode OR press the enter to continue'
|
23
|
+
otpcode = gets.chomp
|
24
|
+
@cleaner = Cleaner.new(username, password, otpcode)
|
25
|
+
puts 'checking gists...'
|
26
|
+
@cleaner.check_gists()
|
27
|
+
@cleaner.delete_gists()
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class Cleaner
|
32
|
+
include HTTParty
|
33
|
+
|
34
|
+
def initialize(username, password, otpcode)
|
35
|
+
@username = username
|
36
|
+
@password = password
|
37
|
+
@otpcode = otpcode
|
38
|
+
end
|
39
|
+
|
40
|
+
def check_gists()
|
41
|
+
self.class.base_uri 'https://api.github.com'
|
42
|
+
self.class.basic_auth @username, @password
|
43
|
+
if @otpcode.empty?
|
44
|
+
@gists = self.class.get("/users/#{@username}/gists", headers: {"User-Agent" => @username})
|
45
|
+
|
46
|
+
if !@gists["message"].empty?
|
47
|
+
abort @gists["message"]
|
48
|
+
end
|
49
|
+
|
50
|
+
puts @gists
|
51
|
+
return
|
52
|
+
public_gists = @gists.select { |g| g["public"] == true }
|
53
|
+
puts "you have #{public_gists.size} public gist"
|
54
|
+
else
|
55
|
+
@gists = self.class.get("/users/#{@username}/gists", headers: {"User-Agent" => @username, "X-GitHub-OTP" => @otpcode})
|
56
|
+
public_gists = @gists.select { |g| g["public"] == true }
|
57
|
+
puts "you have #{public_gists.size} public gist && #{@gists.size - public_gists.size} private gist"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def delete_gists()
|
62
|
+
puts "clean gist 1.private 2.public 3.all. please input mode number: "
|
63
|
+
clean_mode = gets.chomp.to_i
|
64
|
+
if clean_mode < 1 || clean_mode > 3
|
65
|
+
puts "invalid clean mode"
|
66
|
+
return
|
67
|
+
end
|
68
|
+
puts 'enabled two-factor authentication? input optcode OR press the enter to continue'
|
69
|
+
@otpcode = gets.chomp
|
70
|
+
case clean_mode
|
71
|
+
when 1
|
72
|
+
puts "clean private gists"
|
73
|
+
i = 0
|
74
|
+
@gists.each do |g|
|
75
|
+
if g["public"] == false
|
76
|
+
self.delete_gists_action(g, i)
|
77
|
+
i = i + 1
|
78
|
+
end
|
79
|
+
end
|
80
|
+
when 2
|
81
|
+
puts "clean public gists"
|
82
|
+
i = 0
|
83
|
+
@gists.each do |g|
|
84
|
+
if g["public"] == true
|
85
|
+
self.delete_gists_action(g, i)
|
86
|
+
i = i + 1
|
87
|
+
end
|
88
|
+
end
|
89
|
+
when 3
|
90
|
+
puts "clean all gists"
|
91
|
+
i = 0
|
92
|
+
@gists.each do |g|
|
93
|
+
self.delete_gists_action(g, i)
|
94
|
+
i = i + 1
|
95
|
+
end
|
96
|
+
else
|
97
|
+
puts "invalid clean mode"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def delete_gists_action(g, i)
|
102
|
+
id = g["id"]
|
103
|
+
puts "#{i+1}. DELETING: https://gist.github.com/#{@username}/#{id}"
|
104
|
+
if @otpcode.empty?
|
105
|
+
self.class.delete("/gists/#{id}", headers: {"User-Agent" => @username})
|
106
|
+
else
|
107
|
+
self.class.delete("/gists/#{id}", headers: {"User-Agent" => @username, "X-GitHub-OTP" => @otpcode})
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gist_cleaner
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- HongliYu
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.13.7
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.13.7
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.11'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.11'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description: clean all private gist
|
56
|
+
email:
|
57
|
+
- yhlssdone@gmail.com
|
58
|
+
executables:
|
59
|
+
- gist_cleaner
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- CODE_OF_CONDUCT.md
|
65
|
+
- Gemfile
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/console
|
69
|
+
- bin/gist_cleaner
|
70
|
+
- bin/setup
|
71
|
+
- gist_cleaner.gemspec
|
72
|
+
- lib/gist_cleaner.rb
|
73
|
+
- lib/gist_cleaner/version.rb
|
74
|
+
homepage: https://github.com/HongliYu/gist_cleaner
|
75
|
+
licenses: []
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 2.0.0
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.6.1
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: clean all private gist
|
97
|
+
test_files: []
|