github-auto-locker 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -2
- data/bin/github-auto-locker +15 -2
- data/lib/locker.rb +22 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7fe1aeda931f62b891753dde4f0af886d27f4e54
|
4
|
+
data.tar.gz: f148beb5e8b6d9302f9af470a3d384ef7848131a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13c5f9f5cfd2798c8e187bcacf0ee35c9bdc6eaec28887ec3ff82cdff15144327a7ec30eedc82c48ccca8ff1bd315fa6b9feb0a1c4c333c6362089ae6d057ada
|
7
|
+
data.tar.gz: 4ac3e2e746c511e72cc0b73df2f88178913c7d04d5133f7462ae8f113f26da242ce70c88a06407fd3fd05085504bdfb655b75b1c39bc09f7fd8fa3c18164cbde
|
data/README.md
CHANGED
@@ -8,12 +8,21 @@ By default it locks closed issues that are over 120 days old.
|
|
8
8
|
|
9
9
|
This requires Ruby.
|
10
10
|
|
11
|
+
From source:
|
12
|
+
|
11
13
|
* Clone or download repo
|
12
|
-
* Run `./bin/github-auto-locker USER REPO TOKEN [age in days]`
|
14
|
+
* Run `./bin/github-auto-locker USER REPO TOKEN [age in days] [-n]`
|
15
|
+
|
16
|
+
As a gem:
|
17
|
+
|
18
|
+
* Run `gem install github-auto-locker`
|
19
|
+
* Run `github-auto-locker USER REPO TOKEN [age in days]`[-n]
|
13
20
|
|
14
21
|
The age is optional.
|
15
22
|
|
16
|
-
`TOKEN` is a personal access token from [here](https://github.com/settings/tokens). It will require the 'repo' scope.
|
23
|
+
`TOKEN` is a personal access token from [here](https://github.com/settings/tokens). It will require the 'repo' scope. Alternatively, credentials will be loaded from `~/.config/hub` if it exists.
|
24
|
+
|
25
|
+
`-n` can be used to perform a dry run and show which issues *would* be locked, but does not make any changes.
|
17
26
|
|
18
27
|
### License
|
19
28
|
|
data/bin/github-auto-locker
CHANGED
@@ -1,6 +1,19 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require_relative '../lib/locker'
|
3
3
|
|
4
|
-
|
4
|
+
noop = ARGV.delete "-n"
|
5
|
+
user, repo, token, days = ARGV
|
5
6
|
|
6
|
-
|
7
|
+
unless token then
|
8
|
+
hub_config = File.expand_path "~/.config/hub"
|
9
|
+
|
10
|
+
if File.file? hub_config then
|
11
|
+
require "yaml"
|
12
|
+
config = YAML.load File.read hub_config
|
13
|
+
token = config.dig("github.com", 0, "oauth_token")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
abort "Usage: auto-lock [user] [repo] [token] [days]" unless user && repo && token
|
18
|
+
|
19
|
+
Locker.new(user, repo, token, days || 120, noop).lock
|
data/lib/locker.rb
CHANGED
@@ -5,15 +5,17 @@ require 'base64'
|
|
5
5
|
|
6
6
|
# Automatically locks old issues that have been closed already
|
7
7
|
class Locker
|
8
|
-
def initialize user, repo, token, old_days = 120
|
8
|
+
def initialize user, repo, token, old_days = 120, noop = false
|
9
9
|
@user = user
|
10
10
|
@repo = repo
|
11
11
|
@token = token
|
12
12
|
@old_days = old_days
|
13
|
+
@noop = noop
|
13
14
|
end
|
14
15
|
|
15
16
|
# Locks old closed issues
|
16
17
|
def lock
|
18
|
+
notify "Not locking anything due to -n flag" if @noop
|
17
19
|
notify "Getting closed issues..."
|
18
20
|
issues = get_closed_issues
|
19
21
|
|
@@ -22,6 +24,19 @@ class Locker
|
|
22
24
|
else
|
23
25
|
notify "Received #{issues.length} issues"
|
24
26
|
notify "Locking old closed issues..."
|
27
|
+
|
28
|
+
if @noop then
|
29
|
+
total = issues.size
|
30
|
+
|
31
|
+
issues.each_with_index do |issue, i|
|
32
|
+
number = issue['number']
|
33
|
+
locking number, i, total
|
34
|
+
puts issue['title']
|
35
|
+
end
|
36
|
+
|
37
|
+
return
|
38
|
+
end
|
39
|
+
|
25
40
|
lock_old_closed_issues issues
|
26
41
|
end
|
27
42
|
end
|
@@ -38,6 +53,11 @@ class Locker
|
|
38
53
|
|
39
54
|
resp = http.get(path)
|
40
55
|
new_issues = JSON.parse(resp.body)
|
56
|
+
|
57
|
+
unless Array === new_issues then
|
58
|
+
abort "bad response: %p" % new_issues
|
59
|
+
end
|
60
|
+
|
41
61
|
issues += new_issues
|
42
62
|
|
43
63
|
# Pagination
|
@@ -71,7 +91,7 @@ class Locker
|
|
71
91
|
number = issue['number']
|
72
92
|
locking number, i, total
|
73
93
|
|
74
|
-
path = issue["url"]
|
94
|
+
_, _, _, _, _, path, * = URI.split issue["url"]
|
75
95
|
response = http.put("#{path}/lock", '', headers)
|
76
96
|
|
77
97
|
if response.code == "204" # 204 means it worked, apparently
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: github-auto-locker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Collins
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: "Automatically locks GitHub issues older than a specified number of days.\nThis
|
14
14
|
forces people to open new issues instead of attaching themselves to old (typically
|