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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 20ce42e4558ac26ff70d4b7bf0894f5433bdf632
4
- data.tar.gz: c65235c6837014caac8832ea160ef8139158b313
2
+ SHA256:
3
+ metadata.gz: 858eda7dc1d1e986103a660b36f7b055eb6b6469e770b9ea3422567a5aba2ae1
4
+ data.tar.gz: d278bac7d0160ab48d712fcd2cc9d12988fca48fc171775164352f8002a35ab2
5
5
  SHA512:
6
- metadata.gz: 023fac05c29d54e545be8b0e08f087f16be2ab8e81c318d3c081461485044cc7f8b4cd2120359699fa8352a6e0bfa3683ddecb2b09415f0ac080531a47ce0fe1
7
- data.tar.gz: dfce37664a9f2a047f1b105b738757ee80fb4997b38e06f7debced3564ee6752bf136f7053ea46a913c6102cb0e4ade670926f7bcc929fea84af97dabdcfb036
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 USER REPO TOKEN [age in days] [-n]`
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 USER REPO TOKEN [age in days]`[-n]
19
+ * Run `github-auto-locker USER_OR_ORG REPO TOKEN [age in days]`[-n]
20
20
 
21
21
  The age is optional.
22
22
 
@@ -4,7 +4,7 @@ require_relative '../lib/locker'
4
4
  noop = ARGV.delete "-n"
5
5
  user, repo, token, days = ARGV
6
6
 
7
- unless token then
7
+ unless token && !token.empty? then
8
8
  hub_config = File.expand_path "~/.config/hub"
9
9
 
10
10
  if File.file? hub_config then
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&access_token=#@token&sort=updated&direction=asc"
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 /<https:\/\/api\.github\.com(\/[^>]+)>; rel="next",/
71
+ if resp['Link'] and resp['Link'].match(/<https:\/\/api\.github\.com(\/[^>]+)>; rel="next"/)
65
72
  path = $1
66
- page = path.match(/page=(\d+)/)[1]
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.the-key-preview+json', # required for new lock API
90
+ headers = {'Accept' => 'application/vnd.github+json',
84
91
  'Content-Length' => '0', # required for PUT with no body
85
- 'Authorization' => "Basic #{Base64.strict_encode64("#@user:#@token")}"}
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.1.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: 2017-05-20 00:00:00.000000000 Z
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
- rubyforge_project:
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: []