8000 fix: failing release due to renamed repository (#878) · jedwards1211/github@76fdaa3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 76fdaa3

Browse files
authored
fix: failing release due to renamed repository (semantic-release#878)
This 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.
1 parent c70cfbf commit 76fdaa3

File tree

4 files changed

+270
-92
lines changed

4 files changed

+270
-92
lines changed

lib/definitions/errors.js

Lines changed: 11 additions & 0 deletions
10000
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,17 @@ By default the \`repositoryUrl\` option is retrieved from the \`repository\` pro
139139
};
140140
}
141141

142+
export function EMISMATCHGITHUBURL() {
143+
return {
144+
message: "The git repository URL mismatches the GitHub URL.",
145+
details: `The **semantic-release** \`repositoryUrl\` option must match your GitHub URL with the format \`<GitHub_or_GHE_URL>/<owner>/<repo>.git\`.
146+
147+
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.
148+
149+
Note: If you have recently changed your GitHub repository name or owner, update the value in **semantic-release** \`repositoryUrl\` option and the \`repository\` property of your \`package.json\` respectively to match the new GitHub URL.`,
150+
};
151+
}
152+
142153
export function EINVALIDPROXY({ proxy }) {
143154
return {
144155
message: "Invalid `proxy` option.",

lib/verify.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,33 @@ export default async function verify(pluginConfig, context, { Octokit }) {
144144
}
145145
}
146146

147+
// Verify if Repository Name wasn't changed
148+
if (
149+
owner &&
150+
repo &&
151+
githubToken &&
152+
!errors.find(({ code }) => code === "EINVALIDPROXY") &&
153+
!errors.find(({ code }) => code === "EMISSINGREPO")
154+
) {
155+
const octokit = new Octokit(
156+
toOctokitOptions({
157+
githubToken,
158+
githubUrl,
159+
githubApiPathPrefix,
160+
githubApiUrl,
161+
proxy,
162+
}),
163+
);
164+
165+
const {
166< 8000 span class="diff-text-marker">+
status,
167+
data: { clone_url },
168+
} = await octokit.request("GET /repos/{owner}/{repo}", { owner, repo });
169+
if (status !== 200 || repositoryUrl !== clone_url) {
170+
errors.push(getError("EMISMATCHGITHUBURL"));
171+
}
172+
}
173+
147174
if (!githubToken) {
148175
errors.push(getError("ENOGHTOKEN", { owner, repo }));
149176
}

test/integration.test.js

Lines changed: 67 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,16 @@ test("Verify GitHub auth", async (t) => {
2424
repositoryUrl: `git+https://othertesturl.com/${owner}/${repo}.git`,
2525
};
2626

27-
const fetch = fetchMock
28-
.sandbox()
29-
.getOnce(`https://api.github.local/repos/${owner}/${repo}`, {
27+
const fetch = fetchMock.sandbox().get(
28+
`https://api.github.local/repos/${owner}/${repo}`,
29+
{
3030
permissions: { push: true },
31-
});
31+
clone_url: `git+https://othertesturl.com/${owner}/${repo}.git`,
32+
},
33+
{
34+
repeat: 2,
35+
},
36+
);
3237

3338
await t.notThrowsAsync(
3439
t.context.m.verifyConditions(
@@ -54,11 +59,16 @@ test("Verify GitHub auth with publish options", async (t) => {
5459
publish: { path: "@semantic-release/github" },
5560
repositoryUrl: `git+https://othertesturl.com/${owner}/${repo}.git`,
5661
};
57-
const fetch = fetchMock
58-
.sandbox()
59-
.getOnce(`https://api.github.local/repos/${owner}/${repo}`, {
62+
const fetch = fetchMock.sandbox().get(
63+
`https://api.github.local/repos/${owner}/${repo}`,
64+
{
6065
permissions: { push: true },
61-
});
66+
clone_url: `git+https://othertesturl.com/${owner}/${repo}.git`,
67+
},
68+
{
69+
repeat: 2,
70+
},
71+
);
6272

6373
await t.notThrowsAsync(
6474
t.context.m.verifyConditions(
@@ -91,11 +101,16 @@ test("Verify GitHub auth and assets config", async (t) => {
91101
publish: [{ path: "@semantic-release/npm" }],
92102
repositoryUrl: `git+https://othertesturl.com/${owner}/${repo}.git`,
93103
};
94-
const fetch = fetchMock
95-
.sandbox()
96-
.getOnce(`https://api.github.local/repos/${owner}/${repo}`, {
104+
const fetch = fetchMock.sandbox().get(
105+
`https://api.github.local/repos/${owner}/${repo}`,
106+
{
97107
permissions: { push: true },
98-
});
108+
clone_url: `git+https://othertesturl.com/${owner}/${repo}.git`,
109+
},
110+
{
111+
repeat: 2,
112+
},
113+
);
99114

100115
await t.notThrowsAsync(
101116
t.context.m.verifyConditions(
@@ -196,9 +211,16 @@ test("Publish a release with an array of assets", async (t) => {
196211

197212
const fetch = fetchMock
198213
.sandbox()
199-
.getOnce(`https://api.github.local/repos/${owner}/${repo}`, {
200-
permissions: { push: true },
201-
})
214+
.get(
215+
`https://api.github.local/repos/${owner}/${repo}`,
216+
{
217+
permissions: { push: true },
218+
clone_url: `https://github.com/${owner}/${repo}.git`,
219+
},
220+
{
221+
repeat: 2,
222+
},
223+
)
202224
.postOnce(
203225
`https://api.github.local/repos/${owner}/${repo}/releases`,
204226
{ upload_url: uploadUrl, html_url: releaseUrl, id: releaseId },
@@ -288,9 +310,16 @@ test("Publish a release with release information in assets", async (t) => {
288310

289311
const fetch = fetchMock
290312
.sandbox()
291-
.getOnce(`https://api.github.local/repos/${owner}/${repo}`, {
292-
permissions: { push: true },
293-
})
313+
.get(
314+
`https://api.github.local/repos/${owner}/${repo}`,
315+
{
316+
permissions: { push: true },
317+
clone_url: `https://github.com/${owner}/${repo}.git`,
318+
},
319+
{
320+
repeat: 2,
321+
},
322+
)
294323
.postOnce(
295324
`https://api.github.local/repos/${owner}/${repo}/releases`,
296325
{ upload_url: uploadUrl, html_url: releaseUrl, id: releaseId },
@@ -358,9 +387,16 @@ test("Update a release", async (t) => {
358387

359388
const fetch = fetchMock
360389
.sandbox()
361-
.getOnce(`https://api.github.local/repos/${owner}/${repo}`, {
362-
permissions: { push: true },
363-
})
390+
.get(
391+
`https://api.github.local/repos/${owner}/${repo}`,
392+
{
393+
permissions: { push: true },
394+
clone_url: `https://github.com/${owner}/${repo}.git`,
395+
},
396+
{
397+
repeat: 2,
398+
},
399+
)
364400
.getOnce(
365401
`https://api.github.local/repos/${owner}/${repo}/releases/tags/${nextRelease.gitTag}`,
366402
{ id: releaseId },
@@ -426,10 +462,10 @@ test("Comment and add labels on PR included in the releases", async (t) => {
426462
{
427463
permissions: { push: true },
428464
full_name: `${owner}/${repo}`,
465+
clone_url: `https://github.com/${owner}/${repo}.git`,
429466
},
430467
{
431-
// TODO: why do we call the same endpoint twice?
432-
repeat: 2,
468+
repeat: 3,
433469
},
434470
)
435471
.postOnce("https://api.github.local/graphql", {
@@ -529,9 +565,10 @@ test("Open a new issue with the list of errors", async (t) => {
529565
{
530566
permissions: { push: true },
531567
full_name: `${owner}/${repo}`,
568+
clone_url: `https://github.com/${owner}/${repo}.git`,
532569
},
533570
{
534-
repeat: 2,
571+
repeat: 3,
535572
},
536573
)
537574
.getOnce(
@@ -625,9 +662,10 @@ test("Verify, release and notify success", async (t) => {
625662
{
626663
permissions: { push: true },
627664
full_name: `${owner}/${repo}`,
665+
clone_url: `https://github.com/${owner}/${repo}.git`,
628666
},
629667
{
630-
repeat: 2,
668+
repeat: 3,
631669
},
632670
)
633671
.postOnce(
@@ -785,9 +823,10 @@ test("Verify, update release and notify success", async (t) => {
785823
{
786824
permissions: { push: true },
787825
full_name: `${owner}/${repo}`,
826+
clone_url: `https://github.com/${owner}/${repo}.git`,
788827
},
789828
{
790-
repeat: 2,
829+
repeat: 3,
791830
},
792831
)
793832
.getOnce(
@@ -917,9 +956,10 @@ test("Verify and notify failure", async (t) => {
917956
{
918957
permissions: { push: true },
919958
full_name: `${owner}/${repo}`,
959+
clone_url: `https://github.com/${owner}/${repo}.git`,
920960
},
921961
{
922-
repeat: 2,
962+
repeat: 3,
923963
},
924964
)
925965
.getOnce(

0 commit comments

Comments
 (0)
0