├── bun.lockb ├── .prettierrc ├── .env_example ├── README.md ├── package.json ├── tsconfig.json ├── LICENSE ├── .gitignore └── index.ts /bun.lockb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gizmo-ds/github-email-checker/main/bun.lockb -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "semi": false, 3 | "singleQuote": true, 4 | "printWidth": 80 5 | } 6 | -------------------------------------------------------------------------------- /.env_example: -------------------------------------------------------------------------------- 1 | GITHUB_TOKEN=[your token] 2 | USERNAME=gizmo-ds 3 | ORGS=project-vrcat,GizmoOAO 4 | KEYWORDS=@qq.com,@gmail.com 5 | CHECK_COMMITTER=true 6 | MAX_COMMITS_PAGES=10 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # github-email-checker 2 | 3 | To install dependencies: 4 | 5 | ```bash 6 | bun install 7 | ``` 8 | 9 | To run: 10 | 11 | ```bash 12 | bun run index.ts 13 | ``` 14 | 15 | This project was created using `bun init` in bun v0.5.3. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime. 16 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "github-email-checker", 3 | "author": { 4 | "name": "Gizmo", 5 | "email": "me@aika.dev" 6 | }, 7 | "license": "MIT", 8 | "homepage": "https://github.com/gizmo-ds/github-email-checker", 9 | "private": true, 10 | "module": "index.ts", 11 | "type": "module", 12 | "devDependencies": { 13 | "bun-types": "^0.5.0" 14 | }, 15 | "peerDependencies": { 16 | "typescript": "^5.0.0" 17 | }, 18 | "dependencies": { 19 | "dotenv": "^16.3.1", 20 | "winston": "^3.11.0" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "lib": [ 4 | "ESNext" 5 | ], 6 | "module": "esnext", 7 | "target": "esnext", 8 | "moduleResolution": "bundler", 9 | "moduleDetection": "force", 10 | "allowImportingTsExtensions": true, 11 | "strict": true, 12 | "downlevelIteration": true, 13 | "skipLibCheck": true, 14 | "jsx": "preserve", 15 | "allowSyntheticDefaultImports": true, 16 | "forceConsistentCasingInFileNames": true, 17 | "allowJs": true, 18 | "types": [ 19 | "bun-types" // add Bun global 20 | ] 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Gizmo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore 2 | 3 | # Logs 4 | 5 | logs 6 | _.log 7 | npm-debug.log_ 8 | yarn-debug.log* 9 | yarn-error.log* 10 | lerna-debug.log* 11 | .pnpm-debug.log* 12 | 13 | # Diagnostic reports (https://nodejs.org/api/report.html) 14 | 15 | report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json 16 | 17 | # Runtime data 18 | 19 | pids 20 | _.pid 21 | _.seed 22 | \*.pid.lock 23 | 24 | # Directory for instrumented libs generated by jscoverage/JSCover 25 | 26 | lib-cov 27 | 28 | # Coverage directory used by tools like istanbul 29 | 30 | coverage 31 | \*.lcov 32 | 33 | # nyc test coverage 34 | 35 | .nyc_output 36 | 37 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 38 | 39 | .grunt 40 | 41 | # Bower dependency directory (https://bower.io/) 42 | 43 | bower_components 44 | 45 | # node-waf configuration 46 | 47 | .lock-wscript 48 | 49 | # Compiled binary addons (https://nodejs.org/api/addons.html) 50 | 51 | build/Release 52 | 53 | # Dependency directories 54 | 55 | node_modules/ 56 | jspm_packages/ 57 | 58 | # Snowpack dependency directory (https://snowpack.dev/) 59 | 60 | web_modules/ 61 | 62 | # TypeScript cache 63 | 64 | \*.tsbuildinfo 65 | 66 | # Optional npm cache directory 67 | 68 | .npm 69 | 70 | # Optional eslint cache 71 | 72 | .eslintcache 73 | 74 | # Optional stylelint cache 75 | 76 | .stylelintcache 77 | 78 | # Microbundle cache 79 | 80 | .rpt2_cache/ 81 | .rts2_cache_cjs/ 82 | .rts2_cache_es/ 83 | .rts2_cache_umd/ 84 | 85 | # Optional REPL history 86 | 87 | .node_repl_history 88 | 89 | # Output of 'npm pack' 90 | 91 | \*.tgz 92 | 93 | # Yarn Integrity file 94 | 95 | .yarn-integrity 96 | 97 | # dotenv environment variable files 98 | 99 | .env 100 | .env.development.local 101 | .env.test.local 102 | .env.production.local 103 | .env.local 104 | 105 | # parcel-bundler cache (https://parceljs.org/) 106 | 107 | .cache 108 | .parcel-cache 109 | 110 | # Next.js build output 111 | 112 | .next 113 | out 114 | 115 | # Nuxt.js build / generate output 116 | 117 | .nuxt 118 | dist 119 | 120 | # Gatsby files 121 | 122 | .cache/ 123 | 124 | # Comment in the public line in if your project uses Gatsby and not Next.js 125 | 126 | # https://nextjs.org/blog/next-9-1#public-directory-support 127 | 128 | # public 129 | 130 | # vuepress build output 131 | 132 | .vuepress/dist 133 | 134 | # vuepress v2.x temp and cache directory 135 | 136 | .temp 137 | .cache 138 | 139 | # Docusaurus cache and generated files 140 | 141 | .docusaurus 142 | 143 | # Serverless directories 144 | 145 | .serverless/ 146 | 147 | # FuseBox cache 148 | 149 | .fusebox/ 150 | 151 | # DynamoDB Local files 152 | 153 | .dynamodb/ 154 | 155 | # TernJS port file 156 | 157 | .tern-port 158 | 159 | # Stores VSCode versions used for testing VSCode extensions 160 | 161 | .vscode-test 162 | 163 | # yarn v2 164 | 165 | .yarn/cache 166 | .yarn/unplugged 167 | .yarn/build-state.yml 168 | .yarn/install-state.gz 169 | .pnp.\* 170 | 171 | results.txt 172 | -------------------------------------------------------------------------------- /index.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S bun run 2 | import { config } from 'dotenv' 3 | import { createLogger, format, transports } from 'winston' 4 | 5 | config() 6 | 7 | const token = process.env.GITHUB_TOKEN || '' 8 | const username = process.env.USERNAME || '' 9 | const orgs = process.env.ORGS?.split(',') || [] 10 | const keywords = process.env.KEYWORDS?.split(',') || [] 11 | const check_committer = process.env.CHECK_COMMITTER?.toLowerCase() === 'true' 12 | const max_commits_pages = parseInt(process.env.MAX_COMMITS_PAGES || '10') 13 | 14 | const log = createLogger({ 15 | transports: [ 16 | new transports.Console({ 17 | level: 'info', 18 | format: format.cli(), 19 | }), 20 | new transports.File({ 21 | level: 'warn', 22 | filename: 'results.txt', 23 | format: format.simple(), 24 | }), 25 | ], 26 | }) 27 | 28 | async function main() { 29 | let repos = (await get_repos(username)) as any[] 30 | for (const org of orgs) { 31 | repos = repos.concat((await get_organization_repositories(org)) as any[]) 32 | } 33 | 34 | await Promise.all( 35 | repos.map((repo: any) => { 36 | return (async (repo: any) => { 37 | const branches: any = await get_branches(repo.full_name) 38 | for (const branch of branches) { 39 | log.info(`Checking ${repo.full_name}/tree/${branch.name}`) 40 | let commits: any[] = [] 41 | for (let p = 0; p < max_commits_pages; p++) { 42 | const _commits = (await get_commits( 43 | repo.full_name, 44 | branch.name, 45 | p + 1 46 | )) as any[] 47 | commits = commits.concat(_commits) 48 | if (_commits.length < 100) break 49 | } 50 | for (const commit of commits) check_email(commit) 51 | } 52 | })(repo) 53 | }) 54 | ) 55 | } 56 | 57 | function check_email(commit: any) { 58 | const author = commit.commit.author 59 | const committer = commit.commit.committer 60 | for (const keyword of keywords) { 61 | const author_found = author.email.includes(keyword) 62 | const committer_found = committer.email.includes(keyword) 63 | if (author_found || (check_committer && committer_found)) { 64 | const obj = { 65 | url: commit.html_url, 66 | committer: check_committer && committer_found ? committer : undefined, 67 | author: author_found ? author : undefined, 68 | } 69 | log.warn(`Found "${keyword}" in commit: ${JSON.stringify(obj)}`) 70 | return 71 | } 72 | } 73 | } 74 | 75 | async function req( 76 | method: string, 77 | url: string, 78 | body?: BodyInit | null | undefined 79 | ) { 80 | return await fetch(url, { 81 | method: method, 82 | headers: { 83 | Accept: 'application/vnd.github+json', 84 | Authorization: `Bearer ${token}`, 85 | 'X-GitHub-Api-Version': '2022-11-28', 86 | }, 87 | body: body, 88 | }).then((res) => res.json()) 89 | } 90 | 91 | async function get_branches(full_name: string) { 92 | return await req('GET', `https://api.github.com/repos/${full_name}/branches`) 93 | } 94 | 95 | async function get_rate_limit() { 96 | return await req('GET', `https://api.github.com/rate_limit`) 97 | } 98 | 99 | async function get_repos(user: string, page = 1) { 100 | if (user === '') return [] 101 | return await req( 102 | 'GET', 103 | `https://api.github.com/users/${user}/repos?per_page=100&page=${page}` 104 | ) 105 | } 106 | 107 | async function get_organization_repositories(org: string, page = 1) { 108 | return await req( 109 | 'GET', 110 | `https://api.github.com/orgs/${org}/repos?per_page=100&page=${page}` 111 | ) 112 | } 113 | 114 | async function get_commits(full_name: string, sha = '', page = 1) { 115 | return await req( 116 | 'GET', 117 | `https://api.github.com/repos/${full_name}/commits?per_page=100&page=${page}&sha=${sha}` 118 | ) 119 | } 120 | 121 | await main() 122 | 123 | export {} 124 | --------------------------------------------------------------------------------