diff --git a/action.yml b/action.yml index 9bd558a..33a7d7d 100644 --- a/action.yml +++ b/action.yml @@ -24,6 +24,8 @@ inputs: required: false description: "The base branch" default: "main" + auto_merge: + description: "Whether the pull request should be automatically merged" runs: using: 'node16' main: 'dist/index.js' diff --git a/src/config.ts b/src/config.ts index c4b0523..c037ffc 100644 --- a/src/config.ts +++ b/src/config.ts @@ -7,6 +7,7 @@ const image = core.getInput('image') const tag = core.getInput('tag') const PAT = core.getInput('PAT') const base = core.getInput('base') || 'main' +const auto_merge = core.getBooleanInput('auto_merge') export type IConfig = { base: string @@ -21,6 +22,9 @@ export type IConfig = { repoDirectory: string repoUrl: string tag: string + git_name?: string + git_email?: string + auto_merge?: boolean } export function getConfig(): IConfig { @@ -46,6 +50,7 @@ export function getConfig(): IConfig { repo, repoDirectory, repoUrl: `https://bot:${PAT}@github.com/${owner}/${repo}.git`, - tag + tag, + auto_merge } } diff --git a/src/main.ts b/src/main.ts index 1738a0b..15f67d5 100644 --- a/src/main.ts +++ b/src/main.ts @@ -62,24 +62,40 @@ async function run(): Promise { shell.config.fatal = true shell.exec(`git config --global user.name "${config.owner}"`) - //shell.exec(`git config --global user.email "${config.owner}"`) + shell.exec(`git config --global user.email "robot@example.com"`) + shell.mkdir('-p', config.clonePath) shell.cd(config.clonePath) shell.exec(`git clone ${config.repoUrl}`) shell.cd(config.repoDirectory) + if (config.git_name) { + shell.exec(`git config user.name "${config.git_name}"`) + } + if (config.git_email) { + shell.exec(`git config user.email "${config.git_email}"`) + } shell.exec(`git checkout -B ${config.branch}`) await bumpVersions(config) shell.exec(`git add .`) shell.exec(`git commit -m "${config.commitMsg}"`) shell.exec(`git push -u origin ${config.branch}`) - await github.getOctokit(config.PAT).rest.pulls.create({ + const resp = await github.getOctokit(config.PAT).rest.pulls.create({ owner: config.owner, repo: config.repo, title: config.commitMsg, head: config.branch, base: config.base }) + + if (String(config.auto_merge) === "true") { + await github.getOctokit(config.PAT).rest.pulls.merge({ + owner: config.owner, + repo: config.repo, + pull_number: resp.data.number, + merge_method: "squash", + }) + } } catch (e) { if (e instanceof Error) core.setFailed(e.message) }