fix: access pr

This commit is contained in:
sagitchu 2025-03-18 16:54:22 +08:00
parent 179aa92c35
commit 30341bc6b2

View File

@ -14,14 +14,15 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0 # 获取完整历史
- name: Sync upstream pull requests
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }} # 使用默认的 GITHUB_TOKEN
# 或者使用您的自定义 token: ${{ secrets.YOUR_PAT }}
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const upstream = 'songquanpeng/one-api'; // 替换为实际的上游仓库
const upstream = 'songquanpeng/one-api';
const [owner, repo] = upstream.split('/');
// 获取上游仓库的PR
@ -34,22 +35,37 @@ jobs:
// 为每个PR创建或更新对应的PR
for (const pull of pulls.data) {
try {
const branchName = `upstream-pr-${pull.number}`;
// 获取PR详细信息
const prDetails = await github.rest.pulls.get({
owner,
repo,
pull_number: pull.number
});
// 创建新分支
await exec.exec('git', ['fetch', `https://github.com/${owner}/${repo}.git`, `pull/${pull.number}/head:${branchName}`]);
// 检查是否已存在相同的PR
const existingPulls = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
head: `${owner}:${pull.head.ref}`,
head: `${context.repo.owner}:${branchName}`,
});
if (existingPulls.data.length === 0) {
// 推送分支
await exec.exec('git', ['push', 'origin', branchName]);
// 创建新的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,
head: branchName,
base: 'main' // 根据实际情况修改目标分支
});
}
} catch (error) {