github-auto-locker 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +20 -0
- data/bin/github-auto-locker +6 -0
- data/lib/locker.rb +106 -0
- metadata +48 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bc9273f3326183b6f148ea285e832a062f41ecbf
|
4
|
+
data.tar.gz: 8bd1bc2c80f9974e6e693283dc275d6d071cfb52
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: abea29689d9933d08b0df9ffcbe5ed03a4d973bb951143530ebd36ac828bc7b4d5cd0104ce2cf921127f6ddc03b0b292ac062860702fc92cc007bd55a64bded9
|
7
|
+
data.tar.gz: 7cee629c8db329bf402bf34e9e6bed026bdaaca098b3561a3bfabc7b29e5dc1157dea0cbc5588de495491ad4d4173b9dbb8dce5181b49fe6684ee25f325777bb
|
data/README.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
## GitHub AutoLocker
|
2
|
+
|
3
|
+
Automatically locks old GitHub issues that have already been closed.
|
4
|
+
|
5
|
+
By default it locks closed issues that are over 120 days old.
|
6
|
+
|
7
|
+
### Usage
|
8
|
+
|
9
|
+
This requires Ruby.
|
10
|
+
|
11
|
+
* Clone or download repo
|
12
|
+
* Run `./bin/github-auto-locker USER REPO TOKEN [age in days]`
|
13
|
+
|
14
|
+
The age is optional.
|
15
|
+
|
16
|
+
`TOKEN` is a personal access token from [here](https://github.com/settings/tokens). It will require the 'repo' scope.
|
17
|
+
|
18
|
+
### License
|
19
|
+
|
20
|
+
MIT
|
data/lib/locker.rb
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'date'
|
3
|
+
require 'net/http'
|
4
|
+
require 'base64'
|
5
|
+
|
6
|
+
# Automatically locks old issues that have been closed already
|
7
|
+
class Locker
|
8
|
+
def initialize user, repo, token, old_days = 120
|
9
|
+
@user = user
|
10
|
+
@repo = repo
|
11
|
+
@token = token
|
12
|
+
@old_days = old_days
|
13
|
+
end
|
14
|
+
|
15
|
+
# Locks old closed issues
|
16
|
+
def lock
|
17
|
+
notify "Getting closed issues..."
|
18
|
+
issues = get_closed_issues
|
19
|
+
|
20
|
+
if issues.empty?
|
21
|
+
notify "No issues to lock"
|
22
|
+
else
|
23
|
+
notify "Received #{issues.length} issues"
|
24
|
+
notify "Locking old closed issues..."
|
25
|
+
lock_old_closed_issues issues
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Fetches all closed, unlocked issues closed before cutoff date
|
30
|
+
def get_closed_issues
|
31
|
+
issues = []
|
32
|
+
path = "/repos/#@user/#@repo/issues?state=closed&access_token=#@token&sort=updated&direction=asc"
|
33
|
+
page = 1
|
34
|
+
http = Net::HTTP.start("api.github.com", 443, nil, nil, nil, nil, use_ssl: true)
|
35
|
+
|
36
|
+
loop do
|
37
|
+
notify "Retrieving page #{page}..."
|
38
|
+
|
39
|
+
resp = http.get(path)
|
40
|
+
new_issues = JSON.parse(resp.body)
|
41
|
+
issues += new_issues
|
42
|
+
|
43
|
+
# Pagination
|
44
|
+
if resp['Link'].match /<https:\/\/api\.github\.com(\/[^>]+)>; rel="next",/
|
45
|
+
path = $1
|
46
|
+
page = path.match(/page=(\d+)/)[1]
|
47
|
+
else
|
48
|
+
http.finish
|
49
|
+
break
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
cutoff_date = (Date.today - @old_days).iso8601
|
54
|
+
|
55
|
+
issues.reject do |issue|
|
56
|
+
issue["locked"] or
|
57
|
+
issue["closed_at"] > cutoff_date
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# Expects array of issues from API call
|
62
|
+
def lock_old_closed_issues issues
|
63
|
+
headers = {'Accept' => 'application/vnd.github.the-key-preview+json', # required for new lock API
|
64
|
+
'Content-Length' => '0', # required for PUT with no body
|
65
|
+
'Authorization' => "Basic #{Base64.strict_encode64("#@user:#@token")}"}
|
66
|
+
|
67
|
+
Net::HTTP.start("api.github.com", 443, nil, nil, nil, nil, use_ssl: true) do |http|
|
68
|
+
total = issues.length
|
69
|
+
|
70
|
+
issues.each_with_index do |issue, i|
|
71
|
+
number = issue['number']
|
72
|
+
locking number, i, total
|
73
|
+
|
74
|
+
path = issue["url"][22..-1] # pull path from full URL
|
75
|
+
response = http.put("#{path}/lock", '', headers)
|
76
|
+
|
77
|
+
if response.code == "204" # 204 means it worked, apparently
|
78
|
+
locked
|
79
|
+
else
|
80
|
+
error response.inspect
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# Print locking message
|
87
|
+
def locking number, item, total
|
88
|
+
print "[INFO] Locking #{number} (#{item + 1}/#{total})..."
|
89
|
+
end
|
90
|
+
|
91
|
+
# Print locked message
|
92
|
+
def locked
|
93
|
+
puts 'locked!'
|
94
|
+
end
|
95
|
+
|
96
|
+
# Print INFO message
|
97
|
+
def notify message
|
98
|
+
puts "[INFO] #{message}"
|
99
|
+
end
|
100
|
+
|
101
|
+
# Print ERROR message
|
102
|
+
def error message
|
103
|
+
warn "[ERROR] #{message}"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: github-auto-locker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Justin Collins
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-13 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: "Automatically locks GitHub issues older than a specified number of days.\nThis
|
14
|
+
forces people to open new issues instead of attaching themselves to old (typically
|
15
|
+
unrelated) issues. \n"
|
16
|
+
email:
|
17
|
+
executables:
|
18
|
+
- github-auto-locker
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- README.md
|
23
|
+
- bin/github-auto-locker
|
24
|
+
- lib/locker.rb
|
25
|
+
homepage: https://github.com/presidentbeef/github-auto-locker
|
26
|
+
licenses: []
|
27
|
+
metadata: {}
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 2.4.8
|
45
|
+
signing_key:
|
46
|
+
specification_version: 4
|
47
|
+
summary: Simple script to lock closed GitHub issues over a certain age.
|
48
|
+
test_files: []
|