Skip to content

Commit

Permalink
Merge pull request #2 from opentelekomcloud-infra/add-merge
Browse files Browse the repository at this point in the history
add merge
  • Loading branch information
vladimirvshivkov authored Jun 13, 2024
2 parents 3199e11 + 9ed2bcd commit 22754cb
Showing 5 changed files with 82 additions and 26 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/python-lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: python-lint

on:
pull_request:
types:
- opened
- closed
- edited
- reopened
- synchronize

jobs:
lint:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8, 3.9, 3.11]
steps:
- uses: advanced-security/python-lint-code-scanning-action@v1
with:
linter: flake8
python-version: ${{ matrix.python-version }}
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM python:3.11-slim

# Install dependencies
COPY requirements.txt .
RUN pip install -r requirements.txt

# Copy the action script
COPY merge_pr.py /merge_pr.py

# Set the entrypoint to your action
ENTRYPOINT ["python", "/merge_pr.py"]
44 changes: 18 additions & 26 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
---
name: run-github-actions
description: test
name: run-github-merge
description: 'Automatically merges a pull request into a protected branch'
author: OpenTelekomCloud Ecosystem squad
inputs:
github_token:
description: 'GitHub token for authentication'
required: true
base_branch:
description: 'The branch to merge into'
required: true
pr_number:
description: 'The pull request number to merge'
required: true
runs:
using: composite
steps:
- name: Process inputs
id: inputs
shell: bash
run: |
if [[ -n "${{ inputs.working_directory }}" ]]; then
echo "working_directory=${{ inputs.working_directory }}" >> $GITHUB_OUTPUT
else
echo "working_directory=${{ github.workspace }}" >> $GITHUB_OUTPUT
fi
# Due to GHA limitation, caching works only for files within GITHUB_WORKSPACE
# folder, so we are forced to stick this temporary file inside .git, so it
# will not affect the linted repository.
# https://github.com/actions/toolkit/issues/1035
# https://github.com/actions/setup-python/issues/361
- name: Set up Python
if: inputs.setup_python == 'true'
uses: actions/setup-python@v5
with:
cache: pip
cache-dependency-path: ${{ github.workspace }}/.git/test-requirements.txt
python-version: "3.11"
using: docker
image: 'Dockerfile'
args:
- ${{ inputs.github_token }}
- ${{ inputs.base_branch }}
- ${{ inputs.pr_number }}
30 changes: 30 additions & 0 deletions merge_pr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import sys
import os
from github import Github
from github.GithubException import GithubException


def main():
token = sys.argv[1]
base_branch = sys.argv[2]
pr_number = int(sys.argv[3])

g = Github(token)
repo = g.get_repo(os.environ['GITHUB_REPOSITORY'])

try:
pr = repo.get_pull(pr_number)

if pr.is_merged():
repo.merge(base_branch, pr.head.sha, f"Merge PR #{pr_number}")
print(f"Successfully merged PR #{pr_number} into {base_branch}")
else:
print(f"PR #{pr_number} is not merged yet")
sys.exit(1)
except GithubException as e:
print(f"Error: {e}")
sys.exit(1)


if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PyGithub

0 comments on commit 22754cb

Please sign in to comment.