Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: failing release due to renamed repository #878

Merged
merged 12 commits into from
Jul 25, 2024

Conversation

babblebey
Copy link
Member

@babblebey babblebey commented Jul 13, 2024

This Pull request introduces an extra step in the plugin verify lifecycle which verifies that the repositoryUrl and/or project package.json's repository field matches the project's current GitHub URL. This throws an error EMISMATCHGITHUBURL which confirms mismatch and suggests a fix.

Changes Made

  • Added a logic that requests the repo details leveraging the github get-a-repository endpoint, and checks for a status of 200 and a match between the response data's clone_url value and the context.options.repositoryUrl. And it should only run this when we a githubToken is authenticated and we do not have the EINVALIDPROXY and EMISSINGREPO error.

    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"));
      }
    }
  • Added a new error helper function EMISMATCHGITHUBURL for the

    export function EMISMATCHGITHUBURL() {
      return {
        message: "The git repository URL mismatches the GitHub URL.",
        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.`,
      };
    }

Related Issue

Fixes #803

Screencast/Screenshot

screencast-bpconcjcammlapcogcnnelfmaeghhagj-2024.07.14-11_29_00.webm

@babblebey babblebey changed the title fix: failing release for renamed repository fix: failing release due to renamed repository Jul 13, 2024
@babblebey babblebey marked this pull request as ready for review July 14, 2024 10:49
@babblebey babblebey requested a review from a team July 15, 2024 15:14
Copy link
Member

@gr2m gr2m left a comment

Choose a reason for hiding this comment

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

Just a few nits but otherwise good to go

test/integration.test.js Outdated Show resolved Hide resolved
test/integration.test.js Outdated Show resolved Hide resolved
lib/definitions/errors.js Outdated Show resolved Hide resolved
Copy link
Member

@gr2m gr2m left a comment

Choose a reason for hiding this comment

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

🚀

@babblebey babblebey merged commit 76fdaa3 into master Jul 25, 2024
6 checks passed
@babblebey babblebey deleted the feat/verify-repository-name-change branch July 25, 2024 15:57
Copy link

🎉 This issue has been resolved in version 10.1.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@nandreanurag
Copy link

This change is not compatible for users using .releaserc

@jedwards1211
Copy link
Contributor

@gr2m breaking change...just because we have an https:// URL in our package.json and our CI is cloning with a different style of URL doesn't mean we necessarily want it to fail the build

@jedwards1211
Copy link
Contributor

@gr2m also I can't seem to make this error go away. The repository.url in my package.json and my git remote -v are both git+https://github.com/<org>/<repo>.git yet I'm still getting this error.

@@ -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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Outdated package.json "repository" field fails when creating release
4 participants