diff --git a/docs/features/software-templates/installation.md b/docs/features/software-templates/installation.md index 50c2fd303c..eea78e3571 100644 --- a/docs/features/software-templates/installation.md +++ b/docs/features/software-templates/installation.md @@ -177,9 +177,6 @@ docs on creating private GitHub access tokens is available Note that the need for private GitHub access tokens will be replaced with GitHub Apps integration further down the line. -> **Right now it is only possible to scaffold repositories inside GitHub -> organizations, and not under personal accounts.** - The GitHub access token is passed along using the `GITHUB_ACCESS_TOKEN` environment variable. diff --git a/docs/features/techdocs/creating-and-publishing.md b/docs/features/techdocs/creating-and-publishing.md index 0dfa40f819..9866246c5f 100644 --- a/docs/features/techdocs/creating-and-publishing.md +++ b/docs/features/techdocs/creating-and-publishing.md @@ -30,11 +30,6 @@ the documentation template. Create an entity from the documentation template and you will get the needed setup for free. -!!! warning Currently the Backstage Software Templates are limited to create -repositories inside GitHub organizations. You also need to generate an personal -access token and use as an environment variable. Read more about this -[here](../software-templates/installation.md#runtime-dependencies). - ### Manually add documentation setup to already existing repository Prerequisities: diff --git a/plugins/scaffolder-backend/src/scaffolder/__mocks__/@octokit/rest/index.ts b/plugins/scaffolder-backend/src/scaffolder/__mocks__/@octokit/rest/index.ts index 85bed3a223..a302bc5931 100644 --- a/plugins/scaffolder-backend/src/scaffolder/__mocks__/@octokit/rest/index.ts +++ b/plugins/scaffolder-backend/src/scaffolder/__mocks__/@octokit/rest/index.ts @@ -19,6 +19,9 @@ export const mockGithubClient = { createInOrg: jest.fn(), createForAuthenticatedUser: jest.fn(), }, + users: { + getByUsername: jest.fn(), + }, }; export class Octokit { diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.test.ts b/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.test.ts index 93493ab2cc..718c01438c 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.test.ts @@ -19,11 +19,18 @@ jest.mock('nodegit'); import { Octokit } from '@octokit/rest'; import * as NodeGit from 'nodegit'; -import { OctokitResponse, ReposCreateInOrgResponseData } from '@octokit/types'; +import { + OctokitResponse, + ReposCreateInOrgResponseData, + UsersGetByUsernameResponseData, +} from '@octokit/types'; import { GithubPublisher } from './github'; const { mockGithubClient } = require('@octokit/rest') as { - mockGithubClient: { repos: jest.Mocked }; + mockGithubClient: { + repos: jest.Mocked; + users: jest.Mocked; + }; }; const { @@ -59,10 +66,14 @@ describe('GitHub Publisher', () => { clone_url: 'mockclone', }, } as OctokitResponse); + mockGithubClient.users.getByUsername.mockResolvedValue({ + data: { + type: 'Organization', + }, + } as OctokitResponse); await publisher.publish({ values: { - isOrg: true, storePath: 'blam/test', owner: 'bob', }, @@ -81,6 +92,11 @@ describe('GitHub Publisher', () => { clone_url: 'mockclone', }, } as OctokitResponse); + mockGithubClient.users.getByUsername.mockResolvedValue({ + data: { + type: 'User', + }, + } as OctokitResponse); await publisher.publish({ values: { @@ -112,6 +128,12 @@ describe('GitHub Publisher', () => { clone_url: 'mockclone', }, } as OctokitResponse); + mockGithubClient.users.getByUsername.mockResolvedValue({ + data: { + type: 'Organization', + }, + } as OctokitResponse); + it('should call init on the repo with the directory', async () => { await publisher.publish({ values, diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts b/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts index 5fd64d69fc..f3306e3662 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts @@ -45,9 +45,12 @@ export class GithubPublisher implements PublisherBase { ) { const [owner, name] = values.storePath.split('/'); - const repoCreationPromise = values.isOrg - ? this.client.repos.createInOrg({ name, org: owner }) - : this.client.repos.createForAuthenticatedUser({ name }); + const user = await this.client.users.getByUsername({ username: owner }); + + const repoCreationPromise = + user.data.type === 'Organization' + ? this.client.repos.createInOrg({ name, org: owner }) + : this.client.repos.createForAuthenticatedUser({ name }); const { data } = await repoCreationPromise; diff --git a/plugins/scaffolder/src/api.ts b/plugins/scaffolder/src/api.ts index cc69ed7627..f58c8e68d1 100644 --- a/plugins/scaffolder/src/api.ts +++ b/plugins/scaffolder/src/api.ts @@ -46,8 +46,7 @@ export class ScaffolderApi { headers: { 'Content-Type': 'application/json', }, - // TODO(shmidt-i): when repo picker is implemented, take isOrg from it - body: JSON.stringify({ template, values: { ...values, isOrg: true } }), + body: JSON.stringify({ template, values: { ...values } }), }); if (response.status !== 201) {