|
22 | 22 | kit.auto_paginate = true
|
23 | 23 | end
|
24 | 24 |
|
25 |
| -pattern = /\[[^\]]*\]\(([^\)]*)\)/ |
| 25 | +# Extract links to attached files using regexp |
| 26 | +pattern = /\[[^\]]*\]\((#{hostname}[^\)]*\/files\/[^\)]*)\)/ |
| 27 | + |
26 | 28 | 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]}"}} |
| 29 | + # Extract issues containing links to attached files |
| 30 | + issues = Octokit.issues(r, {state: :all}).select do |i| |
| 31 | + i.body.match(pattern) |
| 32 | + end |
| 33 | + issues.each do |issue| |
| 34 | + # Extract the link pattern from issues' body |
| 35 | + matched_links = issue.body.scan(pattern) |
| 36 | + matched_links.each do |file| |
| 37 | + puts "#{issue.html_url},#{file[0]}" |
| 38 | + end |
| 39 | + end |
| 40 | + |
| 41 | + # Issue comments as well (including pull request comments) |
| 42 | + issue_comments = Octokit.issues_comments(r).select do |ic| |
| 43 | + ic.body.match(pattern) |
| 44 | + end |
| 45 | + issue_comments.each do |issue_comment| |
| 46 | + matched_links = issue_comment.body.scan(pattern) |
| 47 | + matched_links.each do |file| |
| 48 | + puts "#{issue_comment.html_url},#{file[0]}" |
| 49 | + end |
| 50 | + end |
| 51 | + |
| 52 | + # Pull request review comments as well |
| 53 | + pr_comments = Octokit.pulls_comments(r).select do |prc| |
| 54 | + prc.body.match(pattern) |
| 55 | + end |
| 56 | + pr_comments.each do |pr_comment| |
| 57 | + matched_links = pr_comment.body.scan(pattern) |
| 58 | + matched_links.each do |file| |
| 59 | + puts "#{pr_comment.html_url},#{file[0]}" |
| 60 | + end |
| 61 | + end |
30 | 62 | end
|
0 commit comments