memfs-or-file-map-to-github-branch
Advanced tools
Comparing version 1.2.0 to 1.2.1
"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" | ||
} | ||
} |
12290
6
155
+ Added@octokit/core@3.6.0(transitive)
+ Added@octokit/graphql@4.8.0(transitive)
+ Added@octokit/plugin-paginate-rest@2.21.3(transitive)
+ Added@octokit/plugin-rest-endpoint-methods@5.16.2(transitive)
+ Added@octokit/rest@18.12.0(transitive)
- Removed@octokit/auth-token@5.1.1(transitive)
- Removed@octokit/core@6.1.2(transitive)
- Removed@octokit/endpoint@10.1.1(transitive)
- Removed@octokit/graphql@8.1.1(transitive)
- Removed@octokit/openapi-types@22.2.0(transitive)
- Removed@octokit/plugin-paginate-rest@1.1.2(transitive)
- Removed@octokit/plugin-rest-endpoint-methods@2.4.0(transitive)
- Removed@octokit/request@9.1.1(transitive)
- Removed@octokit/request-error@1.2.16.1.1(transitive)
- Removed@octokit/rest@16.43.2(transitive)
- Removed@octokit/types@13.5.02.16.2(transitive)
- Removed@types/node@20.14.9(transitive)
- Removedatob-lite@2.0.0(transitive)
- Removedbefore-after-hook@3.0.2(transitive)
- Removedbtoa-lite@1.0.0(transitive)
- Removedcross-spawn@6.0.5(transitive)
- Removedend-of-stream@1.4.4(transitive)
- Removedexeca@1.0.0(transitive)
- Removedget-stream@4.1.0(transitive)
- Removedis-stream@1.1.0(transitive)
- Removedisexe@2.0.0(transitive)
- Removedlodash.get@4.4.2(transitive)
- Removedlodash.set@4.3.2(transitive)
- Removedlodash.uniq@4.5.0(transitive)
- Removedmacos-release@2.5.1(transitive)
- Removednice-try@1.0.5(transitive)
- Removednpm-run-path@2.0.2(transitive)
- Removedoctokit-pagination-methods@1.1.0(transitive)
- Removedos-name@3.1.0(transitive)
- Removedp-finally@1.0.0(transitive)
- Removedpath-key@2.0.1(transitive)
- Removedpump@3.0.0(transitive)
- Removedsemver@5.7.2(transitive)
- Removedshebang-command@1.2.0(transitive)
- Removedshebang-regex@1.0.0(transitive)
- Removedsignal-exit@3.0.7(transitive)
- Removedstrip-eof@1.0.0(transitive)
- Removedundici-types@5.26.5(transitive)
- Removeduniversal-user-agent@4.0.17.0.2(transitive)
- Removedwhich@1.3.1(transitive)
- Removedwindows-release@3.3.3(transitive)