UNPKG

release-notes-cli

Version:

Generate release notes from git for playstore/appstore or github

43 lines (42 loc) 1.82 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; const { Octokit } = require("@octokit/rest"); function searchCommits(octokit, email) { return __awaiter(this, void 0, void 0, function* () { const { data } = yield octokit.search.commits({ q: `author-email:${email}`, sort: "author-date", per_page: 1, }); if (data.total_count === 0) { throw new Error(`Couldn't find username for \`${email}\``); } return data.items[0].author.login; }); } module.exports = function githubUsername(email, { token } = {}) { return __awaiter(this, void 0, void 0, function* () { if (!(typeof email === "string" && email.includes("@"))) { throw new Error("Email required"); } const octokit = new Octokit({ auth: token, userAgent: "https://github.com/nomi9995/github-username", }); const { data } = yield octokit.search.users({ q: `${email} in:email`, }); if (data.total_count === 0) { return searchCommits(octokit, email); } return data.items[0].login; }); };