Class: Fue::Finder
- Inherits:
-
Object
- Object
- Fue::Finder
- Defined in:
- lib/fue/finder.rb
Instance Attribute Summary collapse
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #author_id(username) ⇒ Object
- #contributors(options = {}) ⇒ Object
- #emails(options = {}) ⇒ Object
-
#initialize(token, _options = {}) ⇒ Finder
constructor
A new instance of Finder.
Constructor Details
#initialize(token, _options = {}) ⇒ Finder
Returns a new instance of Finder.
7 8 9 |
# File 'lib/fue/finder.rb', line 7 def initialize(token, = {}) @token = token end |
Instance Attribute Details
#token ⇒ Object (readonly)
Returns the value of attribute token.
5 6 7 |
# File 'lib/fue/finder.rb', line 5 def token @token end |
Instance Method Details
#author_id(username) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/fue/finder.rb', line 11 def (username) query = <<-GRAPHQL query($login: String!) { user(login: $login) { id } } GRAPHQL graphql_client.query(query, login: username).data.user.id end |
#contributors(options = {}) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/fue/finder.rb', line 89 def contributors( = {}) query = <<-GRAPHQL query($owner: String!, $name: String!, $cursor: String) { repository(owner: $owner, name: $name) { defaultBranchRef { target { ... on Commit { history(first: 100, after: $cursor) { nodes { author { user { login } } } pageInfo { endCursor } } } } } } } GRAPHQL repo_owner, repo_name = [:repo].split('/', 2) = { owner: repo_owner, name: repo_name } logins = Set.new $stdout.write 'Fetching contributors .' if [:verbose] loop do response = graphql_client.query(query, ) history = response&.data&.repository&.default_branch_ref&.target&.history history&.nodes&.each do |node| login = node..user&.login logins << login if login end [:cursor] = history&.page_info.end_cursor $stdout.write '.' if [:verbose] break unless [:cursor] end puts " found #{logins.size} contributor#{logins.size == 1 ? '' : 's'}." if [:verbose] logins.map do |login| [login, emails(.merge(username: login))] rescue StandardError => e warn e.to_s end.compact.to_h end |
#emails(options = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/fue/finder.rb', line 22 def emails( = {}) query = <<-GRAPHQL query($login: String!, $author_id: ID!, $depth: Int!, $breadth: Int!, $cursor: String) { user(login: $login) { repositories(last: $breadth, after: $cursor, isFork:false, privacy: PUBLIC) { nodes { defaultBranchRef { target { ... on Commit { history(first: $depth, author: { id: $author_id }) { nodes { author { email name } } } } } } } pageInfo { startCursor } } } } GRAPHQL # max number of repositories to search max_breadth = [:breadth] || 10 = { login: [:username], author_id: ([:username]), # max number of commits to look into depth: [:depth] || 1 } $stdout.write "Searching for emails for #{[:username]} ." if [:verbose] emails = Set.new loop do [:breadth] = [max_breadth, 100].min response = graphql_client.query(query, ) repositories = response&.data&.user&.repositories repositories&.nodes&.each do |history| default_history = history.default_branch_ref&.target&.history default_history&.nodes&.each do |node| emails << "#{node..name} <#{node..email}>" end end [:cursor] = repositories&.page_info&.start_cursor break unless [:cursor] max_breadth -= 100 break if max_breadth <= 0 $stdout.write '.' if [:verbose] end puts " found #{emails.size} email address#{emails.size == 1 ? '' : 'es'}." if [:verbose] emails.to_a end |