Skip to content

Commit

Permalink
add auto merge
Browse files Browse the repository at this point in the history
add auto merge
  • Loading branch information
raphael-papazikas committed Apr 26, 2024
1 parent ada4ad6 commit 78ca48c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
7 changes: 6 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -46,6 +50,7 @@ export function getConfig(): IConfig {
repo,
repoDirectory,
repoUrl: `https://bot:${PAT}@github.com/${owner}/${repo}.git`,
tag
tag,
auto_merge
}
}
20 changes: 18 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,40 @@ async function run(): Promise<void> {
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)
}
Expand Down

0 comments on commit 78ca48c

Please sign in to comment.