From cf5e817ab3364a56d77d7a440985e570191a5219 Mon Sep 17 00:00:00 2001 From: Philipp Horstenkamp Date: Sun, 19 Nov 2023 01:25:24 +0100 Subject: [PATCH] First draft. --- .gitea/workflows/maintenance.yaml | 39 ++++++++++++++++++++++++ .pre-commit-config.yaml | 49 +++++++++++++++++++++++++++++++ index.js | 40 +++++++++++++++++++++++++ 3 files changed, 128 insertions(+) create mode 100644 .gitea/workflows/maintenance.yaml create mode 100644 .pre-commit-config.yaml create mode 100644 index.js diff --git a/.gitea/workflows/maintenance.yaml b/.gitea/workflows/maintenance.yaml new file mode 100644 index 0000000..b75d36e --- /dev/null +++ b/.gitea/workflows/maintenance.yaml @@ -0,0 +1,39 @@ +name: Auto Maintenance Cycle + +on: + schedule: + - cron: '* 1 * * 0' + push: + #paths: + #- .gitea/workflows/maintenance.yaml + +jobs: + auto-update: + name: pre-commit Autoupdate + runs-on: pi64 + steps: + - uses: actions/checkout@v4 + with: + ssh-key: ${{ secrets.DEPLOY_KEY }} + ref: main + ssh-strict: false + + - uses: actions/setup-python@v4 + + - run: pip install pre-commit + shell: bash + - run: pre-commit autoupdate + shell: bash + + - uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: 'chore: update pre-commit hooks' + branch: update/pre-commit-hooks + push_options: --force + create_branch: true + + - name: Run My Action + uses: ./ + with: + branch: ${{ github.ref }} + github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..7b6ca19 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,49 @@ +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: end-of-file-fixer + exclude: (.txt$|.ipynb$|README.md$|readme.mde$) + - id: trailing-whitespace + exclude: (.txt$|README.md$) + - id: check-yaml + - id: check-json + - id: check-toml + - id: check-xml + - id: check-added-large-files + args: [--enforce-all] + - id: name-tests-test + - id: detect-private-key + - id: check-case-conflict + - id: check-symlinks + - id: check-docstring-first + - id: pretty-format-json + - id: check-merge-conflict + - id: no-commit-to-branch + args: [--branch, main] + +- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks + rev: v2.11.0 + hooks: + - id: pretty-format-ini + args: [--autofix] + - id: pretty-format-toml + args: [--autofix] + - id: pretty-format-yaml + args: [--autofix] + +- repo: https://github.com/frnmst/md-toc + rev: 8.2.2 + hooks: + - id: md-toc + +- repo: https://github.com/Lucas-C/pre-commit-hooks-java + rev: 1.3.10 + hooks: + - id: validate-html + +- repo: https://github.com/pre-commit/mirrors-prettier + rev: v3.1.0 + hooks: + - id: prettier + types_or: [css, javascript] diff --git a/index.js b/index.js new file mode 100644 index 0000000..851a9ad --- /dev/null +++ b/index.js @@ -0,0 +1,40 @@ +const core = require("@actions/core"); +const github = require("@actions/github"); +const { Octokit } = require("@octokit/rest"); + +async function run() { + try { + const branch = core.getInput("branch"); + const token = core.getInput("github_token"); + const octokit = new Octokit({ auth: token }); + const context = github.context; + + // Check for existing PRs + const { data: pullRequests } = await octokit.rest.pulls.list({ + owner: context.repo.owner, + repo: context.repo.repo, + head: `${context.repo.owner}:${branch}`, + }); + + if (pullRequests.length > 0) { + console.log("A pull request already exists for this branch."); + return; + } + + // Creating a new PR + const newPr = await octokit.rest.pulls.create({ + owner: context.repo.owner, + repo: context.repo.repo, + title: "Your PR Title", // Customize your PR title + head: branch, + base: "main", // Change this to your default branch if it's not 'main' + body: "Your PR description", // Customize your PR description + }); + + console.log(`Created a new pull request: ${newPr.data.html_url}`); + } catch (error) { + core.setFailed(`Action failed with error ${error}`); + } +} + +run();