Skip to content

Commit

Permalink
Merge branch 'main' into change-default-strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
Marina Limeira committed Aug 24, 2023
2 parents 3671a2e + fccda1b commit d791001
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
22 changes: 16 additions & 6 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13582,6 +13582,11 @@ function pullRequestTitle(dependency, workingDir) {
}
return title;
}
async function wasCodeUpdated() {
const output = await exec.getExecOutput("git", ["status", "--porcelain"]);
// If there are changes, they will appear in the stdout. Otherwise, it returns blank.
return !!output.stdout;
}
async function commitAndPushChanges(gitCommiter, dependency, workingDir, token) {
const { owner, repo } = github.context.repo;
const head = pullRequestBranch(dependency, workingDir);
Expand Down Expand Up @@ -13679,12 +13684,17 @@ async function runPatcher(octokit, gitCommiter, binaryPath, command, { updateStr
core.startGroup("Running 'patcher update'");
const updateOutput = await exec.getExecOutput(binaryPath, updateArgs(updateStrategy, dependency, workingDir), { env: getPatcherEnvVars(token) });
core.endGroup();
core.startGroup("Commit and push changes");
await commitAndPushChanges(gitCommiter, dependency, workingDir, token);
core.endGroup();
core.startGroup("Opening pull request");
await openPullRequest(octokit, gitCommiter, updateOutput.stdout, dependency, workingDir, token);
core.endGroup();
if (await wasCodeUpdated()) {
core.startGroup("Commit and push changes");
await commitAndPushChanges(gitCommiter, dependency, workingDir, token);
core.endGroup();
core.startGroup("Opening pull request");
// await openPullRequest(octokit, gitCommiter, updateOutput.stdout, dependency, workingDir, token)
core.endGroup();
}
else {
core.info(`No changes in ${dependency} after running Patcher. No further action is necessary.`);
}
return;
}
}
Expand Down
26 changes: 19 additions & 7 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ function pullRequestTitle(dependency: string, workingDir: string): string {
return title
}

async function wasCodeUpdated() {
const output = await exec.getExecOutput("git", ["status", "--porcelain"])
// If there are changes, they will appear in the stdout. Otherwise, it returns blank.
return !!output.stdout;
}

async function commitAndPushChanges(gitCommiter: GitCommitter, dependency: string, workingDir: string, token: string) {
const { owner, repo } = github.context.repo;
const head = pullRequestBranch(dependency, workingDir)
Expand All @@ -97,11 +103,13 @@ async function commitAndPushChanges(gitCommiter: GitCommitter, dependency: strin
// Checkout to new branch and commit
await exec.exec("git", ["checkout", "-b", head])
await exec.exec("git", ["add", "."])

const commitMessage = "Update dependencies using Patcher by Gruntwork"
await exec.exec("git", ["commit", "-m", commitMessage])

// Push changes to head branch
await exec.exec("git", ["push", "--force", "origin", `${head}:refs/heads/${head}`])

}

async function openPullRequest(octokit: GitHub, gitCommiter: GitCommitter, patcherRawOutput: string, dependency: string, workingDir: string, token: string) {
Expand Down Expand Up @@ -216,13 +224,17 @@ async function runPatcher(octokit: GitHub, gitCommiter: GitCommitter, binaryPath
{env: getPatcherEnvVars(token)});
core.endGroup()

core.startGroup("Commit and push changes")
await commitAndPushChanges(gitCommiter, dependency, workingDir, token)
core.endGroup()

core.startGroup("Opening pull request")
await openPullRequest(octokit, gitCommiter, updateOutput.stdout, dependency, workingDir, token)
core.endGroup()
if (await wasCodeUpdated()) {
core.startGroup("Commit and push changes")
await commitAndPushChanges(gitCommiter, dependency, workingDir, token)
core.endGroup()

core.startGroup("Opening pull request")
await openPullRequest(octokit, gitCommiter, updateOutput.stdout, dependency, workingDir, token)
core.endGroup()
} else {
core.info(`No changes in ${dependency} after running Patcher. No further action is necessary.`)
}

return
}
Expand Down

0 comments on commit d791001

Please sign in to comment.