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
  • Loading branch information
raphael-papazikas committed Apr 26, 2024
1 parent ada4ad6 commit 85e6d45
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"project": "./tsconfig.json"
},
"rules": {
"no-console": "off",
"i18n-text/no-en": "off",
"eslint-comments/no-use": "off",
"import/no-namespace": "off",
Expand Down
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
}
}
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

console.log('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)

console.log('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}"`)
}

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

console.log('Bump Version')
await bumpVersions(config)

console.log('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({
console.log('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
})

console.log('Pull Request Created')
console.log(resp.data)

if (String(config.auto_merge) === 'true') {
console.log('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'
})
console.log('Merge Response')
console.log(mergeResponse.data)
}
} catch (e) {
if (e instanceof Error) core.setFailed(e.message)
}
console.log('Cleanup')
shell.rm('-rf', config.clonePath)
}

Expand Down

0 comments on commit 85e6d45

Please sign in to comment.