Skip to content

Commit

Permalink
add auto merge
Browse files Browse the repository at this point in the history
add auto merge

add some logging

fix: lint

chore: improve action logging

support auto merge
  • Loading branch information
raphael-papazikas committed Apr 26, 2024
1 parent ada4ad6 commit f9c2792
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 9 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'
44 changes: 39 additions & 5 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.

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
}
}
39 changes: 37 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,28 +61,63 @@ async function run(): Promise<void> {
try {
shell.config.fatal = true

core.info('Configuring Git')
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)

core.info('Cloning Repository')
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}"`)
}

core.info('Creating Branch')
shell.exec(`git checkout -B ${config.branch}`)

core.info('Bump Version')
await bumpVersions(config)

core.info('Committing Changes')
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({
core.info('Creating Pull Request')
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
})

core.info('Pull Request Created')
core.debug(JSON.stringify(resp.data))

if (String(config.auto_merge) === 'true') {
core.info('Auto Merge is configured')
const mergeResponse = await github
.getOctokit(config.PAT)
.rest.pulls.merge({
owner: config.owner,
repo: config.repo,
pull_number: resp.data.number,
merge_method: 'squash'
})
core.debug('Merge Response')
core.debug(JSON.stringify(mergeResponse.data))
}
} catch (e) {
if (e instanceof Error) core.setFailed(e.message)
}
core.info('Cleanup')
shell.rm('-rf', config.clonePath)
}

Expand Down

0 comments on commit f9c2792

Please sign in to comment.