Last active
April 25, 2021 19:10
-
-
Save vladimir-ivanov/f6d11ff6f12e11311cf3359b158bd360 to your computer and use it in GitHub Desktop.
release branch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {Repository, Branch, Enums, Cred} = require('nodegit'); | |
const {version} = require('./package.json'); | |
const branchName = `release-${version}`; | |
const run = async () => { | |
try { | |
const repo = await Repository.open('./'); | |
await repo.checkoutBranch('master'); | |
const status = await repo.getStatus(); | |
if (status.length > 0) { | |
throw new Error('You have uncommitted code'); | |
} | |
const mainCommit = await repo.getHeadCommit(); | |
const branchRef = await repo.createBranch( | |
branchName, | |
mainCommit, | |
1, | |
'i am user one', | |
'created a new branch named: new_branch' | |
); | |
await Branch.setUpstream(branchRef, 'origin'); | |
await repo.checkoutBranch(branchName); | |
const branch = await repo.getBranch(branchName); | |
const branchCommit = await repo.getHeadCommit(); | |
await repo.createTag(branchCommit, branchName, 'tag created'); | |
console.log(branch.isHead() ? 'branch create success' : 'branch create failed'); | |
const remote = await repo.getRemote('origin'); | |
await remote.connect(Enums.DIRECTION.PUSH,{ | |
credentials: (url, userName) => { | |
console.log(url); | |
console.log(userName); | |
return Cred.sshKeyFromAgent(userName); | |
} | |
}); | |
await remote.push( | |
[`refs/heads/${branchName}:refs/heads/${branchName}`], | |
null, | |
repo.defaultSignature(), | |
'Push to release branch') | |
} catch (e) { | |
console.error(e); | |
} | |
} | |
run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment