feat: add force push option

This commit is contained in:
Borja Canseco
2020-06-03 23:38:10 -05:00
parent ebdf401d4b
commit 2fb495ce7b
2 changed files with 12 additions and 2 deletions

View File

@@ -111,6 +111,7 @@ Keep reading for more cool stuff like:
| `INCLUDE_WEEKENDS` | A boolean indicating whether or not to make commits on weekends. | `true` | |
| `MIN_COMMITS_PER_DAY` | The minimum integer number of commits to make per day (inclusive). Used by a pseudo-RNG. | `1` | |
| `MAX_COMMITS_PER_DAY` | The maximum integer number of commits to make per day (inclusive). Used by a pseudo-RNG. | `1` | |
| `FORCE_PUSH` | A boolean indicating whether or not to force push. **WARNING:** Setting this to `true` will clear out your repo on each run! | `false` | |
### Advanced environment variables 🧙‍♂️

View File

@@ -1,3 +1,4 @@
import fs from 'fs/promises';
import git from 'simple-git/promise';
import subDays from 'date-fns/fp/subDays';
import getUnixTime from 'date-fns/fp/getUnixTime';
@@ -21,6 +22,7 @@ const {
INCLUDE_WEEKENDS = true,
MIN_COMMITS_PER_DAY = 1,
MAX_COMMITS_PER_DAY = 1,
FORCE_PUSH = false,
} = process.env;
const repoPath = `https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@${GIT_HOST}/${GITHUB_REPOSITORY}`;
@@ -29,7 +31,14 @@ const secondLine = 'Committed via https://github.com/marketplace/actions/autopop
const dayOffsets = [...Array(Number(MAX_DAYS)).keys()];
const originDay = fromUnixTime(ORIGIN_TIMESTAMP);
await git().clone(repoPath, localPath, ['--single-branch', '-b', GIT_BRANCH]);
await fs.mkdir(localPath);
if (JSON.parse(FORCE_PUSH)) {
await git(localPath).init();
} else {
await git().clone(repoPath, localPath, ['--single-branch', '-b', GIT_BRANCH]);
}
await git(localPath).env({GIT_SSH_COMMAND});
await git(localPath).addConfig('user.name', GITHUB_ACTOR);
await git(localPath).addConfig('user.email', GIT_EMAIL);
@@ -51,4 +60,4 @@ await dayOffsets
.flat()
.reduce((commitPromises, nextPromise) => commitPromises.then(nextPromise), Promise.resolve());
await git(localPath).push(repoPath, GIT_BRANCH);
await git(localPath).push(repoPath, GIT_BRANCH, JSON.parse(FORCE_PUSH) && {'--force': null});