github-cherry-pick
Advanced tools
Comparing version 0.1.15 to 0.2.0
510
lib/index.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _git = require("shared-github-internals/lib/git"); | ||
var _debug = _interopRequireDefault(require("debug")); | ||
var _package = require("../package"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } | ||
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } | ||
const createCommit = | ||
/*#__PURE__*/ | ||
function () { | ||
var _ref = _asyncToGenerator(function* ({ | ||
author, | ||
committer, | ||
message, | ||
octokit, | ||
owner, | ||
parent, | ||
repo, | ||
tree | ||
}) { | ||
const { | ||
data: { | ||
sha | ||
} | ||
} = yield octokit.gitdata.createCommit({ | ||
author, | ||
committer, | ||
message, | ||
owner, | ||
parents: [parent], | ||
repo, | ||
// No PGP signature support for now. | ||
// See https://developer.github.com/v3/git/commits/#create-a-commit. | ||
tree | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
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); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const createDebug = require("debug"); | ||
const git_1 = require("shared-github-internals/lib/git"); | ||
const debug = createDebug("github-cherry-pick"); | ||
const createCommit = ({ author, committer, message, octokit, owner, parent, repo, tree, }) => __awaiter(this, void 0, void 0, function* () { | ||
const { data: { sha }, } = yield octokit.gitdata.createCommit({ | ||
author, | ||
committer, | ||
message, | ||
owner, | ||
parents: [parent], | ||
repo, | ||
// No PGP signature support for now. | ||
// See https://developer.github.com/v3/git/commits/#create-a-commit. | ||
tree, | ||
}); | ||
return sha; | ||
}); | ||
return function createCommit(_x) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}(); | ||
const merge = | ||
/*#__PURE__*/ | ||
function () { | ||
var _ref2 = _asyncToGenerator(function* ({ | ||
base, | ||
commit, | ||
octokit, | ||
owner, | ||
repo | ||
}) { | ||
const { | ||
data: { | ||
commit: { | ||
tree: { | ||
sha: tree | ||
} | ||
} | ||
} | ||
} = yield octokit.repos.merge({ | ||
base, | ||
head: commit, | ||
owner, | ||
repo | ||
}); | ||
const merge = ({ base, commit, octokit, owner, repo, }) => __awaiter(this, void 0, void 0, function* () { | ||
const { data: { commit: { tree: { sha: tree }, }, }, } = yield octokit.repos.merge({ | ||
base, | ||
head: commit, | ||
owner, | ||
repo, | ||
}); | ||
return tree; | ||
}); | ||
return function merge(_x2) { | ||
return _ref2.apply(this, arguments); | ||
}; | ||
}(); | ||
const retrieveCommitDetails = | ||
/*#__PURE__*/ | ||
function () { | ||
var _ref3 = _asyncToGenerator(function* ({ | ||
commit, | ||
octokit, | ||
owner, | ||
repo | ||
}) { | ||
const { | ||
data: { | ||
}); | ||
const retrieveCommitDetails = ({ commit, octokit, owner, repo, }) => __awaiter(this, void 0, void 0, function* () { | ||
const { data: { author, committer, message, parents: [{ sha: parent }], }, } = yield octokit.gitdata.getCommit({ | ||
commit_sha: commit, | ||
owner, | ||
repo, | ||
}); | ||
return { author, committer, message, parent }; | ||
}); | ||
const createSiblingCommit = ({ commit, head: { author, committer, ref, tree }, octokit, owner, parent, repo, }) => __awaiter(this, void 0, void 0, function* () { | ||
const sha = yield createCommit({ | ||
author, | ||
committer, | ||
message, | ||
parents: [{ | ||
sha: parent | ||
}] | ||
} | ||
} = yield octokit.gitdata.getCommit({ | ||
commit_sha: commit, | ||
owner, | ||
repo | ||
message: `Sibling of ${commit}`, | ||
octokit, | ||
owner, | ||
parent, | ||
repo, | ||
tree, | ||
}); | ||
return { | ||
author, | ||
committer, | ||
message, | ||
parent | ||
}; | ||
}); | ||
return function retrieveCommitDetails(_x3) { | ||
return _ref3.apply(this, arguments); | ||
}; | ||
}(); | ||
const createSiblingCommit = | ||
/*#__PURE__*/ | ||
function () { | ||
var _ref4 = _asyncToGenerator(function* ({ | ||
commit, | ||
head: { | ||
author, | ||
committer, | ||
ref, | ||
tree | ||
}, | ||
octokit, | ||
owner, | ||
parent, | ||
repo | ||
}) { | ||
const sha = yield createCommit({ | ||
author, | ||
committer, | ||
message: `Sibling of ${commit}`, | ||
octokit, | ||
owner, | ||
parent, | ||
repo, | ||
tree | ||
yield git_1.updateReference({ | ||
force: true, | ||
octokit, | ||
owner, | ||
ref, | ||
repo, | ||
sha, | ||
}); | ||
yield (0, _git.updateReference)({ | ||
force: true, | ||
octokit, | ||
owner, | ||
ref, | ||
repo, | ||
sha | ||
}); | ||
const cherryPickCommit = ({ commit, head: { ref, sha, tree }, octokit, owner, repo, }) => __awaiter(this, void 0, void 0, function* () { | ||
const { author, committer, message, parent } = yield retrieveCommitDetails({ | ||
commit, | ||
octokit, | ||
owner, | ||
repo, | ||
}); | ||
}); | ||
return function createSiblingCommit(_x4) { | ||
return _ref4.apply(this, arguments); | ||
}; | ||
}(); | ||
const cherryPickCommit = | ||
/*#__PURE__*/ | ||
function () { | ||
var _ref5 = _asyncToGenerator(function* ({ | ||
commit, | ||
debug, | ||
head: { | ||
ref, | ||
sha, | ||
tree | ||
}, | ||
octokit, | ||
owner, | ||
repo | ||
}) { | ||
const { | ||
author, | ||
committer, | ||
message, | ||
parent | ||
} = yield retrieveCommitDetails({ | ||
commit, | ||
octokit, | ||
owner, | ||
repo | ||
}); | ||
debug("creating sibling commit"); | ||
yield createSiblingCommit({ | ||
commit, | ||
head: { | ||
author, | ||
committer, | ||
ref, | ||
tree | ||
}, | ||
octokit, | ||
owner, | ||
parent, | ||
repo | ||
commit, | ||
head: { author, committer, ref, tree }, | ||
octokit, | ||
owner, | ||
parent, | ||
repo, | ||
}); | ||
debug("merging"); | ||
const newHeadTree = yield merge({ | ||
base: ref, | ||
commit, | ||
octokit, | ||
owner, | ||
repo | ||
base: ref, | ||
commit, | ||
octokit, | ||
owner, | ||
repo, | ||
}); | ||
debug("creating commit with different tree", newHeadTree); | ||
const newHeadSha = yield createCommit({ | ||
author, | ||
committer, | ||
message, | ||
octokit, | ||
owner, | ||
parent: sha, | ||
repo, | ||
tree: newHeadTree | ||
author, | ||
committer, | ||
message, | ||
octokit, | ||
owner, | ||
parent: sha, | ||
repo, | ||
tree: newHeadTree, | ||
}); | ||
debug("updating reference", newHeadSha); | ||
yield (0, _git.updateReference)({ | ||
// Overwrite the merge commit and its parent on the branch by a single commit. | ||
// The result will be equivalent to what would have happened with a fast-forward merge. | ||
force: true, | ||
octokit, | ||
owner, | ||
ref, | ||
repo, | ||
sha: newHeadSha | ||
yield git_1.updateReference({ | ||
// Overwrite the merge commit and its parent on the branch by a single commit. | ||
// The result will be equivalent to what would have happened with a fast-forward merge. | ||
force: true, | ||
octokit, | ||
owner, | ||
ref, | ||
repo, | ||
sha: newHeadSha, | ||
}); | ||
return { | ||
sha: newHeadSha, | ||
tree: newHeadTree | ||
sha: newHeadSha, | ||
tree: newHeadTree, | ||
}; | ||
}); | ||
return function cherryPickCommit(_x5) { | ||
return _ref5.apply(this, arguments); | ||
}; | ||
}(); | ||
const cherryPickCommitsOnReference = | ||
/*#__PURE__*/ | ||
function () { | ||
var _ref6 = _asyncToGenerator(function* ({ | ||
commits, | ||
debug, | ||
initialHeadSha, | ||
octokit, | ||
owner, | ||
ref, | ||
repo | ||
}) { | ||
const { | ||
data: { | ||
tree: { | ||
sha: initialHeadTree | ||
} | ||
} | ||
} = yield octokit.gitdata.getCommit({ | ||
commit_sha: initialHeadSha, | ||
owner, | ||
repo | ||
}); | ||
const cherryPickCommitsOnReference = ({ commits, initialHeadSha, octokit, owner, ref, repo, }) => __awaiter(this, void 0, void 0, function* () { | ||
const { data: { tree: { sha: initialHeadTree }, }, } = yield octokit.gitdata.getCommit({ | ||
commit_sha: initialHeadSha, | ||
owner, | ||
repo, | ||
}); | ||
const { | ||
sha: newHeadSha | ||
} = yield commits.reduce( | ||
/*#__PURE__*/ | ||
function () { | ||
var _ref7 = _asyncToGenerator(function* (previousCherryPick, commit) { | ||
const { | ||
sha, | ||
tree | ||
} = yield previousCherryPick; | ||
debug("cherry-picking", { | ||
commit, | ||
ref, | ||
sha | ||
}); | ||
const { sha: newHeadSha } = yield commits.reduce((previousCherryPick, commit) => __awaiter(this, void 0, void 0, function* () { | ||
const { sha, tree } = yield previousCherryPick; | ||
debug("cherry-picking", { commit, ref, sha }); | ||
return cherryPickCommit({ | ||
commit, | ||
debug, | ||
head: { | ||
ref, | ||
sha, | ||
tree | ||
}, | ||
octokit, | ||
owner, | ||
repo | ||
commit, | ||
head: { ref, sha, tree }, | ||
octokit, | ||
owner, | ||
repo, | ||
}); | ||
}); | ||
return function (_x7, _x8) { | ||
return _ref7.apply(this, arguments); | ||
}; | ||
}(), Promise.resolve({ | ||
sha: initialHeadSha, | ||
tree: initialHeadTree | ||
}), Promise.resolve({ | ||
sha: initialHeadSha, | ||
tree: initialHeadTree, | ||
})); | ||
return newHeadSha; | ||
}); | ||
return function cherryPickCommitsOnReference(_x6) { | ||
return _ref6.apply(this, arguments); | ||
}; | ||
}(); // eslint-disable-next-line max-lines-per-function | ||
const cherryPickCommits = | ||
/*#__PURE__*/ | ||
function () { | ||
var _ref8 = _asyncToGenerator(function* ({ | ||
// Should only be used in tests. | ||
_intercept = () => Promise.resolve(), | ||
commits, | ||
head, | ||
octokit, | ||
owner, | ||
repo | ||
}) { | ||
const debug = (0, _debug.default)(_package.name); | ||
debug("starting", { | ||
commits, | ||
head, | ||
owner, | ||
repo | ||
}); | ||
// eslint-disable-next-line max-lines-per-function | ||
const cherryPickCommits = ({ | ||
// Should only be used in tests. | ||
_intercept = () => Promise.resolve(), commits, head, octokit, owner, repo, }) => __awaiter(this, void 0, void 0, function* () { | ||
debug("starting", { commits, head, owner, repo }); | ||
const initialHeadSha = yield git_1.fetchReferenceSha({ | ||
octokit, | ||
owner, | ||
ref: head, | ||
repo, | ||
}); | ||
const initialHeadSha = yield (0, _git.fetchReferenceSha)({ | ||
octokit, | ||
owner, | ||
ref: head, | ||
repo | ||
yield _intercept({ initialHeadSha }); | ||
return git_1.withTemporaryReference({ | ||
action: (temporaryRef) => __awaiter(this, void 0, void 0, function* () { | ||
debug({ temporaryRef }); | ||
const newSha = yield cherryPickCommitsOnReference({ | ||
commits, | ||
initialHeadSha, | ||
octokit, | ||
owner, | ||
ref: temporaryRef, | ||
repo, | ||
}); | ||
debug("updating reference with new SHA", newSha); | ||
yield git_1.updateReference({ | ||
// Make sure it's a fast-forward update. | ||
force: false, | ||
octokit, | ||
owner, | ||
ref: head, | ||
repo, | ||
sha: newSha, | ||
}); | ||
debug("reference updated"); | ||
return newSha; | ||
}), | ||
octokit, | ||
owner, | ||
ref: `cherry-pick-${head}`, | ||
repo, | ||
sha: initialHeadSha, | ||
}); | ||
yield _intercept({ | ||
initialHeadSha | ||
}); | ||
return (0, _git.withTemporaryReference)({ | ||
action: function () { | ||
var _ref9 = _asyncToGenerator(function* (temporaryRef) { | ||
debug({ | ||
temporaryRef | ||
}); | ||
const newSha = yield cherryPickCommitsOnReference({ | ||
commits, | ||
debug, | ||
initialHeadSha, | ||
octokit, | ||
owner, | ||
ref: temporaryRef, | ||
repo | ||
}); | ||
debug("updating reference with new SHA", newSha); | ||
yield (0, _git.updateReference)({ | ||
// Make sure it's a fast-forward update. | ||
force: false, | ||
octokit, | ||
owner, | ||
ref: head, | ||
repo, | ||
sha: newSha | ||
}); | ||
debug("reference updated"); | ||
return newSha; | ||
}); | ||
return function action(_x10) { | ||
return _ref9.apply(this, arguments); | ||
}; | ||
}(), | ||
octokit, | ||
owner, | ||
ref: `cherry-pick-${head}`, | ||
repo, | ||
sha: initialHeadSha | ||
}); | ||
}); | ||
return function cherryPickCommits(_x9) { | ||
return _ref8.apply(this, arguments); | ||
}; | ||
}(); | ||
var _default = cherryPickCommits; | ||
exports.default = _default; | ||
}); | ||
exports.default = cherryPickCommits; |
{ | ||
"author": "Thibault Derousseaux <tibdex@gmail.com>", | ||
"dependencies": { | ||
"@octokit/rest": "^15.12.0", | ||
"@types/debug": "^0.0.31", | ||
"@types/node": "^10.12.0", | ||
"debug": "^4.0.1", | ||
"shared-github-internals": "^0.1.5" | ||
"shared-github-internals": "^0.2.0" | ||
}, | ||
"description": "Cherry-pick several commits on a branch using the low level Git Data operations provided by the GitHub REST API", | ||
"devDependencies": { | ||
"@babel/cli": "^7.1.0", | ||
"@babel/core": "^7.1.0", | ||
"@babel/preset-env": "^7.1.0", | ||
"@babel/preset-flow": "^7.0.0", | ||
"babel-core": "^7.0.0-bridge", | ||
"babel-eslint": "^9.0.0", | ||
"babel-jest": "^23.6.0", | ||
"eslint": "^5.6.0", | ||
"eslint-config-prettier": "^3.0.1", | ||
"eslint-plugin-flowtype": "^2.50.1", | ||
"eslint-plugin-import": "^2.14.0", | ||
"eslint-plugin-security": "^1.4.0", | ||
"eslint-plugin-unicorn": "^6.0.1", | ||
"flow-bin": "^0.81.0", | ||
"flow-copy-source": "^2.0.2", | ||
"flow-typed": "^2.5.1", | ||
"@types/jest": "^23.3.5", | ||
"jest": "^23.6.0", | ||
"jest-junit": "^5.1.0", | ||
"prettier": "^1.14.3" | ||
"prettier": "^1.14.3", | ||
"ts-jest": "^23.10.4", | ||
"tslint": "^5.11.0", | ||
"tslint-config-prettier": "^1.15.0", | ||
"typescript": "^3.1.3" | ||
}, | ||
@@ -47,11 +39,9 @@ "engines": { | ||
"scripts": { | ||
"build": "babel src --out-dir lib && flow-copy-source src lib", | ||
"eslint": "eslint . --max-warnings 0", | ||
"flow": "flow", | ||
"flow-typed": "flow-typed", | ||
"build": "tsc --build tsconfig.build.json", | ||
"prepublishOnly": "yarn build", | ||
"prettier": "prettier \"**/*.{js,json,md,yml}\"", | ||
"test": "jest" | ||
"prettier": "prettier --ignore-path .gitignore \"**/*.{js,json,md,ts,yml}\"", | ||
"test": "jest", | ||
"tslint": "tslint --format stylish --project ." | ||
}, | ||
"version": "0.1.15" | ||
"version": "0.2.0" | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
8
14749
5
193
1
+ Added@octokit/rest@^15.12.0
+ Added@types/debug@^0.0.31
+ Added@types/node@^10.12.0
+ Added@types/debug@0.0.31(transitive)
+ Added@types/execa@0.9.0(transitive)
+ Added@types/node@10.17.60(transitive)
+ Added@types/tempy@0.2.0(transitive)
+ Added@types/uuid@3.4.13(transitive)
+ Addedms@2.1.3(transitive)
+ Addedshared-github-internals@0.2.0(transitive)
- Removedshared-github-internals@0.1.5(transitive)