diff --git a/transforms/github-pages.js b/transforms/github-pages.js index fa51382..6146d8c 100644 --- a/transforms/github-pages.js +++ b/transforms/github-pages.js @@ -28,16 +28,22 @@ module.exports = async function ({ source.branch = target; - await octokit.repos.updateInformationAboutPagesSite({ - owner, - repo, - source, - }); + if (!dryRun) { + await octokit.repos.updateInformationAboutPagesSite({ + owner, + repo, + source, + }); + } log( `Updated GitHub pages from [${old}] to [${target}] with path [${source.path}]` ); } catch (e) { - log(`No GitHub Pages found for [${owner}/${repo}]`); + if (e.status === 404) { + log(`No GitHub Pages found for [${owner}/${repo}]`); + return; + } + throw e; } }; diff --git a/transforms/github-pages.test.js b/transforms/github-pages.test.js index 67a1e88..f083a4e 100644 --- a/transforms/github-pages.test.js +++ b/transforms/github-pages.test.js @@ -83,6 +83,31 @@ describe("#github-pages", () => { ); }); + it("respects dryRun", async () => { + nock("https://api.github.com/") + .get("/repos/demo/repo/pages") + .reply(200, { + source: { + branch: "master", + path: "/", + }, + }); + + await githubPages({ + owner: "demo", + repo: "repo", + old: "master", + target: "main", + octokit, + log, + dryRun: true, + }); + + expect(log.logger).toBeCalledWith( + "Updated GitHub pages from [master] to [main] with path [/]" + ); + }); + it("configures actions with the new branch (custom path)", async () => { nock("https://api.github.com/") .get("/repos/demo/repo/pages")