mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-09-18 01:26:37 +08:00
fix: access pr
This commit is contained in:
parent
179aa92c35
commit
30341bc6b2
28
.github/workflows/sync-upstream.yml
vendored
28
.github/workflows/sync-upstream.yml
vendored
@ -14,14 +14,15 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
fetch-depth: 0 # 获取完整历史
|
||||||
|
|
||||||
- name: Sync upstream pull requests
|
- name: Sync upstream pull requests
|
||||||
uses: actions/github-script@v6
|
uses: actions/github-script@v6
|
||||||
with:
|
with:
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }} # 使用默认的 GITHUB_TOKEN
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
# 或者使用您的自定义 token: ${{ secrets.YOUR_PAT }}
|
|
||||||
script: |
|
script: |
|
||||||
const upstream = 'songquanpeng/one-api'; // 替换为实际的上游仓库
|
const upstream = 'songquanpeng/one-api';
|
||||||
const [owner, repo] = upstream.split('/');
|
const [owner, repo] = upstream.split('/');
|
||||||
|
|
||||||
// 获取上游仓库的PR
|
// 获取上游仓库的PR
|
||||||
@ -34,22 +35,37 @@ jobs:
|
|||||||
// 为每个PR创建或更新对应的PR
|
// 为每个PR创建或更新对应的PR
|
||||||
for (const pull of pulls.data) {
|
for (const pull of pulls.data) {
|
||||||
try {
|
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
|
// 检查是否已存在相同的PR
|
||||||
const existingPulls = await github.rest.pulls.list({
|
const existingPulls = await github.rest.pulls.list({
|
||||||
owner: context.repo.owner,
|
owner: context.repo.owner,
|
||||||
repo: context.repo.repo,
|
repo: context.repo.repo,
|
||||||
head: `${owner}:${pull.head.ref}`,
|
head: `${context.repo.owner}:${branchName}`,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (existingPulls.data.length === 0) {
|
if (existingPulls.data.length === 0) {
|
||||||
|
// 推送分支
|
||||||
|
await exec.exec('git', ['push', 'origin', branchName]);
|
||||||
|
|
||||||
// 创建新的PR
|
// 创建新的PR
|
||||||
await github.rest.pulls.create({
|
await github.rest.pulls.create({
|
||||||
owner: context.repo.owner,
|
owner: context.repo.owner,
|
||||||
repo: context.repo.repo,
|
repo: context.repo.repo,
|
||||||
title: `[Upstream] ${pull.title}`,
|
title: `[Upstream] ${pull.title}`,
|
||||||
body: `Synced from upstream PR: ${pull.html_url}\n\n${pull.body || ''}`,
|
body: `Synced from upstream PR: ${pull.html_url}\n\n${pull.body || ''}`,
|
||||||
head: `${owner}:${pull.head.ref}`,
|
head: branchName,
|
||||||
base: pull.base.ref,
|
base: 'main' // 根据实际情况修改目标分支
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user