mirror of
https://github.com/RayLabsHQ/gitea-mirror.git
synced 2025-12-09 13:06:45 +03:00
Updates to PR as issues
This commit is contained in:
@@ -1583,9 +1583,26 @@ export async function mirrorGitRepoPullRequestsToGitea({
|
|||||||
// Pull requests are typically created through Git operations
|
// Pull requests are typically created through Git operations
|
||||||
// For now, we'll create them as issues with a special label
|
// For now, we'll create them as issues with a special label
|
||||||
|
|
||||||
// Get or create a PR label
|
// Get existing labels from Gitea and ensure "pull-request" label exists
|
||||||
|
const giteaLabelsRes = await httpGet(
|
||||||
|
`${config.giteaConfig.url}/api/v1/repos/${giteaOwner}/${repository.name}/labels`,
|
||||||
|
{
|
||||||
|
Authorization: `token ${decryptedConfig.giteaConfig.token}`,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const giteaLabels = giteaLabelsRes.data;
|
||||||
|
const labelMap = new Map<string, number>(
|
||||||
|
giteaLabels.map((label: any) => [label.name, label.id])
|
||||||
|
);
|
||||||
|
|
||||||
|
// Ensure "pull-request" label exists
|
||||||
|
let pullRequestLabelId: number | null = null;
|
||||||
|
if (labelMap.has("pull-request")) {
|
||||||
|
pullRequestLabelId = labelMap.get("pull-request")!;
|
||||||
|
} else {
|
||||||
try {
|
try {
|
||||||
await httpPost(
|
const created = await httpPost(
|
||||||
`${config.giteaConfig.url}/api/v1/repos/${giteaOwner}/${repository.name}/labels`,
|
`${config.giteaConfig.url}/api/v1/repos/${giteaOwner}/${repository.name}/labels`,
|
||||||
{
|
{
|
||||||
name: "pull-request",
|
name: "pull-request",
|
||||||
@@ -1596,8 +1613,11 @@ export async function mirrorGitRepoPullRequestsToGitea({
|
|||||||
Authorization: `token ${decryptedConfig.giteaConfig.token}`,
|
Authorization: `token ${decryptedConfig.giteaConfig.token}`,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
pullRequestLabelId = created.data.id;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Label might already exist, continue
|
console.error(`Failed to create "pull-request" label in Gitea: ${error}`);
|
||||||
|
// Continue without labels if creation fails
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const { processWithRetry } = await import("@/lib/utils/concurrency");
|
const { processWithRetry } = await import("@/lib/utils/concurrency");
|
||||||
@@ -1681,7 +1701,7 @@ export async function mirrorGitRepoPullRequestsToGitea({
|
|||||||
const issueData = {
|
const issueData = {
|
||||||
title: issueTitle,
|
title: issueTitle,
|
||||||
body: richBody,
|
body: richBody,
|
||||||
labels: [{ name: "pull-request" }],
|
labels: pullRequestLabelId ? [pullRequestLabelId] : [],
|
||||||
state: pr.state === "closed" ? "closed" : "open",
|
state: pr.state === "closed" ? "closed" : "open",
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1701,7 +1721,7 @@ export async function mirrorGitRepoPullRequestsToGitea({
|
|||||||
const basicIssueData = {
|
const basicIssueData = {
|
||||||
title: `[PR #${pr.number}] ${pr.title}`,
|
title: `[PR #${pr.number}] ${pr.title}`,
|
||||||
body: `**Original Pull Request:** ${pr.html_url}\n\n**State:** ${pr.state}\n**Merged:** ${pr.merged_at ? 'Yes' : 'No'}\n\n---\n\n${pr.body || 'No description provided'}`,
|
body: `**Original Pull Request:** ${pr.html_url}\n\n**State:** ${pr.state}\n**Merged:** ${pr.merged_at ? 'Yes' : 'No'}\n\n---\n\n${pr.body || 'No description provided'}`,
|
||||||
labels: [{ name: "pull-request" }],
|
labels: pullRequestLabelId ? [pullRequestLabelId] : [],
|
||||||
state: pr.state === "closed" ? "closed" : "open",
|
state: pr.state === "closed" ? "closed" : "open",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user