Skip to content

Commit 070483a

Browse files
fix: fixed pr comments
1 parent 7aa426e commit 070483a

1 file changed

Lines changed: 52 additions & 10 deletions

File tree

scripts/release-make-it-native.mjs

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,23 +81,65 @@ async function createPRUpdateChangelog() {
8181
await git.addConfig("user.email", GIT_AUTHOR_EMAIL, ["--global"]);
8282

8383
// Get the current branch name (the one selected in GitHub Actions UI)
84-
const currentBranch = await git.revparse(["--abbrev-ref", "HEAD"]);
84+
const currentBranch = process.env.GITHUB_REF_NAME;
85+
if (!currentBranch) {
86+
throw new Error("GITHUB_REF_NAME environment variable is not set");
87+
}
8588

8689
await git.checkoutLocalBranch(CHANGELOG_BRANCH_NAME);
8790

8891
await git.add("CHANGELOG.md");
8992
await git.commit(`chore: update CHANGELOG for v${MIN_VERSION}`);
9093
await git.push("origin", CHANGELOG_BRANCH_NAME, ["--force-with-lease"]);
9194

92-
await octokit.pulls.create({
93-
owner: process.env.GITHUB_REPOSITORY_OWNER,
94-
repo: process.env.GITHUB_REPOSITORY.split("/")[1],
95-
title: `Update CHANGELOG for v${MIN_VERSION}`,
96-
head: CHANGELOG_BRANCH_NAME,
97-
base: currentBranch,
98-
body: "**Note:** Please do not take any action on this pull request unless it has been reviewed and approved by a member of the Mobile team.",
99-
draft: true,
100-
});
95+
const owner = process.env.GITHUB_REPOSITORY_OWNER;
96+
const repo = process.env.GITHUB_REPOSITORY.split("/")[1];
97+
const prBody = "**Note:** Please do not take any action on this pull request unless it has been reviewed and approved by a member of the Mobile team.";
98+
99+
try {
100+
await octokit.pulls.create({
101+
owner,
102+
repo,
103+
title: `Update CHANGELOG for v${MIN_VERSION}`,
104+
head: CHANGELOG_BRANCH_NAME,
105+
base: currentBranch,
106+
body: prBody,
107+
draft: true,
108+
});
109+
console.log("✅ Created PR to update CHANGELOG in make-it-native");
110+
} catch (err) {
111+
const isPRExistsError =
112+
err.status === 422 &&
113+
(err.message?.includes("A pull request already exists") ||
114+
err.response?.data?.errors?.some(
115+
(e) => e.resource === "PullRequest" && e.message?.includes("A pull request already exists")
116+
));
117+
118+
if (isPRExistsError) {
119+
console.log("ℹ️ PR already exists, updating existing PR...");
120+
const { data: existingPRs } = await octokit.pulls.list({
121+
owner,
122+
repo,
123+
head: CHANGELOG_BRANCH_NAME,
124+
base: currentBranch,
125+
state: "open",
126+
});
127+
if (existingPRs.length > 0) {
128+
const existingPR = existingPRs[0];
129+
await octokit.pulls.update({
130+
owner,
131+
repo,
132+
pull_number: existingPR.number,
133+
body: prBody,
134+
});
135+
console.log(`✅ Updated existing PR #${existingPR.number}`);
136+
} else {
137+
throw new Error("PR exists but could not be found for update");
138+
}
139+
} else {
140+
throw err;
141+
}
142+
}
101143
}
102144

103145
// Docs

0 commit comments

Comments
 (0)