mirror of
https://github.com/changesets/action
synced 2026-10-26 16:39:56 +08:00
Added pullRequestNumber to the action's outputs (#167)
* feat: set pullRequesstNumber as action output * chore: add changeset * fix: feedback from pr review * Update .changeset/long-mayflies-yell.md Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com> Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
This commit is contained in:
co-authored by
Mateusz Burzyński
parent
c7c59f0c6f
commit
993a0a090d
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@changesets/action": minor
|
||||||
|
---
|
||||||
|
|
||||||
|
Added `pullRequestNumber` to the action's outputs
|
||||||
@@ -36,6 +36,8 @@ outputs:
|
|||||||
A JSON array to present the published packages. The format is `[{"name": "@xx/xx", "version": "1.2.0"}, {"name": "@xx/xy", "version": "0.8.9"}]`
|
A JSON array to present the published packages. The format is `[{"name": "@xx/xx", "version": "1.2.0"}, {"name": "@xx/xy", "version": "0.8.9"}]`
|
||||||
hasChangesets:
|
hasChangesets:
|
||||||
description: A boolean about whether there were changesets. Useful if you want to create your own publishing functionality.
|
description: A boolean about whether there were changesets. Useful if you want to create your own publishing functionality.
|
||||||
|
pullRequestNumber:
|
||||||
|
description: The pull request number that was created or updated
|
||||||
branding:
|
branding:
|
||||||
icon: "package"
|
icon: "package"
|
||||||
color: "blue"
|
color: "blue"
|
||||||
|
|||||||
+4
-1
@@ -97,13 +97,16 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case hasChangesets:
|
case hasChangesets:
|
||||||
await runVersion({
|
const { pullRequestNumber } = await runVersion({
|
||||||
script: getOptionalInput("version"),
|
script: getOptionalInput("version"),
|
||||||
githubToken,
|
githubToken,
|
||||||
prTitle: getOptionalInput("title"),
|
prTitle: getOptionalInput("title"),
|
||||||
commitMessage: getOptionalInput("commit"),
|
commitMessage: getOptionalInput("commit"),
|
||||||
hasPublishScript,
|
hasPublishScript,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
core.setOutput("pullRequestNumber", String(pullRequestNumber));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
})().catch((err) => {
|
})().catch((err) => {
|
||||||
|
|||||||
@@ -57,6 +57,10 @@ describe("version", () => {
|
|||||||
() => ({ data: { items: [] } })
|
() => ({ data: { items: [] } })
|
||||||
);
|
);
|
||||||
|
|
||||||
|
mockedGithubMethods.pulls.create.mockImplementationOnce(
|
||||||
|
() => ({ data: { number: 123 } })
|
||||||
|
);
|
||||||
|
|
||||||
await writeChangesets(
|
await writeChangesets(
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
@@ -92,6 +96,10 @@ describe("version", () => {
|
|||||||
() => ({ data: { items: [] } })
|
() => ({ data: { items: [] } })
|
||||||
);
|
);
|
||||||
|
|
||||||
|
mockedGithubMethods.pulls.create.mockImplementationOnce(
|
||||||
|
() => ({ data: { number: 123 } })
|
||||||
|
);
|
||||||
|
|
||||||
await writeChangesets(
|
await writeChangesets(
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
@@ -123,6 +131,10 @@ describe("version", () => {
|
|||||||
() => ({ data: { items: [] } })
|
() => ({ data: { items: [] } })
|
||||||
);
|
);
|
||||||
|
|
||||||
|
mockedGithubMethods.pulls.create.mockImplementationOnce(
|
||||||
|
() => ({ data: { number: 123 } })
|
||||||
|
);
|
||||||
|
|
||||||
await writeChangesets(
|
await writeChangesets(
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
|
|||||||
+17
-3
@@ -177,6 +177,10 @@ type VersionOptions = {
|
|||||||
hasPublishScript?: boolean;
|
hasPublishScript?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type RunVersionResult = {
|
||||||
|
pullRequestNumber: number;
|
||||||
|
};
|
||||||
|
|
||||||
export async function runVersion({
|
export async function runVersion({
|
||||||
script,
|
script,
|
||||||
githubToken,
|
githubToken,
|
||||||
@@ -184,7 +188,7 @@ export async function runVersion({
|
|||||||
prTitle = "Version Packages",
|
prTitle = "Version Packages",
|
||||||
commitMessage = "Version Packages",
|
commitMessage = "Version Packages",
|
||||||
hasPublishScript = false,
|
hasPublishScript = false,
|
||||||
}: VersionOptions) {
|
}: VersionOptions): Promise<RunVersionResult> {
|
||||||
let repo = `${github.context.repo.owner}/${github.context.repo.repo}`;
|
let repo = `${github.context.repo.owner}/${github.context.repo.repo}`;
|
||||||
let branch = github.context.ref.replace("refs/heads/", "");
|
let branch = github.context.ref.replace("refs/heads/", "");
|
||||||
let versionBranch = `changeset-release/${branch}`;
|
let versionBranch = `changeset-release/${branch}`;
|
||||||
@@ -280,20 +284,30 @@ ${
|
|||||||
console.log(JSON.stringify(searchResult.data, null, 2));
|
console.log(JSON.stringify(searchResult.data, null, 2));
|
||||||
if (searchResult.data.items.length === 0) {
|
if (searchResult.data.items.length === 0) {
|
||||||
console.log("creating pull request");
|
console.log("creating pull request");
|
||||||
await octokit.pulls.create({
|
const {
|
||||||
|
data: { number },
|
||||||
|
} = await octokit.pulls.create({
|
||||||
base: branch,
|
base: branch,
|
||||||
head: versionBranch,
|
head: versionBranch,
|
||||||
title: finalPrTitle,
|
title: finalPrTitle,
|
||||||
body: await prBodyPromise,
|
body: await prBodyPromise,
|
||||||
...github.context.repo,
|
...github.context.repo,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
pullRequestNumber: number,
|
||||||
|
};
|
||||||
} else {
|
} else {
|
||||||
octokit.pulls.update({
|
await octokit.pulls.update({
|
||||||
pull_number: searchResult.data.items[0].number,
|
pull_number: searchResult.data.items[0].number,
|
||||||
title: finalPrTitle,
|
title: finalPrTitle,
|
||||||
body: await prBodyPromise,
|
body: await prBodyPromise,
|
||||||
...github.context.repo,
|
...github.context.repo,
|
||||||
});
|
});
|
||||||
console.log("pull request found");
|
console.log("pull request found");
|
||||||
|
|
||||||
|
return {
|
||||||
|
pullRequestNumber: searchResult.data.items[0].number,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user