Skip to content

Commit

Permalink
refactor: enhance checkModifiedFiles to return modified status and st…
Browse files Browse the repository at this point in the history
…reamline updateChanges logic
  • Loading branch information
DE7924 committed Dec 20, 2024
1 parent def719a commit 4a6a1f6
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 33 deletions.
40 changes: 25 additions & 15 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

30 changes: 16 additions & 14 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,25 +192,27 @@ export async function run(): Promise<void> {
? await commandComment({ label: "TSDoc", command: "npm run docs" })
: undefined;

const checkModifiedFilesStr: StepResponse | undefined =
const [checkModifiedFilesStr, modified]: [StepResponse, boolean] =
await checkModifiedFiles({
label: "Check for modified files",
command:
'echo "modified=$(if [ -n "$(git status --porcelain)" ]; then echo "true"; else echo "false"; fi)" >> $GITHUB_ENV',
command: "git status --porcelain",
// 'echo "modified=$(if [ -n "$(git status --porcelain)" ]; then echo "true"; else echo "false"; fi)" >> $GITHUB_ENV',
});

// TODO: THIS DIDN't fail
const updateChangesStr: StepResponse | undefined = await updateChanges({
label: "Update changes in GitHub repository",
command: "",
commandList: [
'git config --global user.name "github-actions"',
'git config --global user.email "[email protected]"',
"git add -A",
'git commit -m "[automated commit] lint format and import sort"',
"git push",
],
});
const updateChangesStr: StepResponse | undefined = modified
? await updateChanges({
label: "Update changes in GitHub repository",
command: "",
commandList: [
'git config --global user.name "github-actions"',
'git config --global user.email "[email protected]"',
"git add -A",
'git commit -m "[automated commit] lint format and import sort"',
"git push",
],
})
: undefined;

// runCoverage
// const coverageStr: StepResponse | undefined = runCoverage
Expand Down
12 changes: 9 additions & 3 deletions src/scripts/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,25 @@ import { buildComment, Command, runBashCommand, StepResponse } from "src/main";

export const checkModifiedFiles = async (
command: Command,
): Promise<StepResponse> => {
): Promise<[StepResponse, boolean]> => {
let filesModified = false;
const result = await runBashCommand(command.command)
.then(async (str) => {
const response = { output: "", error: false };
return await buildComment(response, str, command.label);
if (str.trim() !== "") {
filesModified = true;
return await buildComment(response, str, command.label);
} else {
return await buildComment(response, str, command.label);
}
})
.catch(async (error) => {
setFailed(`Failed to check for modified files: ${error as string}`);
const response = { output: "", error: true };
return await buildComment(response, error.message, command.label);
});

return result;
return [result, filesModified];
};

export const updateChanges = async (
Expand Down

0 comments on commit 4a6a1f6

Please sign in to comment.