Skip to content

Commit

Permalink
fix: do not count commits from the beginning on the very first run
Browse files Browse the repository at this point in the history
Signed-off-by: Ar Rakin <[email protected]>
  • Loading branch information
virtual-designer committed Aug 29, 2024
1 parent ae436ba commit 68ddee3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
16 changes: 8 additions & 8 deletions build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35426,6 +35426,7 @@ class GitClient {
return __awaiter(this, arguments, void 0, function* ({ args, exitCodeCheck = true }) {
const code = yield (0, exec_1.exec)(this.gitPath, args, {
ignoreReturnCode: !exitCodeCheck,
silent: true,
});
if (exitCodeCheck && code !== 0) {
throw new Error(`Failed to execute git command.`);
Expand All @@ -35436,6 +35437,7 @@ class GitClient {
return __awaiter(this, arguments, void 0, function* ({ args, exitCodeCheck = true }) {
const { stdout, exitCode } = yield (0, exec_1.getExecOutput)(this.gitPath, args, {
ignoreReturnCode: !exitCodeCheck,
silent: true,
});
if (exitCodeCheck && exitCode !== 0) {
throw new Error(`Failed to execute git command.`);
Expand Down Expand Up @@ -35600,6 +35602,7 @@ class GitClient {
let keyId;
const { stdout, stderr } = yield (0, exec_1.getExecOutput)("gpg", ["--import"], {
input: Buffer.from(key, "utf-8"),
silent: true,
});
for (const data of `${stdout}\n${stderr}`.split(/\r?\n/g)) {
const match = data.match(/^gpg: key ([0-9A-F]+):/);
Expand Down Expand Up @@ -35862,18 +35865,15 @@ function run() {
gpgKey: gitGPPKey || undefined,
});
yield gitClient.pull(gitPushRemote, gitPushBranch !== null && gitPushBranch !== void 0 ? gitPushBranch : "HEAD");
if (!createCommit) {
core.info("Creating commits is disabled.");
metadataFileJSON = {
lastReadCommit: github.context.payload.before,
};
}
else if (!(0, fs_1.existsSync)(metadataFile)) {
if (!(0, fs_1.existsSync)(metadataFile) || !createCommit) {
if (createCommit) {
core.info("Metadata file not found, will be created after the first run.");
}
else {
core.info("Creating commits is disabled.");
}
metadataFileJSON = {
lastReadCommit: (yield gitClient.getFirstCommit()) || "",
lastReadCommit: github.context.payload.before,
};
}
else {
Expand Down
3 changes: 3 additions & 0 deletions src/GitClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class GitClient implements AsyncDisposable {
private async exec({ args, exitCodeCheck = true }: ExecOptions) {
const code = await exec(this.gitPath, args, {
ignoreReturnCode: !exitCodeCheck,
silent: true,
});

if (exitCodeCheck && code !== 0) {
Expand All @@ -43,6 +44,7 @@ class GitClient implements AsyncDisposable {
private async execWithOutput({ args, exitCodeCheck = true }: ExecOptions) {
const { stdout, exitCode } = await getExecOutput(this.gitPath, args, {
ignoreReturnCode: !exitCodeCheck,
silent: true,
});

if (exitCodeCheck && exitCode !== 0) {
Expand Down Expand Up @@ -217,6 +219,7 @@ class GitClient implements AsyncDisposable {

const { stdout, stderr } = await getExecOutput("gpg", ["--import"], {
input: Buffer.from(key, "utf-8"),
silent: true,
});

for (const data of `${stdout}\n${stderr}`.split(/\r?\n/g)) {
Expand Down
12 changes: 4 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,17 @@ async function run() {

await gitClient.pull(gitPushRemote, gitPushBranch ?? "HEAD");

if (!createCommit) {
core.info("Creating commits is disabled.");

metadataFileJSON = {
lastReadCommit: github.context.payload.before,
};
} else if (!existsSync(metadataFile)) {
if (!existsSync(metadataFile) || !createCommit) {
if (createCommit) {
core.info(
"Metadata file not found, will be created after the first run.",
);
} else {
core.info("Creating commits is disabled.");
}

metadataFileJSON = {
lastReadCommit: (await gitClient.getFirstCommit()) || "",
lastReadCommit: github.context.payload.before,
};
} else {
metadataFileJSON = JSON.parse(await readFile(metadataFile, "utf-8"));
Expand Down

0 comments on commit 68ddee3

Please sign in to comment.