find_github_email 1.0.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 +7 -0
- data/.github/workflows/main.yml +31 -0
- data/.gitignore +4 -0
- data/.rspec +3 -0
- data/.rubocop.yml +59 -0
- data/CHANGELOG.md +13 -0
- data/CODE_OF_CONDUCT.md +76 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +75 -0
- data/README.md +59 -0
- data/bin/find_github_email +65 -0
- data/find_github_email.gemspec +32 -0
- data/lib/find_github_email.rb +8 -0
- data/lib/find_github_email/client.rb +18 -0
- data/lib/find_github_email/errors.rb +48 -0
- data/lib/find_github_email/finder.rb +51 -0
- data/lib/find_github_email/github_access_token.rb +28 -0
- data/lib/find_github_email/queries.rb +53 -0
- data/lib/find_github_email/version.rb +5 -0
- metadata +133 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 201870ef41eec5c3ff5ae341171ceab90e7095c752755b8d34cd4569f54d52f2
|
|
4
|
+
data.tar.gz: 7af2c259307efa3051ca0873844d701015c44174b7e26eaf915b116b8093075d
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 4cbcc885efb535d6cdfcc2169e6fff96420037b4719fc48b1cec8bedbcecb1bc4d9b0aeaf2792175a91c35769b624b0bf4a9a4db86c05632a4c244af34001ccc
|
|
7
|
+
data.tar.gz: b0a7feb2d016d4f3400c628479a257dd1df548be8fb1a20f3d4e7165407b955f2e15ec38dea603d9e63675de202537ac68cdbf7cdc2c7bec258c4f86bb93a517
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
name: Main
|
|
2
|
+
on:
|
|
3
|
+
pull_request:
|
|
4
|
+
branches:
|
|
5
|
+
- main
|
|
6
|
+
push:
|
|
7
|
+
branches:
|
|
8
|
+
- main
|
|
9
|
+
jobs:
|
|
10
|
+
ci:
|
|
11
|
+
name: CI
|
|
12
|
+
strategy:
|
|
13
|
+
fail-fast: false
|
|
14
|
+
matrix:
|
|
15
|
+
ruby: [jruby, 2.5, 2.6, 2.7]
|
|
16
|
+
runs-on: ubuntu-latest
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@main
|
|
19
|
+
- uses: ruby/setup-ruby@v1
|
|
20
|
+
with:
|
|
21
|
+
ruby-version: ${{ matrix.ruby }}
|
|
22
|
+
- uses: actions/cache@v1
|
|
23
|
+
with:
|
|
24
|
+
path: vendor/bundle
|
|
25
|
+
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
|
|
26
|
+
restore-keys: |
|
|
27
|
+
${{ runner.os }}-gems-
|
|
28
|
+
- run: bundle install --jobs 4 --retry 3
|
|
29
|
+
- run: bundle exec rspec
|
|
30
|
+
- run: bundle exec rubocop
|
|
31
|
+
if: matrix.ruby == 2.7
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
require:
|
|
2
|
+
- rubocop-rspec
|
|
3
|
+
|
|
4
|
+
AllCops:
|
|
5
|
+
NewCops: enable
|
|
6
|
+
TargetRubyVersion: 2.5
|
|
7
|
+
|
|
8
|
+
Layout/DotPosition:
|
|
9
|
+
EnforcedStyle: trailing
|
|
10
|
+
|
|
11
|
+
Layout/LineLength:
|
|
12
|
+
Max: 80
|
|
13
|
+
|
|
14
|
+
Lint/AmbiguousBlockAssociation:
|
|
15
|
+
Exclude:
|
|
16
|
+
- spec/**/*
|
|
17
|
+
|
|
18
|
+
Metrics/AbcSize:
|
|
19
|
+
Enabled: false
|
|
20
|
+
|
|
21
|
+
Metrics/BlockLength:
|
|
22
|
+
Exclude:
|
|
23
|
+
- spec/**/*
|
|
24
|
+
|
|
25
|
+
Metrics/ClassLength:
|
|
26
|
+
Enabled: false
|
|
27
|
+
|
|
28
|
+
Metrics/CyclomaticComplexity:
|
|
29
|
+
Enabled: false
|
|
30
|
+
|
|
31
|
+
Metrics/MethodLength:
|
|
32
|
+
Enabled: false
|
|
33
|
+
|
|
34
|
+
Metrics/PerceivedComplexity:
|
|
35
|
+
Max: 10
|
|
36
|
+
|
|
37
|
+
RSpec/AnyInstance:
|
|
38
|
+
Enabled: false
|
|
39
|
+
|
|
40
|
+
RSpec/HookArgument:
|
|
41
|
+
EnforcedStyle: each
|
|
42
|
+
|
|
43
|
+
RSpec/MultipleMemoizedHelpers:
|
|
44
|
+
Enabled: false
|
|
45
|
+
|
|
46
|
+
RSpec/NamedSubject:
|
|
47
|
+
Enabled: false
|
|
48
|
+
|
|
49
|
+
RSpec/NestedGroups:
|
|
50
|
+
Enabled: false
|
|
51
|
+
|
|
52
|
+
RSpec/MultipleExpectations:
|
|
53
|
+
Enabled: false
|
|
54
|
+
|
|
55
|
+
Style/GuardClause:
|
|
56
|
+
Enabled: false
|
|
57
|
+
|
|
58
|
+
Style/StringLiterals:
|
|
59
|
+
EnforcedStyle: double_quotes
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [1.0.0] - 2020-11-09
|
|
9
|
+
### Added
|
|
10
|
+
- Initial release of gem 🎉
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
[Unreleased]: https://github.com/jemmaissroff/find_github_email/releases/tag/v1.0.0
|
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting [Jemma Issroff](https://github.com/jemmaissroff). All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
|
62
|
+
incident. Further details of specific enforcement policies may be posted
|
|
63
|
+
separately.
|
|
64
|
+
|
|
65
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
66
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
67
|
+
members of the project's leadership.
|
|
68
|
+
|
|
69
|
+
## Attribution
|
|
70
|
+
|
|
71
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
72
|
+
version 1.4, available at
|
|
73
|
+
[https://contributor-covenant.org/version/1/4][version]
|
|
74
|
+
|
|
75
|
+
[homepage]: https://contributor-covenant.org
|
|
76
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
find_github_email (0.1.0)
|
|
5
|
+
graphql (~> 1.2.0)
|
|
6
|
+
graphql-client (~> 0.2.3)
|
|
7
|
+
|
|
8
|
+
GEM
|
|
9
|
+
remote: https://rubygems.org/
|
|
10
|
+
specs:
|
|
11
|
+
activesupport (5.2.4.4)
|
|
12
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
13
|
+
i18n (>= 0.7, < 2)
|
|
14
|
+
minitest (~> 5.1)
|
|
15
|
+
tzinfo (~> 1.1)
|
|
16
|
+
ast (2.4.1)
|
|
17
|
+
concurrent-ruby (1.1.7)
|
|
18
|
+
diff-lcs (1.4.4)
|
|
19
|
+
graphql (1.2.6)
|
|
20
|
+
graphql-client (0.2.6)
|
|
21
|
+
activesupport (>= 3.0, < 6.0)
|
|
22
|
+
graphql (>= 0.19.2)
|
|
23
|
+
i18n (1.8.5)
|
|
24
|
+
concurrent-ruby (~> 1.0)
|
|
25
|
+
minitest (5.14.2)
|
|
26
|
+
parallel (1.20.0)
|
|
27
|
+
parser (2.7.2.0)
|
|
28
|
+
ast (~> 2.4.1)
|
|
29
|
+
rainbow (3.0.0)
|
|
30
|
+
regexp_parser (1.8.2)
|
|
31
|
+
rexml (3.2.4)
|
|
32
|
+
rspec (3.10.0)
|
|
33
|
+
rspec-core (~> 3.10.0)
|
|
34
|
+
rspec-expectations (~> 3.10.0)
|
|
35
|
+
rspec-mocks (~> 3.10.0)
|
|
36
|
+
rspec-core (3.10.0)
|
|
37
|
+
rspec-support (~> 3.10.0)
|
|
38
|
+
rspec-expectations (3.10.0)
|
|
39
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
40
|
+
rspec-support (~> 3.10.0)
|
|
41
|
+
rspec-mocks (3.10.0)
|
|
42
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
43
|
+
rspec-support (~> 3.10.0)
|
|
44
|
+
rspec-support (3.10.0)
|
|
45
|
+
rubocop (1.2.0)
|
|
46
|
+
parallel (~> 1.10)
|
|
47
|
+
parser (>= 2.7.1.5)
|
|
48
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
49
|
+
regexp_parser (>= 1.8)
|
|
50
|
+
rexml
|
|
51
|
+
rubocop-ast (>= 1.0.1)
|
|
52
|
+
ruby-progressbar (~> 1.7)
|
|
53
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
|
54
|
+
rubocop-ast (1.1.1)
|
|
55
|
+
parser (>= 2.7.1.5)
|
|
56
|
+
rubocop-rspec (2.0.0)
|
|
57
|
+
rubocop (~> 1.0)
|
|
58
|
+
rubocop-ast (>= 1.1.0)
|
|
59
|
+
ruby-progressbar (1.10.1)
|
|
60
|
+
thread_safe (0.3.6)
|
|
61
|
+
tzinfo (1.2.8)
|
|
62
|
+
thread_safe (~> 0.1)
|
|
63
|
+
unicode-display_width (1.7.0)
|
|
64
|
+
|
|
65
|
+
PLATFORMS
|
|
66
|
+
ruby
|
|
67
|
+
|
|
68
|
+
DEPENDENCIES
|
|
69
|
+
find_github_email!
|
|
70
|
+
rspec (~> 3.10)
|
|
71
|
+
rubocop (~> 1.2.0)
|
|
72
|
+
rubocop-rspec (~> 2.0.0)
|
|
73
|
+
|
|
74
|
+
BUNDLED WITH
|
|
75
|
+
2.1.4
|
data/README.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Find GitHub Email
|
|
2
|
+
|
|
3
|
+
[](https://github.com/jemmaissroff/find_github_email/actions?query=workflow%3AMain)
|
|
4
|
+
[](https://hakiri.io/github/jemmaissroff/find_github_email/main)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
[](https://rubygems.org/gems/find_github_email)
|
|
7
|
+
[](https://rubygems.org/gems/find_github_email)
|
|
8
|
+
|
|
9
|
+
### ☀️ **The warmest start to a cold email** ❄️
|
|
10
|
+
|
|
11
|
+
Find GitHub Email allows you to find any GitHub user's email addresses based on their commit history and GitHub profile.
|
|
12
|
+
|
|
13
|
+
## ⏬ Installation
|
|
14
|
+
|
|
15
|
+
$ gem install find_github_email
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
Find Github Email uses [GitHub's API](https://developer.github.com/v4/). In order to use Find GitHub Email, you need a GitHub API token 🔑. Fortunately, these are very easy to obtain:
|
|
19
|
+
|
|
20
|
+
1. 👩💻 Visit https://github.com/settings/tokens/new
|
|
21
|
+
2. ✍️ Label the token whatever you would like
|
|
22
|
+
3. ✔️ Select the `read:user` box within the `user` section
|
|
23
|
+
4. 🟩 Click the green `Generate Token` button
|
|
24
|
+
5. 📝 Copy your token
|
|
25
|
+
|
|
26
|
+
Once you have your API token, in a console run
|
|
27
|
+
|
|
28
|
+
$ find_github_email -g <GITHUB_API_TOKEN>
|
|
29
|
+
|
|
30
|
+
You will only need to run this command once 🎉. It will store your API token at `~/.find_github_email_access_token`, and the gem will always look for it at that location.
|
|
31
|
+
|
|
32
|
+
## 📬 Usage
|
|
33
|
+
|
|
34
|
+
After you've followed the installation instructions, you can run:
|
|
35
|
+
|
|
36
|
+
$ find_github_email <USERNAME>
|
|
37
|
+
|
|
38
|
+
For example:
|
|
39
|
+
|
|
40
|
+
$ find_github_email torvalds
|
|
41
|
+
torvalds@linux-foundation.org
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
## 👩💻 Contributing
|
|
45
|
+
|
|
46
|
+
[Bug reports](https://github.com/jemmaissroff/find_github_email/issues) and
|
|
47
|
+
[pull requests](https://github.com/jemmaissroff/find_github_email/pulls) are welcome on GitHub at
|
|
48
|
+
https://github.com/jemmaissroff/find_github_email. This project is intended to be a safe,
|
|
49
|
+
welcoming space for collaboration, and contributors are expected to adhere to
|
|
50
|
+
the [code of conduct](https://github.com/jemmaissroff/find_github_email/blob/main/CODE_OF_CONDUCT.md).
|
|
51
|
+
|
|
52
|
+
## 📃 License
|
|
53
|
+
|
|
54
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
55
|
+
|
|
56
|
+
## ♥️ Code of Conduct
|
|
57
|
+
|
|
58
|
+
Everyone interacting in Find GitHub Email's codebase is expected to follow the
|
|
59
|
+
[code of conduct](https://github.com/jemmaissroff/find_github_email/blob/main/CODE_OF_CONDUCT.md).
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "optparse"
|
|
5
|
+
require "find_github_email"
|
|
6
|
+
|
|
7
|
+
begin
|
|
8
|
+
options = {}
|
|
9
|
+
OptionParser.new do |opts|
|
|
10
|
+
opts.banner = "Usage: find_github_email [options] <username>\n\n" \
|
|
11
|
+
"GitHub access token must be set to find a user's email address.\n" \
|
|
12
|
+
"For instructions on how to create a GitHub access token, " \
|
|
13
|
+
"see <>\n\n"
|
|
14
|
+
|
|
15
|
+
opts.on(
|
|
16
|
+
"-g GITHUB_ACCESS_TOKEN",
|
|
17
|
+
"--github-access-token GITHUB_ACCESS_TOKEN",
|
|
18
|
+
"Set GitHub access token. Only needs to be set once!"
|
|
19
|
+
) do |access_token|
|
|
20
|
+
FindGithubEmail::GithubAccessToken.github_access_token = (access_token)
|
|
21
|
+
exit if ARGV.empty? && !options[:username]
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
opts.on(
|
|
25
|
+
"-u USERNAME",
|
|
26
|
+
"--username USERNAME",
|
|
27
|
+
"Find GitHub email for username. " \
|
|
28
|
+
"Also accepted as the last argument without a flag"
|
|
29
|
+
) { |username| options[:username] = username }
|
|
30
|
+
|
|
31
|
+
opts.on("-v", "--verbose", "Wordier output") do
|
|
32
|
+
options[:verbose] = true
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
opts.on("-h", "--help", "Prints this help") do |_|
|
|
36
|
+
puts opts
|
|
37
|
+
exit
|
|
38
|
+
end
|
|
39
|
+
end.parse!
|
|
40
|
+
|
|
41
|
+
username = options[:username] || ARGV[0]
|
|
42
|
+
|
|
43
|
+
raise FindGithubEmail::Errors::NoUsernameProvided unless username
|
|
44
|
+
|
|
45
|
+
found_emails = FindGithubEmail::Finder.find(username)
|
|
46
|
+
|
|
47
|
+
output = found_emails.join("\n")
|
|
48
|
+
|
|
49
|
+
if options[:verbose]
|
|
50
|
+
if found_emails.size > 1
|
|
51
|
+
plural = "es"
|
|
52
|
+
article = "these"
|
|
53
|
+
else
|
|
54
|
+
article = "an"
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
output =
|
|
58
|
+
"Found #{article} email address#{plural} on GitHub for #{username}:\n" +
|
|
59
|
+
output
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
puts output
|
|
63
|
+
rescue FindGithubEmail::Errors::Error => e
|
|
64
|
+
abort(e.message)
|
|
65
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "lib/find_github_email/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "find_github_email"
|
|
7
|
+
spec.version = FindGithubEmail::VERSION
|
|
8
|
+
spec.authors = ["Jemma Issroff"]
|
|
9
|
+
spec.date = "2020-10-04"
|
|
10
|
+
spec.summary = "The warmest start to a cold email"
|
|
11
|
+
spec.homepage = "http://github.com/jemmaissroff/find_github_email"
|
|
12
|
+
spec.license = "MIT"
|
|
13
|
+
spec.description = <<-DESCRIPTION
|
|
14
|
+
Find GitHub Email is a gem to find any GitHub user's email addresses based
|
|
15
|
+
on their commit history.
|
|
16
|
+
DESCRIPTION
|
|
17
|
+
spec.email = "jemmaissroff@gmail.com"
|
|
18
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
|
|
19
|
+
spec.executables = ["find_github_email"]
|
|
20
|
+
|
|
21
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |file|
|
|
22
|
+
file.match(%r{^(spec)/})
|
|
23
|
+
end
|
|
24
|
+
spec.require_paths = ["lib"]
|
|
25
|
+
|
|
26
|
+
spec.add_dependency "graphql", "~> 1.2.0"
|
|
27
|
+
spec.add_dependency "graphql-client", "~> 0.2.3"
|
|
28
|
+
|
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.10"
|
|
30
|
+
spec.add_development_dependency "rubocop", "~> 1.2.0"
|
|
31
|
+
spec.add_development_dependency "rubocop-rspec", "~> 2.0.0"
|
|
32
|
+
end
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "find_github_email/client"
|
|
4
|
+
require "find_github_email/finder"
|
|
5
|
+
require "find_github_email/errors"
|
|
6
|
+
require "find_github_email/github_access_token"
|
|
7
|
+
require "find_github_email/queries"
|
|
8
|
+
require "find_github_email/version"
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "graphql/client/http"
|
|
4
|
+
require "graphql/client"
|
|
5
|
+
|
|
6
|
+
# Creates a GraphQL client to connect to GitHub's API
|
|
7
|
+
module FindGithubEmail
|
|
8
|
+
Client ||= GraphQL::Client.new(
|
|
9
|
+
execute: GraphQL::Client::HTTP.new("https://api.github.com/graphql") do
|
|
10
|
+
def headers(context)
|
|
11
|
+
{
|
|
12
|
+
"Authorization":
|
|
13
|
+
"Bearer #{context[:bearer]}"
|
|
14
|
+
}
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
)
|
|
18
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# rubocop:disable Style/Documentation
|
|
4
|
+
module FindGithubEmail
|
|
5
|
+
module Errors
|
|
6
|
+
class Error < RuntimeError
|
|
7
|
+
def initialize(access_token: nil, username: nil)
|
|
8
|
+
@access_token = access_token
|
|
9
|
+
@username = username
|
|
10
|
+
super
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
HELP_OUTPUT = "\nFor help, run: `find_github_email --help`"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
class InvalidAccessToken < Error
|
|
17
|
+
def message
|
|
18
|
+
"Oops, the access token `#{@access_token}` is invalid #{HELP_OUTPUT}"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
class NoAccessToken < Error
|
|
23
|
+
def message
|
|
24
|
+
"Oops, no access token set #{HELP_OUTPUT}"
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
class NoGithubUser < Error
|
|
29
|
+
def message
|
|
30
|
+
"Ooops, there is no GitHub user with username " \
|
|
31
|
+
"#{@username} #{HELP_OUTPUT}"
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
class NoEmailData < Error
|
|
36
|
+
def message
|
|
37
|
+
"#{@username} has no email data in GitHub"
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
class NoUsernameProvided < Error
|
|
42
|
+
def message
|
|
43
|
+
"Ooops, no username provided!#{HELP_OUTPUT}"
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
# rubocop:enable Style/Documentation
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "find_github_email"
|
|
4
|
+
|
|
5
|
+
module FindGithubEmail
|
|
6
|
+
# Finds a user's GitHub email addres by their username using GitHub's
|
|
7
|
+
# GrapQL API
|
|
8
|
+
class Finder
|
|
9
|
+
def self.find(username)
|
|
10
|
+
response = Client.query(
|
|
11
|
+
EmailQuery,
|
|
12
|
+
variables: { username: username },
|
|
13
|
+
context: { bearer: GithubAccessToken.github_access_token }
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
raise Errors::InvalidAccessToken if response.errors.any?
|
|
17
|
+
|
|
18
|
+
data = response.data.user&.data
|
|
19
|
+
|
|
20
|
+
raise Errors::NoGithubUser.new(username: username) unless data
|
|
21
|
+
|
|
22
|
+
# See spec/find_github_email/finder_spec.rb for examples of what the data
|
|
23
|
+
# format looks like
|
|
24
|
+
found_emails =
|
|
25
|
+
([data["email"]] +
|
|
26
|
+
find_emails(data["repositories"], username) +
|
|
27
|
+
find_emails(data["repositoriesContributedTo"], username) +
|
|
28
|
+
find_emails(data["topRepositories"], username)).
|
|
29
|
+
uniq.
|
|
30
|
+
compact.
|
|
31
|
+
reject { |s| s == "" || s =~ /noreply.github.com/ }
|
|
32
|
+
|
|
33
|
+
raise Errors::NoEmailData.new(username: username) if found_emails.empty?
|
|
34
|
+
|
|
35
|
+
found_emails
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def self.find_emails(data, username)
|
|
39
|
+
username = username.downcase
|
|
40
|
+
data["nodes"].compact.flat_map do |node|
|
|
41
|
+
node["refs"]["nodes"].flat_map do |sub_node|
|
|
42
|
+
author = sub_node["target"]["author"]
|
|
43
|
+
login = author["user"]&.[]"login"
|
|
44
|
+
if [login, author["name"]].compact.map(&:downcase).include?(username)
|
|
45
|
+
author["email"]
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "find_github_email"
|
|
4
|
+
|
|
5
|
+
module FindGithubEmail
|
|
6
|
+
# Allows a user to set and retrieve their GitHub access token to use the API
|
|
7
|
+
class GithubAccessToken
|
|
8
|
+
# Stores a user's access token at this file path
|
|
9
|
+
ACCESS_TOKEN_FILE_PATH =
|
|
10
|
+
File.expand_path("~/.find_github_email_access_token")
|
|
11
|
+
|
|
12
|
+
def self.github_access_token
|
|
13
|
+
raise Errors::NoAccessToken unless File.exist?(ACCESS_TOKEN_FILE_PATH)
|
|
14
|
+
|
|
15
|
+
@github_access_token ||= File.read(ACCESS_TOKEN_FILE_PATH)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.github_access_token=(access_token)
|
|
19
|
+
if Client.query(HelloQuery, context: { bearer: access_token }).errors.any?
|
|
20
|
+
raise Errors::InvalidAccessToken.new(access_token: access_token)
|
|
21
|
+
else
|
|
22
|
+
File.write(ACCESS_TOKEN_FILE_PATH, access_token)
|
|
23
|
+
@github_access_token = access_token
|
|
24
|
+
puts "Successfully set GitHub access token"
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "find_github_email/client"
|
|
4
|
+
|
|
5
|
+
module FindGithubEmail
|
|
6
|
+
HelloQuery = Client.parse <<-"GRAPHQL"
|
|
7
|
+
{
|
|
8
|
+
viewer {
|
|
9
|
+
login
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
GRAPHQL
|
|
13
|
+
|
|
14
|
+
EmailQuery = Client.parse <<-"GRAPHQL"
|
|
15
|
+
query($username: String!) {
|
|
16
|
+
user(login: $username) {
|
|
17
|
+
email
|
|
18
|
+
repositories(first: 100) {
|
|
19
|
+
...userFields
|
|
20
|
+
}
|
|
21
|
+
repositoriesContributedTo(first: 100) {
|
|
22
|
+
...userFields
|
|
23
|
+
}
|
|
24
|
+
topRepositories(
|
|
25
|
+
first: 100,
|
|
26
|
+
orderBy: {field:UPDATED_AT, direction:ASC}
|
|
27
|
+
) {
|
|
28
|
+
...userFields
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
fragment userFields on RepositoryConnection {
|
|
34
|
+
nodes {
|
|
35
|
+
refs(refPrefix: "refs/heads/", first: 100) {
|
|
36
|
+
nodes {
|
|
37
|
+
target {
|
|
38
|
+
... on Commit {
|
|
39
|
+
author {
|
|
40
|
+
email
|
|
41
|
+
name
|
|
42
|
+
user {
|
|
43
|
+
login
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
GRAPHQL
|
|
53
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: find_github_email
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Jemma Issroff
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2020-10-04 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: graphql
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 1.2.0
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 1.2.0
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: graphql-client
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 0.2.3
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 0.2.3
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.10'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.10'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rubocop
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: 1.2.0
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: 1.2.0
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rubocop-rspec
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: 2.0.0
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: 2.0.0
|
|
83
|
+
description: |2
|
|
84
|
+
Find GitHub Email is a gem to find any GitHub user's email addresses based
|
|
85
|
+
on their commit history.
|
|
86
|
+
email: jemmaissroff@gmail.com
|
|
87
|
+
executables:
|
|
88
|
+
- find_github_email
|
|
89
|
+
extensions: []
|
|
90
|
+
extra_rdoc_files: []
|
|
91
|
+
files:
|
|
92
|
+
- ".github/workflows/main.yml"
|
|
93
|
+
- ".gitignore"
|
|
94
|
+
- ".rspec"
|
|
95
|
+
- ".rubocop.yml"
|
|
96
|
+
- CHANGELOG.md
|
|
97
|
+
- CODE_OF_CONDUCT.md
|
|
98
|
+
- Gemfile
|
|
99
|
+
- Gemfile.lock
|
|
100
|
+
- README.md
|
|
101
|
+
- bin/find_github_email
|
|
102
|
+
- find_github_email.gemspec
|
|
103
|
+
- lib/find_github_email.rb
|
|
104
|
+
- lib/find_github_email/client.rb
|
|
105
|
+
- lib/find_github_email/errors.rb
|
|
106
|
+
- lib/find_github_email/finder.rb
|
|
107
|
+
- lib/find_github_email/github_access_token.rb
|
|
108
|
+
- lib/find_github_email/queries.rb
|
|
109
|
+
- lib/find_github_email/version.rb
|
|
110
|
+
homepage: http://github.com/jemmaissroff/find_github_email
|
|
111
|
+
licenses:
|
|
112
|
+
- MIT
|
|
113
|
+
metadata: {}
|
|
114
|
+
post_install_message:
|
|
115
|
+
rdoc_options: []
|
|
116
|
+
require_paths:
|
|
117
|
+
- lib
|
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
119
|
+
requirements:
|
|
120
|
+
- - ">="
|
|
121
|
+
- !ruby/object:Gem::Version
|
|
122
|
+
version: 2.5.0
|
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
|
+
requirements:
|
|
125
|
+
- - ">="
|
|
126
|
+
- !ruby/object:Gem::Version
|
|
127
|
+
version: '0'
|
|
128
|
+
requirements: []
|
|
129
|
+
rubygems_version: 3.1.4
|
|
130
|
+
signing_key:
|
|
131
|
+
specification_version: 4
|
|
132
|
+
summary: The warmest start to a cold email
|
|
133
|
+
test_files: []
|