-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgitUtils.js
40 lines (33 loc) · 1015 Bytes
/
gitUtils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { exec } from "@actions/exec";
export const setupUser = async () => {
await exec("git", ["config", "user.name", `"github-actions[bot]"`]);
await exec("git", [
"config",
"user.email",
`"github-actions[bot]@users.noreply.github.com"`,
]);
};
export const diff = async (path) => {
return await exec("git", ["diff", "--exit-code", path], {
ignoreReturnCode: true,
});
};
export const checkout = async (branch) => {
const exitCode = await exec("git", ["checkout", "-b", branch], {
ignoreReturnCode: true,
});
if (exitCode !== 0) {
await exec("git", ["branch", "-D", branch]);
await exec("git", ["checkout", "-b", branch]);
}
};
export const commit = async (message, path) => {
await exec("git", ["add", path]);
await exec("git", ["commit", "-m", message]);
};
export const push = async (branch) => {
await exec("git", ["push", "-u", "-f", "origin", branch]);
};
export const pull = async (branch) => {
await exec("git", ["pull", "origin", branch]);
};