Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@changesets/get-github-info

Package Overview
Dependencies
Maintainers
3
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@changesets/get-github-info - npm Package Compare versions

Comparing version 0.4.4 to 0.4.5

6

CHANGELOG.md
# @changesets/get-github-info
## 0.4.5
### Patch Changes
- [`3436c53`](https://github.com/atlassian/changesets/commit/3436c53acf444c2ce19f8548920b7b73461a9c76) [#510](https://github.com/atlassian/changesets/pull/510) Thanks [@tuanddd](https://github.com/tuanddd)! - Added validation rule for invalid `repo` arguments.
## 0.4.4

@@ -4,0 +10,0 @@

18

dist/get-github-info.cjs.dev.js

@@ -5,8 +5,12 @@ 'use strict';

function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var fetch = require('node-fetch');
var DataLoader = require('dataloader');
var fetch = _interopDefault(require('node-fetch'));
var DataLoader = _interopDefault(require('dataloader'));
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
var fetch__default = /*#__PURE__*/_interopDefault(fetch);
var DataLoader__default = /*#__PURE__*/_interopDefault(DataLoader);
// @ts-ignore
const validRepoNameRegex = /^[\w.-]+\/[\w.-]+$/;

@@ -55,3 +59,3 @@ function makeQuery(repos) {

const GHDataLoader = new DataLoader(async requests => {
const GHDataLoader = new DataLoader__default['default'](async requests => {
if (!process.env.GITHUB_TOKEN) {

@@ -72,3 +76,3 @@ throw new Error("Please create a GitHub personal access token at https://github.com/settings/tokens/new and add it as the GITHUB_TOKEN environment variable");

});
const data = await fetch("https://api.github.com/graphql", {
const data = await fetch__default['default']("https://api.github.com/graphql", {
method: "POST",

@@ -110,2 +114,6 @@ headers: {

if (!validRepoNameRegex.test(request.repo)) {
throw new Error(`Please pass a valid GitHub repository in the form of userOrOrg/repoName to getInfo (it has to match the "${validRepoNameRegex.source}" pattern)`);
}
const data = await GHDataLoader.load(request);

@@ -112,0 +120,0 @@ let user = null;

"use strict";
function _interopDefault(ex) {
return ex && "object" == typeof ex && "default" in ex ? ex.default : ex;
}
Object.defineProperty(exports, "__esModule", {

@@ -11,18 +7,28 @@ value: !0

var fetch = _interopDefault(require("node-fetch")), DataLoader = _interopDefault(require("dataloader"));
var fetch = require("node-fetch"), DataLoader = require("dataloader");
function _interopDefault(e) {
return e && e.__esModule ? e : {
default: e
};
}
var fetch__default = _interopDefault(fetch), DataLoader__default = _interopDefault(DataLoader);
const validRepoNameRegex = /^[\w.-]+\/[\w.-]+$/;
function makeQuery(repos) {
return `\n query {\n ${Object.keys(repos).map((repo, i) => `a${i}: repository(\n owner: ${JSON.stringify(repo.split("/")[0])}\n name: ${JSON.stringify(repo.split("/")[1])}\n ) {\n ${repos[repo].map(commit => `a${commit}: object(expression: ${JSON.stringify(commit)}) {\n ... on Commit {\n commitUrl\n associatedPullRequests(first: 50) {\n nodes {\n number\n url\n mergedAt\n author {\n login\n url\n }\n }\n }\n author {\n user {\n login\n url\n }\n }\n }}`).join("\n")}\n }`).join("\n")}\n }\n `;
return `\n query {\n ${Object.keys(repos).map(((repo, i) => `a${i}: repository(\n owner: ${JSON.stringify(repo.split("/")[0])}\n name: ${JSON.stringify(repo.split("/")[1])}\n ) {\n ${repos[repo].map((commit => `a${commit}: object(expression: ${JSON.stringify(commit)}) {\n ... on Commit {\n commitUrl\n associatedPullRequests(first: 50) {\n nodes {\n number\n url\n mergedAt\n author {\n login\n url\n }\n }\n }\n author {\n user {\n login\n url\n }\n }\n }}`)).join("\n")}\n }`)).join("\n")}\n }\n `;
}
const GHDataLoader = new DataLoader(async requests => {
const GHDataLoader = new DataLoader__default.default((async requests => {
if (!process.env.GITHUB_TOKEN) throw new Error("Please create a GitHub personal access token at https://github.com/settings/tokens/new and add it as the GITHUB_TOKEN environment variable");
let repos = {};
requests.forEach(({commit: commit, repo: repo}) => {
requests.forEach((({commit: commit, repo: repo}) => {
void 0 === repos[repo] && (repos[repo] = []), repos[repo].push(commit);
});
const data = await fetch("https://api.github.com/graphql", {
}));
const data = await fetch__default.default("https://api.github.com/graphql", {
method: "POST",
headers: {
Authorization: `Token ${process.env.GITHUB_TOKEN}`
Authorization: "Token " + process.env.GITHUB_TOKEN
},

@@ -32,10 +38,10 @@ body: JSON.stringify({

})
}).then(x => x.json());
if (!data.data) throw new Error(`An error occurred when fetching data from GitHub\n${JSON.stringify(data)}`);
}).then((x => x.json()));
if (!data.data) throw new Error("An error occurred when fetching data from GitHub\n" + JSON.stringify(data));
let cleanedData = {}, dataKeys = Object.keys(data.data);
return Object.keys(repos).forEach((repo, index) => {
return Object.keys(repos).forEach(((repo, index) => {
cleanedData[repo] = {};
for (let nearlyCommit in data.data[dataKeys[index]]) cleanedData[repo][nearlyCommit.substring(1)] = data.data[dataKeys[index]][nearlyCommit];
}), requests.map(({repo: repo, commit: commit}) => cleanedData[repo][commit]);
});
})), requests.map((({repo: repo, commit: commit}) => cleanedData[repo][commit]));
}));

@@ -45,6 +51,7 @@ async function getInfo(request) {

if (!request.repo) throw new Error("Please pass a GitHub repository in the form of userOrOrg/repoName to getInfo");
if (!validRepoNameRegex.test(request.repo)) throw new Error(`Please pass a valid GitHub repository in the form of userOrOrg/repoName to getInfo (it has to match the "${validRepoNameRegex.source}" pattern)`);
const data = await GHDataLoader.load(request);
let user = null;
data.author && data.author.user && (user = data.author.user);
let associatedPullRequest = data.associatedPullRequests && data.associatedPullRequests.nodes && data.associatedPullRequests.nodes.length ? data.associatedPullRequests.nodes.sort((a, b) => null === a.mergedAt && null === b.mergedAt ? 0 : null === a.mergedAt ? 1 : null === b.mergedAt ? -1 : (a = new Date(a.mergedAt)) > (b = new Date(b.mergedAt)) ? 1 : a < b ? -1 : 0)[0] : null;
let associatedPullRequest = data.associatedPullRequests && data.associatedPullRequests.nodes && data.associatedPullRequests.nodes.length ? data.associatedPullRequests.nodes.sort(((a, b) => null === a.mergedAt && null === b.mergedAt ? 0 : null === a.mergedAt ? 1 : null === b.mergedAt ? -1 : (a = new Date(a.mergedAt)) > (b = new Date(b.mergedAt)) ? 1 : a < b ? -1 : 0))[0] : null;
return associatedPullRequest && (user = associatedPullRequest.author), {

@@ -51,0 +58,0 @@ user: user ? user.login : null,

@@ -5,2 +5,3 @@ import fetch from 'node-fetch';

// @ts-ignore
const validRepoNameRegex = /^[\w.-]+\/[\w.-]+$/;

@@ -102,2 +103,6 @@ function makeQuery(repos) {

if (!validRepoNameRegex.test(request.repo)) {
throw new Error(`Please pass a valid GitHub repository in the form of userOrOrg/repoName to getInfo (it has to match the "${validRepoNameRegex.source}" pattern)`);
}
const data = await GHDataLoader.load(request);

@@ -104,0 +109,0 @@ let user = null;

{
"name": "@changesets/get-github-info",
"version": "0.4.4",
"version": "0.4.5",
"description": "Get the GitHub username and PR number from a commit. Intended for use with changesets.",

@@ -5,0 +5,0 @@ "main": "dist/get-github-info.cjs.js",

@@ -5,3 +5,2 @@ # @changesets/get-github-info

> Get the GitHub username and PR number from a commit. Intended for use with changesets.

@@ -8,0 +7,0 @@

@@ -308,1 +308,27 @@ import { getInfo } from ".";

});
test("throws error on missing repo name", () => {
const request = {
commit: "c7e9c69"
};
expect(async () =>
// @ts-expect-error
getInfo(request)
).rejects.toThrowErrorMatchingInlineSnapshot(
`"Please pass a GitHub repository in the form of userOrOrg/repoName to getInfo"`
);
});
test("throws error on invalid repo name", () => {
const request = {
commit: "c7e9c69",
repo: "https://github.com/JedWatson/react-select"
};
expect(async () =>
getInfo(request)
).rejects.toThrowErrorMatchingInlineSnapshot(
`"Please pass a valid GitHub repository in the form of userOrOrg/repoName to getInfo (it has to match the \\"^[\\\\w.-]+\\\\/[\\\\w.-]+$\\" pattern)"`
);
});

@@ -5,2 +5,4 @@ // @ts-ignore

const validRepoNameRegex = /^[\w.-]+\/[\w.-]+$/;
type RequestData = {

@@ -131,2 +133,8 @@ commit: string;

if (!validRepoNameRegex.test(request.repo)) {
throw new Error(
`Please pass a valid GitHub repository in the form of userOrOrg/repoName to getInfo (it has to match the "${validRepoNameRegex.source}" pattern)`
);
}
const data = await GHDataLoader.load(request);

@@ -133,0 +141,0 @@ let user = null;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc