Skip to content

Commit

Permalink
Add git helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
Ackuq committed Jun 2, 2024
1 parent d5b7d7e commit 2db6698
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 623 deletions.
5 changes: 3 additions & 2 deletions actions/update-standpoints/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
"build:watch": "pnpm run build --watch"
},
"dependencies": {
"@actions/core": "^1.10.1",
"@actions/github": "^6.0.0"
"@actions/core": "1.10.1",
"@actions/exec": "1.1.1",
"@actions/github": "6.0.0"
},
"devDependencies": {
"@vercel/ncc": "^0.38.1"
Expand Down
45 changes: 45 additions & 0 deletions actions/update-standpoints/src/git-helper.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// @ts-check
import { getExecOutput } from "@actions/exec";

/**
* Create a new branch
* @param {string} branch
* @param {string} startPoint
*/
export async function checkout(branch, startPoint) {
const command = ["checkout", "-b", branch, startPoint];
await exec(command);
}

export async function add() {
const command = ["add", "."];
await exec(command);
}

/**
* @param {string} message
*/
export async function commit(message) {
const command = ["commit", "-m", message];
await exec(command);
}

export async function push() {
const command = ["push", "--set-upstream", "origin", "HEAD"];
await exec(command);
}

export async function hasDiff() {
const command = ["diff", "--quiet"];
const output = await exec(command);
// Exit code 1 means there are differences
return output.exitCode === 1;
}

/**
* Run a git command
* @param {string[]} command
*/
function exec(command) {
return getExecOutput("git", command);
}
Loading

0 comments on commit 2db6698

Please sign in to comment.