Skip to content

Commit e89e08f

Browse files
author
doublemarket
committed
added list_issue_attached_files.rb
1 parent cf11259 commit e89e08f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
require 'octokit'
2+
3+
# Lists all files attached to issues and pull requests on a instance.
4+
# The list doesn't contain files that are uploaded but not referenced.
5+
6+
## Check for environment variables
7+
begin
8+
access_token = ENV.fetch("GITHUB_TOKEN")
9+
hostname = ENV.fetch("GITHUB_HOSTNAME")
10+
rescue KeyError
11+
puts
12+
puts "To run this script, please set the following environment variables:"
13+
puts "- GITHUB_TOKEN: A valid access token"
14+
puts "- GITHUB_HOSTNAME: A valid GitHub Enterprise hostname"
15+
exit 1
16+
end
17+
18+
# Set up Octokit
19+
Octokit.configure do |kit|
20+
kit.api_endpoint = "#{hostname}/api/v3"
21+
kit.access_token = access_token
22+
kit.auto_paginate = true
23+
end
24+
25+
pattern = /\[[^\]]*\]\(([^\)]*)\)/
26+
Octokit.repositories.map{|repo| repo.full_name}.each do |r|
27+
Octokit.issues(r, {state: :all}).select{|i| i.body.match(pattern)}.each{|mi| mi.body.scan(pattern).each{|s| puts "#{mi.html_url},#{s[0]}"}}
28+
Octokit.issues_comments(r).select{|ic| ic.body.match(pattern)}.each{|mic| mic.body.scan(pattern).each{|s| puts "#{mic.html_url},#{s[0]}"}}
29+
Octokit.pulls_comments(r).select{|prc| prc.body.match(pattern)}.each{|mprc| mprc.body.scan(pattern).each{|s| puts "#{mprc.html_url},#{s[0]}"}}
30+
end

0 commit comments

Comments
 (0)