find-gh-commit-emails 1.0.0 → 1.1.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.
package/README.md CHANGED
@@ -3,14 +3,30 @@
3
3
  [![npm](https://img.shields.io/npm/v/find-gh-commit-emails/latest)](https://www.npmjs.com/package/find-gh-commit-emails)
4
4
  [![license: MIT](https://img.shields.io/npm/l/find-gh-commit-emails)](https://github.com/reifiedbeans/find-gh-commit-emails/blob/main/LICENSE)
5
5
 
6
- A script to search for emails used by a given GitHub user.
6
+ Utilities for finding emails used by a given GitHub user.
7
7
 
8
8
  ## Usage
9
9
 
10
+ This package provides an executable that can be invoked directly.
11
+
10
12
  ```shell
11
13
  npx find-gh-commit-emails <username>
12
14
  ```
13
15
 
16
+ A utility function is also provided for use in Node.js applications.
17
+
18
+ ```javascript
19
+ import { findEmails } from "find-gh-commit-emails";
20
+
21
+ const username = "<username>";
22
+ const token = "[token]";
23
+ const options = {
24
+ includeCommitter: true,
25
+ };
26
+
27
+ const emailMap = await findEmails(username, token, options);
28
+ ```
29
+
14
30
  ## License
15
31
 
16
32
  Licensed under the [MIT License](https://github.com/reifiedbeans/find-gh-commit-emails/blob/main/LICENSE).
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ findEmails
4
+ } from "../chunk-3EWDPDCO.js";
5
+
6
+ // bin/cli.ts
7
+ import { program } from "@commander-js/extra-typings";
8
+ program.name("find-gh-commit-emails").description(
9
+ "Search for emails used by a given GitHub user. Setting the GITHUB_TOKEN environment variable to a valid GitHub personal access token will enable searching in non-public repositories."
10
+ ).argument("username", "GitHub username to find emails for").option("--include-committer", "include committer email in results", false).configureHelp({ helpWidth: 80 }).showHelpAfterError().action(async (username, opts) => {
11
+ const token = process.env["GITHUB_TOKEN"];
12
+ const emailsMap = await findEmails(username, token, opts);
13
+ console.log(JSON.stringify(emailsMap, null, 2));
14
+ });
15
+ program.parse(process.argv);
@@ -0,0 +1,35 @@
1
+ // lib/index.ts
2
+ import { Octokit } from "octokit";
3
+ async function findEmails(username, token, opts) {
4
+ const github = new Octokit({ auth: token });
5
+ const commitData = await github.paginate("GET /search/commits", {
6
+ q: `author:${username}`
7
+ });
8
+ const emailMap = /* @__PURE__ */ new Map();
9
+ for (const entry of commitData) {
10
+ const repo = entry.repository.full_name;
11
+ const emails = [entry.commit.author.email];
12
+ if (opts?.includeCommitter && entry.commit.committer?.email) {
13
+ emails.push(entry.commit.committer.email);
14
+ }
15
+ for (const email of emails) {
16
+ let repos = emailMap.get(email);
17
+ if (!repos) {
18
+ repos = /* @__PURE__ */ new Set();
19
+ emailMap.set(email, repos);
20
+ }
21
+ repos.add(repo);
22
+ }
23
+ }
24
+ const object = {};
25
+ for (const [email, repos] of emailMap) {
26
+ Object.assign(object, {
27
+ [email]: Array.from(repos)
28
+ });
29
+ }
30
+ return object;
31
+ }
32
+
33
+ export {
34
+ findEmails
35
+ };
@@ -0,0 +1,14 @@
1
+ interface Options {
2
+ readonly includeCommitter?: boolean;
3
+ }
4
+ /**
5
+ * Find emails for a GitHub user
6
+ * @param username a GitHub username
7
+ * @param token a GitHub token
8
+ * @param opts additional options
9
+ */
10
+ declare function findEmails(username: string, token?: string, opts?: Options): Promise<{
11
+ [key: string]: string[];
12
+ }>;
13
+
14
+ export { findEmails };
@@ -0,0 +1,6 @@
1
+ import {
2
+ findEmails
3
+ } from "../chunk-3EWDPDCO.js";
4
+ export {
5
+ findEmails
6
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "find-gh-commit-emails",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Search for emails used by a given GitHub user",
5
5
  "repository": {
6
6
  "type": "git",
@@ -9,23 +9,26 @@
9
9
  "license": "MIT",
10
10
  "type": "module",
11
11
  "files": [
12
- "index.js"
12
+ "dist"
13
13
  ],
14
+ "main": "dist/lib/index.js",
15
+ "types": "dist/lib/index.d.ts",
14
16
  "bin": {
15
- "find-gh-commit-emails": "index.js"
17
+ "find-gh-commit-emails": "dist/bin/cli.js"
16
18
  },
17
19
  "engines": {
18
20
  "node": ">=18"
19
21
  },
20
22
  "scripts": {
23
+ "build": "tsup",
21
24
  "format": "prettier --write .",
22
25
  "format:check": "prettier --check .",
23
- "lint": "eslint --cache --max-warnings=0 .",
24
- "lint:fix": "eslint --fix --cache --max-warnings=0 .",
25
- "prepack": "npm-run-all lint format:check"
26
+ "lint": "tsc && eslint --cache --max-warnings=0 .",
27
+ "lint:fix": "tsc && eslint --fix --cache --max-warnings=0 .",
28
+ "prepack": "npm-run-all build lint format:check"
26
29
  },
27
30
  "dependencies": {
28
- "commander": "^12.1.0",
31
+ "@commander-js/extra-typings": "^12.1.0",
29
32
  "octokit": "^4.0.2"
30
33
  },
31
34
  "devDependencies": {
@@ -36,7 +39,9 @@
36
39
  "eslint": "^8.57.0",
37
40
  "eslint-config-prettier": "^9.1.0",
38
41
  "npm-run-all": "^4.1.5",
39
- "prettier": "^3.3.2"
42
+ "prettier": "^3.3.2",
43
+ "tsup": "^8.1.0",
44
+ "typescript": "^5.5.3"
40
45
  },
41
46
  "publishConfig": {
42
47
  "access": "public"
package/index.js DELETED
@@ -1,58 +0,0 @@
1
- #!/usr/bin/env node
2
- import { program } from "commander";
3
- import { Octokit } from "octokit";
4
-
5
- program
6
- .name("find-gh-commit-emails")
7
- .description(
8
- "Search for emails used by a given GitHub user. " +
9
- "Setting the GITHUB_TOKEN environment variable to a valid GitHub personal " +
10
- "access token will enable searching in non-public repositories.",
11
- )
12
- .argument("username", "GitHub username to find emails for")
13
- .option("--include-committer", "include committer email in results", false)
14
- .configureHelp({ helpWidth: 80 })
15
- .showHelpAfterError();
16
- program.parse(process.argv);
17
-
18
- const [username] = program.args;
19
- const { includeCommitter } = program.opts();
20
-
21
- const token = process.env["GITHUB_TOKEN"];
22
-
23
- const github = new Octokit({ auth: token });
24
-
25
- const commitData = await github.paginate("GET /search/commits", {
26
- q: `author:${username}`,
27
- });
28
-
29
- /** @type {Map<string, Set<string>>} */
30
- const emailMap = new Map();
31
-
32
- for (const entry of commitData) {
33
- const repo = entry.repository.full_name;
34
- const emails = [entry.commit.author.email];
35
-
36
- if (includeCommitter) {
37
- emails.push(entry.commit.committer.email);
38
- }
39
-
40
- for (const email of emails) {
41
- let repos = emailMap.get(email);
42
- if (!repos) {
43
- repos = new Set();
44
- emailMap.set(email, repos);
45
- }
46
- repos.add(repo);
47
- }
48
- }
49
-
50
- const json = JSON.stringify(
51
- Object.fromEntries(emailMap),
52
- (key, value) => {
53
- if (value instanceof Set) return Array.from(value);
54
- else return value;
55
- },
56
- 2,
57
- );
58
- console.log(json);