Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/definitions/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,17 @@ By default the \`repositoryUrl\` option is retrieved from the \`repository\` pro
};
}

export function EMISMATCHGITHUBURL() {
return {
message: "The git repository URL mismatches the GitHub URL.",
Copy link
Contributor

@jedwards1211 jedwards1211 Jul 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gr2m @babblebey it would be a lot more convenient to include the two values that didn't match in an error message like this

details: `The **semantic-release** \`repositoryUrl\` option must match your GitHub URL with the format \`<GitHub_or_GHE_URL>/<owner>/<repo>.git\`.

By default the \`repositoryUrl\` option is retrieved from the \`repository\` property of your \`package.json\` or the [git origin url](https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes) of the repository cloned by your CI environment.

NB: If you have recently changed your GitHub repository name or owner, kindly update the value in **semantic-release** \`repositoryUrl\` option and the \`repository\` property of your \`package.json\` respectively to match the new GitHub URL.`,
};
}

export function EINVALIDPROXY({ proxy }) {
return {
message: "Invalid `proxy` option.",
Expand Down
27 changes: 27 additions & 0 deletions lib/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,33 @@ export default async function verify(pluginConfig, context, { Octokit }) {
}
}

// Verify if Repository Name wasn't changed
if (
owner &&
repo &&
githubToken &&
!errors.find(({ code }) => code === "EINVALIDPROXY") &&
!errors.find(({ code }) => code === "EMISSINGREPO")
) {
const octokit = new Octokit(
toOctokitOptions({
githubToken,
githubUrl,
githubApiPathPrefix,
githubApiUrl,
proxy,
}),
);

const {
status,
data: { clone_url },
} = await octokit.request("GET /repos/{owner}/{repo}", { owner, repo });
if (status !== 200 || repositoryUrl !== clone_url) {
errors.push(getError("EMISMATCHGITHUBURL"));
}
}

if (!githubToken) {
errors.push(getError("ENOGHTOKEN", { owner, repo }));
}
Expand Down
33 changes: 22 additions & 11 deletions test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ test("Verify GitHub auth", async (t) => {

const fetch = fetchMock
.sandbox()
.getOnce(`https://api.github.local/repos/${owner}/${repo}`, {
.get(`https://api.github.local/repos/${owner}/${repo}`, {
permissions: { push: true },
clone_url: `git+https://othertesturl.com/${owner}/${repo}.git`,
});

await t.notThrowsAsync(
Expand Down Expand Up @@ -56,8 +57,9 @@ test("Verify GitHub auth with publish options", async (t) => {
};
const fetch = fetchMock
.sandbox()
.getOnce(`https://api.github.local/repos/${owner}/${repo}`, {
.get(`https://api.github.local/repos/${owner}/${repo}`, {
permissions: { push: true },
clone_url: `git+https://othertesturl.com/${owner}/${repo}.git`,
});

await t.notThrowsAsync(
Expand Down Expand Up @@ -93,8 +95,9 @@ test("Verify GitHub auth and assets config", async (t) => {
};
const fetch = fetchMock
.sandbox()
.getOnce(`https://api.github.local/repos/${owner}/${repo}`, {
.get(`https://api.github.local/repos/${owner}/${repo}`, {
permissions: { push: true },
clone_url: `git+https://othertesturl.com/${owner}/${repo}.git`,
});

await t.notThrowsAsync(
Expand Down Expand Up @@ -196,8 +199,9 @@ test("Publish a release with an array of assets", async (t) => {

const fetch = fetchMock
.sandbox()
.getOnce(`https://api.github.local/repos/${owner}/${repo}`, {
.get(`https://api.github.local/repos/${owner}/${repo}`, {
permissions: { push: true },
clone_url: `https://github.com/${owner}/${repo}.git`,
})
.postOnce(
`https://api.github.local/repos/${owner}/${repo}/releases`,
Expand Down Expand Up @@ -288,8 +292,9 @@ test("Publish a release with release information in assets", async (t) => {

const fetch = fetchMock
.sandbox()
.getOnce(`https://api.github.local/repos/${owner}/${repo}`, {
.get(`https://api.github.local/repos/${owner}/${repo}`, {
permissions: { push: true },
clone_url: `https://github.com/${owner}/${repo}.git`,
})
.postOnce(
`https://api.github.local/repos/${owner}/${repo}/releases`,
Expand Down Expand Up @@ -358,8 +363,9 @@ test("Update a release", async (t) => {

const fetch = fetchMock
.sandbox()
.getOnce(`https://api.github.local/repos/${owner}/${repo}`, {
.get(`https://api.github.local/repos/${owner}/${repo}`, {
permissions: { push: true },
clone_url: `https://github.com/${owner}/${repo}.git`,
})
.getOnce(
`https://api.github.local/repos/${owner}/${repo}/releases/tags/${nextRelease.gitTag}`,
Expand Down Expand Up @@ -426,10 +432,11 @@ test("Comment and add labels on PR included in the releases", async (t) => {
{
permissions: { push: true },
full_name: `${owner}/${repo}`,
clone_url: `https://github.com/${owner}/${repo}.git`,
},
{
// TODO: why do we call the same endpoint twice?
repeat: 2,
repeat: 3,
},
)
.postOnce("https://api.github.local/graphql", {
Expand Down Expand Up @@ -529,9 +536,10 @@ test("Open a new issue with the list of errors", async (t) => {
{
permissions: { push: true },
full_name: `${owner}/${repo}`,
clone_url: `https://github.com/${owner}/${repo}.git`,
},
{
repeat: 2,
repeat: 3,
},
)
.getOnce(
Expand Down Expand Up @@ -625,9 +633,10 @@ test("Verify, release and notify success", async (t) => {
{
permissions: { push: true },
full_name: `${owner}/${repo}`,
clone_url: `https://github.com/${owner}/${repo}.git`,
},
{
repeat: 2,
repeat: 3,
},
)
.postOnce(
Expand Down Expand Up @@ -785,9 +794,10 @@ test("Verify, update release and notify success", async (t) => {
{
permissions: { push: true },
full_name: `${owner}/${repo}`,
clone_url: `https://github.com/${owner}/${repo}.git`,
},
{
repeat: 2,
repeat: 3,
},
)
.getOnce(
Expand Down Expand Up @@ -917,9 +927,10 @@ test("Verify and notify failure", async (t) => {
{
permissions: { push: true },
full_name: `${owner}/${repo}`,
clone_url: `https://github.com/${owner}/${repo}.git`,
},
{
repeat: 2,
repeat: 3,
},
)
.getOnce(
Expand Down
Loading