From 8122fe74fbda011dad083b3094e7ba198b8d4f1c Mon Sep 17 00:00:00 2001 From: sagitchu <601096721@qq.com> Date: Tue, 18 Mar 2025 16:29:27 +0800 Subject: [PATCH] fix: fix secrets --- .github/workflows/sync-upstream.yml | 54 ++++++++++++++++++++++++++ .github/workflows/sync-upstreem-pr.yml | 8 ++-- 2 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/sync-upstream.yml diff --git a/.github/workflows/sync-upstream.yml b/.github/workflows/sync-upstream.yml new file mode 100644 index 00000000..0ffe38d0 --- /dev/null +++ b/.github/workflows/sync-upstream.yml @@ -0,0 +1,54 @@ +name: Sync Upstream PRs + +on: + schedule: + - cron: '0 */6 * * *' # 每6小时运行一次 + workflow_dispatch: # 允许手动触发 + +jobs: + sync: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Sync upstream pull requests + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.sync.TOKEN }} + script: | + const upstream = 'upstream-owner/upstream-repo'; // 替换为实际的上游仓库 + const [owner, repo] = upstream.split('/'); + + // 获取上游仓库的PR + const pulls = await github.rest.pulls.list({ + owner, + repo, + state: 'open' + }); + + // 为每个PR创建或更新对应的PR + for (const pull of pulls.data) { + try { + // 检查是否已存在相同的PR + const existingPulls = await github.rest.pulls.list({ + owner: context.repo.owner, + repo: context.repo.repo, + head: `${owner}:${pull.head.ref}`, + }); + + if (existingPulls.data.length === 0) { + // 创建新的PR + await github.rest.pulls.create({ + owner: context.repo.owner, + repo: context.repo.repo, + title: `[Upstream] ${pull.title}`, + body: `Synced from upstream PR: ${pull.html_url}\n\n${pull.body || ''}`, + head: `${owner}:${pull.head.ref}`, + base: pull.base.ref, + }); + } + } catch (error) { + console.log(`Error processing PR #${pull.number}: ${error.message}`); + } + } diff --git a/.github/workflows/sync-upstreem-pr.yml b/.github/workflows/sync-upstreem-pr.yml index ce992f79..3ba0311d 100644 --- a/.github/workflows/sync-upstreem-pr.yml +++ b/.github/workflows/sync-upstreem-pr.yml @@ -23,11 +23,11 @@ jobs: - name: Sync Upstream PRs env: - # GITHUB_TOKEN: ${{ secrets.TOKEN }} + GITHUB_TOKEN: ${{ secrets.sync.TOKEN }} GH_TOKEN: ${{ github.token }} - UPSTREAM_REPO: ${{ secrets.UPSTREAM_REPO }} # 例如 'original-owner/original-repo' - UPSTREAM_OWNER: ${{ secrets.UPSTREAM_OWNER }} # 例如 'original-owner' - UPSTREAM_REPO_NAME: ${{ secrets.UPSTREAM_REPO_NAME }} # 例如 'original-repo' + UPSTREAM_REPO: ${{ secrets.sync.UPSTREAM_REPO }} # 例如 'original-owner/original-repo' + UPSTREAM_OWNER: ${{ secrets.sync.UPSTREAM_OWNER }} # 例如 'original-owner' + UPSTREAM_REPO_NAME: ${{ secrets.sync.UPSTREAM_REPO_NAME }} # 例如 'original-repo' REPO_OWNER: ${{ github.repository_owner }} REPO_NAME: ${{ github.event.repository.name }} run: |