Socket
Socket
Sign inDemoInstall

memfs-or-file-map-to-github-branch

Package Overview
Dependencies
25
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.2.0 to 1.2.1

.editorconfig

37

build/index.js
"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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());

@@ -11,21 +12,24 @@ });

Object.defineProperty(exports, "__esModule", { value: true });
exports.updateReference = exports.createACommit = exports.createTree = exports.filepathContentsMapToUpdateGitHubBranch = exports.memFSToGitHubCommits = void 0;
/**
* Creates a bunch of blobs, wraps them in a tree, updates a reference from a memfs volume
*/
exports.memFSToGitHubCommits = (api, volume, settings) => __awaiter(this, void 0, void 0, function* () {
const memFSToGitHubCommits = (api, volume, settings) => __awaiter(void 0, void 0, void 0, function* () {
const fileMap = volume.toJSON();
return exports.filepathContentsMapToUpdateGitHubBranch(api, fileMap, settings);
return (0, exports.filepathContentsMapToUpdateGitHubBranch)(api, fileMap, settings);
});
exports.memFSToGitHubCommits = memFSToGitHubCommits;
/**
* Creates a bunch of blobs, wraps them in a tree, updates a reference from a map of files to contents
*/
exports.filepathContentsMapToUpdateGitHubBranch = (api, fileMap, settings) => __awaiter(this, void 0, void 0, function* () {
const filepathContentsMapToUpdateGitHubBranch = (api, fileMap, settings) => __awaiter(void 0, void 0, void 0, function* () {
const getSha = yield shaForBranch(api, settings);
const baseSha = getSha.data.object.sha;
const tree = yield exports.createTree(api, settings)(fileMap, baseSha);
const commit = yield exports.createACommit(api, settings)(tree.sha, baseSha);
yield exports.updateReference(api, settings)(commit.data.sha);
const tree = yield (0, exports.createTree)(api, settings)(fileMap, baseSha);
const commit = yield (0, exports.createACommit)(api, settings)(tree.sha, baseSha);
yield (0, exports.updateReference)(api, settings)(commit.data.sha);
});
exports.filepathContentsMapToUpdateGitHubBranch = filepathContentsMapToUpdateGitHubBranch;
/** If we want to make a commit, or update a reference, we'll need the original commit */
const shaForBranch = (api, settings) => __awaiter(this, void 0, void 0, function* () {
const shaForBranch = (api, settings) => __awaiter(void 0, void 0, void 0, function* () {
return api.git.getRef({

@@ -45,5 +49,5 @@ owner: settings.owner,

*/
exports.createTree = (api, settings) => (fileMap, baseSha) => __awaiter(this, void 0, void 0, function* () {
const createTree = (api, settings) => (fileMap, baseSha) => __awaiter(void 0, void 0, void 0, function* () {
const blobSettings = { owner: settings.owner, repo: settings.repo };
const createBlobs = Object.keys(fileMap).map(filename => api.git.createBlob(Object.assign({}, blobSettings, { content: fileMap[filename] })).then((blob) => ({
const createBlobs = Object.keys(fileMap).map(filename => api.git.createBlob(Object.assign(Object.assign({}, blobSettings), { content: fileMap[filename] })).then((blob) => ({
sha: blob.data.sha,

@@ -55,5 +59,6 @@ path: filename,

const blobs = yield Promise.all(createBlobs);
const tree = yield api.git.createTree(Object.assign({}, blobSettings, { tree: blobs, base_tree: baseSha }));
const tree = yield api.git.createTree(Object.assign(Object.assign({}, blobSettings), { tree: blobs, base_tree: baseSha }));
return tree.data;
});
exports.createTree = createTree;
/**

@@ -64,3 +69,3 @@ * A Git commit is a snapshot of the hierarchy (Git tree) and the contents of the files (Git blob) in a Git repository

*/
exports.createACommit = (api, settings) => (treeSha, parentSha) => api.git.createCommit({
const createACommit = (api, settings) => (treeSha, parentSha) => api.git.createCommit({
owner: settings.owner,

@@ -72,2 +77,3 @@ repo: settings.repo,

});
exports.createACommit = createACommit;
/**

@@ -80,3 +86,3 @@ * A Git reference (git ref) is just a file that contains a Git commit SHA-1 hash. When referring

*/
exports.updateReference = (api, settings) => (newSha) => __awaiter(this, void 0, void 0, function* () {
const updateReference = (api, settings) => (newSha) => __awaiter(void 0, void 0, void 0, function* () {
const refSettings = {

@@ -90,8 +96,9 @@ owner: settings.owner,

// It must exist, so we should update it
return api.git.createRef(Object.assign({}, refSettings, { sha: newSha }));
return api.git.createRef(Object.assign(Object.assign({}, refSettings), { sha: newSha }));
}
catch (error) {
// We have to create the reference because it doesn't exist yet
return api.git.createRef(Object.assign({}, refSettings, { sha: newSha }));
return api.git.createRef(Object.assign(Object.assign({}, refSettings), { sha: newSha }));
}
});
exports.updateReference = updateReference;
{
"name": "memfs-or-file-map-to-github-branch",
"version": "1.2.0",
"version": "1.2.1",
"description": "Handles making a GitHub branch with the commits from a memfs instance or a file map",

@@ -15,8 +15,8 @@ "main": "build/index.js",

"devDependencies": {
"@types/node": "^10.11.3",
"typescript": "^3.1.1"
"@types/node": "^16.11.21",
"typescript": "^4.5.5"
},
"dependencies": {
"@octokit/rest": "^16.43.1"
"@octokit/rest": "^16.43.0 || ^17.11.0 || ^18.12.0"
}
}
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc