Merge GitHub scaffolding instructions

This commit is contained in:
Taras Mankovski
2020-09-15 16:31:35 -04:00
parent 6ea4ac7b17
commit a7d5ade5a1
2 changed files with 47 additions and 12 deletions
@@ -90,17 +90,19 @@ import {
GithubPublisher,
CreateReactAppTemplater,
Templaters,
RepoVisilityOptions,
} from '@backstage/plugin-scaffolder-backend';
import { Octokit } from '@octokit/rest';
import type { PluginEnvironment } from '../types';
import Docker from 'dockerode';
export default async function createPlugin({ logger }: PluginEnvironment) {
export default async function createPlugin({
logger,
config,
}: PluginEnvironment) {
const cookiecutterTemplater = new CookieCutter();
const craTemplater = new CreateReactAppTemplater();
const templaters = new Templaters();
// Register default templaters
templaters.register('cookiecutter', cookiecutterTemplater);
templaters.register('cra', craTemplater);
@@ -108,13 +110,20 @@ export default async function createPlugin({ logger }: PluginEnvironment) {
const githubPreparer = new GithubPreparer();
const preparers = new Preparers();
// Register default preparers
preparers.register('file', filePreparer);
preparers.register('github', githubPreparer);
// Create GitHub client with your access token from environment variables
const githubClient = new Octokit({ auth: process.env.GITHUB_ACCESS_TOKEN });
const publisher = new GithubPublisher({ client: githubClient });
const githubToken = config.getString('scaffolder.github.token');
const repoVisibility = config.getString(
'scaffolder.github.visibility',
) as RepoVisilityOptions;
const githubClient = new Octokit({ auth: githubToken });
const publisher = new GithubPublisher({
client: githubClient,
token: githubToken,
repoVisibility,
});
const dockerClient = new Docker();
return await createRouter({
@@ -177,8 +186,21 @@ 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.
The GitHub access token is passed along using the `GITHUB_ACCESS_TOKEN`
environment variable.
> **Right now it is only possible to scaffold repositories inside GitHub
> organizations, and not under personal accounts.**
The Github access token is retrieved from environment variables by the
config. The config file needs to specify what environment variable the
token is retrieved from. Your config should have the following objects.
```yaml
scaffolder:
github:
token:
$secret:
env: GITHUB_ACCESS_TOKEN
visibility: public # or 'internal' or 'private'
```
### Running the Backend
@@ -7,12 +7,16 @@ import {
GithubPublisher,
CreateReactAppTemplater,
Templaters,
RepoVisilityOptions,
} from '@backstage/plugin-scaffolder-backend';
import { Octokit } from '@octokit/rest';
import type { PluginEnvironment } from '../types';
import Docker from 'dockerode';
export default async function createPlugin({ logger }: PluginEnvironment) {
export default async function createPlugin({
logger,
config,
}: PluginEnvironment) {
const cookiecutterTemplater = new CookieCutter();
const craTemplater = new CreateReactAppTemplater();
const templaters = new Templaters();
@@ -26,8 +30,17 @@ export default async function createPlugin({ logger }: PluginEnvironment) {
preparers.register('file', filePreparer);
preparers.register('github', githubPreparer);
const githubClient = new Octokit({ auth: process.env.GITHUB_ACCESS_TOKEN });
const publisher = new GithubPublisher({ client: githubClient });
const githubToken = config.getString('scaffolder.github.token');
const repoVisibility = config.getString(
'scaffolder.github.visibility',
) as RepoVisilityOptions;
const githubClient = new Octokit({ auth: githubToken });
const publisher = new GithubPublisher({
client: githubClient,
token: githubToken,
repoVisibility,
});
const dockerClient = new Docker();
return await createRouter({