diff --git a/plugins/scaffolder-backend-module-github/src/actions/github.ts b/plugins/scaffolder-backend-module-github/src/actions/github.ts index 4c04087670..6c47a2dade 100644 --- a/plugins/scaffolder-backend-module-github/src/actions/github.ts +++ b/plugins/scaffolder-backend-module-github/src/actions/github.ts @@ -227,6 +227,10 @@ export function createPublishGithubAction(options: { const { host, owner, repo } = parseRepoUrl(repoUrl, integrations); + if (!owner) { + throw new InputError('Invalid repository owner provided in repoUrl'); + } + const octokitOptions = await getOctokitOptions({ integrations, credentialsProvider: githubCredentialsProvider, @@ -237,10 +241,6 @@ export function createPublishGithubAction(options: { }); const client = new Octokit(octokitOptions); - if (!owner) { - throw new InputError('Invalid repository owner provided in repoUrl'); - } - const newRepo = await createGithubRepoWithCollaboratorsAndTopics( client, repo, diff --git a/plugins/scaffolder-backend-module-github/src/actions/githubBranchProtection.ts b/plugins/scaffolder-backend-module-github/src/actions/githubBranchProtection.ts index 5d5366a7b1..6de447541b 100644 --- a/plugins/scaffolder-backend-module-github/src/actions/githubBranchProtection.ts +++ b/plugins/scaffolder-backend-module-github/src/actions/githubBranchProtection.ts @@ -117,6 +117,10 @@ export function createGithubBranchProtectionAction(options: { const { host, owner, repo } = parseRepoUrl(repoUrl, integrations); + if (!owner) { + throw new InputError(`No owner provided for repo ${repoUrl}`); + } + const octokitOptions = await getOctokitOptions({ integrations, token: providedToken, @@ -126,10 +130,6 @@ export function createGithubBranchProtectionAction(options: { }); const client = new Octokit(octokitOptions); - if (!owner) { - throw new InputError(`No owner provided for repo ${repoUrl}`); - } - const repository = await client.rest.repos.get({ owner: owner, repo: repo, diff --git a/plugins/scaffolder-backend-module-github/src/actions/githubDeployKey.ts b/plugins/scaffolder-backend-module-github/src/actions/githubDeployKey.ts index 6a7a2f86c6..a91ac8ba5e 100644 --- a/plugins/scaffolder-backend-module-github/src/actions/githubDeployKey.ts +++ b/plugins/scaffolder-backend-module-github/src/actions/githubDeployKey.ts @@ -109,6 +109,10 @@ export function createGithubDeployKeyAction(options: { const { host, owner, repo } = parseRepoUrl(repoUrl, integrations); + if (!owner) { + throw new InputError(`No owner provided for repo ${repoUrl}`); + } + const octokitOptions = await getOctokitOptions({ integrations, token: providedToken, @@ -117,10 +121,6 @@ export function createGithubDeployKeyAction(options: { repo, }); - if (!owner) { - throw new InputError(`No owner provided for repo ${repoUrl}`); - } - const client = new Octokit(octokitOptions); await client.rest.repos.createDeployKey({ diff --git a/plugins/scaffolder-backend-module-github/src/actions/githubEnvironment.ts b/plugins/scaffolder-backend-module-github/src/actions/githubEnvironment.ts index 5d3817ee6d..49bd96db9d 100644 --- a/plugins/scaffolder-backend-module-github/src/actions/githubEnvironment.ts +++ b/plugins/scaffolder-backend-module-github/src/actions/githubEnvironment.ts @@ -177,6 +177,10 @@ export function createGithubEnvironmentAction(options: { const { host, owner, repo } = parseRepoUrl(repoUrl, integrations); + if (!owner) { + throw new InputError(`No owner provided for repo ${repoUrl}`); + } + const octokitOptions = await getOctokitOptions({ integrations, token: providedToken, @@ -185,10 +189,6 @@ export function createGithubEnvironmentAction(options: { repo, }); - if (!owner) { - throw new InputError(`No owner provided for repo ${repoUrl}`); - } - const client = new Octokit(octokitOptions); const repository = await client.rest.repos.get({ owner: owner, diff --git a/plugins/scaffolder-backend-module-github/src/actions/githubPagesEnable.ts b/plugins/scaffolder-backend-module-github/src/actions/githubPagesEnable.ts index 54bcfbcc43..9212f77338 100644 --- a/plugins/scaffolder-backend-module-github/src/actions/githubPagesEnable.ts +++ b/plugins/scaffolder-backend-module-github/src/actions/githubPagesEnable.ts @@ -94,6 +94,10 @@ export function createGithubPagesEnableAction(options: { const { host, owner, repo } = parseRepoUrl(repoUrl, integrations); + if (!owner) { + throw new InputError('Invalid repository owner provided in repoUrl'); + } + const octokitOptions = await getOctokitOptions({ integrations, credentialsProvider: githubCredentialsProvider, @@ -104,10 +108,6 @@ export function createGithubPagesEnableAction(options: { }); const client = new Octokit(octokitOptions); - if (!owner) { - throw new InputError('Invalid repository owner provided in repoUrl'); - } - ctx.logger.info( `Attempting to enable GitHub Pages for ${owner}/${repo} with "${buildType}" build type, on source branch "${sourceBranch}" and source path "${sourcePath}"`, ); diff --git a/plugins/scaffolder-backend-module-github/src/actions/githubRepoCreate.ts b/plugins/scaffolder-backend-module-github/src/actions/githubRepoCreate.ts index b103dffb15..d32f7447a6 100644 --- a/plugins/scaffolder-backend-module-github/src/actions/githubRepoCreate.ts +++ b/plugins/scaffolder-backend-module-github/src/actions/githubRepoCreate.ts @@ -182,6 +182,10 @@ export function createGithubRepoCreateAction(options: { const { host, owner, repo } = parseRepoUrl(repoUrl, integrations); + if (!owner) { + throw new InputError('Invalid repository owner provided in repoUrl'); + } + const octokitOptions = await getOctokitOptions({ integrations, credentialsProvider: githubCredentialsProvider, @@ -192,10 +196,6 @@ export function createGithubRepoCreateAction(options: { }); const client = new Octokit(octokitOptions); - if (!owner) { - throw new InputError('Invalid repository owner provided in repoUrl'); - } - const newRepo = await createGithubRepoWithCollaboratorsAndTopics( client, repo,