github-auto-locker 1.1.1 → 1.2.0
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 +5 -5
- data/README.md +2 -2
- data/bin/github-auto-locker +1 -1
- data/lib/locker.rb +22 -11
- metadata +3 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 858eda7dc1d1e986103a660b36f7b055eb6b6469e770b9ea3422567a5aba2ae1
|
4
|
+
data.tar.gz: d278bac7d0160ab48d712fcd2cc9d12988fca48fc171775164352f8002a35ab2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fdbe802ba0c8a1da7dbee5e53c1c354fdf572b9aedd041caad033ff26b725e1a75e46b9ef6b5eddb806ad5ebb78993848824fdb1fa093cfde5b405170d69d8b9
|
7
|
+
data.tar.gz: 04e1339be0eb202a13bcb5d4ce2f248badf74cce154f3f9b8ed9b030a07c8f862c12ac8c577cea5791e330511f26f616d1b869a9346efe43efa0d311ca019f27
|
data/README.md
CHANGED
@@ -11,12 +11,12 @@ This requires Ruby.
|
|
11
11
|
From source:
|
12
12
|
|
13
13
|
* Clone or download repo
|
14
|
-
* Run `./bin/github-auto-locker
|
14
|
+
* Run `./bin/github-auto-locker USER_OR_ORG REPO TOKEN [age in days] [-n]`
|
15
15
|
|
16
16
|
As a gem:
|
17
17
|
|
18
18
|
* Run `gem install github-auto-locker`
|
19
|
-
* Run `github-auto-locker
|
19
|
+
* Run `github-auto-locker USER_OR_ORG REPO TOKEN [age in days]`[-n]
|
20
20
|
|
21
21
|
The age is optional.
|
22
22
|
|
data/bin/github-auto-locker
CHANGED
data/lib/locker.rb
CHANGED
@@ -5,18 +5,19 @@ 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, noop = false
|
8
|
+
def initialize user, repo, token, old_days = 120, noop = false, level = 2
|
9
9
|
@user = user
|
10
10
|
@repo = repo
|
11
11
|
@token = token
|
12
12
|
@old_days = old_days.to_i
|
13
13
|
@noop = noop
|
14
|
+
@level = level || 0
|
14
15
|
end
|
15
16
|
|
16
17
|
# Locks old closed issues
|
17
18
|
def lock
|
18
19
|
notify "Not locking anything due to -n flag" if @noop
|
19
|
-
notify "Getting closed issues..."
|
20
|
+
notify "Getting closed issues for %s/%s..." % [@user, @repo]
|
20
21
|
issues = get_closed_issues
|
21
22
|
|
22
23
|
if issues.empty?
|
@@ -28,7 +29,7 @@ class Locker
|
|
28
29
|
if @noop then
|
29
30
|
total = issues.size
|
30
31
|
|
31
|
-
issues.each_with_index do |issue, i|
|
32
|
+
issues.sort_by { |h| h["number"] }.each_with_index do |issue, i|
|
32
33
|
number = issue['number']
|
33
34
|
locking number, i, total
|
34
35
|
puts issue['title']
|
@@ -44,14 +45,20 @@ class Locker
|
|
44
45
|
# Fetches all closed, unlocked issues closed before cutoff date
|
45
46
|
def get_closed_issues
|
46
47
|
issues = []
|
47
|
-
path = "/repos/#@user/#@repo/issues?state=closed&
|
48
|
+
path = "/repos/#@user/#@repo/issues?state=closed&per_page=100&sort=updated&direction=asc"
|
48
49
|
page = 1
|
50
|
+
headers = {
|
51
|
+
'Authorization' => "Bearer #@token",
|
52
|
+
'Accept' => 'application/vnd.github+json',
|
53
|
+
'X-GitHub-Api-Version' => '2022-11-28'
|
54
|
+
}
|
55
|
+
|
49
56
|
http = Net::HTTP.start("api.github.com", 443, nil, nil, nil, nil, use_ssl: true)
|
50
57
|
|
51
58
|
loop do
|
52
59
|
notify "Retrieving page #{page}..."
|
53
60
|
|
54
|
-
resp = http.get(path)
|
61
|
+
resp = http.get(path, headers)
|
55
62
|
new_issues = JSON.parse(resp.body)
|
56
63
|
|
57
64
|
unless Array === new_issues then
|
@@ -61,9 +68,9 @@ class Locker
|
|
61
68
|
issues += new_issues
|
62
69
|
|
63
70
|
# Pagination
|
64
|
-
if resp['Link'] and resp['Link'].match
|
71
|
+
if resp['Link'] and resp['Link'].match(/<https:\/\/api\.github\.com(\/[^>]+)>; rel="next"/)
|
65
72
|
path = $1
|
66
|
-
page = path.match(
|
73
|
+
page = path.match(/&page=(\d+)/)[1]
|
67
74
|
else
|
68
75
|
http.finish
|
69
76
|
break
|
@@ -80,9 +87,12 @@ class Locker
|
|
80
87
|
|
81
88
|
# Expects array of issues from API call
|
82
89
|
def lock_old_closed_issues issues
|
83
|
-
headers = {'Accept' => 'application/vnd.github
|
90
|
+
headers = {'Accept' => 'application/vnd.github+json',
|
84
91
|
'Content-Length' => '0', # required for PUT with no body
|
85
|
-
'Authorization' => "
|
92
|
+
'Authorization' => "Bearer #@token",
|
93
|
+
'X-GitHub-Api-Version' => '2022-11-28',
|
94
|
+
'Content-Type' => 'application/json',
|
95
|
+
}
|
86
96
|
|
87
97
|
Net::HTTP.start("api.github.com", 443, nil, nil, nil, nil, use_ssl: true) do |http|
|
88
98
|
total = issues.length
|
@@ -92,7 +102,7 @@ class Locker
|
|
92
102
|
locking number, i, total
|
93
103
|
|
94
104
|
_, _, _, _, _, path, * = URI.split issue["url"]
|
95
|
-
response = http.put("#{path}/lock", '', headers)
|
105
|
+
response = http.put("#{path}/lock", '{"lock_reason":"off-topic"}', headers)
|
96
106
|
|
97
107
|
if response.code == "204" # 204 means it worked, apparently
|
98
108
|
locked
|
@@ -105,6 +115,7 @@ class Locker
|
|
105
115
|
|
106
116
|
# Print locking message
|
107
117
|
def locking number, item, total
|
118
|
+
return unless @level >= 1
|
108
119
|
print "[INFO] Locking #{number} (#{item + 1}/#{total})..."
|
109
120
|
end
|
110
121
|
|
@@ -115,6 +126,7 @@ class Locker
|
|
115
126
|
|
116
127
|
# Print INFO message
|
117
128
|
def notify message
|
129
|
+
return unless @level >= 2
|
118
130
|
puts "[INFO] #{message}"
|
119
131
|
end
|
120
132
|
|
@@ -123,4 +135,3 @@ class Locker
|
|
123
135
|
warn "[ERROR] #{message}"
|
124
136
|
end
|
125
137
|
end
|
126
|
-
|
metadata
CHANGED
@@ -1,19 +1,17 @@
|
|
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.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Collins
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-06-25 00:00:00.000000000 Z
|
12
11
|
dependencies: []
|
13
12
|
description: "Automatically locks GitHub issues older than a specified number of days.\nThis
|
14
13
|
forces people to open new issues instead of attaching themselves to old (typically
|
15
14
|
unrelated) issues. \n"
|
16
|
-
email:
|
17
15
|
executables:
|
18
16
|
- github-auto-locker
|
19
17
|
extensions: []
|
@@ -25,7 +23,6 @@ files:
|
|
25
23
|
homepage: https://github.com/presidentbeef/github-auto-locker
|
26
24
|
licenses: []
|
27
25
|
metadata: {}
|
28
|
-
post_install_message:
|
29
26
|
rdoc_options: []
|
30
27
|
require_paths:
|
31
28
|
- lib
|
@@ -40,9 +37,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
40
37
|
- !ruby/object:Gem::Version
|
41
38
|
version: '0'
|
42
39
|
requirements: []
|
43
|
-
|
44
|
-
rubygems_version: 2.4.8
|
45
|
-
signing_key:
|
40
|
+
rubygems_version: 3.6.2
|
46
41
|
specification_version: 4
|
47
42
|
summary: Simple script to lock closed GitHub issues over a certain age.
|
48
43
|
test_files: []
|