Merge branch 'master' of github.com:getndazn/backstage into feat/scaffolder-run-task-auditlog
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/core-components': minor
|
||||
---
|
||||
|
||||
Add `transformLinkUri` and `transformImageUri` to `MarkdownContent`
|
||||
@@ -0,0 +1,6 @@
|
||||
---
|
||||
'@backstage/plugin-kubernetes-backend': patch
|
||||
'@backstage/plugin-kubernetes-common': patch
|
||||
---
|
||||
|
||||
Fixed the lack of `limitranges` as part of the Default Objects to fetch from the kubernetes api
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/core-components': patch
|
||||
---
|
||||
|
||||
Fix the EntityLayout header style so that EntityContextMenu button can display in correct shape when user hover on it
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-scaffolder': minor
|
||||
---
|
||||
|
||||
Add `allowedRepos` `ui:option` to `RepoUrlPicker` component, and move `repoName` field to own component
|
||||
@@ -0,0 +1,6 @@
|
||||
---
|
||||
'@backstage/plugin-vault': patch
|
||||
'@backstage/plugin-vault-backend': patch
|
||||
---
|
||||
|
||||
Added a path notion in addition to secret name to allow to differentiate secrets in sub-paths
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-scaffolder-backend': minor
|
||||
---
|
||||
|
||||
Update GitLab Merge Request Action to allow source branch to be deleted
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/catalog-model': minor
|
||||
---
|
||||
|
||||
Introduced `GroupDefaultParentEntityPolicy` to set a default group entity parent.
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-kafka-backend': patch
|
||||
---
|
||||
|
||||
Updated dependency `kafkajs` to `^2.0.0`.
|
||||
@@ -0,0 +1,16 @@
|
||||
---
|
||||
'@backstage/backend-common': patch
|
||||
'@backstage/backend-tasks': patch
|
||||
'@backstage/backend-test-utils': patch
|
||||
'@backstage/plugin-app-backend': patch
|
||||
'@backstage/plugin-auth-backend': patch
|
||||
'@backstage/plugin-bazaar-backend': patch
|
||||
'@backstage/plugin-catalog-backend': patch
|
||||
'@backstage/plugin-code-coverage-backend': patch
|
||||
'@backstage/plugin-scaffolder-backend': patch
|
||||
'@backstage/plugin-search-backend-module-pg': patch
|
||||
'@backstage/plugin-tech-insights-backend': patch
|
||||
'@backstage/plugin-techdocs-backend': patch
|
||||
---
|
||||
|
||||
Updated dependency `knex` to `^2.0.0`.
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-techdocs': patch
|
||||
---
|
||||
|
||||
Fix: When docs are shown in an entity page under the docs tab the sidebars start overlapping with the header and tabs in the page when you scroll the documentation content.
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-scaffolder-backend': minor
|
||||
---
|
||||
|
||||
Added two new scaffolder actions: `github:repo:create` and `github:repo:push`
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-scaffolder': patch
|
||||
---
|
||||
|
||||
Add `allowArbitraryValues` to `ui:options` in `OwnedEntityPicker`, similar to `allowArbitraryValues` in `EntityPicker`
|
||||
@@ -0,0 +1,43 @@
|
||||
---
|
||||
'@backstage/plugin-catalog': patch
|
||||
'@backstage/plugin-catalog-react': patch
|
||||
---
|
||||
|
||||
Added new `EntityProcessingStatusPicker` that will filter for entities with orphans and/or errors.
|
||||
|
||||
If you are using the default Catalog page this picker will be added automatically. For those who have customized their Catalog page you'll need to add this manually by doing something like this:
|
||||
|
||||
```diff
|
||||
...
|
||||
import {
|
||||
CatalogFilterLayout,
|
||||
EntityTypePicker,
|
||||
UserListPicker,
|
||||
EntityTagPicker
|
||||
+ EntityProcessingStatusPicker,
|
||||
} from '@backstage/plugin-catalog-react';
|
||||
...
|
||||
export const CustomCatalogPage = ({
|
||||
columns,
|
||||
actions,
|
||||
initiallySelectedFilter = 'owned',
|
||||
}: CatalogPageProps) => {
|
||||
return (
|
||||
...
|
||||
<EntityListProvider>
|
||||
<CatalogFilterLayout>
|
||||
<CatalogFilterLayout.Filters>
|
||||
<EntityKindPicker initialFilter="component" hidden />
|
||||
<EntityTypePicker />
|
||||
<UserListPicker initialFilter={initiallySelectedFilter} />
|
||||
<EntityTagPicker />
|
||||
+ <EntityProcessingStatusPicker />
|
||||
<CatalogFilterLayout.Filters>
|
||||
<CatalogFilterLayout.Content>
|
||||
<CatalogTable columns={columns} actions={actions} />
|
||||
</CatalogFilterLayout.Content>
|
||||
</CatalogFilterLayout>
|
||||
</EntityListProvider>
|
||||
...
|
||||
};
|
||||
```
|
||||
@@ -1,85 +0,0 @@
|
||||
name: Automate Merge Renovate PRs
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: '*/10 * * * *'
|
||||
|
||||
jobs:
|
||||
diff:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/github-script@v6
|
||||
with:
|
||||
script: |
|
||||
const owner = "backstage";
|
||||
const repo = "backstage";
|
||||
const query = `{
|
||||
repository(owner: "backstage", name: "backstage") {
|
||||
pullRequests(labels: ["dependencies"], last: 10, states: [OPEN]) {
|
||||
nodes {
|
||||
title
|
||||
author {
|
||||
login
|
||||
}
|
||||
number
|
||||
mergeable
|
||||
files(first: 1) {
|
||||
nodes {
|
||||
path
|
||||
}
|
||||
}
|
||||
changedFiles
|
||||
commits(last: 1) {
|
||||
nodes {
|
||||
commit {
|
||||
statusCheckRollup {
|
||||
state
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
reviewDecision
|
||||
reviews(first: 10) {
|
||||
nodes {
|
||||
author {
|
||||
login
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}`;
|
||||
|
||||
const date = new Date();
|
||||
if (date.getDay() === 2) {
|
||||
console.log("Skipping auto merge because Tuesday is release day");
|
||||
return;
|
||||
}
|
||||
|
||||
const r = await github.graphql(query);
|
||||
const mergable = r.repository.pullRequests.nodes.filter(
|
||||
(pr) =>
|
||||
pr.author.login === "renovate" &&
|
||||
pr.mergeable === "MERGEABLE" &&
|
||||
pr.changedFiles === 1 &&
|
||||
pr.files.nodes[0].path.split("/").slice(-1)[0] === "yarn.lock" &&
|
||||
pr.commits.nodes[0].commit.statusCheckRollup.state === "SUCCESS" &&
|
||||
pr.reviewDecision === "APPROVED"
|
||||
);
|
||||
|
||||
if (mergable.length === 0) {
|
||||
console.log("no mergable PRs");
|
||||
return;
|
||||
}
|
||||
|
||||
for (const pr of mergable) {
|
||||
console.log(`Merging #${pr.number} - ${pr.title}`);
|
||||
await github.rest.pulls.merge({
|
||||
owner,
|
||||
repo,
|
||||
pull_number: pr.number,
|
||||
});
|
||||
await new Promise((r) => setTimeout(r, 2000));
|
||||
}
|
||||
@@ -64,45 +64,16 @@ jobs:
|
||||
- name: fetch branch master
|
||||
run: git fetch origin master
|
||||
|
||||
# Beginning of yarn setup, keep in sync between all workflows.
|
||||
# TODO(Rugvip): move this to composite action once all features we use are supported
|
||||
- name: use node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
registry-url: https://registry.npmjs.org/ # Needed for auth
|
||||
|
||||
# Cache every node_modules folder inside the monorepo
|
||||
- name: cache all node_modules
|
||||
id: cache-modules
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: '**/node_modules'
|
||||
# We use both yarn.lock and package.json as cache keys to ensure that
|
||||
# changes to local monorepo packages bust the cache.
|
||||
key: ${{ runner.os }}-v${{ matrix.node-version }}-node_modules-${{ hashFiles('yarn.lock', '**/package.json') }}
|
||||
|
||||
# If we get a cache hit for node_modules, there's no need to bring in the global
|
||||
# yarn cache or run yarn install, as all dependencies will be installed already.
|
||||
|
||||
- name: find location of global yarn cache
|
||||
id: yarn-cache
|
||||
if: steps.cache-modules.outputs.cache-hit != 'true'
|
||||
run: echo "::set-output name=dir::$(yarn cache dir)"
|
||||
|
||||
- name: cache global yarn cache
|
||||
uses: actions/cache@v3
|
||||
if: steps.cache-modules.outputs.cache-hit != 'true'
|
||||
with:
|
||||
path: ${{ steps.yarn-cache.outputs.dir }}
|
||||
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-yarn-
|
||||
|
||||
- name: yarn install
|
||||
if: steps.cache-modules.outputs.cache-hit != 'true'
|
||||
run: yarn install --frozen-lockfile
|
||||
# End of yarn setup
|
||||
uses: backstage/actions/yarn-install@v0.2.1
|
||||
with:
|
||||
cache-prefix: ${{ runner.os }}-v${{ matrix.node-version }}
|
||||
|
||||
- name: check for yarn.lock changes
|
||||
id: yarn-lock
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
name: Cron
|
||||
on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: '*/5 * * * *'
|
||||
|
||||
jobs:
|
||||
cron:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: backstage/actions/cron@v0.2.2
|
||||
with:
|
||||
app-id: ${{ secrets.BACKSTAGE_GOALIE_APPLICATION_ID }}
|
||||
private-key: ${{ secrets.BACKSTAGE_GOALIE_PRIVATE_KEY }}
|
||||
installation-id: ${{ secrets.BACKSTAGE_GOALIE_INSTALLATION_ID }}
|
||||
@@ -20,33 +20,15 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
# Beginning of yarn setup, keep in sync between all workflows, see ci.yml
|
||||
- name: use node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
registry-url: https://registry.npmjs.org/ # Needed for auth
|
||||
- name: cache all node_modules
|
||||
id: cache-modules
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: '**/node_modules'
|
||||
key: ${{ runner.os }}-v${{ matrix.node-version }}-node_modules-${{ hashFiles('yarn.lock', '**/package.json') }}
|
||||
- name: find location of global yarn cache
|
||||
id: yarn-cache
|
||||
if: steps.cache-modules.outputs.cache-hit != 'true'
|
||||
run: echo "::set-output name=dir::$(yarn cache dir)"
|
||||
- name: cache global yarn cache
|
||||
uses: actions/cache@v3
|
||||
if: steps.cache-modules.outputs.cache-hit != 'true'
|
||||
with:
|
||||
path: ${{ steps.yarn-cache.outputs.dir }}
|
||||
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-yarn-
|
||||
- name: yarn install
|
||||
run: yarn install --frozen-lockfile
|
||||
# End of yarn setup
|
||||
uses: backstage/actions/yarn-install@v0.2.1
|
||||
with:
|
||||
cache-prefix: ${{ runner.os }}-v${{ matrix.node-version }}
|
||||
|
||||
# No verification done here, only build & publish. If the master branch
|
||||
# is broken we will see that from those builds, but we still want to push nightly
|
||||
|
||||
@@ -61,33 +61,15 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
# Beginning of yarn setup, keep in sync between all workflows, see ci.yml
|
||||
- name: use node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
registry-url: https://registry.npmjs.org/ # Needed for auth
|
||||
- name: cache all node_modules
|
||||
id: cache-modules
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: '**/node_modules'
|
||||
key: ${{ runner.os }}-v${{ matrix.node-version }}-node_modules-${{ hashFiles('yarn.lock', '**/package.json') }}
|
||||
- name: find location of global yarn cache
|
||||
id: yarn-cache
|
||||
if: steps.cache-modules.outputs.cache-hit != 'true'
|
||||
run: echo "::set-output name=dir::$(yarn cache dir)"
|
||||
- name: cache global yarn cache
|
||||
uses: actions/cache@v3
|
||||
if: steps.cache-modules.outputs.cache-hit != 'true'
|
||||
with:
|
||||
path: ${{ steps.yarn-cache.outputs.dir }}
|
||||
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-yarn-
|
||||
- name: yarn install
|
||||
run: yarn install --frozen-lockfile
|
||||
# End of yarn setup
|
||||
uses: backstage/actions/yarn-install@v0.2.1
|
||||
with:
|
||||
cache-prefix: ${{ runner.os }}-v${{ matrix.node-version }}
|
||||
|
||||
- name: Fetch previous commit for release check
|
||||
run: git fetch origin '${{ github.event.before }}'
|
||||
@@ -157,33 +139,15 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
# Beginning of yarn setup, keep in sync between all workflows, see ci.yml
|
||||
- name: use node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
registry-url: https://registry.npmjs.org/ # Needed for auth
|
||||
- name: cache all node_modules
|
||||
id: cache-modules
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: '**/node_modules'
|
||||
key: ${{ runner.os }}-v${{ matrix.node-version }}-node_modules-${{ hashFiles('yarn.lock', '**/package.json') }}
|
||||
- name: find location of global yarn cache
|
||||
id: yarn-cache
|
||||
if: steps.cache-modules.outputs.cache-hit != 'true'
|
||||
run: echo "::set-output name=dir::$(yarn cache dir)"
|
||||
- name: cache global yarn cache
|
||||
uses: actions/cache@v3
|
||||
if: steps.cache-modules.outputs.cache-hit != 'true'
|
||||
with:
|
||||
path: ${{ steps.yarn-cache.outputs.dir }}
|
||||
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-yarn-
|
||||
- name: yarn install
|
||||
run: yarn install --frozen-lockfile
|
||||
# End of yarn setup
|
||||
uses: backstage/actions/yarn-install@v0.2.1
|
||||
with:
|
||||
cache-prefix: ${{ runner.os }}-v${{ matrix.node-version }}
|
||||
|
||||
- name: build type declarations
|
||||
run: yarn tsc:full
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
name: Issue
|
||||
on:
|
||||
issues:
|
||||
types: [opened]
|
||||
|
||||
jobs:
|
||||
sync:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
if: github.repository == 'backstage/backstage'
|
||||
steps:
|
||||
- name: Issue sync
|
||||
uses: backstage/actions/issue-sync@v0.2.1
|
||||
@@ -0,0 +1,14 @@
|
||||
name: PR
|
||||
on:
|
||||
pull_request_target:
|
||||
|
||||
jobs:
|
||||
sync:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
if: github.repository == 'backstage/backstage'
|
||||
steps:
|
||||
- name: PR sync
|
||||
uses: backstage/actions/pr-sync@v0.2.1
|
||||
with:
|
||||
github-token: ${{ secrets.GH_SERVICE_ACCOUNT_TOKEN }}
|
||||
@@ -1,37 +0,0 @@
|
||||
name: Approve renovate lock file changes
|
||||
on:
|
||||
pull_request_target:
|
||||
paths:
|
||||
- '.github/workflows/sync_renovate-changesets.yml'
|
||||
- '**/yarn.lock'
|
||||
|
||||
jobs:
|
||||
generate-changeset:
|
||||
runs-on: ubuntu-latest
|
||||
if: github.actor == 'renovate[bot]' && github.repository == 'backstage/backstage'
|
||||
steps:
|
||||
- name: Approve
|
||||
uses: actions/github-script@v6
|
||||
with:
|
||||
github-token: ${{ secrets.GH_SERVICE_ACCOUNT_TOKEN }}
|
||||
script: |
|
||||
const owner = 'backstage';
|
||||
const repo = 'backstage';
|
||||
|
||||
const r = await github.rest.pulls.listFiles({
|
||||
owner,
|
||||
repo,
|
||||
pull_number: context.issue.number,
|
||||
});
|
||||
|
||||
if (r.data.some((f) => f.filename.split('/').slice(-1)[0] !== 'yarn.lock')) {
|
||||
console.log('skipping approval since some files are not yarn.lock');
|
||||
return;
|
||||
}
|
||||
|
||||
await github.rest.pulls.createReview({
|
||||
owner,
|
||||
repo,
|
||||
pull_number: context.issue.number,
|
||||
event: 'APPROVE'
|
||||
})
|
||||
@@ -14,33 +14,15 @@ jobs:
|
||||
# Fetch changes to previous commit - required for 'only_changed' in Prettier action
|
||||
fetch-depth: 0
|
||||
|
||||
# Beginning of yarn setup, keep in sync between all workflows, see ci.yml
|
||||
- name: use node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
registry-url: https://registry.npmjs.org/ # Needed for auth
|
||||
- name: cache all node_modules
|
||||
id: cache-modules
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: '**/node_modules'
|
||||
key: ${{ runner.os }}-v${{ matrix.node-version }}-node_modules-${{ hashFiles('yarn.lock', '**/package.json') }}
|
||||
- name: find location of global yarn cache
|
||||
id: yarn-cache
|
||||
if: steps.cache-modules.outputs.cache-hit != 'true'
|
||||
run: echo "::set-output name=dir::$(yarn cache dir)"
|
||||
- name: cache global yarn cache
|
||||
uses: actions/cache@v3
|
||||
if: steps.cache-modules.outputs.cache-hit != 'true'
|
||||
with:
|
||||
path: ${{ steps.yarn-cache.outputs.dir }}
|
||||
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-yarn-
|
||||
- name: yarn install
|
||||
run: yarn install --frozen-lockfile
|
||||
# End of yarn setup
|
||||
uses: backstage/actions/yarn-install@v0.2.1
|
||||
with:
|
||||
cache-prefix: ${{ runner.os }}-v${{ matrix.node-version }}
|
||||
|
||||
- name: Run Prettier on ADOPTERS.md
|
||||
uses: creyD/prettier_action@v4.2
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
name: Sync Issue Labels
|
||||
on:
|
||||
issues:
|
||||
types: [opened]
|
||||
jobs:
|
||||
label-issue:
|
||||
runs-on: ubuntu-latest
|
||||
if: github.repository == 'backstage/backstage'
|
||||
steps:
|
||||
- name: View context attributes
|
||||
uses: actions/github-script@v6
|
||||
with:
|
||||
script: |
|
||||
const keywords = {
|
||||
'techdocs|tech-docs|tech docs': 'docs-like-code',
|
||||
'search': 'search',
|
||||
'catalog': 'catalog',
|
||||
'scaffolder': 'scaffolder',
|
||||
};
|
||||
|
||||
const labels = Object.entries(keywords)
|
||||
.map(([regexp, label]) => {
|
||||
if (new RegExp(regexp, 'gi').test(context.payload.issue.title)) {
|
||||
return label;
|
||||
}
|
||||
})
|
||||
.filter(Boolean);
|
||||
|
||||
if(!labels.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
github.rest.issues.addLabels({
|
||||
issue_number: context.issue.number,
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
labels
|
||||
});
|
||||
@@ -16,33 +16,15 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
# Beginning of yarn setup, keep in sync between all workflows, see ci.yml
|
||||
- name: use node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
registry-url: https://registry.npmjs.org/ # Needed for auth
|
||||
- name: cache all node_modules
|
||||
id: cache-modules
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: '**/node_modules'
|
||||
key: ${{ runner.os }}-v${{ matrix.node-version }}-node_modules-${{ hashFiles('yarn.lock', '**/package.json') }}
|
||||
- name: find location of global yarn cache
|
||||
id: yarn-cache
|
||||
if: steps.cache-modules.outputs.cache-hit != 'true'
|
||||
run: echo "::set-output name=dir::$(yarn cache dir)"
|
||||
- name: cache global yarn cache
|
||||
uses: actions/cache@v3
|
||||
if: steps.cache-modules.outputs.cache-hit != 'true'
|
||||
with:
|
||||
path: ${{ steps.yarn-cache.outputs.dir }}
|
||||
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-yarn-
|
||||
- name: yarn install
|
||||
run: yarn install --frozen-lockfile
|
||||
# End of yarn setup
|
||||
uses: backstage/actions/yarn-install@v0.2.1
|
||||
with:
|
||||
cache-prefix: ${{ runner.os }}-v${{ matrix.node-version }}
|
||||
|
||||
- name: Create Snyk report
|
||||
uses: snyk/actions/node@master
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
name: Verify DCO
|
||||
on:
|
||||
schedule:
|
||||
- cron: '*/15 * * * *'
|
||||
|
||||
jobs:
|
||||
dco-helper:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Verify DCO status for open pull requests
|
||||
uses: actions/github-script@v6
|
||||
with:
|
||||
script: |
|
||||
const owner = "backstage";
|
||||
const repo = "backstage";
|
||||
const pulls = await github.paginate(github.rest.pulls.list, {
|
||||
state: "open",
|
||||
owner,
|
||||
repo,
|
||||
});
|
||||
|
||||
for (const pull of pulls) {
|
||||
// Pick out the PRs that have the DCO check
|
||||
const checks = await github.rest.checks.listForRef({
|
||||
owner,
|
||||
repo,
|
||||
ref: pull.head.sha,
|
||||
check_name: "DCO",
|
||||
status: "completed",
|
||||
});
|
||||
// Skip if there are no checks
|
||||
if (!checks.data.check_runs.length) {
|
||||
continue;
|
||||
}
|
||||
// Skip if the conclusion is not action_required
|
||||
if (checks.data.check_runs[0].conclusion !== "action_required") {
|
||||
console.log(`No checks found for PR #${pull.number}, skipping`);
|
||||
continue;
|
||||
}
|
||||
|
||||
const comments = await github.paginate(github.rest.issues.listComments, {
|
||||
owner,
|
||||
repo,
|
||||
issue_number: pull.number,
|
||||
});
|
||||
if (comments.find((c) =>
|
||||
c.user.login === "github-actions[bot]" &&
|
||||
c.body.includes("<!-- dco -->")
|
||||
)
|
||||
) {
|
||||
console.log(`already commented on PR #${pull.number}, skipping`);
|
||||
continue;
|
||||
}
|
||||
console.log(`creating comment on PR #${pull.number}`);
|
||||
const body = `
|
||||
Thanks for the contribution!
|
||||
All commits need to be DCO signed before they are reviewed. Please refer to the the [DCO section in CONTRIBUTING.md](https://github.com/backstage/backstage/blob/master/CONTRIBUTING.md#developer-certificate-of-origin) or the [DCO](${checks.data.check_runs[0].html_url}) status for more info.
|
||||
<!-- dco -->`;
|
||||
await github.rest.issues.createComment({
|
||||
repo,
|
||||
owner,
|
||||
issue_number: pull.number,
|
||||
body,
|
||||
});
|
||||
}
|
||||
@@ -40,35 +40,15 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
# Beginning of yarn setup, keep in sync between all workflows, see ci.yml
|
||||
- name: use node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
registry-url: https://registry.npmjs.org/ # Needed for auth
|
||||
- name: cache all node_modules
|
||||
id: cache-modules
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: '**/node_modules'
|
||||
key: ${{ runner.os }}-v${{ matrix.node-version }}-node_modules-${{ hashFiles('yarn.lock', '**/package.json') }}
|
||||
- name: find location of global yarn cache
|
||||
id: yarn-cache
|
||||
if: steps.cache-modules.outputs.cache-hit != 'true'
|
||||
run: echo "::set-output name=dir::$(yarn cache dir)"
|
||||
- name: setup chrome
|
||||
uses: browser-actions/setup-chrome@latest
|
||||
- name: cache global yarn cache
|
||||
uses: actions/cache@v3
|
||||
if: steps.cache-modules.outputs.cache-hit != 'true'
|
||||
with:
|
||||
path: ${{ steps.yarn-cache.outputs.dir }}
|
||||
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-yarn-
|
||||
- name: yarn install
|
||||
run: yarn install --frozen-lockfile
|
||||
# End of yarn setup
|
||||
uses: backstage/actions/yarn-install@v0.2.1
|
||||
with:
|
||||
cache-prefix: ${{ runner.os }}-v${{ matrix.node-version }}
|
||||
|
||||
- run: yarn tsc
|
||||
- run: yarn backstage-cli repo build
|
||||
|
||||
@@ -17,44 +17,30 @@ on:
|
||||
|
||||
jobs:
|
||||
chromatic:
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest]
|
||||
node-version: [16.x]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0 # Required to retrieve git history
|
||||
|
||||
# Beginning of yarn setup, keep in sync between all workflows, see ci.yml
|
||||
- name: use node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
registry-url: https://registry.npmjs.org/ # Needed for auth
|
||||
- name: cache all node_modules
|
||||
id: cache-modules
|
||||
uses: actions/cache@v3
|
||||
- name: yarn install
|
||||
uses: backstage/actions/yarn-install@v0.2.1
|
||||
with:
|
||||
path: '**/node_modules'
|
||||
key: ${{ runner.os }}-v${{ matrix.node-version }}-node_modules-${{ hashFiles('yarn.lock', '**/package.json') }}
|
||||
- name: find location of global yarn cache
|
||||
id: yarn-cache
|
||||
if: steps.cache-modules.outputs.cache-hit != 'true'
|
||||
run: echo "::set-output name=dir::$(yarn cache dir)"
|
||||
- name: cache global yarn cache
|
||||
uses: actions/cache@v3
|
||||
if: steps.cache-modules.outputs.cache-hit != 'true'
|
||||
with:
|
||||
path: ${{ steps.yarn-cache.outputs.dir }}
|
||||
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-yarn-
|
||||
|
||||
- name: top-level install
|
||||
run: yarn install --frozen-lockfile
|
||||
|
||||
cache-prefix: ${{ runner.os }}-v${{ matrix.node-version }}
|
||||
- name: storybook yarn install
|
||||
run: yarn install --frozen-lockfile
|
||||
working-directory: storybook
|
||||
# End of yarn setup
|
||||
|
||||
- run: yarn build-storybook
|
||||
|
||||
|
||||
@@ -26,25 +26,15 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
# Beginning of yarn setup, keep in sync between all workflows, see ci.yml
|
||||
- name: use node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
registry-url: https://registry.npmjs.org/ # Needed for auth
|
||||
- name: find location of global yarn cache
|
||||
id: yarn-cache
|
||||
run: echo "::set-output name=dir::$(yarn cache dir)"
|
||||
- name: cache global yarn cache
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: ${{ steps.yarn-cache.outputs.dir }}
|
||||
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-yarn-
|
||||
|
||||
# Windows file operation slowness means there's no point caching this
|
||||
- name: yarn install
|
||||
run: yarn install --frozen-lockfile
|
||||
# End of yarn setup
|
||||
|
||||
- name: lint
|
||||
run: yarn backstage-cli repo lint
|
||||
|
||||
+6
-2
@@ -1,6 +1,8 @@
|
||||
# Adopters
|
||||
|
||||
_If you're using Backstage in your organization, please try to add your company name to this list. This really helps the project to gain momentum and credibility. It's a small contribution back to the project with a big impact._
|
||||
_If you're using Backstage in your organization, please try to add your company name to this list. It really helps the project to gain momentum and credibility. It's a small contribution back to the project with a big impact._
|
||||
_You can do this by using the [Adopter form](https://form.typeform.com/to/zcOaKikB) or by editing this file after following the [CONTRIBUTING.md](./CONTRIBUTING.md)._
|
||||
|
||||
|
||||
| Organization | Contact | Description of Use |
|
||||
|-----------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
@@ -36,7 +38,7 @@ _If you're using Backstage in your organization, please try to add your company
|
||||
| [PagerDuty](https://www.pagerduty.com/) | [Mark Shaw](https://github.com/markshawtoronto) | Developer portal, initially focused on software templates and tech-docs. |
|
||||
| [MoonShiner](https://moonshiner.at) | [Fabian Hippmann](https://github.com/FabianHippmann) | Developer portal - helps us keep track of our customer projects, onboard new developers & improve our development process 🌕🚀🧑🚀 |
|
||||
| [FundApps](https://www.fundapps.co/) | [Elliot Greenwood](https://github.com/egnwd) | Developer Portal - A place for us to keep track of our projects and documentation for all services and processes |
|
||||
| [DAZN](https://dazn.com/) | [Lou Bichard](https://twitter.com/loujaybee), [Marco Crivellaro](https://github.com/crivetechie), [Alex Hollerith](mailto:alex.hollerith@dazn.com), [Kamil Wolny](https://github.com/mrwolny) | Ingesting all of DAZN's repos for the catalog, migrating our internal platform apps (pull request boards, release information, inner source marketplace etc) to Backstage plugins (where applicable). |
|
||||
| [DAZN](https://dazn.com/) | [David Rubio Vidal](https://github.com/davidrv87), [Marco Crivellaro](https://github.com/crivetechie), [Alex Hollerith](mailto:alex.hollerith@dazn.com), [Kamil Wolny](https://github.com/mrwolny) | Ingesting all of DAZN's repos for the catalog, migrating our internal platform apps (pull request boards, release information, inner source marketplace etc) to Backstage plugins (where applicable). |
|
||||
| [HelloFresh](https://www.hellofresh.de/) | [@iammuho](https://github.com/iammuho), [@ElenaForester](https://github.com/ElenaForester), [@diegomarangoni](https://github.com/diegomarangoni) | Our developer portal at HelloFresh - Spread across an organisation of 500+ engineers globally. |
|
||||
| [FactSet](https://www.factset.com/) | [@kuangp](https://github.com/kuangp) | Developer portal to provide discoverability to all internal components, APIs, documentation, and scaffold templates with integrations to our internal infrastructure tools. |
|
||||
| [Workrise](https://www.workrise.com/) | [Michael Rode](https://github.com/michaelrode) | Developer portal, main gateway to our infrastructure, documentation and internal tooling. |
|
||||
@@ -186,3 +188,5 @@ _If you're using Backstage in your organization, please try to add your company
|
||||
| [Cho Tot](https://www.chotot.com) | [Chotot Team](mailto:sre@chotot.vn) | Internal developer portal, service catalog with CI/CD tools. |
|
||||
| [William Hill](https://www.williamhillgroup.com/) | [Pat Mills](mailto:pat.mills@williamhill.com), [Nathan Flynn](mailto:nflynn@williamhill.co.uk), and [Nishkarsh Raj](mailto:nishkarsh.raj@williamhill.co.uk) | William Hill are leveraging Backstage to build our Engineering Portal. Our mission is to centralize the software catalog inventory to enable service discoverability, reduce the onboarding time for new Engineers, provide a single pane of glass to accelerate Developer Productivity and Save Engineers time. Our aspiration is to create an InnerSource community focussed on organization-wide patterns that are re-usable and can be self-served with the Scaffolder. |
|
||||
| [Vodafone NewZealand Limited](https://vodafone.co.nz) | [Ankit Gupta](mailto:ankit.gupta@vodafone.nz), [DevOps COE](mailto:devopstooling@vodafone.nz) | Vodafone NZ are leveraging Backstage to build centralised and self service Engineering Portal. Our mission is to standardised Pipeline templates across the Engineering teams, One shop stop to create the pipelines and repository with a template approach which reduces creation part from days to minutes and no wait time for developers. A unified view for Azure DevOps pipeline, Azure Repo pull requests, Deployment status from Azure RedHat Openshift-ArgoCD and SonarQube Security and code quality scans report on a single pan to provide a streamlined view for all microservices across the app stack. |
|
||||
| [Coamo](http://www.coamo.com.br) | [@holiiveira](https://github.com/holiiveira), [@gpxlnx](https://github.com/gpxlnx) | We're starting to use it as the main tool of a DevOps platform. Our goal is to provide software templates, centralize our software catalog enabling efficient service discovery, and make it easy to manage the entire software ecosystem in one place.
|
||||
|
|
||||
|
||||
+2
-2
@@ -58,9 +58,9 @@ If you are proposing a feature:
|
||||
- Remember that this is a volunteer-driven project, and that contributions
|
||||
are welcome :)
|
||||
|
||||
### Add your company to ADOPTERS
|
||||
### Add your company to `ADOPTERS`
|
||||
|
||||
Have you started using Backstage? Adding your company to [ADOPTERS](ADOPTERS.md) really helps the project.
|
||||
Have you started using Backstage? Adding your company to [ADOPTERS](ADOPTERS.md) really helps the project, you can do this by filling out this [Adopter form](https://form.typeform.com/to/zcOaKikB).
|
||||
|
||||
## Get Started!
|
||||
|
||||
|
||||
+3
-3
@@ -304,9 +304,9 @@ cross-spawn@^7.0.0:
|
||||
which "^2.0.1"
|
||||
|
||||
cypress@^10.0.0:
|
||||
version "10.2.0"
|
||||
resolved "https://registry.npmjs.org/cypress/-/cypress-10.2.0.tgz#ca078abfceb13be2a33cbba6e0e80ded770f542a"
|
||||
integrity sha512-+i9lY5ENlfi2mJwsggzR+XASOIgMd7S/Gd3/13NCpv596n3YSplMAueBTIxNLcxDpTcIksp+9pM3UaDrJDpFqA==
|
||||
version "10.3.0"
|
||||
resolved "https://registry.npmjs.org/cypress/-/cypress-10.3.0.tgz#fae8d32f0822fcfb938e79c7c31ef344794336ae"
|
||||
integrity sha512-txkQWKzvBVnWdCuKs5Xc08gjpO89W2Dom2wpZgT9zWZT5jXxqPIxqP/NC1YArtkpmp3fN5HW8aDjYBizHLUFvg==
|
||||
dependencies:
|
||||
"@cypress/request" "^2.88.10"
|
||||
"@cypress/xvfb" "^1.2.4"
|
||||
|
||||
@@ -106,8 +106,7 @@ with [Static Location Configuration](#static-location-configuration) or a
|
||||
discovery processor like
|
||||
[GitHub Discovery](../../integrations/github/discovery.md). To enforce usage of
|
||||
processors to locate entities we can configure the catalog into `readonly` mode.
|
||||
This configuration disables the mutating backend catalog APIs and disallows
|
||||
users from registering new entities at run-time.
|
||||
This configuration disables registering and deleting locations with the catalog APIs.
|
||||
|
||||
```yaml
|
||||
catalog:
|
||||
@@ -117,6 +116,8 @@ catalog:
|
||||
> **Note that any plugin relying on the catalog API for creating, updating and
|
||||
> deleting entities will not work in this mode.**
|
||||
|
||||
Deleting an entity by UUID, `DELETE /entities/by-uid/:uid`, is allowed when using this mode. It may be rediscovered as noted in [explicit deletion](life-of-an-entity.md#explicit-deletion).
|
||||
|
||||
A common use case for this configuration is when organizations have a remote
|
||||
source that should be mirrored into Backstage. To make Backstage a mirror of
|
||||
this remote source, users cannot also register new entities with e.g. the
|
||||
|
||||
@@ -86,6 +86,13 @@ contains more information about the required fields.
|
||||
Once we have a `template.yaml` ready, we can then add it to the software catalog
|
||||
for use by the scaffolder.
|
||||
|
||||
> Note: When you add or modify a template, you will need to refresh the location entity.
|
||||
> Otherwise, Backstage won't display the template in the available templates,
|
||||
> or it will keep showing the old template. You can refresh the location instance by
|
||||
> going into `Catalog` web page, choosing `Locations` instead of `Components`, and selecting the correct location entity.
|
||||
> From there, you can click on the refresh icon representing "Scheduled entity refresh" action.
|
||||
> Afterwards, you should see your template updated.
|
||||
|
||||
You can add the template files to the catalog through
|
||||
[static location configuration](../software-catalog/configuration.md#static-location-configuration),
|
||||
for example:
|
||||
@@ -97,6 +104,8 @@ catalog:
|
||||
target: https://github.com/backstage/software-templates/blob/main/scaffolder-templates/react-ssr-template/template.yaml
|
||||
rules:
|
||||
- allow: [Template]
|
||||
- type: file
|
||||
target: template.yaml # Backstage will expect the file to be in packages/backend/template.yaml
|
||||
```
|
||||
|
||||
Or you can add the template using the `catalog-import` plugin, which unless
|
||||
|
||||
@@ -9,8 +9,9 @@ by writing custom actions which can be used along side our
|
||||
[built-in actions](./builtin-actions.md).
|
||||
|
||||
> Note: When adding custom actions, the actions array will **replace the
|
||||
> built-in actions too**. To ensure you can continue to include the builtin
|
||||
> actions, see below to include them during registration of your action.
|
||||
> built-in actions too**. Meaning, you will no longer be able to use them.
|
||||
> If you want to continue using the builtin actions, include them in the actions
|
||||
> array when registering your custom actions, as seen below.
|
||||
|
||||
## Writing your Custom Action
|
||||
|
||||
@@ -122,27 +123,32 @@ will set the available actions that the scaffolder has access to.
|
||||
```ts
|
||||
import { createBuiltinActions } from '@backstage/plugin-scaffolder-backend';
|
||||
import { ScmIntegrations } from '@backstage/integration';
|
||||
import { createNewFileAction } from './actions/custom';
|
||||
|
||||
const integrations = ScmIntegrations.fromConfig(env.config);
|
||||
export default async function createPlugin(
|
||||
env: PluginEnvironment,
|
||||
): Promise<Router> {
|
||||
const catalogClient = new CatalogClient({ discoveryApi: env.discovery });
|
||||
const integrations = ScmIntegrations.fromConfig(env.config);
|
||||
|
||||
const builtInActions = createBuiltinActions({
|
||||
containerRunner,
|
||||
integrations,
|
||||
catalogClient,
|
||||
config: env.config,
|
||||
reader: env.reader,
|
||||
});
|
||||
const builtInActions = createBuiltinActions({
|
||||
integrations,
|
||||
catalogClient,
|
||||
config: env.config,
|
||||
reader: env.reader,
|
||||
});
|
||||
|
||||
const actions = [...builtInActions, createNewFileAction()];
|
||||
return await createRouter({
|
||||
containerRunner,
|
||||
catalogClient,
|
||||
actions,
|
||||
logger: env.logger,
|
||||
config: env.config,
|
||||
database: env.database,
|
||||
reader: env.reader,
|
||||
});
|
||||
const actions = [...builtInActions, createNewFileAction()];
|
||||
|
||||
return createRouter({
|
||||
actions,
|
||||
catalogClient: catalogClient,
|
||||
logger: env.logger,
|
||||
config: env.config,
|
||||
database: env.database,
|
||||
reader: env.reader,
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
## List of custom action packages
|
||||
|
||||
@@ -320,6 +320,30 @@ The `allowedHosts` part should be set to where you wish to enable this template
|
||||
to publish to. And it can be any host that is listed in your `integrations`
|
||||
config in `app-config.yaml`.
|
||||
|
||||
Besides specifying `allowedHosts` you can also restrict the template to publish to
|
||||
repositories owned by specific users/groups/namespaces by setting the `allowedOwners`
|
||||
option. With the `allowedRepos` option you are able to narrow it down further to a
|
||||
specific set of repository names. A full example could look like this:
|
||||
|
||||
```yaml
|
||||
- title: Choose a location
|
||||
required:
|
||||
- repoUrl
|
||||
properties:
|
||||
repoUrl:
|
||||
title: Repository Location
|
||||
type: string
|
||||
ui:field: RepoUrlPicker
|
||||
ui:options:
|
||||
allowedHosts:
|
||||
- github.com
|
||||
allowedOwners:
|
||||
- backstage
|
||||
- someGithubUser
|
||||
allowedRepos:
|
||||
- backstage
|
||||
```
|
||||
|
||||
The `RepoUrlPicker` is a custom field that we provide part of the
|
||||
`plugin-scaffolder`. You can provide your own custom fields by
|
||||
[writing your own Custom Field Extensions](./writing-custom-field-extensions.md)
|
||||
@@ -485,6 +509,64 @@ the value of `firstName` from the parameters). This is great for passing the
|
||||
values from the form into different steps and reusing these input variables.
|
||||
These template strings preserve the type of the parameter.
|
||||
|
||||
The `${{ parameters.firstName }}` pattern will work only in the template file.
|
||||
If you want to start using values provided from the UI in your code, you will have to use
|
||||
the `${{ values.firstName }}` pattern. Additionally, you have to pass
|
||||
the parameters from the UI to the input of the `fetch:template` step.
|
||||
|
||||
```yaml
|
||||
apiVersion: scaffolder.backstage.io/v1beta3
|
||||
kind: Template
|
||||
metadata:
|
||||
name: v1beta3-demo
|
||||
title: Test Action
|
||||
description: scaffolder v1beta3 template demo
|
||||
spec:
|
||||
owner: backstage/techdocs-core
|
||||
type: service
|
||||
parameters:
|
||||
- title: Fill in some steps
|
||||
required:
|
||||
- name
|
||||
properties:
|
||||
name:
|
||||
title: Name
|
||||
type: string
|
||||
description: Unique name of your project
|
||||
urlParameter:
|
||||
title: URL endpoint
|
||||
type: string
|
||||
description: URL endpoint at which the component can be reached
|
||||
default: 'https://www.example.com'
|
||||
enabledDB:
|
||||
title: Enable Database
|
||||
type: boolean
|
||||
default: false
|
||||
...
|
||||
steps:
|
||||
- id: fetch-base
|
||||
name: Fetch Base
|
||||
action: fetch:template
|
||||
input:
|
||||
url: ./template
|
||||
values:
|
||||
name: ${{ parameters.name }}
|
||||
url: ${{ parameters.urlParameter }}
|
||||
enabledDB: ${{ parameters.enabledDB }}
|
||||
```
|
||||
|
||||
Afterwards, if you are using the builtin templating action, you can start using
|
||||
the variables in your code. You can use also any other templating functions from
|
||||
[Nunjucks](https://mozilla.github.io/nunjucks/templating.html#tags) as well.
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
echo "Hi my name is ${{ values.name }}, and you can fine me at ${{ values.url }}!"
|
||||
{% if values.enabledDB %}
|
||||
echo "You have enabled your database!"
|
||||
{% endif %}
|
||||
```
|
||||
|
||||
As you can see above in the `Outputs` section, `actions` and `steps` can also
|
||||
output things. You can grab that output using `steps.$stepId.output.$property`.
|
||||
|
||||
|
||||
@@ -52,6 +52,8 @@ Addons are rendered in the order in which they are registered.
|
||||
|
||||
## Installing and using Addons
|
||||
|
||||
To start using Addons you need to add the `@backstage/plugin-techdocs-module-addons-contrib` package to your app. You can do that by running this command from the root of your project: `yarn add --cwd packages/app @backstage/plugin-techdocs-module-addons-contrib`
|
||||
|
||||
Addons can be installed and configured in much the same way as extensions for
|
||||
other Backstage plugins: by adding them underneath an extension registry
|
||||
component (`<TechDocsAddons>`) under the route representing the TechDocs Reader
|
||||
@@ -74,6 +76,18 @@ import { ReportIssue } from '@backstage/plugin-techdocs-module-addons-contrib';
|
||||
</Route>;
|
||||
```
|
||||
|
||||
If you are using a custom [TechDocs reader page](./how-to-guides.md#how-to-customize-the-techdocs-reader-page) your setup will be very similar, here's an example:
|
||||
|
||||
```ts
|
||||
<Route path="/docs/:namespace/:kind/:name/*" element={<TechDocsReaderPage />}>
|
||||
<TechDocsAddons>
|
||||
<ReportIssue />
|
||||
{/* Other addons can be added here. */}
|
||||
</TechDocsAddons>
|
||||
{techDocsPage} // This is your custom TechDocs reader page
|
||||
</Route>
|
||||
```
|
||||
|
||||
The process for configuring Addons on the documentation tab on the entity page
|
||||
is very similar; instead of adding the `<TechDocsAddons>` registry under a
|
||||
`<Route>`, you'd add it as a child of `<EntityTechdocsContent />`:
|
||||
|
||||
@@ -160,7 +160,8 @@ techdocs:
|
||||
|
||||
# techdocs.cache is optional, and is only recommended when you've configured
|
||||
# an external techdocs.publisher.type above. Also requires backend.cache to
|
||||
# be configured with a valid cache store.
|
||||
# be configured with a valid cache store. Configure techdocs.cache.ttl to
|
||||
# enable caching of techdocs assets.
|
||||
cache:
|
||||
# Represents the number of milliseconds a statically built asset should
|
||||
# stay cached. Cache invalidation is handled automatically by the frontend,
|
||||
|
||||
@@ -65,7 +65,7 @@
|
||||
"keyv": "^4.0.3",
|
||||
"keyv-memcache": "^1.2.5",
|
||||
"@keyv/redis": "^2.2.3",
|
||||
"knex": "^1.0.2",
|
||||
"knex": "^2.0.0",
|
||||
"lodash": "^4.17.21",
|
||||
"logform": "^2.3.2",
|
||||
"luxon": "^2.3.1",
|
||||
|
||||
@@ -251,7 +251,7 @@ export class DatabaseManager {
|
||||
// include base connection if client type has not been overridden
|
||||
...(overridden ? {} : baseConnection),
|
||||
...connection,
|
||||
};
|
||||
} as Partial<Knex.StaticConnectionConfig>;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
"@backstage/types": "^1.0.0",
|
||||
"@types/luxon": "^2.0.4",
|
||||
"cron": "^2.0.0",
|
||||
"knex": "^1.0.2",
|
||||
"knex": "^2.0.0",
|
||||
"lodash": "^4.17.21",
|
||||
"luxon": "^2.0.2",
|
||||
"node-abort-controller": "^3.0.1",
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
"@backstage/cli": "^0.18.0-next.1",
|
||||
"@backstage/config": "^1.0.1",
|
||||
"better-sqlite3": "^7.5.0",
|
||||
"knex": "^1.0.2",
|
||||
"knex": "^2.0.0",
|
||||
"msw": "^0.42.0",
|
||||
"mysql2": "^2.2.5",
|
||||
"pg": "^8.3.0",
|
||||
|
||||
@@ -230,6 +230,13 @@ export function getEntitySourceLocation(entity: Entity): {
|
||||
target: string;
|
||||
};
|
||||
|
||||
// @public
|
||||
export class GroupDefaultParentEntityPolicy implements EntityPolicy {
|
||||
constructor(parentEntityRef: string);
|
||||
// (undocumented)
|
||||
enforce(entity: Entity): Promise<Entity>;
|
||||
}
|
||||
|
||||
// @public
|
||||
interface GroupEntityV1alpha1 extends Entity {
|
||||
// (undocumented)
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright 2022 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { UserEntity, GroupEntity } from '../../kinds';
|
||||
import { GroupDefaultParentEntityPolicy } from './GroupDefaultParentEntityPolicy';
|
||||
|
||||
describe('GroupDefaultParentEntityPolicy', () => {
|
||||
it('should ignore non-group entities', async () => {
|
||||
const p = new GroupDefaultParentEntityPolicy('name');
|
||||
const u: UserEntity = {
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'User',
|
||||
metadata: { name: 'n' },
|
||||
spec: { profile: {}, memberOf: ['c'] },
|
||||
};
|
||||
const result = await p.enforce(u);
|
||||
expect(result).toEqual({
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'User',
|
||||
metadata: { name: 'n' },
|
||||
spec: { profile: {}, memberOf: ['c'] },
|
||||
});
|
||||
});
|
||||
|
||||
it('should parent group entities', async () => {
|
||||
const p = new GroupDefaultParentEntityPolicy('name');
|
||||
const g: GroupEntity = {
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'Group',
|
||||
metadata: { name: 'n' },
|
||||
spec: { type: 'foo', children: [] },
|
||||
};
|
||||
const result = await p.enforce(g);
|
||||
expect(result).toEqual({
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'Group',
|
||||
metadata: { name: 'n' },
|
||||
spec: { type: 'foo', parent: 'group:default/name', children: [] },
|
||||
});
|
||||
});
|
||||
|
||||
it('should not replace existing parents', async () => {
|
||||
const p = new GroupDefaultParentEntityPolicy('namespace/name');
|
||||
const g: GroupEntity = {
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'Group',
|
||||
metadata: { name: 'n' },
|
||||
spec: { type: 'foo', parent: 'group:something/else', children: [] },
|
||||
};
|
||||
const result = await p.enforce(g);
|
||||
expect(result).toEqual({
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'Group',
|
||||
metadata: { name: 'n' },
|
||||
spec: { type: 'foo', parent: 'group:something/else', children: [] },
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 2022 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Entity } from '../Entity';
|
||||
import { GroupEntity } from '../../kinds';
|
||||
import { EntityPolicy } from './types';
|
||||
import { DEFAULT_NAMESPACE } from '../constants';
|
||||
import { parseEntityRef, stringifyEntityRef } from '../ref';
|
||||
|
||||
/**
|
||||
* DefaultParentPolicy is an EntityPolicy that updates group entities
|
||||
* with a parent of last resort. This ensures that, while we preserve
|
||||
* any existing group hierarchies, we can guarantee that there is a
|
||||
* single global root of the group hierarchy.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export class GroupDefaultParentEntityPolicy implements EntityPolicy {
|
||||
private readonly parentRef: string;
|
||||
|
||||
constructor(parentEntityRef: string) {
|
||||
const { kind, namespace, name } = parseEntityRef(parentEntityRef, {
|
||||
defaultKind: 'Group',
|
||||
defaultNamespace: DEFAULT_NAMESPACE,
|
||||
});
|
||||
|
||||
if (kind.toLocaleUpperCase('en-US') !== 'GROUP') {
|
||||
throw new TypeError('group parent must be a group');
|
||||
}
|
||||
|
||||
this.parentRef = stringifyEntityRef({
|
||||
kind: kind,
|
||||
namespace: namespace,
|
||||
name: name,
|
||||
});
|
||||
}
|
||||
|
||||
async enforce(entity: Entity): Promise<Entity> {
|
||||
if (entity.kind !== 'Group') {
|
||||
return entity;
|
||||
}
|
||||
|
||||
const group = entity as GroupEntity;
|
||||
if (group.spec.parent) {
|
||||
return group;
|
||||
}
|
||||
|
||||
// Avoid making the parent entity it's own parent.
|
||||
if (stringifyEntityRef(group) !== this.parentRef) {
|
||||
group.spec.parent = this.parentRef;
|
||||
}
|
||||
|
||||
return group;
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
export { DefaultNamespaceEntityPolicy } from './DefaultNamespaceEntityPolicy';
|
||||
export { GroupDefaultParentEntityPolicy } from './GroupDefaultParentEntityPolicy';
|
||||
export { FieldFormatEntityPolicy } from './FieldFormatEntityPolicy';
|
||||
export { NoForeignRootFieldsEntityPolicy } from './NoForeignRootFieldsEntityPolicy';
|
||||
export { SchemaValidEntityPolicy } from './SchemaValidEntityPolicy';
|
||||
|
||||
@@ -62,4 +62,42 @@ describe('<MarkdownContent />', () => {
|
||||
expect(fp2).toBeInTheDocument();
|
||||
expect(rendered.getByText(');', { selector: 'span' })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('render MarkdownContent component with transformed link', async () => {
|
||||
const rendered = await renderWithEffects(
|
||||
wrapInTestApp(
|
||||
<MarkdownContent
|
||||
content="[Title](https://backstage.io/link)"
|
||||
transformLinkUri={href => {
|
||||
return `${href}-modified`;
|
||||
}}
|
||||
/>,
|
||||
),
|
||||
);
|
||||
const fp1 = rendered.getByText('Title', {
|
||||
selector: 'a',
|
||||
});
|
||||
expect(fp1).toBeInTheDocument();
|
||||
expect(fp1.getAttribute('href')).toEqual(
|
||||
'https://backstage.io/link-modified',
|
||||
);
|
||||
});
|
||||
|
||||
it('render MarkdownContent component with transformed image', async () => {
|
||||
const rendered = await renderWithEffects(
|
||||
wrapInTestApp(
|
||||
<MarkdownContent
|
||||
content=""
|
||||
transformImageUri={() => {
|
||||
return `https://example.com/blog/assets/6/header.png`;
|
||||
}}
|
||||
/>,
|
||||
),
|
||||
);
|
||||
const fp1 = rendered.getByAltText('Image');
|
||||
expect(fp1).toBeInTheDocument();
|
||||
expect(fp1.getAttribute('src')).toEqual(
|
||||
'https://example.com/blog/assets/6/header.png',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -68,6 +68,8 @@ type Props = {
|
||||
content: string;
|
||||
dialect?: 'gfm' | 'common-mark';
|
||||
linkTarget?: Options['linkTarget'];
|
||||
transformLinkUri?: (href: string) => string;
|
||||
transformImageUri?: (href: string) => string;
|
||||
};
|
||||
|
||||
const components: Options['components'] = {
|
||||
@@ -91,7 +93,13 @@ const components: Options['components'] = {
|
||||
* If you just want to render to plain [CommonMark](https://commonmark.org/), set the dialect to `'common-mark'`
|
||||
*/
|
||||
export function MarkdownContent(props: Props) {
|
||||
const { content, dialect = 'gfm', linkTarget } = props;
|
||||
const {
|
||||
content,
|
||||
dialect = 'gfm',
|
||||
linkTarget,
|
||||
transformLinkUri,
|
||||
transformImageUri,
|
||||
} = props;
|
||||
const classes = useStyles();
|
||||
return (
|
||||
<ReactMarkdown
|
||||
@@ -100,6 +108,8 @@ export function MarkdownContent(props: Props) {
|
||||
children={content}
|
||||
components={components}
|
||||
linkTarget={linkTarget}
|
||||
transformLinkUri={transformLinkUri}
|
||||
transformImageUri={transformImageUri}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -63,6 +63,7 @@ const useStyles = makeStyles<BackstageTheme>(
|
||||
},
|
||||
rightItemsBox: {
|
||||
width: 'auto',
|
||||
alignItems: 'center',
|
||||
},
|
||||
title: {
|
||||
color: theme.palette.bursts.fontColor,
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
"express-promise-router": "^4.1.0",
|
||||
"fs-extra": "10.1.0",
|
||||
"helmet": "^5.0.2",
|
||||
"knex": "^1.0.2",
|
||||
"knex": "^2.0.0",
|
||||
"lodash": "^4.17.21",
|
||||
"luxon": "^2.0.2",
|
||||
"winston": "^3.2.1",
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
"google-auth-library": "^8.0.0",
|
||||
"jose": "^4.6.0",
|
||||
"jwt-decode": "^3.1.0",
|
||||
"knex": "^1.0.2",
|
||||
"knex": "^2.0.0",
|
||||
"lodash": "^4.17.21",
|
||||
"luxon": "^2.0.2",
|
||||
"minimatch": "^5.0.0",
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
"@types/express": "^4.17.6",
|
||||
"express": "^4.17.1",
|
||||
"express-promise-router": "^4.1.0",
|
||||
"knex": "^1.0.2",
|
||||
"knex": "^2.0.0",
|
||||
"winston": "^3.2.1",
|
||||
"yn": "^4.0.0"
|
||||
},
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
"fs-extra": "10.1.0",
|
||||
"git-url-parse": "^11.6.0",
|
||||
"glob": "^7.1.6",
|
||||
"knex": "^1.0.2",
|
||||
"knex": "^2.0.0",
|
||||
"lodash": "^4.17.21",
|
||||
"luxon": "^2.0.2",
|
||||
"node-fetch": "^2.6.7",
|
||||
|
||||
@@ -78,6 +78,7 @@ export type CatalogReactComponentsNameToClassKey = {
|
||||
CatalogReactEntitySearchBar: CatalogReactEntitySearchBarClassKey;
|
||||
CatalogReactEntityTagPicker: CatalogReactEntityTagPickerClassKey;
|
||||
CatalogReactEntityOwnerPicker: CatalogReactEntityOwnerPickerClassKey;
|
||||
CatalogReactEntityProcessingStatusPicker: CatalogReactEntityProcessingStatusPickerClassKey;
|
||||
};
|
||||
|
||||
// @public (undocumented)
|
||||
@@ -86,6 +87,9 @@ export type CatalogReactEntityLifecyclePickerClassKey = 'input';
|
||||
// @public (undocumented)
|
||||
export type CatalogReactEntityOwnerPickerClassKey = 'input';
|
||||
|
||||
// @public (undocumented)
|
||||
export type CatalogReactEntityProcessingStatusPickerClassKey = 'input';
|
||||
|
||||
// @public (undocumented)
|
||||
export type CatalogReactEntitySearchBarClassKey = 'searchToolbar' | 'input';
|
||||
|
||||
@@ -137,8 +141,19 @@ export type DefaultEntityFilters = {
|
||||
lifecycles?: EntityLifecycleFilter;
|
||||
tags?: EntityTagFilter;
|
||||
text?: EntityTextFilter;
|
||||
orphan?: EntityOrphanFilter;
|
||||
error?: EntityErrorFilter;
|
||||
};
|
||||
|
||||
// @public
|
||||
export class EntityErrorFilter implements EntityFilter {
|
||||
constructor(value: boolean);
|
||||
// (undocumented)
|
||||
filterEntity(entity: Entity): boolean;
|
||||
// (undocumented)
|
||||
readonly value: boolean;
|
||||
}
|
||||
|
||||
// @public (undocumented)
|
||||
export type EntityFilter = {
|
||||
getCatalogFilters?: () => Record<
|
||||
@@ -222,6 +237,15 @@ export type EntityLoadingStatus<TEntity extends Entity = Entity> = {
|
||||
refresh?: VoidFunction;
|
||||
};
|
||||
|
||||
// @public
|
||||
export class EntityOrphanFilter implements EntityFilter {
|
||||
constructor(value: boolean);
|
||||
// (undocumented)
|
||||
filterEntity(entity: Entity): boolean;
|
||||
// (undocumented)
|
||||
readonly value: boolean;
|
||||
}
|
||||
|
||||
// @public
|
||||
export class EntityOwnerFilter implements EntityFilter {
|
||||
constructor(values: string[]);
|
||||
@@ -236,6 +260,9 @@ export class EntityOwnerFilter implements EntityFilter {
|
||||
// @public (undocumented)
|
||||
export const EntityOwnerPicker: () => JSX.Element | null;
|
||||
|
||||
// @public (undocumented)
|
||||
export const EntityProcessingStatusPicker: () => JSX.Element;
|
||||
|
||||
// @public
|
||||
export const EntityProvider: (props: EntityProviderProps) => JSX.Element;
|
||||
|
||||
|
||||
+152
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* Copyright 2022 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
import { fireEvent, render } from '@testing-library/react';
|
||||
import React from 'react';
|
||||
import { EntityErrorFilter, EntityOrphanFilter } from '../../filters';
|
||||
import { MockEntityListContextProvider } from '../../testUtils/providers';
|
||||
import { EntityProcessingStatusPicker } from './EntityProcessingStatusPicker';
|
||||
|
||||
const orphanAnnotation: Record<string, string> = {};
|
||||
orphanAnnotation['backstage.io/orphan'] = 'true';
|
||||
|
||||
const sampleEntities: Entity[] = [
|
||||
{
|
||||
apiVersion: '1',
|
||||
kind: 'Component',
|
||||
metadata: {
|
||||
name: 'valid-component',
|
||||
},
|
||||
},
|
||||
{
|
||||
apiVersion: '1',
|
||||
kind: 'Component',
|
||||
metadata: {
|
||||
name: 'orphan-component',
|
||||
annotations: orphanAnnotation,
|
||||
},
|
||||
},
|
||||
{
|
||||
apiVersion: '1',
|
||||
kind: 'Component',
|
||||
metadata: {
|
||||
name: 'error-component',
|
||||
tags: ['Invalid Tag'],
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
describe('<EntityProcessingStatusPicker/>', () => {
|
||||
it('renders all processing status options', () => {
|
||||
const rendered = render(
|
||||
<MockEntityListContextProvider
|
||||
value={{ entities: sampleEntities, backendEntities: sampleEntities }}
|
||||
>
|
||||
<EntityProcessingStatusPicker />
|
||||
</MockEntityListContextProvider>,
|
||||
);
|
||||
expect(rendered.getByText('Processing Status')).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(rendered.getByTestId('processing-status-picker-expand'));
|
||||
expect(rendered.getByText('Is Orphan')).toBeInTheDocument();
|
||||
expect(rendered.getByText('Has Error')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('adds orphan to orphan filter', () => {
|
||||
const updateFilters = jest.fn();
|
||||
const rendered = render(
|
||||
<MockEntityListContextProvider
|
||||
value={{
|
||||
entities: sampleEntities,
|
||||
backendEntities: sampleEntities,
|
||||
updateFilters,
|
||||
}}
|
||||
>
|
||||
<EntityProcessingStatusPicker />
|
||||
</MockEntityListContextProvider>,
|
||||
);
|
||||
|
||||
fireEvent.click(rendered.getByTestId('processing-status-picker-expand'));
|
||||
fireEvent.click(rendered.getByText('Is Orphan'));
|
||||
expect(updateFilters).toHaveBeenCalledWith({
|
||||
orphan: new EntityOrphanFilter(true),
|
||||
});
|
||||
});
|
||||
|
||||
it('adds error to error filter', () => {
|
||||
const updateFilters = jest.fn();
|
||||
const rendered = render(
|
||||
<MockEntityListContextProvider
|
||||
value={{
|
||||
entities: sampleEntities,
|
||||
backendEntities: sampleEntities,
|
||||
updateFilters,
|
||||
}}
|
||||
>
|
||||
<EntityProcessingStatusPicker />
|
||||
</MockEntityListContextProvider>,
|
||||
);
|
||||
|
||||
fireEvent.click(rendered.getByTestId('processing-status-picker-expand'));
|
||||
fireEvent.click(rendered.getByText('Has Error'));
|
||||
expect(updateFilters).toHaveBeenCalledWith({
|
||||
error: new EntityErrorFilter(true),
|
||||
});
|
||||
});
|
||||
|
||||
it('remove orphan from orphan filter', () => {
|
||||
const updateFilters = jest.fn();
|
||||
const rendered = render(
|
||||
<MockEntityListContextProvider
|
||||
value={{
|
||||
entities: sampleEntities,
|
||||
backendEntities: sampleEntities,
|
||||
updateFilters,
|
||||
}}
|
||||
>
|
||||
<EntityProcessingStatusPicker />
|
||||
</MockEntityListContextProvider>,
|
||||
);
|
||||
|
||||
fireEvent.click(rendered.getByTestId('processing-status-picker-expand'));
|
||||
fireEvent.click(rendered.getByText('Is Orphan'));
|
||||
expect(updateFilters).toHaveBeenCalledWith({
|
||||
orphan: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
it('remove error from error filter', () => {
|
||||
const updateFilters = jest.fn();
|
||||
const rendered = render(
|
||||
<MockEntityListContextProvider
|
||||
value={{
|
||||
entities: sampleEntities,
|
||||
backendEntities: sampleEntities,
|
||||
updateFilters,
|
||||
}}
|
||||
>
|
||||
<EntityProcessingStatusPicker />
|
||||
</MockEntityListContextProvider>,
|
||||
);
|
||||
|
||||
fireEvent.click(rendered.getByTestId('processing-status-picker-expand'));
|
||||
fireEvent.click(rendered.getByText('Has Error'));
|
||||
expect(updateFilters).toHaveBeenCalledWith({
|
||||
error: undefined,
|
||||
});
|
||||
});
|
||||
});
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright 2022 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { EntityErrorFilter, EntityOrphanFilter } from '../../filters';
|
||||
import {
|
||||
Box,
|
||||
Checkbox,
|
||||
FormControlLabel,
|
||||
makeStyles,
|
||||
TextField,
|
||||
Typography,
|
||||
} from '@material-ui/core';
|
||||
import CheckBoxIcon from '@material-ui/icons/CheckBox';
|
||||
import CheckBoxOutlineBlankIcon from '@material-ui/icons/CheckBoxOutlineBlank';
|
||||
import ExpandMoreIcon from '@material-ui/icons/ExpandMore';
|
||||
import React, { useState } from 'react';
|
||||
import { useEntityList } from '../../hooks';
|
||||
import { Autocomplete } from '@material-ui/lab';
|
||||
|
||||
/** @public */
|
||||
export type CatalogReactEntityProcessingStatusPickerClassKey = 'input';
|
||||
|
||||
const useStyles = makeStyles(
|
||||
{
|
||||
input: {},
|
||||
},
|
||||
{
|
||||
name: 'CatalogReactEntityProcessingStatusPickerPicker',
|
||||
},
|
||||
);
|
||||
|
||||
const icon = <CheckBoxOutlineBlankIcon fontSize="small" />;
|
||||
const checkedIcon = <CheckBoxIcon fontSize="small" />;
|
||||
|
||||
/** @public */
|
||||
export const EntityProcessingStatusPicker = () => {
|
||||
const classes = useStyles();
|
||||
const { updateFilters } = useEntityList();
|
||||
|
||||
const [selectedAdvancedItems, setSelectedAdvancedItems] = useState<string[]>(
|
||||
[],
|
||||
);
|
||||
|
||||
function orphanChange(value: boolean) {
|
||||
updateFilters({
|
||||
orphan: value ? new EntityOrphanFilter(value) : undefined,
|
||||
});
|
||||
}
|
||||
|
||||
function errorChange(value: boolean) {
|
||||
updateFilters({
|
||||
error: value ? new EntityErrorFilter(value) : undefined,
|
||||
});
|
||||
}
|
||||
|
||||
const availableAdvancedItems = ['Is Orphan', 'Has Error'];
|
||||
|
||||
return (
|
||||
<Box pb={1} pt={1}>
|
||||
<Typography variant="button" component="label">
|
||||
Processing Status
|
||||
<Autocomplete
|
||||
multiple
|
||||
options={availableAdvancedItems}
|
||||
value={selectedAdvancedItems}
|
||||
onChange={(_: object, value: string[]) => {
|
||||
setSelectedAdvancedItems(value);
|
||||
orphanChange(value.includes('Is Orphan'));
|
||||
errorChange(value.includes('Has Error'));
|
||||
}}
|
||||
renderOption={(option, { selected }) => (
|
||||
<FormControlLabel
|
||||
control={
|
||||
<Checkbox
|
||||
icon={icon}
|
||||
checkedIcon={checkedIcon}
|
||||
checked={selected}
|
||||
/>
|
||||
}
|
||||
label={option}
|
||||
/>
|
||||
)}
|
||||
size="small"
|
||||
popupIcon={
|
||||
<ExpandMoreIcon data-testid="processing-status-picker-expand" />
|
||||
}
|
||||
renderInput={params => (
|
||||
<TextField
|
||||
{...params}
|
||||
className={classes.input}
|
||||
variant="outlined"
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
</Typography>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2022 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
export { EntityProcessingStatusPicker as EntityProcessingStatusPicker } from './EntityProcessingStatusPicker';
|
||||
export type { CatalogReactEntityProcessingStatusPickerClassKey } from './EntityProcessingStatusPicker';
|
||||
@@ -27,3 +27,4 @@ export * from './FavoriteEntity';
|
||||
export * from './InspectEntityDialog';
|
||||
export * from './UnregisterEntityDialog';
|
||||
export * from './UserListPicker';
|
||||
export * from './EntityProcessingStatusPicker';
|
||||
|
||||
@@ -14,9 +14,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
import { AlphaEntity, Entity } from '@backstage/catalog-model';
|
||||
import { TemplateEntityV1beta3 } from '@backstage/plugin-scaffolder-common';
|
||||
import { EntityTextFilter } from './filters';
|
||||
import {
|
||||
EntityErrorFilter,
|
||||
EntityOrphanFilter,
|
||||
EntityTextFilter,
|
||||
} from './filters';
|
||||
|
||||
const entities: Entity[] = [
|
||||
{
|
||||
@@ -91,3 +95,50 @@ describe('EntityTextFilter', () => {
|
||||
expect(filter.filterEntity(entities[1])).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('EntityOrphanFilter', () => {
|
||||
const orphanAnnotation: Record<string, string> = {};
|
||||
orphanAnnotation['backstage.io/orphan'] = 'true';
|
||||
|
||||
const orphan: Entity = {
|
||||
apiVersion: '1',
|
||||
kind: 'Component',
|
||||
metadata: {
|
||||
name: 'orphaned-service',
|
||||
annotations: orphanAnnotation,
|
||||
},
|
||||
};
|
||||
|
||||
it('should find orphans', () => {
|
||||
const filter = new EntityOrphanFilter(true);
|
||||
expect(filter.filterEntity(orphan)).toBeTruthy();
|
||||
expect(filter.filterEntity(entities[1])).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('EntityErrorFilter', () => {
|
||||
const error: AlphaEntity = {
|
||||
apiVersion: '1',
|
||||
kind: 'Component',
|
||||
metadata: {
|
||||
name: 'service-with-error',
|
||||
tags: ['Invalid Tag'],
|
||||
},
|
||||
status: {
|
||||
items: [
|
||||
{
|
||||
type: 'invalid-tag',
|
||||
level: 'error',
|
||||
message: 'Tag is not valid',
|
||||
error: undefined,
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
it('should find errors', () => {
|
||||
const filter = new EntityErrorFilter(true);
|
||||
expect(filter.filterEntity(error)).toBeTruthy();
|
||||
expect(filter.filterEntity(entities[1])).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -14,7 +14,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Entity, RELATION_OWNED_BY } from '@backstage/catalog-model';
|
||||
import {
|
||||
AlphaEntity,
|
||||
Entity,
|
||||
RELATION_OWNED_BY,
|
||||
} from '@backstage/catalog-model';
|
||||
import { humanizeEntityRef } from './components/EntityRefLink';
|
||||
import { EntityFilter, UserListFilterKind } from './types';
|
||||
import { getEntityRelations } from './utils';
|
||||
@@ -159,3 +163,28 @@ export class UserListFilter implements EntityFilter {
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters entities based if it is an orphan or not.
|
||||
* @public
|
||||
*/
|
||||
export class EntityOrphanFilter implements EntityFilter {
|
||||
constructor(readonly value: boolean) {}
|
||||
filterEntity(entity: Entity): boolean {
|
||||
const orphan = entity.metadata.annotations?.['backstage.io/orphan'];
|
||||
return orphan !== undefined && this.value.toString() === orphan;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters entities based on if it has errors or not.
|
||||
* @public
|
||||
*/
|
||||
export class EntityErrorFilter implements EntityFilter {
|
||||
constructor(readonly value: boolean) {}
|
||||
filterEntity(entity: Entity): boolean {
|
||||
const error =
|
||||
((entity as AlphaEntity)?.status?.items?.length as number) > 0;
|
||||
return error !== undefined && this.value === error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,8 +31,10 @@ import useDebounce from 'react-use/lib/useDebounce';
|
||||
import useMountedState from 'react-use/lib/useMountedState';
|
||||
import { catalogApiRef } from '../api';
|
||||
import {
|
||||
EntityErrorFilter,
|
||||
EntityKindFilter,
|
||||
EntityLifecycleFilter,
|
||||
EntityOrphanFilter,
|
||||
EntityOwnerFilter,
|
||||
EntityTagFilter,
|
||||
EntityTextFilter,
|
||||
@@ -52,6 +54,8 @@ export type DefaultEntityFilters = {
|
||||
lifecycles?: EntityLifecycleFilter;
|
||||
tags?: EntityTagFilter;
|
||||
text?: EntityTextFilter;
|
||||
orphan?: EntityOrphanFilter;
|
||||
error?: EntityErrorFilter;
|
||||
};
|
||||
|
||||
/** @public */
|
||||
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
CatalogReactEntitySearchBarClassKey,
|
||||
CatalogReactEntityTagPickerClassKey,
|
||||
CatalogReactEntityOwnerPickerClassKey,
|
||||
CatalogReactEntityProcessingStatusPickerClassKey,
|
||||
} from './components';
|
||||
|
||||
/** @public */
|
||||
@@ -31,6 +32,7 @@ export type CatalogReactComponentsNameToClassKey = {
|
||||
CatalogReactEntitySearchBar: CatalogReactEntitySearchBarClassKey;
|
||||
CatalogReactEntityTagPicker: CatalogReactEntityTagPickerClassKey;
|
||||
CatalogReactEntityOwnerPicker: CatalogReactEntityOwnerPickerClassKey;
|
||||
CatalogReactEntityProcessingStatusPicker: CatalogReactEntityProcessingStatusPickerClassKey;
|
||||
};
|
||||
|
||||
/** @public */
|
||||
|
||||
@@ -28,6 +28,7 @@ import {
|
||||
CatalogFilterLayout,
|
||||
EntityLifecyclePicker,
|
||||
EntityListProvider,
|
||||
EntityProcessingStatusPicker,
|
||||
EntityOwnerPicker,
|
||||
EntityTagPicker,
|
||||
EntityTypePicker,
|
||||
@@ -84,6 +85,7 @@ export function DefaultCatalogPage(props: DefaultCatalogPageProps) {
|
||||
<EntityOwnerPicker />
|
||||
<EntityLifecyclePicker />
|
||||
<EntityTagPicker />
|
||||
<EntityProcessingStatusPicker />
|
||||
</CatalogFilterLayout.Filters>
|
||||
<CatalogFilterLayout.Content>
|
||||
<CatalogTable
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
"express": "^4.17.1",
|
||||
"express-promise-router": "^4.1.0",
|
||||
"express-xml-bodyparser": "^0.3.0",
|
||||
"knex": "^1.0.2",
|
||||
"knex": "^2.0.0",
|
||||
"uuid": "^8.3.2",
|
||||
"winston": "^3.2.1",
|
||||
"yn": "^4.0.0"
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
"@types/express": "^4.17.6",
|
||||
"express": "^4.17.1",
|
||||
"express-promise-router": "^4.1.0",
|
||||
"kafkajs": "^1.16.0-beta.6",
|
||||
"kafkajs": "^2.0.0",
|
||||
"lodash": "^4.17.21",
|
||||
"winston": "^3.2.1"
|
||||
},
|
||||
|
||||
@@ -214,6 +214,7 @@ export type KubernetesObjectTypes =
|
||||
| 'services'
|
||||
| 'configmaps'
|
||||
| 'deployments'
|
||||
| 'limitranges'
|
||||
| 'replicasets'
|
||||
| 'horizontalpodautoscalers'
|
||||
| 'jobs'
|
||||
|
||||
@@ -70,6 +70,12 @@ export const DEFAULT_OBJECTS: ObjectToFetch[] = [
|
||||
plural: 'configmaps',
|
||||
objectType: 'configmaps',
|
||||
},
|
||||
{
|
||||
group: '',
|
||||
apiVersion: 'v1',
|
||||
plural: 'limitranges',
|
||||
objectType: 'limitranges',
|
||||
},
|
||||
{
|
||||
group: 'apps',
|
||||
apiVersion: 'v1',
|
||||
|
||||
@@ -101,6 +101,7 @@ export type KubernetesObjectTypes =
|
||||
| 'services'
|
||||
| 'configmaps'
|
||||
| 'deployments'
|
||||
| 'limitranges'
|
||||
| 'replicasets'
|
||||
| 'horizontalpodautoscalers'
|
||||
| 'jobs'
|
||||
|
||||
@@ -11,6 +11,7 @@ import { V1Deployment } from '@kubernetes/client-node';
|
||||
import { V1HorizontalPodAutoscaler } from '@kubernetes/client-node';
|
||||
import { V1Ingress } from '@kubernetes/client-node';
|
||||
import { V1Job } from '@kubernetes/client-node';
|
||||
import { V1LimitRange } from '@kubernetes/client-node';
|
||||
import { V1Pod } from '@kubernetes/client-node';
|
||||
import { V1ReplicaSet } from '@kubernetes/client-node';
|
||||
import { V1Service } from '@kubernetes/client-node';
|
||||
@@ -131,6 +132,7 @@ export type FetchResponse =
|
||||
| ServiceFetchResponse
|
||||
| ConfigMapFetchResponse
|
||||
| DeploymentFetchResponse
|
||||
| LimitRangeFetchReponse
|
||||
| ReplicaSetsFetchResponse
|
||||
| HorizontalPodAutoscalersFetchResponse
|
||||
| JobsFetchResponse
|
||||
@@ -212,6 +214,16 @@ export interface KubernetesRequestBody {
|
||||
entity: Entity;
|
||||
}
|
||||
|
||||
// Warning: (ae-missing-release-tag) "LimitRangeFetchReponse" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
|
||||
//
|
||||
// @public (undocumented)
|
||||
export interface LimitRangeFetchReponse {
|
||||
// (undocumented)
|
||||
resources: Array<V1LimitRange>;
|
||||
// (undocumented)
|
||||
type: 'limitranges';
|
||||
}
|
||||
|
||||
// Warning: (ae-missing-release-tag) "ObjectsByEntityResponse" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
|
||||
//
|
||||
// @public (undocumented)
|
||||
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
V1HorizontalPodAutoscaler,
|
||||
V1Ingress,
|
||||
V1Job,
|
||||
V1LimitRange,
|
||||
V1Pod,
|
||||
V1ReplicaSet,
|
||||
V1Service,
|
||||
@@ -97,6 +98,7 @@ export type FetchResponse =
|
||||
| ServiceFetchResponse
|
||||
| ConfigMapFetchResponse
|
||||
| DeploymentFetchResponse
|
||||
| LimitRangeFetchReponse
|
||||
| ReplicaSetsFetchResponse
|
||||
| HorizontalPodAutoscalersFetchResponse
|
||||
| JobsFetchResponse
|
||||
@@ -130,6 +132,11 @@ export interface ReplicaSetsFetchResponse {
|
||||
resources: Array<V1ReplicaSet>;
|
||||
}
|
||||
|
||||
export interface LimitRangeFetchReponse {
|
||||
type: 'limitranges';
|
||||
resources: Array<V1LimitRange>;
|
||||
}
|
||||
|
||||
export interface HorizontalPodAutoscalersFetchResponse {
|
||||
type: 'horizontalpodautoscalers';
|
||||
resources: Array<V1HorizontalPodAutoscaler>;
|
||||
|
||||
@@ -168,6 +168,62 @@ export type CreateGithubPullRequestClientFactoryInput = {
|
||||
token?: string;
|
||||
};
|
||||
|
||||
// @public
|
||||
export function createGithubRepoCreateAction(options: {
|
||||
integrations: ScmIntegrationRegistry;
|
||||
githubCredentialsProvider?: GithubCredentialsProvider;
|
||||
}): TemplateAction<{
|
||||
repoUrl: string;
|
||||
description?: string | undefined;
|
||||
access?: string | undefined;
|
||||
deleteBranchOnMerge?: boolean | undefined;
|
||||
gitAuthorName?: string | undefined;
|
||||
gitAuthorEmail?: string | undefined;
|
||||
allowRebaseMerge?: boolean | undefined;
|
||||
allowSquashMerge?: boolean | undefined;
|
||||
allowMergeCommit?: boolean | undefined;
|
||||
requireCodeOwnerReviews?: boolean | undefined;
|
||||
requiredStatusCheckContexts?: string[] | undefined;
|
||||
repoVisibility?: 'internal' | 'private' | 'public' | undefined;
|
||||
collaborators?:
|
||||
| (
|
||||
| {
|
||||
user: string;
|
||||
access: 'pull' | 'push' | 'admin' | 'maintain' | 'triage';
|
||||
}
|
||||
| {
|
||||
team: string;
|
||||
access: 'pull' | 'push' | 'admin' | 'maintain' | 'triage';
|
||||
}
|
||||
| {
|
||||
username: string;
|
||||
access: 'pull' | 'push' | 'admin' | 'maintain' | 'triage';
|
||||
}
|
||||
)[]
|
||||
| undefined;
|
||||
token?: string | undefined;
|
||||
topics?: string[] | undefined;
|
||||
}>;
|
||||
|
||||
// @public
|
||||
export function createGithubRepoPushAction(options: {
|
||||
integrations: ScmIntegrationRegistry;
|
||||
config: Config;
|
||||
githubCredentialsProvider?: GithubCredentialsProvider;
|
||||
}): TemplateAction<{
|
||||
repoUrl: string;
|
||||
description?: string | undefined;
|
||||
defaultBranch?: string | undefined;
|
||||
protectDefaultBranch?: boolean | undefined;
|
||||
gitCommitMessage?: string | undefined;
|
||||
gitAuthorName?: string | undefined;
|
||||
gitAuthorEmail?: string | undefined;
|
||||
requireCodeOwnerReviews?: boolean | undefined;
|
||||
requiredStatusCheckContexts?: string[] | undefined;
|
||||
sourcePath?: string | undefined;
|
||||
token?: string | undefined;
|
||||
}>;
|
||||
|
||||
// @public
|
||||
export function createGithubWebhookAction(options: {
|
||||
integrations: ScmIntegrationRegistry;
|
||||
@@ -345,6 +401,7 @@ export const createPublishGitlabMergeRequestAction: (options: {
|
||||
targetPath: string;
|
||||
token?: string | undefined;
|
||||
projectid?: string | undefined;
|
||||
removeSourceBranch?: boolean | undefined;
|
||||
}>;
|
||||
|
||||
// @public
|
||||
|
||||
@@ -59,7 +59,7 @@
|
||||
"isbinaryfile": "^5.0.0",
|
||||
"isomorphic-git": "^1.8.0",
|
||||
"jsonschema": "^1.2.6",
|
||||
"knex": "^1.0.2",
|
||||
"knex": "^2.0.0",
|
||||
"lodash": "^4.17.21",
|
||||
"luxon": "^2.0.2",
|
||||
"morgan": "^1.10.0",
|
||||
|
||||
@@ -15,25 +15,34 @@
|
||||
*/
|
||||
|
||||
import { UrlReader } from '@backstage/backend-common';
|
||||
import { JsonObject } from '@backstage/types';
|
||||
import { CatalogApi } from '@backstage/catalog-client';
|
||||
import {
|
||||
GithubCredentialsProvider,
|
||||
ScmIntegrations,
|
||||
DefaultGithubCredentialsProvider,
|
||||
} from '@backstage/integration';
|
||||
import { Config } from '@backstage/config';
|
||||
import {
|
||||
createCatalogWriteAction,
|
||||
DefaultGithubCredentialsProvider,
|
||||
GithubCredentialsProvider,
|
||||
ScmIntegrations,
|
||||
} from '@backstage/integration';
|
||||
import { JsonObject } from '@backstage/types';
|
||||
import {
|
||||
createCatalogRegisterAction,
|
||||
createCatalogWriteAction,
|
||||
} from './catalog';
|
||||
|
||||
import { TemplateFilter } from '../../../lib';
|
||||
import { TemplateAction } from '../types';
|
||||
import { createDebugLogAction } from './debug';
|
||||
import { createFetchPlainAction, createFetchTemplateAction } from './fetch';
|
||||
import {
|
||||
createFilesystemDeleteAction,
|
||||
createFilesystemRenameAction,
|
||||
} from './filesystem';
|
||||
import {
|
||||
createGithubActionsDispatchAction,
|
||||
createGithubIssuesLabelAction,
|
||||
createGithubRepoCreateAction,
|
||||
createGithubRepoPushAction,
|
||||
createGithubWebhookAction,
|
||||
} from './github';
|
||||
import {
|
||||
createPublishAzureAction,
|
||||
createPublishBitbucketAction,
|
||||
@@ -45,13 +54,6 @@ import {
|
||||
createPublishGitlabAction,
|
||||
createPublishGitlabMergeRequestAction,
|
||||
} from './publish';
|
||||
import {
|
||||
createGithubActionsDispatchAction,
|
||||
createGithubWebhookAction,
|
||||
createGithubIssuesLabelAction,
|
||||
} from './github';
|
||||
import { TemplateFilter } from '../../../lib';
|
||||
import { TemplateAction } from '../types';
|
||||
|
||||
/**
|
||||
* The options passed to {@link createBuiltinActions}
|
||||
@@ -165,6 +167,15 @@ export const createBuiltinActions = (
|
||||
integrations,
|
||||
githubCredentialsProvider,
|
||||
}),
|
||||
createGithubRepoCreateAction({
|
||||
integrations,
|
||||
githubCredentialsProvider,
|
||||
}),
|
||||
createGithubRepoPushAction({
|
||||
integrations,
|
||||
config,
|
||||
githubCredentialsProvider,
|
||||
}),
|
||||
];
|
||||
|
||||
return actions as TemplateAction<JsonObject>[];
|
||||
|
||||
+416
@@ -0,0 +1,416 @@
|
||||
/*
|
||||
* Copyright 2021 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { TemplateAction } from '../../types';
|
||||
|
||||
jest.mock('../helpers');
|
||||
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import {
|
||||
DefaultGithubCredentialsProvider,
|
||||
GithubCredentialsProvider,
|
||||
ScmIntegrations,
|
||||
} from '@backstage/integration';
|
||||
import { when } from 'jest-when';
|
||||
import { PassThrough } from 'stream';
|
||||
import { createGithubRepoCreateAction } from './githubRepoCreate';
|
||||
|
||||
const mockOctokit = {
|
||||
rest: {
|
||||
users: {
|
||||
getByUsername: jest.fn(),
|
||||
},
|
||||
repos: {
|
||||
addCollaborator: jest.fn(),
|
||||
createInOrg: jest.fn(),
|
||||
createForAuthenticatedUser: jest.fn(),
|
||||
replaceAllTopics: jest.fn(),
|
||||
},
|
||||
teams: {
|
||||
addOrUpdateRepoPermissionsInOrg: jest.fn(),
|
||||
},
|
||||
},
|
||||
};
|
||||
jest.mock('octokit', () => ({
|
||||
Octokit: class {
|
||||
constructor() {
|
||||
return mockOctokit;
|
||||
}
|
||||
},
|
||||
}));
|
||||
|
||||
describe('github:repo:create', () => {
|
||||
const config = new ConfigReader({
|
||||
integrations: {
|
||||
github: [
|
||||
{ host: 'github.com', token: 'tokenlols' },
|
||||
{ host: 'ghe.github.com' },
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
const integrations = ScmIntegrations.fromConfig(config);
|
||||
let githubCredentialsProvider: GithubCredentialsProvider;
|
||||
let action: TemplateAction<any>;
|
||||
|
||||
const mockContext = {
|
||||
input: {
|
||||
repoUrl: 'github.com?repo=repo&owner=owner',
|
||||
description: 'description',
|
||||
repoVisibility: 'private' as const,
|
||||
access: 'owner/blam',
|
||||
},
|
||||
workspacePath: 'lol',
|
||||
logger: getVoidLogger(),
|
||||
logStream: new PassThrough(),
|
||||
output: jest.fn(),
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
githubCredentialsProvider =
|
||||
DefaultGithubCredentialsProvider.fromIntegrations(integrations);
|
||||
action = createGithubRepoCreateAction({
|
||||
integrations,
|
||||
githubCredentialsProvider,
|
||||
});
|
||||
});
|
||||
|
||||
it('should call the githubApis with the correct values for createInOrg', async () => {
|
||||
mockOctokit.rest.users.getByUsername.mockResolvedValue({
|
||||
data: { type: 'Organization' },
|
||||
});
|
||||
|
||||
mockOctokit.rest.repos.createInOrg.mockResolvedValue({ data: {} });
|
||||
|
||||
await action.handler(mockContext);
|
||||
expect(mockOctokit.rest.repos.createInOrg).toHaveBeenCalledWith({
|
||||
description: 'description',
|
||||
name: 'repo',
|
||||
org: 'owner',
|
||||
private: true,
|
||||
delete_branch_on_merge: false,
|
||||
allow_squash_merge: true,
|
||||
allow_merge_commit: true,
|
||||
allow_rebase_merge: true,
|
||||
visibility: 'private',
|
||||
});
|
||||
|
||||
await action.handler({
|
||||
...mockContext,
|
||||
input: {
|
||||
...mockContext.input,
|
||||
repoVisibility: 'public',
|
||||
},
|
||||
});
|
||||
expect(mockOctokit.rest.repos.createInOrg).toHaveBeenCalledWith({
|
||||
description: 'description',
|
||||
name: 'repo',
|
||||
org: 'owner',
|
||||
private: false,
|
||||
delete_branch_on_merge: false,
|
||||
allow_squash_merge: true,
|
||||
allow_merge_commit: true,
|
||||
allow_rebase_merge: true,
|
||||
visibility: 'public',
|
||||
});
|
||||
});
|
||||
|
||||
it('should call the githubApis with the correct values for createForAuthenticatedUser', async () => {
|
||||
mockOctokit.rest.users.getByUsername.mockResolvedValue({
|
||||
data: { type: 'User' },
|
||||
});
|
||||
|
||||
mockOctokit.rest.repos.createForAuthenticatedUser.mockResolvedValue({
|
||||
data: {},
|
||||
});
|
||||
|
||||
await action.handler(mockContext);
|
||||
expect(
|
||||
mockOctokit.rest.repos.createForAuthenticatedUser,
|
||||
).toHaveBeenCalledWith({
|
||||
description: 'description',
|
||||
name: 'repo',
|
||||
private: true,
|
||||
delete_branch_on_merge: false,
|
||||
allow_squash_merge: true,
|
||||
allow_merge_commit: true,
|
||||
allow_rebase_merge: true,
|
||||
});
|
||||
|
||||
await action.handler({
|
||||
...mockContext,
|
||||
input: {
|
||||
...mockContext.input,
|
||||
repoVisibility: 'public',
|
||||
},
|
||||
});
|
||||
expect(
|
||||
mockOctokit.rest.repos.createForAuthenticatedUser,
|
||||
).toHaveBeenCalledWith({
|
||||
description: 'description',
|
||||
name: 'repo',
|
||||
private: false,
|
||||
delete_branch_on_merge: false,
|
||||
allow_squash_merge: true,
|
||||
allow_merge_commit: true,
|
||||
allow_rebase_merge: true,
|
||||
});
|
||||
});
|
||||
|
||||
it('should add access for the team when it starts with the owner', async () => {
|
||||
mockOctokit.rest.users.getByUsername.mockResolvedValue({
|
||||
data: { type: 'User' },
|
||||
});
|
||||
|
||||
mockOctokit.rest.repos.createForAuthenticatedUser.mockResolvedValue({
|
||||
data: {
|
||||
clone_url: 'https://github.com/clone/url.git',
|
||||
html_url: 'https://github.com/html/url',
|
||||
},
|
||||
});
|
||||
|
||||
await action.handler(mockContext);
|
||||
|
||||
expect(
|
||||
mockOctokit.rest.teams.addOrUpdateRepoPermissionsInOrg,
|
||||
).toHaveBeenCalledWith({
|
||||
org: 'owner',
|
||||
team_slug: 'blam',
|
||||
owner: 'owner',
|
||||
repo: 'repo',
|
||||
permission: 'admin',
|
||||
});
|
||||
});
|
||||
|
||||
it('should add outside collaborators when provided', async () => {
|
||||
mockOctokit.rest.users.getByUsername.mockResolvedValue({
|
||||
data: { type: 'User' },
|
||||
});
|
||||
|
||||
mockOctokit.rest.repos.createForAuthenticatedUser.mockResolvedValue({
|
||||
data: {
|
||||
clone_url: 'https://github.com/clone/url.git',
|
||||
html_url: 'https://github.com/html/url',
|
||||
},
|
||||
});
|
||||
|
||||
await action.handler({
|
||||
...mockContext,
|
||||
input: {
|
||||
...mockContext.input,
|
||||
access: 'outsidecollaborator',
|
||||
},
|
||||
});
|
||||
|
||||
expect(mockOctokit.rest.repos.addCollaborator).toHaveBeenCalledWith({
|
||||
username: 'outsidecollaborator',
|
||||
owner: 'owner',
|
||||
repo: 'repo',
|
||||
permission: 'admin',
|
||||
});
|
||||
});
|
||||
|
||||
it('should add multiple collaborators when provided', async () => {
|
||||
mockOctokit.rest.users.getByUsername.mockResolvedValue({
|
||||
data: { type: 'User' },
|
||||
});
|
||||
|
||||
mockOctokit.rest.repos.createForAuthenticatedUser.mockResolvedValue({
|
||||
data: {
|
||||
clone_url: 'https://github.com/clone/url.git',
|
||||
html_url: 'https://github.com/html/url',
|
||||
},
|
||||
});
|
||||
|
||||
await action.handler({
|
||||
...mockContext,
|
||||
input: {
|
||||
...mockContext.input,
|
||||
collaborators: [
|
||||
{
|
||||
access: 'pull',
|
||||
user: 'robot-1',
|
||||
},
|
||||
{
|
||||
access: 'push',
|
||||
team: 'robot-2',
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
const commonProperties = {
|
||||
owner: 'owner',
|
||||
repo: 'repo',
|
||||
};
|
||||
|
||||
expect(mockOctokit.rest.repos.addCollaborator).toHaveBeenCalledWith({
|
||||
...commonProperties,
|
||||
username: 'robot-1',
|
||||
permission: 'pull',
|
||||
});
|
||||
|
||||
expect(
|
||||
mockOctokit.rest.teams.addOrUpdateRepoPermissionsInOrg,
|
||||
).toHaveBeenCalledWith({
|
||||
...commonProperties,
|
||||
org: 'owner',
|
||||
team_slug: 'robot-2',
|
||||
permission: 'push',
|
||||
});
|
||||
});
|
||||
|
||||
it('should ignore failures when adding multiple collaborators', async () => {
|
||||
mockOctokit.rest.users.getByUsername.mockResolvedValue({
|
||||
data: { type: 'User' },
|
||||
});
|
||||
|
||||
mockOctokit.rest.repos.createForAuthenticatedUser.mockResolvedValue({
|
||||
data: {
|
||||
clone_url: 'https://github.com/clone/url.git',
|
||||
html_url: 'https://github.com/html/url',
|
||||
},
|
||||
});
|
||||
|
||||
when(mockOctokit.rest.teams.addOrUpdateRepoPermissionsInOrg)
|
||||
.calledWith({
|
||||
org: 'owner',
|
||||
owner: 'owner',
|
||||
repo: 'repo',
|
||||
team_slug: 'robot-1',
|
||||
permission: 'pull',
|
||||
})
|
||||
.mockRejectedValueOnce(new Error('Something bad happened') as never);
|
||||
|
||||
await action.handler({
|
||||
...mockContext,
|
||||
input: {
|
||||
...mockContext.input,
|
||||
collaborators: [
|
||||
{
|
||||
access: 'pull',
|
||||
team: 'robot-1',
|
||||
},
|
||||
{
|
||||
access: 'push',
|
||||
team: 'robot-2',
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
expect(
|
||||
mockOctokit.rest.teams.addOrUpdateRepoPermissionsInOrg.mock.calls[2],
|
||||
).toEqual([
|
||||
{
|
||||
org: 'owner',
|
||||
owner: 'owner',
|
||||
repo: 'repo',
|
||||
team_slug: 'robot-2',
|
||||
permission: 'push',
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('should add topics when provided', async () => {
|
||||
mockOctokit.rest.users.getByUsername.mockResolvedValue({
|
||||
data: { type: 'User' },
|
||||
});
|
||||
|
||||
mockOctokit.rest.repos.createForAuthenticatedUser.mockResolvedValue({
|
||||
data: {
|
||||
clone_url: 'https://github.com/clone/url.git',
|
||||
html_url: 'https://github.com/html/url',
|
||||
},
|
||||
});
|
||||
|
||||
mockOctokit.rest.repos.replaceAllTopics.mockResolvedValue({
|
||||
data: {
|
||||
names: ['node.js'],
|
||||
},
|
||||
});
|
||||
|
||||
await action.handler({
|
||||
...mockContext,
|
||||
input: {
|
||||
...mockContext.input,
|
||||
topics: ['node.js'],
|
||||
},
|
||||
});
|
||||
|
||||
expect(mockOctokit.rest.repos.replaceAllTopics).toHaveBeenCalledWith({
|
||||
owner: 'owner',
|
||||
repo: 'repo',
|
||||
names: ['node.js'],
|
||||
});
|
||||
});
|
||||
|
||||
it('should lowercase topics when provided', async () => {
|
||||
mockOctokit.rest.users.getByUsername.mockResolvedValue({
|
||||
data: { type: 'User' },
|
||||
});
|
||||
|
||||
mockOctokit.rest.repos.createForAuthenticatedUser.mockResolvedValue({
|
||||
data: {
|
||||
clone_url: 'https://github.com/clone/url.git',
|
||||
html_url: 'https://github.com/html/url',
|
||||
},
|
||||
});
|
||||
|
||||
mockOctokit.rest.repos.replaceAllTopics.mockResolvedValue({
|
||||
data: {
|
||||
names: ['backstage'],
|
||||
},
|
||||
});
|
||||
|
||||
await action.handler({
|
||||
...mockContext,
|
||||
input: {
|
||||
...mockContext.input,
|
||||
topics: ['BACKSTAGE'],
|
||||
},
|
||||
});
|
||||
|
||||
expect(mockOctokit.rest.repos.replaceAllTopics).toHaveBeenCalledWith({
|
||||
owner: 'owner',
|
||||
repo: 'repo',
|
||||
names: ['backstage'],
|
||||
});
|
||||
});
|
||||
|
||||
it('should call output with the remoteUrl', async () => {
|
||||
mockOctokit.rest.users.getByUsername.mockResolvedValue({
|
||||
data: { type: 'User' },
|
||||
});
|
||||
|
||||
mockOctokit.rest.repos.createForAuthenticatedUser.mockResolvedValue({
|
||||
data: {
|
||||
clone_url: 'https://github.com/clone/url.git',
|
||||
html_url: 'https://github.com/html/url',
|
||||
},
|
||||
});
|
||||
|
||||
await action.handler(mockContext);
|
||||
|
||||
expect(mockContext.output).toHaveBeenCalledWith(
|
||||
'remoteUrl',
|
||||
'https://github.com/clone/url.git',
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* Copyright 2021 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { InputError } from '@backstage/errors';
|
||||
import {
|
||||
GithubCredentialsProvider,
|
||||
ScmIntegrationRegistry,
|
||||
} from '@backstage/integration';
|
||||
import { Octokit } from 'octokit';
|
||||
import { createTemplateAction } from '../../createTemplateAction';
|
||||
import { parseRepoUrl } from '../publish/util';
|
||||
import {
|
||||
createGithubRepoWithCollaboratorsAndTopics,
|
||||
getOctokitOptions,
|
||||
} from './helpers';
|
||||
import * as inputProps from './inputProperties';
|
||||
import * as outputProps from './outputProperties';
|
||||
|
||||
/**
|
||||
* Creates a new action that initializes a git repository
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export function createGithubRepoCreateAction(options: {
|
||||
integrations: ScmIntegrationRegistry;
|
||||
githubCredentialsProvider?: GithubCredentialsProvider;
|
||||
}) {
|
||||
const { integrations, githubCredentialsProvider } = options;
|
||||
|
||||
return createTemplateAction<{
|
||||
repoUrl: string;
|
||||
description?: string;
|
||||
access?: string;
|
||||
deleteBranchOnMerge?: boolean;
|
||||
gitAuthorName?: string;
|
||||
gitAuthorEmail?: string;
|
||||
allowRebaseMerge?: boolean;
|
||||
allowSquashMerge?: boolean;
|
||||
allowMergeCommit?: boolean;
|
||||
requireCodeOwnerReviews?: boolean;
|
||||
requiredStatusCheckContexts?: string[];
|
||||
repoVisibility?: 'private' | 'internal' | 'public';
|
||||
collaborators?: Array<
|
||||
| {
|
||||
user: string;
|
||||
access: 'pull' | 'push' | 'admin' | 'maintain' | 'triage';
|
||||
}
|
||||
| {
|
||||
team: string;
|
||||
access: 'pull' | 'push' | 'admin' | 'maintain' | 'triage';
|
||||
}
|
||||
| {
|
||||
/** @deprecated This field is deprecated in favor of team */
|
||||
username: string;
|
||||
access: 'pull' | 'push' | 'admin' | 'maintain' | 'triage';
|
||||
}
|
||||
>;
|
||||
token?: string;
|
||||
topics?: string[];
|
||||
}>({
|
||||
id: 'github:repo:create',
|
||||
description: 'Creates a GitHub repository.',
|
||||
schema: {
|
||||
input: {
|
||||
type: 'object',
|
||||
required: ['repoUrl'],
|
||||
properties: {
|
||||
repoUrl: inputProps.repoUrl,
|
||||
description: inputProps.description,
|
||||
access: inputProps.access,
|
||||
requireCodeOwnerReviews: inputProps.requireCodeOwnerReviews,
|
||||
requiredStatusCheckContexts: inputProps.requiredStatusCheckContexts,
|
||||
repoVisibility: inputProps.repoVisibility,
|
||||
deleteBranchOnMerge: inputProps.deleteBranchOnMerge,
|
||||
allowMergeCommit: inputProps.allowMergeCommit,
|
||||
allowSquashMerge: inputProps.allowSquashMerge,
|
||||
allowRebaseMerge: inputProps.allowRebaseMerge,
|
||||
collaborators: inputProps.collaborators,
|
||||
token: inputProps.token,
|
||||
topics: inputProps.topics,
|
||||
},
|
||||
},
|
||||
output: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
remoteUrl: outputProps.remoteUrl,
|
||||
repoContentsUrl: outputProps.repoContentsUrl,
|
||||
},
|
||||
},
|
||||
},
|
||||
async handler(ctx) {
|
||||
const {
|
||||
repoUrl,
|
||||
description,
|
||||
access,
|
||||
repoVisibility = 'private',
|
||||
deleteBranchOnMerge = false,
|
||||
allowMergeCommit = true,
|
||||
allowSquashMerge = true,
|
||||
allowRebaseMerge = true,
|
||||
collaborators,
|
||||
topics,
|
||||
token: providedToken,
|
||||
} = ctx.input;
|
||||
|
||||
const octokitOptions = await getOctokitOptions({
|
||||
integrations,
|
||||
credentialsProvider: githubCredentialsProvider,
|
||||
token: providedToken,
|
||||
repoUrl: repoUrl,
|
||||
});
|
||||
const client = new Octokit(octokitOptions);
|
||||
|
||||
const { owner, repo } = parseRepoUrl(repoUrl, integrations);
|
||||
|
||||
if (!owner) {
|
||||
throw new InputError('Invalid repository owner provided in repoUrl');
|
||||
}
|
||||
|
||||
const newRepo = await createGithubRepoWithCollaboratorsAndTopics(
|
||||
client,
|
||||
repo,
|
||||
owner,
|
||||
repoVisibility,
|
||||
description,
|
||||
deleteBranchOnMerge,
|
||||
allowMergeCommit,
|
||||
allowSquashMerge,
|
||||
allowRebaseMerge,
|
||||
access,
|
||||
collaborators,
|
||||
topics,
|
||||
ctx.logger,
|
||||
);
|
||||
|
||||
ctx.output('remoteUrl', newRepo.clone_url);
|
||||
},
|
||||
});
|
||||
}
|
||||
+400
@@ -0,0 +1,400 @@
|
||||
/*
|
||||
* Copyright 2021 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { TemplateAction } from '../../types';
|
||||
|
||||
jest.mock('../helpers');
|
||||
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import {
|
||||
DefaultGithubCredentialsProvider,
|
||||
GithubCredentialsProvider,
|
||||
ScmIntegrations,
|
||||
} from '@backstage/integration';
|
||||
import { PassThrough } from 'stream';
|
||||
import {
|
||||
enableBranchProtectionOnDefaultRepoBranch,
|
||||
initRepoAndPush,
|
||||
} from '../helpers';
|
||||
import { createGithubRepoPushAction } from './githubRepoPush';
|
||||
|
||||
const mockOctokit = {
|
||||
rest: {
|
||||
repos: {
|
||||
get: jest.fn(),
|
||||
},
|
||||
},
|
||||
};
|
||||
jest.mock('octokit', () => ({
|
||||
Octokit: class {
|
||||
constructor() {
|
||||
return mockOctokit;
|
||||
}
|
||||
},
|
||||
}));
|
||||
|
||||
describe('github:repo:push', () => {
|
||||
const config = new ConfigReader({
|
||||
integrations: {
|
||||
github: [
|
||||
{ host: 'github.com', token: 'tokenlols' },
|
||||
{ host: 'ghe.github.com' },
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
const integrations = ScmIntegrations.fromConfig(config);
|
||||
let githubCredentialsProvider: GithubCredentialsProvider;
|
||||
let action: TemplateAction<any>;
|
||||
|
||||
const mockContext = {
|
||||
input: {
|
||||
repoUrl: 'github.com?repo=repository&owner=owner',
|
||||
description: 'description',
|
||||
repoVisibility: 'private' as const,
|
||||
access: 'owner/blam',
|
||||
},
|
||||
workspacePath: 'lol',
|
||||
logger: getVoidLogger(),
|
||||
logStream: new PassThrough(),
|
||||
output: jest.fn(),
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
githubCredentialsProvider =
|
||||
DefaultGithubCredentialsProvider.fromIntegrations(integrations);
|
||||
action = createGithubRepoPushAction({
|
||||
integrations,
|
||||
config,
|
||||
githubCredentialsProvider,
|
||||
});
|
||||
});
|
||||
|
||||
it('should call initRepoAndPush with the correct values', async () => {
|
||||
mockOctokit.rest.repos.get.mockResolvedValue({
|
||||
data: {
|
||||
clone_url: 'https://github.com/clone/url.git',
|
||||
html_url: 'https://github.com/html/url',
|
||||
},
|
||||
});
|
||||
|
||||
await action.handler(mockContext);
|
||||
|
||||
expect(initRepoAndPush).toHaveBeenCalledWith({
|
||||
dir: mockContext.workspacePath,
|
||||
remoteUrl: 'https://github.com/clone/url.git',
|
||||
defaultBranch: 'master',
|
||||
auth: { username: 'x-access-token', password: 'tokenlols' },
|
||||
logger: mockContext.logger,
|
||||
commitMessage: 'initial commit',
|
||||
gitAuthorInfo: {},
|
||||
});
|
||||
});
|
||||
|
||||
it('should call initRepoAndPush with the correct defaultBranch main', async () => {
|
||||
mockOctokit.rest.repos.get.mockResolvedValue({
|
||||
data: {
|
||||
clone_url: 'https://github.com/clone/url.git',
|
||||
html_url: 'https://github.com/html/url',
|
||||
},
|
||||
});
|
||||
|
||||
await action.handler({
|
||||
...mockContext,
|
||||
input: {
|
||||
...mockContext.input,
|
||||
defaultBranch: 'main',
|
||||
},
|
||||
});
|
||||
|
||||
expect(initRepoAndPush).toHaveBeenCalledWith({
|
||||
dir: mockContext.workspacePath,
|
||||
remoteUrl: 'https://github.com/clone/url.git',
|
||||
defaultBranch: 'main',
|
||||
auth: { username: 'x-access-token', password: 'tokenlols' },
|
||||
logger: mockContext.logger,
|
||||
commitMessage: 'initial commit',
|
||||
gitAuthorInfo: {},
|
||||
});
|
||||
});
|
||||
|
||||
it('should call initRepoAndPush with the configured defaultAuthor', async () => {
|
||||
const customAuthorConfig = new ConfigReader({
|
||||
integrations: {
|
||||
github: [
|
||||
{ host: 'github.com', token: 'tokenlols' },
|
||||
{ host: 'ghe.github.com' },
|
||||
],
|
||||
},
|
||||
scaffolder: {
|
||||
defaultAuthor: {
|
||||
name: 'Test',
|
||||
email: 'example@example.com',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const customAuthorIntegrations =
|
||||
ScmIntegrations.fromConfig(customAuthorConfig);
|
||||
const customAuthorAction = createGithubRepoPushAction({
|
||||
integrations: customAuthorIntegrations,
|
||||
config: customAuthorConfig,
|
||||
githubCredentialsProvider,
|
||||
});
|
||||
|
||||
mockOctokit.rest.repos.get.mockResolvedValue({
|
||||
data: {
|
||||
clone_url: 'https://github.com/clone/url.git',
|
||||
html_url: 'https://github.com/html/url',
|
||||
},
|
||||
});
|
||||
|
||||
await customAuthorAction.handler(mockContext);
|
||||
|
||||
expect(initRepoAndPush).toHaveBeenCalledWith({
|
||||
dir: mockContext.workspacePath,
|
||||
remoteUrl: 'https://github.com/clone/url.git',
|
||||
defaultBranch: 'master',
|
||||
auth: { username: 'x-access-token', password: 'tokenlols' },
|
||||
logger: mockContext.logger,
|
||||
commitMessage: 'initial commit',
|
||||
gitAuthorInfo: { name: 'Test', email: 'example@example.com' },
|
||||
});
|
||||
});
|
||||
|
||||
it('should call initRepoAndPush with the configured defaultCommitMessage', async () => {
|
||||
const customAuthorConfig = new ConfigReader({
|
||||
integrations: {
|
||||
github: [
|
||||
{ host: 'github.com', token: 'tokenlols' },
|
||||
{ host: 'ghe.github.com' },
|
||||
],
|
||||
},
|
||||
scaffolder: {
|
||||
defaultCommitMessage: 'Test commit message',
|
||||
},
|
||||
});
|
||||
|
||||
const customAuthorIntegrations =
|
||||
ScmIntegrations.fromConfig(customAuthorConfig);
|
||||
const customAuthorAction = createGithubRepoPushAction({
|
||||
integrations: customAuthorIntegrations,
|
||||
config: customAuthorConfig,
|
||||
githubCredentialsProvider,
|
||||
});
|
||||
|
||||
mockOctokit.rest.repos.get.mockResolvedValue({
|
||||
data: {
|
||||
clone_url: 'https://github.com/clone/url.git',
|
||||
html_url: 'https://github.com/html/url',
|
||||
},
|
||||
});
|
||||
|
||||
await customAuthorAction.handler(mockContext);
|
||||
|
||||
expect(initRepoAndPush).toHaveBeenCalledWith({
|
||||
dir: mockContext.workspacePath,
|
||||
remoteUrl: 'https://github.com/clone/url.git',
|
||||
defaultBranch: 'master',
|
||||
auth: { username: 'x-access-token', password: 'tokenlols' },
|
||||
logger: mockContext.logger,
|
||||
commitMessage: 'initial commit',
|
||||
gitAuthorInfo: { email: undefined, name: undefined },
|
||||
});
|
||||
});
|
||||
|
||||
it('should call output with the remoteUrl and the repoContentsUrl', async () => {
|
||||
mockOctokit.rest.repos.get.mockResolvedValue({
|
||||
data: {
|
||||
clone_url: 'https://github.com/clone/url.git',
|
||||
html_url: 'https://github.com/html/url',
|
||||
},
|
||||
});
|
||||
|
||||
await action.handler(mockContext);
|
||||
|
||||
expect(mockContext.output).toHaveBeenCalledWith(
|
||||
'remoteUrl',
|
||||
'https://github.com/clone/url.git',
|
||||
);
|
||||
expect(mockContext.output).toHaveBeenCalledWith(
|
||||
'repoContentsUrl',
|
||||
'https://github.com/html/url/blob/master',
|
||||
);
|
||||
});
|
||||
|
||||
it('should use main as default branch', async () => {
|
||||
mockOctokit.rest.repos.get.mockResolvedValue({
|
||||
data: {
|
||||
clone_url: 'https://github.com/clone/url.git',
|
||||
html_url: 'https://github.com/html/url',
|
||||
},
|
||||
});
|
||||
|
||||
await action.handler({
|
||||
...mockContext,
|
||||
input: {
|
||||
...mockContext.input,
|
||||
defaultBranch: 'main',
|
||||
},
|
||||
});
|
||||
|
||||
expect(mockContext.output).toHaveBeenCalledWith(
|
||||
'remoteUrl',
|
||||
'https://github.com/clone/url.git',
|
||||
);
|
||||
expect(mockContext.output).toHaveBeenCalledWith(
|
||||
'repoContentsUrl',
|
||||
'https://github.com/html/url/blob/main',
|
||||
);
|
||||
});
|
||||
|
||||
it('should call enableBranchProtectionOnDefaultRepoBranch with the correct values of requireCodeOwnerReviews', async () => {
|
||||
mockOctokit.rest.repos.get.mockResolvedValue({
|
||||
data: {
|
||||
clone_url: 'https://github.com/clone/url.git',
|
||||
html_url: 'https://github.com/html/url',
|
||||
},
|
||||
});
|
||||
|
||||
await action.handler(mockContext);
|
||||
|
||||
expect(enableBranchProtectionOnDefaultRepoBranch).toHaveBeenCalledWith({
|
||||
owner: 'owner',
|
||||
client: mockOctokit,
|
||||
repoName: 'repository',
|
||||
logger: mockContext.logger,
|
||||
defaultBranch: 'master',
|
||||
requireCodeOwnerReviews: false,
|
||||
requiredStatusCheckContexts: [],
|
||||
});
|
||||
|
||||
await action.handler({
|
||||
...mockContext,
|
||||
input: {
|
||||
...mockContext.input,
|
||||
requireCodeOwnerReviews: true,
|
||||
},
|
||||
});
|
||||
|
||||
expect(enableBranchProtectionOnDefaultRepoBranch).toHaveBeenCalledWith({
|
||||
owner: 'owner',
|
||||
client: mockOctokit,
|
||||
repoName: 'repository',
|
||||
logger: mockContext.logger,
|
||||
defaultBranch: 'master',
|
||||
requireCodeOwnerReviews: true,
|
||||
requiredStatusCheckContexts: [],
|
||||
});
|
||||
|
||||
await action.handler({
|
||||
...mockContext,
|
||||
input: {
|
||||
...mockContext.input,
|
||||
requireCodeOwnerReviews: false,
|
||||
},
|
||||
});
|
||||
|
||||
expect(enableBranchProtectionOnDefaultRepoBranch).toHaveBeenCalledWith({
|
||||
owner: 'owner',
|
||||
client: mockOctokit,
|
||||
repoName: 'repository',
|
||||
logger: mockContext.logger,
|
||||
defaultBranch: 'master',
|
||||
requireCodeOwnerReviews: false,
|
||||
requiredStatusCheckContexts: [],
|
||||
});
|
||||
});
|
||||
|
||||
it('should call enableBranchProtectionOnDefaultRepoBranch with the correct values of requiredStatusCheckContexts', async () => {
|
||||
mockOctokit.rest.repos.get.mockResolvedValue({
|
||||
data: {
|
||||
clone_url: 'https://github.com/clone/url.git',
|
||||
html_url: 'https://github.com/html/url',
|
||||
},
|
||||
});
|
||||
|
||||
await action.handler(mockContext);
|
||||
|
||||
expect(enableBranchProtectionOnDefaultRepoBranch).toHaveBeenCalledWith({
|
||||
owner: 'owner',
|
||||
client: mockOctokit,
|
||||
repoName: 'repository',
|
||||
logger: mockContext.logger,
|
||||
defaultBranch: 'master',
|
||||
requireCodeOwnerReviews: false,
|
||||
requiredStatusCheckContexts: [],
|
||||
});
|
||||
|
||||
await action.handler({
|
||||
...mockContext,
|
||||
input: {
|
||||
...mockContext.input,
|
||||
requiredStatusCheckContexts: ['statusCheck'],
|
||||
},
|
||||
});
|
||||
|
||||
expect(enableBranchProtectionOnDefaultRepoBranch).toHaveBeenCalledWith({
|
||||
owner: 'owner',
|
||||
client: mockOctokit,
|
||||
repoName: 'repository',
|
||||
logger: mockContext.logger,
|
||||
defaultBranch: 'master',
|
||||
requireCodeOwnerReviews: false,
|
||||
requiredStatusCheckContexts: ['statusCheck'],
|
||||
});
|
||||
|
||||
await action.handler({
|
||||
...mockContext,
|
||||
input: {
|
||||
...mockContext.input,
|
||||
requiredStatusCheckContexts: [],
|
||||
},
|
||||
});
|
||||
|
||||
expect(enableBranchProtectionOnDefaultRepoBranch).toHaveBeenCalledWith({
|
||||
owner: 'owner',
|
||||
client: mockOctokit,
|
||||
repoName: 'repository',
|
||||
logger: mockContext.logger,
|
||||
defaultBranch: 'master',
|
||||
requireCodeOwnerReviews: false,
|
||||
requiredStatusCheckContexts: [],
|
||||
});
|
||||
});
|
||||
|
||||
it('should not call enableBranchProtectionOnDefaultRepoBranch with protectDefaultBranch disabled', async () => {
|
||||
mockOctokit.rest.repos.get.mockResolvedValue({
|
||||
data: {
|
||||
clone_url: 'https://github.com/clone/url.git',
|
||||
html_url: 'https://github.com/html/url',
|
||||
},
|
||||
});
|
||||
|
||||
await action.handler({
|
||||
...mockContext,
|
||||
input: {
|
||||
...mockContext.input,
|
||||
protectDefaultBranch: false,
|
||||
},
|
||||
});
|
||||
|
||||
expect(enableBranchProtectionOnDefaultRepoBranch).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* Copyright 2021 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { Config } from '@backstage/config';
|
||||
import { InputError } from '@backstage/errors';
|
||||
import {
|
||||
GithubCredentialsProvider,
|
||||
ScmIntegrationRegistry,
|
||||
} from '@backstage/integration';
|
||||
import { Octokit } from 'octokit';
|
||||
import { createTemplateAction } from '../../createTemplateAction';
|
||||
import { parseRepoUrl } from '../publish/util';
|
||||
import { getOctokitOptions, initRepoPushAndProtect } from './helpers';
|
||||
import * as inputProps from './inputProperties';
|
||||
import * as outputProps from './outputProperties';
|
||||
|
||||
/**
|
||||
* Creates a new action that initializes a git repository of the content in the workspace
|
||||
* and publishes it to GitHub.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export function createGithubRepoPushAction(options: {
|
||||
integrations: ScmIntegrationRegistry;
|
||||
config: Config;
|
||||
githubCredentialsProvider?: GithubCredentialsProvider;
|
||||
}) {
|
||||
const { integrations, config, githubCredentialsProvider } = options;
|
||||
|
||||
return createTemplateAction<{
|
||||
repoUrl: string;
|
||||
description?: string;
|
||||
defaultBranch?: string;
|
||||
protectDefaultBranch?: boolean;
|
||||
gitCommitMessage?: string;
|
||||
gitAuthorName?: string;
|
||||
gitAuthorEmail?: string;
|
||||
requireCodeOwnerReviews?: boolean;
|
||||
requiredStatusCheckContexts?: string[];
|
||||
sourcePath?: string;
|
||||
token?: string;
|
||||
}>({
|
||||
id: 'github:repo:push',
|
||||
description:
|
||||
'Initializes a git repository of contents in workspace and publishes it to GitHub.',
|
||||
schema: {
|
||||
input: {
|
||||
type: 'object',
|
||||
required: ['repoUrl'],
|
||||
properties: {
|
||||
repoUrl: inputProps.repoUrl,
|
||||
requireCodeOwnerReviews: inputProps.requireCodeOwnerReviews,
|
||||
requiredStatusCheckContexts: inputProps.requiredStatusCheckContexts,
|
||||
defaultBranch: inputProps.defaultBranch,
|
||||
protectDefaultBranch: inputProps.protectDefaultBranch,
|
||||
gitCommitMessage: inputProps.gitCommitMessage,
|
||||
gitAuthorName: inputProps.gitAuthorName,
|
||||
gitAuthorEmail: inputProps.gitAuthorEmail,
|
||||
sourcePath: inputProps.sourcePath,
|
||||
token: inputProps.token,
|
||||
},
|
||||
},
|
||||
output: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
remoteUrl: outputProps.remoteUrl,
|
||||
repoContentsUrl: outputProps.repoContentsUrl,
|
||||
},
|
||||
},
|
||||
},
|
||||
async handler(ctx) {
|
||||
const {
|
||||
repoUrl,
|
||||
defaultBranch = 'master',
|
||||
protectDefaultBranch = true,
|
||||
gitCommitMessage = 'initial commit',
|
||||
gitAuthorName,
|
||||
gitAuthorEmail,
|
||||
requireCodeOwnerReviews = false,
|
||||
requiredStatusCheckContexts = [],
|
||||
token: providedToken,
|
||||
} = ctx.input;
|
||||
|
||||
const { owner, repo } = parseRepoUrl(repoUrl, integrations);
|
||||
|
||||
if (!owner) {
|
||||
throw new InputError('Invalid repository owner provided in repoUrl');
|
||||
}
|
||||
|
||||
const octokitOptions = await getOctokitOptions({
|
||||
integrations,
|
||||
credentialsProvider: githubCredentialsProvider,
|
||||
token: providedToken,
|
||||
repoUrl,
|
||||
});
|
||||
|
||||
const client = new Octokit(octokitOptions);
|
||||
|
||||
const targetRepo = await client.rest.repos.get({ owner, repo });
|
||||
|
||||
const remoteUrl = targetRepo.data.clone_url;
|
||||
const repoContentsUrl = `${targetRepo.data.html_url}/blob/${defaultBranch}`;
|
||||
|
||||
await initRepoPushAndProtect(
|
||||
remoteUrl,
|
||||
octokitOptions.auth,
|
||||
ctx.workspacePath,
|
||||
ctx.input.sourcePath,
|
||||
defaultBranch,
|
||||
protectDefaultBranch,
|
||||
owner,
|
||||
client,
|
||||
repo,
|
||||
requireCodeOwnerReviews,
|
||||
requiredStatusCheckContexts,
|
||||
config,
|
||||
ctx.logger,
|
||||
gitCommitMessage,
|
||||
gitAuthorName,
|
||||
gitAuthorEmail,
|
||||
);
|
||||
|
||||
ctx.output('remoteUrl', remoteUrl);
|
||||
ctx.output('repoContentsUrl', repoContentsUrl);
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -13,14 +13,21 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { InputError } from '@backstage/errors';
|
||||
import { Config } from '@backstage/config';
|
||||
import { assertError, InputError } from '@backstage/errors';
|
||||
import {
|
||||
DefaultGithubCredentialsProvider,
|
||||
GithubCredentialsProvider,
|
||||
ScmIntegrationRegistry,
|
||||
} from '@backstage/integration';
|
||||
import { OctokitOptions } from '@octokit/core/dist-types/types';
|
||||
import { parseRepoUrl } from '../publish/util';
|
||||
import { Octokit } from 'octokit';
|
||||
import { Logger } from 'winston';
|
||||
import {
|
||||
enableBranchProtectionOnDefaultRepoBranch,
|
||||
initRepoAndPush,
|
||||
} from '../helpers';
|
||||
import { getRepoSourceDirectory, parseRepoUrl } from '../publish/util';
|
||||
|
||||
const DEFAULT_TIMEOUT_MS = 60_000;
|
||||
|
||||
@@ -83,3 +90,213 @@ export async function getOctokitOptions(options: {
|
||||
previews: ['nebula-preview'],
|
||||
};
|
||||
}
|
||||
|
||||
export async function createGithubRepoWithCollaboratorsAndTopics(
|
||||
client: Octokit,
|
||||
repo: string,
|
||||
owner: string,
|
||||
repoVisibility: 'private' | 'internal' | 'public',
|
||||
description: string | undefined,
|
||||
deleteBranchOnMerge: boolean,
|
||||
allowMergeCommit: boolean,
|
||||
allowSquashMerge: boolean,
|
||||
allowRebaseMerge: boolean,
|
||||
access: string | undefined,
|
||||
collaborators:
|
||||
| (
|
||||
| {
|
||||
user: string;
|
||||
access: 'pull' | 'push' | 'admin' | 'maintain' | 'triage';
|
||||
}
|
||||
| {
|
||||
team: string;
|
||||
access: 'pull' | 'push' | 'admin' | 'maintain' | 'triage';
|
||||
}
|
||||
| {
|
||||
/** @deprecated This field is deprecated in favor of team */
|
||||
username: string;
|
||||
access: 'pull' | 'push' | 'admin' | 'maintain' | 'triage';
|
||||
}
|
||||
)[]
|
||||
| undefined,
|
||||
topics: string[] | undefined,
|
||||
logger: Logger,
|
||||
) {
|
||||
const user = await client.rest.users.getByUsername({
|
||||
username: owner,
|
||||
});
|
||||
|
||||
const repoCreationPromise =
|
||||
user.data.type === 'Organization'
|
||||
? client.rest.repos.createInOrg({
|
||||
name: repo,
|
||||
org: owner,
|
||||
private: repoVisibility === 'private',
|
||||
visibility: repoVisibility,
|
||||
description: description,
|
||||
delete_branch_on_merge: deleteBranchOnMerge,
|
||||
allow_merge_commit: allowMergeCommit,
|
||||
allow_squash_merge: allowSquashMerge,
|
||||
allow_rebase_merge: allowRebaseMerge,
|
||||
})
|
||||
: client.rest.repos.createForAuthenticatedUser({
|
||||
name: repo,
|
||||
private: repoVisibility === 'private',
|
||||
description: description,
|
||||
delete_branch_on_merge: deleteBranchOnMerge,
|
||||
allow_merge_commit: allowMergeCommit,
|
||||
allow_squash_merge: allowSquashMerge,
|
||||
allow_rebase_merge: allowRebaseMerge,
|
||||
});
|
||||
|
||||
let newRepo;
|
||||
|
||||
try {
|
||||
newRepo = (await repoCreationPromise).data;
|
||||
} catch (e) {
|
||||
assertError(e);
|
||||
if (e.message === 'Resource not accessible by integration') {
|
||||
logger.warn(
|
||||
`The GitHub app or token provided may not have the required permissions to create the ${user.data.type} repository ${owner}/${repo}.`,
|
||||
);
|
||||
}
|
||||
throw new Error(
|
||||
`Failed to create the ${user.data.type} repository ${owner}/${repo}, ${e.message}`,
|
||||
);
|
||||
}
|
||||
|
||||
if (access?.startsWith(`${owner}/`)) {
|
||||
const [, team] = access.split('/');
|
||||
await client.rest.teams.addOrUpdateRepoPermissionsInOrg({
|
||||
org: owner,
|
||||
team_slug: team,
|
||||
owner,
|
||||
repo,
|
||||
permission: 'admin',
|
||||
});
|
||||
// No need to add access if it's the person who owns the personal account
|
||||
} else if (access && access !== owner) {
|
||||
await client.rest.repos.addCollaborator({
|
||||
owner,
|
||||
repo,
|
||||
username: access,
|
||||
permission: 'admin',
|
||||
});
|
||||
}
|
||||
|
||||
if (collaborators) {
|
||||
for (const collaborator of collaborators) {
|
||||
try {
|
||||
if ('user' in collaborator) {
|
||||
await client.rest.repos.addCollaborator({
|
||||
owner,
|
||||
repo,
|
||||
username: collaborator.user,
|
||||
permission: collaborator.access,
|
||||
});
|
||||
} else if ('team' in collaborator) {
|
||||
await client.rest.teams.addOrUpdateRepoPermissionsInOrg({
|
||||
org: owner,
|
||||
team_slug: collaborator.team,
|
||||
owner,
|
||||
repo,
|
||||
permission: collaborator.access,
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
assertError(e);
|
||||
const name = extractCollaboratorName(collaborator);
|
||||
logger.warn(
|
||||
`Skipping ${collaborator.access} access for ${name}, ${e.message}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (topics) {
|
||||
try {
|
||||
await client.rest.repos.replaceAllTopics({
|
||||
owner,
|
||||
repo,
|
||||
names: topics.map(t => t.toLowerCase()),
|
||||
});
|
||||
} catch (e) {
|
||||
assertError(e);
|
||||
logger.warn(`Skipping topics ${topics.join(' ')}, ${e.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
return newRepo;
|
||||
}
|
||||
|
||||
export async function initRepoPushAndProtect(
|
||||
remoteUrl: string,
|
||||
password: string,
|
||||
workspacePath: string,
|
||||
sourcePath: string | undefined,
|
||||
defaultBranch: string,
|
||||
protectDefaultBranch: boolean,
|
||||
owner: string,
|
||||
client: Octokit,
|
||||
repo: string,
|
||||
requireCodeOwnerReviews: boolean,
|
||||
requiredStatusCheckContexts: string[],
|
||||
config: Config,
|
||||
logger: any,
|
||||
gitCommitMessage?: string,
|
||||
gitAuthorName?: string,
|
||||
gitAuthorEmail?: string,
|
||||
) {
|
||||
const gitAuthorInfo = {
|
||||
name: gitAuthorName
|
||||
? gitAuthorName
|
||||
: config.getOptionalString('scaffolder.defaultAuthor.name'),
|
||||
email: gitAuthorEmail
|
||||
? gitAuthorEmail
|
||||
: config.getOptionalString('scaffolder.defaultAuthor.email'),
|
||||
};
|
||||
|
||||
const commitMessage = gitCommitMessage
|
||||
? gitCommitMessage
|
||||
: config.getOptionalString('scaffolder.defaultCommitMessage');
|
||||
|
||||
await initRepoAndPush({
|
||||
dir: getRepoSourceDirectory(workspacePath, sourcePath),
|
||||
remoteUrl,
|
||||
defaultBranch,
|
||||
auth: {
|
||||
username: 'x-access-token',
|
||||
password,
|
||||
},
|
||||
logger,
|
||||
commitMessage,
|
||||
gitAuthorInfo,
|
||||
});
|
||||
|
||||
if (protectDefaultBranch) {
|
||||
try {
|
||||
await enableBranchProtectionOnDefaultRepoBranch({
|
||||
owner,
|
||||
client,
|
||||
repoName: repo,
|
||||
logger,
|
||||
defaultBranch,
|
||||
requireCodeOwnerReviews,
|
||||
requiredStatusCheckContexts,
|
||||
});
|
||||
} catch (e) {
|
||||
assertError(e);
|
||||
logger.warn(
|
||||
`Skipping: default branch protection on '${repo}', ${e.message}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function extractCollaboratorName(
|
||||
collaborator: { user: string } | { team: string } | { username: string },
|
||||
) {
|
||||
if ('username' in collaborator) return collaborator.username;
|
||||
if ('user' in collaborator) return collaborator.user;
|
||||
return collaborator.team;
|
||||
}
|
||||
|
||||
@@ -15,5 +15,7 @@
|
||||
*/
|
||||
|
||||
export { createGithubActionsDispatchAction } from './githubActionsDispatch';
|
||||
export { createGithubWebhookAction } from './githubWebhook';
|
||||
export { createGithubIssuesLabelAction } from './githubIssuesLabel';
|
||||
export { createGithubRepoCreateAction } from './githubRepoCreate';
|
||||
export { createGithubRepoPushAction } from './githubRepoPush';
|
||||
export { createGithubWebhookAction } from './githubWebhook';
|
||||
|
||||
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
* Copyright 2021 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const repoUrl = {
|
||||
title: 'Repository Location',
|
||||
description: `Accepts the format 'github.com?repo=reponame&owner=owner' where 'reponame' is the new repository name and 'owner' is an organization or username`,
|
||||
type: 'string',
|
||||
};
|
||||
const description = {
|
||||
title: 'Repository Description',
|
||||
type: 'string',
|
||||
};
|
||||
const access = {
|
||||
title: 'Repository Access',
|
||||
description: `Sets an admin collaborator on the repository. Can either be a user reference different from 'owner' in 'repoUrl' or team reference, eg. 'org/team-name'`,
|
||||
type: 'string',
|
||||
};
|
||||
const requireCodeOwnerReviews = {
|
||||
title: 'Require CODEOWNER Reviews?',
|
||||
description:
|
||||
'Require an approved review in PR including files with a designated Code Owner',
|
||||
type: 'boolean',
|
||||
};
|
||||
const requiredStatusCheckContexts = {
|
||||
title: 'Required Status Check Contexts',
|
||||
description:
|
||||
'The list of status checks to require in order to merge into this branch',
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string',
|
||||
},
|
||||
};
|
||||
const repoVisibility = {
|
||||
title: 'Repository Visibility',
|
||||
type: 'string',
|
||||
enum: ['private', 'public', 'internal'],
|
||||
};
|
||||
const deleteBranchOnMerge = {
|
||||
title: 'Delete Branch On Merge',
|
||||
type: 'boolean',
|
||||
description: `Delete the branch after merging the PR. The default value is 'false'`,
|
||||
};
|
||||
const gitAuthorName = {
|
||||
title: 'Default Author Name',
|
||||
type: 'string',
|
||||
description: `Sets the default author name for the commit. The default value is 'Scaffolder'`,
|
||||
};
|
||||
const gitAuthorEmail = {
|
||||
title: 'Default Author Email',
|
||||
type: 'string',
|
||||
description: `Sets the default author email for the commit.`,
|
||||
};
|
||||
const allowMergeCommit = {
|
||||
title: 'Allow Merge Commits',
|
||||
type: 'boolean',
|
||||
description: `Allow merge commits. The default value is 'true'`,
|
||||
};
|
||||
const allowSquashMerge = {
|
||||
title: 'Allow Squash Merges',
|
||||
type: 'boolean',
|
||||
description: `Allow squash merges. The default value is 'true'`,
|
||||
};
|
||||
const allowRebaseMerge = {
|
||||
title: 'Allow Rebase Merges',
|
||||
type: 'boolean',
|
||||
description: `Allow rebase merges. The default value is 'true'`,
|
||||
};
|
||||
const collaborators = {
|
||||
title: 'Collaborators',
|
||||
description: 'Provide additional users or teams with permissions',
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'object',
|
||||
additionalProperties: false,
|
||||
required: ['access'],
|
||||
properties: {
|
||||
access: {
|
||||
type: 'string',
|
||||
description: 'The type of access for the user',
|
||||
enum: ['push', 'pull', 'admin', 'maintain', 'triage'],
|
||||
},
|
||||
user: {
|
||||
type: 'string',
|
||||
description:
|
||||
'The name of the user that will be added as a collaborator',
|
||||
},
|
||||
team: {
|
||||
type: 'string',
|
||||
description:
|
||||
'The name of the team that will be added as a collaborator',
|
||||
},
|
||||
},
|
||||
oneOf: [{ required: ['user'] }, { required: ['team'] }],
|
||||
},
|
||||
};
|
||||
const token = {
|
||||
title: 'Authentication Token',
|
||||
type: 'string',
|
||||
description: 'The token to use for authorization to GitHub',
|
||||
};
|
||||
const topics = {
|
||||
title: 'Topics',
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string',
|
||||
},
|
||||
};
|
||||
const defaultBranch = {
|
||||
title: 'Default Branch',
|
||||
type: 'string',
|
||||
description: `Sets the default branch on the repository. The default value is 'master'`,
|
||||
};
|
||||
const protectDefaultBranch = {
|
||||
title: 'Protect Default Branch',
|
||||
type: 'boolean',
|
||||
description: `Protect the default branch after creating the repository. The default value is 'true'`,
|
||||
};
|
||||
const gitCommitMessage = {
|
||||
title: 'Git Commit Message',
|
||||
type: 'string',
|
||||
description: `Sets the commit message on the repository. The default value is 'initial commit'`,
|
||||
};
|
||||
const sourcePath = {
|
||||
title: 'Source Path',
|
||||
description:
|
||||
'Path within the workspace that will be used as the repository root. If omitted, the entire workspace will be published as the repository.',
|
||||
type: 'string',
|
||||
};
|
||||
|
||||
export { access };
|
||||
export { allowMergeCommit };
|
||||
export { allowRebaseMerge };
|
||||
export { allowSquashMerge };
|
||||
export { collaborators };
|
||||
export { defaultBranch };
|
||||
export { deleteBranchOnMerge };
|
||||
export { description };
|
||||
export { gitAuthorEmail };
|
||||
export { gitAuthorName };
|
||||
export { gitCommitMessage };
|
||||
export { protectDefaultBranch };
|
||||
export { repoUrl };
|
||||
export { repoVisibility };
|
||||
export { requireCodeOwnerReviews };
|
||||
export { requiredStatusCheckContexts };
|
||||
export { sourcePath };
|
||||
export { token };
|
||||
export { topics };
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2021 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const remoteUrl = {
|
||||
title: 'A URL to the repository with the provider',
|
||||
type: 'string',
|
||||
};
|
||||
const repoContentsUrl = {
|
||||
title: 'A URL to the root of the repository',
|
||||
type: 'string',
|
||||
};
|
||||
|
||||
export { remoteUrl };
|
||||
export { repoContentsUrl };
|
||||
@@ -14,12 +14,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { SpawnOptionsWithoutStdio, spawn } from 'child_process';
|
||||
import { Git } from '@backstage/backend-common';
|
||||
import { Config } from '@backstage/config';
|
||||
import { assertError } from '@backstage/errors';
|
||||
import { spawn, SpawnOptionsWithoutStdio } from 'child_process';
|
||||
import { Octokit } from 'octokit';
|
||||
import { PassThrough, Writable } from 'stream';
|
||||
import { Logger } from 'winston';
|
||||
import { Git } from '@backstage/backend-common';
|
||||
import { Octokit } from 'octokit';
|
||||
import { assertError } from '@backstage/errors';
|
||||
|
||||
/** @public */
|
||||
export type RunCommandOptions = {
|
||||
@@ -200,3 +201,12 @@ export const enableBranchProtectionOnDefaultRepoBranch = async ({
|
||||
await tryOnce();
|
||||
}
|
||||
};
|
||||
|
||||
export function getGitCommitMessage(
|
||||
gitCommitMessage: string | undefined,
|
||||
config: Config,
|
||||
): string | undefined {
|
||||
return gitCommitMessage
|
||||
? gitCommitMessage
|
||||
: config.getOptionalString('scaffolder.defaultCommitMessage');
|
||||
}
|
||||
|
||||
@@ -18,20 +18,20 @@ import { TemplateAction } from '../../types';
|
||||
|
||||
jest.mock('../helpers');
|
||||
|
||||
import { createPublishGithubAction } from './github';
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import {
|
||||
ScmIntegrations,
|
||||
DefaultGithubCredentialsProvider,
|
||||
GithubCredentialsProvider,
|
||||
ScmIntegrations,
|
||||
} from '@backstage/integration';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { when } from 'jest-when';
|
||||
import { PassThrough } from 'stream';
|
||||
import {
|
||||
enableBranchProtectionOnDefaultRepoBranch,
|
||||
initRepoAndPush,
|
||||
} from '../helpers';
|
||||
import { when } from 'jest-when';
|
||||
import { createPublishGithubAction } from './github';
|
||||
|
||||
const mockOctokit = {
|
||||
rest: {
|
||||
@@ -609,7 +609,7 @@ describe('publish:github', () => {
|
||||
|
||||
mockOctokit.rest.repos.createForAuthenticatedUser.mockResolvedValue({
|
||||
data: {
|
||||
name: 'repository',
|
||||
name: 'repo',
|
||||
},
|
||||
});
|
||||
|
||||
@@ -618,7 +618,7 @@ describe('publish:github', () => {
|
||||
expect(enableBranchProtectionOnDefaultRepoBranch).toHaveBeenCalledWith({
|
||||
owner: 'owner',
|
||||
client: mockOctokit,
|
||||
repoName: 'repository',
|
||||
repoName: 'repo',
|
||||
logger: mockContext.logger,
|
||||
defaultBranch: 'master',
|
||||
requireCodeOwnerReviews: false,
|
||||
@@ -636,7 +636,7 @@ describe('publish:github', () => {
|
||||
expect(enableBranchProtectionOnDefaultRepoBranch).toHaveBeenCalledWith({
|
||||
owner: 'owner',
|
||||
client: mockOctokit,
|
||||
repoName: 'repository',
|
||||
repoName: 'repo',
|
||||
logger: mockContext.logger,
|
||||
defaultBranch: 'master',
|
||||
requireCodeOwnerReviews: true,
|
||||
@@ -654,7 +654,7 @@ describe('publish:github', () => {
|
||||
expect(enableBranchProtectionOnDefaultRepoBranch).toHaveBeenCalledWith({
|
||||
owner: 'owner',
|
||||
client: mockOctokit,
|
||||
repoName: 'repository',
|
||||
repoName: 'repo',
|
||||
logger: mockContext.logger,
|
||||
defaultBranch: 'master',
|
||||
requireCodeOwnerReviews: false,
|
||||
@@ -669,7 +669,7 @@ describe('publish:github', () => {
|
||||
|
||||
mockOctokit.rest.repos.createForAuthenticatedUser.mockResolvedValue({
|
||||
data: {
|
||||
name: 'repository',
|
||||
name: 'repo',
|
||||
},
|
||||
});
|
||||
|
||||
@@ -678,7 +678,7 @@ describe('publish:github', () => {
|
||||
expect(enableBranchProtectionOnDefaultRepoBranch).toHaveBeenCalledWith({
|
||||
owner: 'owner',
|
||||
client: mockOctokit,
|
||||
repoName: 'repository',
|
||||
repoName: 'repo',
|
||||
logger: mockContext.logger,
|
||||
defaultBranch: 'master',
|
||||
requireCodeOwnerReviews: false,
|
||||
@@ -696,7 +696,7 @@ describe('publish:github', () => {
|
||||
expect(enableBranchProtectionOnDefaultRepoBranch).toHaveBeenCalledWith({
|
||||
owner: 'owner',
|
||||
client: mockOctokit,
|
||||
repoName: 'repository',
|
||||
repoName: 'repo',
|
||||
logger: mockContext.logger,
|
||||
defaultBranch: 'master',
|
||||
requireCodeOwnerReviews: false,
|
||||
@@ -714,7 +714,7 @@ describe('publish:github', () => {
|
||||
expect(enableBranchProtectionOnDefaultRepoBranch).toHaveBeenCalledWith({
|
||||
owner: 'owner',
|
||||
client: mockOctokit,
|
||||
repoName: 'repository',
|
||||
repoName: 'repo',
|
||||
logger: mockContext.logger,
|
||||
defaultBranch: 'master',
|
||||
requireCodeOwnerReviews: false,
|
||||
@@ -729,7 +729,7 @@ describe('publish:github', () => {
|
||||
|
||||
mockOctokit.rest.repos.createForAuthenticatedUser.mockResolvedValue({
|
||||
data: {
|
||||
name: 'repository',
|
||||
name: 'repo',
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -13,21 +13,22 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { Config } from '@backstage/config';
|
||||
import { InputError } from '@backstage/errors';
|
||||
import {
|
||||
GithubCredentialsProvider,
|
||||
ScmIntegrationRegistry,
|
||||
} from '@backstage/integration';
|
||||
import {
|
||||
enableBranchProtectionOnDefaultRepoBranch,
|
||||
initRepoAndPush,
|
||||
} from '../helpers';
|
||||
import { getRepoSourceDirectory, parseRepoUrl } from './util';
|
||||
import { createTemplateAction } from '../../createTemplateAction';
|
||||
import { Config } from '@backstage/config';
|
||||
import { assertError, InputError } from '@backstage/errors';
|
||||
import { getOctokitOptions } from '../github/helpers';
|
||||
import { Octokit } from 'octokit';
|
||||
|
||||
import { createTemplateAction } from '../../createTemplateAction';
|
||||
import {
|
||||
createGithubRepoWithCollaboratorsAndTopics,
|
||||
getOctokitOptions,
|
||||
initRepoPushAndProtect,
|
||||
} from '../github/helpers';
|
||||
import * as inputProps from '../github/inputProperties';
|
||||
import * as outputProps from '../github/outputProperties';
|
||||
import { parseRepoUrl } from './util';
|
||||
/**
|
||||
* Creates a new action that initializes a git repository of the content in the workspace
|
||||
* and publishes it to GitHub.
|
||||
@@ -84,153 +85,32 @@ export function createPublishGithubAction(options: {
|
||||
type: 'object',
|
||||
required: ['repoUrl'],
|
||||
properties: {
|
||||
repoUrl: {
|
||||
title: 'Repository Location',
|
||||
description: `Accepts the format 'github.com?repo=reponame&owner=owner' where 'reponame' is the new repository name and 'owner' is an organization or username`,
|
||||
type: 'string',
|
||||
},
|
||||
description: {
|
||||
title: 'Repository Description',
|
||||
type: 'string',
|
||||
},
|
||||
access: {
|
||||
title: 'Repository Access',
|
||||
description: `Sets an admin collaborator on the repository. Can either be a user reference different from 'owner' in 'repoUrl' or team reference, eg. 'org/team-name'`,
|
||||
type: 'string',
|
||||
},
|
||||
requireCodeOwnerReviews: {
|
||||
title: 'Require CODEOWNER Reviews?',
|
||||
description:
|
||||
'Require an approved review in PR including files with a designated Code Owner',
|
||||
type: 'boolean',
|
||||
},
|
||||
requiredStatusCheckContexts: {
|
||||
title: 'Required Status Check Contexts',
|
||||
description:
|
||||
'The list of status checks to require in order to merge into this branch',
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
repoVisibility: {
|
||||
title: 'Repository Visibility',
|
||||
type: 'string',
|
||||
enum: ['private', 'public', 'internal'],
|
||||
},
|
||||
defaultBranch: {
|
||||
title: 'Default Branch',
|
||||
type: 'string',
|
||||
description: `Sets the default branch on the repository. The default value is 'master'`,
|
||||
},
|
||||
protectDefaultBranch: {
|
||||
title: 'Protect Default Branch',
|
||||
type: 'boolean',
|
||||
description: `Protect the default branch after creating the repository. The default value is 'true'`,
|
||||
},
|
||||
deleteBranchOnMerge: {
|
||||
title: 'Delete Branch On Merge',
|
||||
type: 'boolean',
|
||||
description: `Delete the branch after merging the PR. The default value is 'false'`,
|
||||
},
|
||||
gitCommitMessage: {
|
||||
title: 'Git Commit Message',
|
||||
type: 'string',
|
||||
description: `Sets the commit message on the repository. The default value is 'initial commit'`,
|
||||
},
|
||||
gitAuthorName: {
|
||||
title: 'Default Author Name',
|
||||
type: 'string',
|
||||
description: `Sets the default author name for the commit. The default value is 'Scaffolder'`,
|
||||
},
|
||||
gitAuthorEmail: {
|
||||
title: 'Default Author Email',
|
||||
type: 'string',
|
||||
description: `Sets the default author email for the commit.`,
|
||||
},
|
||||
allowMergeCommit: {
|
||||
title: 'Allow Merge Commits',
|
||||
type: 'boolean',
|
||||
description: `Allow merge commits. The default value is 'true'`,
|
||||
},
|
||||
allowSquashMerge: {
|
||||
title: 'Allow Squash Merges',
|
||||
type: 'boolean',
|
||||
description: `Allow squash merges. The default value is 'true'`,
|
||||
},
|
||||
allowRebaseMerge: {
|
||||
title: 'Allow Rebase Merges',
|
||||
type: 'boolean',
|
||||
description: `Allow rebase merges. The default value is 'true'`,
|
||||
},
|
||||
sourcePath: {
|
||||
title: 'Source Path',
|
||||
description:
|
||||
'Path within the workspace that will be used as the repository root. If omitted, the entire workspace will be published as the repository.',
|
||||
type: 'string',
|
||||
},
|
||||
collaborators: {
|
||||
title: 'Collaborators',
|
||||
description: 'Provide additional users or teams with permissions',
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'object',
|
||||
additionalProperties: false,
|
||||
required: ['access'],
|
||||
properties: {
|
||||
access: {
|
||||
type: 'string',
|
||||
description: 'The type of access for the user',
|
||||
enum: ['push', 'pull', 'admin', 'maintain', 'triage'],
|
||||
},
|
||||
user: {
|
||||
type: 'string',
|
||||
description:
|
||||
'The name of the user that will be added as a collaborator',
|
||||
},
|
||||
username: {
|
||||
type: 'string',
|
||||
description:
|
||||
'Deprecated. Use the `team` or `user` field instead.',
|
||||
},
|
||||
team: {
|
||||
type: 'string',
|
||||
description:
|
||||
'The name of the team that will be added as a collaborator',
|
||||
},
|
||||
},
|
||||
oneOf: [
|
||||
{ required: ['user'] },
|
||||
{ required: ['username'] },
|
||||
{ required: ['team'] },
|
||||
],
|
||||
},
|
||||
},
|
||||
token: {
|
||||
title: 'Authentication Token',
|
||||
type: 'string',
|
||||
description: 'The token to use for authorization to GitHub',
|
||||
},
|
||||
topics: {
|
||||
title: 'Topics',
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
repoUrl: inputProps.repoUrl,
|
||||
description: inputProps.description,
|
||||
access: inputProps.access,
|
||||
requireCodeOwnerReviews: inputProps.requireCodeOwnerReviews,
|
||||
requiredStatusCheckContexts: inputProps.requiredStatusCheckContexts,
|
||||
repoVisibility: inputProps.repoVisibility,
|
||||
defaultBranch: inputProps.defaultBranch,
|
||||
protectDefaultBranch: inputProps.protectDefaultBranch,
|
||||
deleteBranchOnMerge: inputProps.deleteBranchOnMerge,
|
||||
gitCommitMessage: inputProps.gitCommitMessage,
|
||||
gitAuthorName: inputProps.gitAuthorName,
|
||||
gitAuthorEmail: inputProps.gitAuthorEmail,
|
||||
allowMergeCommit: inputProps.allowMergeCommit,
|
||||
allowSquashMerge: inputProps.allowSquashMerge,
|
||||
allowRebaseMerge: inputProps.allowRebaseMerge,
|
||||
sourcePath: inputProps.sourcePath,
|
||||
collaborators: inputProps.collaborators,
|
||||
token: inputProps.token,
|
||||
topics: inputProps.topics,
|
||||
},
|
||||
},
|
||||
output: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
remoteUrl: {
|
||||
title: 'A URL to the repository with the provider',
|
||||
type: 'string',
|
||||
},
|
||||
repoContentsUrl: {
|
||||
title: 'A URL to the root of the repository',
|
||||
type: 'string',
|
||||
},
|
||||
remoteUrl: outputProps.remoteUrl,
|
||||
repoContentsUrl: outputProps.repoContentsUrl,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -256,192 +136,60 @@ export function createPublishGithubAction(options: {
|
||||
token: providedToken,
|
||||
} = ctx.input;
|
||||
|
||||
const octokitOptions = await getOctokitOptions({
|
||||
integrations,
|
||||
credentialsProvider: githubCredentialsProvider,
|
||||
token: providedToken,
|
||||
repoUrl: repoUrl,
|
||||
});
|
||||
const client = new Octokit(octokitOptions);
|
||||
|
||||
const { owner, repo } = parseRepoUrl(repoUrl, integrations);
|
||||
|
||||
if (!owner) {
|
||||
throw new InputError('Invalid repository owner provided in repoUrl');
|
||||
}
|
||||
|
||||
const octokitOptions = await getOctokitOptions({
|
||||
integrations,
|
||||
credentialsProvider: githubCredentialsProvider,
|
||||
token: providedToken,
|
||||
repoUrl,
|
||||
});
|
||||
|
||||
const client = new Octokit(octokitOptions);
|
||||
|
||||
const user = await client.rest.users.getByUsername({
|
||||
username: owner,
|
||||
});
|
||||
|
||||
const repoCreationPromise =
|
||||
user.data.type === 'Organization'
|
||||
? client.rest.repos.createInOrg({
|
||||
name: repo,
|
||||
org: owner,
|
||||
private: repoVisibility === 'private',
|
||||
visibility: repoVisibility,
|
||||
description: description,
|
||||
delete_branch_on_merge: deleteBranchOnMerge,
|
||||
allow_merge_commit: allowMergeCommit,
|
||||
allow_squash_merge: allowSquashMerge,
|
||||
allow_rebase_merge: allowRebaseMerge,
|
||||
})
|
||||
: client.rest.repos.createForAuthenticatedUser({
|
||||
name: repo,
|
||||
private: repoVisibility === 'private',
|
||||
description: description,
|
||||
delete_branch_on_merge: deleteBranchOnMerge,
|
||||
allow_merge_commit: allowMergeCommit,
|
||||
allow_squash_merge: allowSquashMerge,
|
||||
allow_rebase_merge: allowRebaseMerge,
|
||||
});
|
||||
|
||||
let newRepo;
|
||||
|
||||
try {
|
||||
newRepo = (await repoCreationPromise).data;
|
||||
} catch (e) {
|
||||
assertError(e);
|
||||
if (e.message === 'Resource not accessible by integration') {
|
||||
ctx.logger.warn(
|
||||
`The GitHub app or token provided may not have the required permissions to create the ${user.data.type} repository ${owner}/${repo}.`,
|
||||
);
|
||||
}
|
||||
throw new Error(
|
||||
`Failed to create the ${user.data.type} repository ${owner}/${repo}, ${e.message}`,
|
||||
);
|
||||
}
|
||||
|
||||
if (access?.startsWith(`${owner}/`)) {
|
||||
const [, team] = access.split('/');
|
||||
await client.rest.teams.addOrUpdateRepoPermissionsInOrg({
|
||||
org: owner,
|
||||
team_slug: team,
|
||||
owner,
|
||||
repo,
|
||||
permission: 'admin',
|
||||
});
|
||||
// No need to add access if it's the person who owns the personal account
|
||||
} else if (access && access !== owner) {
|
||||
await client.rest.repos.addCollaborator({
|
||||
owner,
|
||||
repo,
|
||||
username: access,
|
||||
permission: 'admin',
|
||||
});
|
||||
}
|
||||
|
||||
if (collaborators) {
|
||||
for (const collaborator of collaborators) {
|
||||
try {
|
||||
if ('user' in collaborator) {
|
||||
await client.rest.repos.addCollaborator({
|
||||
owner,
|
||||
repo,
|
||||
username: collaborator.user,
|
||||
permission: collaborator.access,
|
||||
});
|
||||
} else if ('username' in collaborator) {
|
||||
ctx.logger.warn(
|
||||
'The field `username` is deprecated in favor of `team` and will be removed in the future.',
|
||||
);
|
||||
await client.rest.teams.addOrUpdateRepoPermissionsInOrg({
|
||||
org: owner,
|
||||
team_slug: collaborator.username,
|
||||
owner,
|
||||
repo,
|
||||
permission: collaborator.access,
|
||||
});
|
||||
} else if ('team' in collaborator) {
|
||||
await client.rest.teams.addOrUpdateRepoPermissionsInOrg({
|
||||
org: owner,
|
||||
team_slug: collaborator.team,
|
||||
owner,
|
||||
repo,
|
||||
permission: collaborator.access,
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
assertError(e);
|
||||
const name = extractCollaboratorName(collaborator);
|
||||
ctx.logger.warn(
|
||||
`Skipping ${collaborator.access} access for ${name}, ${e.message}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (topics) {
|
||||
try {
|
||||
await client.rest.repos.replaceAllTopics({
|
||||
owner,
|
||||
repo,
|
||||
names: topics.map(t => t.toLowerCase()),
|
||||
});
|
||||
} catch (e) {
|
||||
assertError(e);
|
||||
ctx.logger.warn(`Skipping topics ${topics.join(' ')}, ${e.message}`);
|
||||
}
|
||||
}
|
||||
const newRepo = await createGithubRepoWithCollaboratorsAndTopics(
|
||||
client,
|
||||
repo,
|
||||
owner,
|
||||
repoVisibility,
|
||||
description,
|
||||
deleteBranchOnMerge,
|
||||
allowMergeCommit,
|
||||
allowSquashMerge,
|
||||
allowRebaseMerge,
|
||||
access,
|
||||
collaborators,
|
||||
topics,
|
||||
ctx.logger,
|
||||
);
|
||||
|
||||
const remoteUrl = newRepo.clone_url;
|
||||
const repoContentsUrl = `${newRepo.html_url}/blob/${defaultBranch}`;
|
||||
|
||||
const gitAuthorInfo = {
|
||||
name: gitAuthorName
|
||||
? gitAuthorName
|
||||
: config.getOptionalString('scaffolder.defaultAuthor.name'),
|
||||
email: gitAuthorEmail
|
||||
? gitAuthorEmail
|
||||
: config.getOptionalString('scaffolder.defaultAuthor.email'),
|
||||
};
|
||||
|
||||
await initRepoAndPush({
|
||||
dir: getRepoSourceDirectory(ctx.workspacePath, ctx.input.sourcePath),
|
||||
await initRepoPushAndProtect(
|
||||
remoteUrl,
|
||||
octokitOptions.auth,
|
||||
ctx.workspacePath,
|
||||
ctx.input.sourcePath,
|
||||
defaultBranch,
|
||||
auth: {
|
||||
username: 'x-access-token',
|
||||
password: octokitOptions.auth,
|
||||
},
|
||||
logger: ctx.logger,
|
||||
commitMessage: gitCommitMessage
|
||||
? gitCommitMessage
|
||||
: config.getOptionalString('scaffolder.defaultCommitMessage'),
|
||||
gitAuthorInfo,
|
||||
});
|
||||
|
||||
if (protectDefaultBranch) {
|
||||
try {
|
||||
await enableBranchProtectionOnDefaultRepoBranch({
|
||||
owner,
|
||||
client,
|
||||
repoName: newRepo.name,
|
||||
logger: ctx.logger,
|
||||
defaultBranch,
|
||||
requireCodeOwnerReviews,
|
||||
requiredStatusCheckContexts,
|
||||
});
|
||||
} catch (e) {
|
||||
assertError(e);
|
||||
ctx.logger.warn(
|
||||
`Skipping: default branch protection on '${newRepo.name}', ${e.message}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
protectDefaultBranch,
|
||||
owner,
|
||||
client,
|
||||
repo,
|
||||
requireCodeOwnerReviews,
|
||||
requiredStatusCheckContexts,
|
||||
config,
|
||||
ctx.logger,
|
||||
gitCommitMessage,
|
||||
gitAuthorName,
|
||||
gitAuthorEmail,
|
||||
);
|
||||
|
||||
ctx.output('remoteUrl', remoteUrl);
|
||||
ctx.output('repoContentsUrl', repoContentsUrl);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function extractCollaboratorName(
|
||||
collaborator: { user: string } | { team: string } | { username: string },
|
||||
) {
|
||||
if ('username' in collaborator) return collaborator.username;
|
||||
if ('user' in collaborator) return collaborator.user;
|
||||
return collaborator.team;
|
||||
}
|
||||
|
||||
+207
@@ -0,0 +1,207 @@
|
||||
/*
|
||||
* Copyright 2022 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { getRootLogger } from '@backstage/backend-common';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { ScmIntegrations } from '@backstage/integration';
|
||||
import mockFs from 'mock-fs';
|
||||
import os from 'os';
|
||||
import { resolve as resolvePath } from 'path';
|
||||
import { Writable } from 'stream';
|
||||
import { TemplateAction } from '../../types';
|
||||
import { createPublishGitlabMergeRequestAction } from './gitlabMergeRequest';
|
||||
|
||||
const root = os.platform() === 'win32' ? 'C:\\root' : '/root';
|
||||
const workspacePath = resolvePath(root, 'my-workspace');
|
||||
|
||||
const mockGitlabClient = {
|
||||
Namespaces: {
|
||||
show: jest.fn(),
|
||||
},
|
||||
Branches: {
|
||||
create: jest.fn(),
|
||||
},
|
||||
Commits: {
|
||||
create: jest.fn(),
|
||||
},
|
||||
MergeRequests: {
|
||||
create: jest.fn(async (_: any) => {
|
||||
return {
|
||||
default_branch: 'main',
|
||||
};
|
||||
}),
|
||||
},
|
||||
Projects: {
|
||||
create: jest.fn(),
|
||||
show: jest.fn(async (_: any) => {
|
||||
return {
|
||||
default_branch: 'main',
|
||||
};
|
||||
}),
|
||||
},
|
||||
Users: {
|
||||
current: jest.fn(),
|
||||
},
|
||||
};
|
||||
|
||||
jest.mock('@gitbeaker/node', () => ({
|
||||
Gitlab: class {
|
||||
constructor() {
|
||||
return mockGitlabClient;
|
||||
}
|
||||
},
|
||||
}));
|
||||
|
||||
describe('createGitLabMergeRequest', () => {
|
||||
let instance: TemplateAction<any>;
|
||||
|
||||
beforeEach(() => {
|
||||
const config = new ConfigReader({
|
||||
integrations: {
|
||||
gitlab: [
|
||||
{
|
||||
host: 'gitlab.com',
|
||||
token: 'token',
|
||||
apiBaseUrl: 'https://api.gitlab.com',
|
||||
},
|
||||
{
|
||||
host: 'hosted.gitlab.com',
|
||||
apiBaseUrl: 'https://api.hosted.gitlab.com',
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
const integrations = ScmIntegrations.fromConfig(config);
|
||||
instance = createPublishGitlabMergeRequestAction({ integrations });
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
mockFs.restore();
|
||||
});
|
||||
|
||||
describe('createGitLabMergeRequestWithoutRemoveBranch', () => {
|
||||
it('removeSourceBranch is false by default when not passed in options', async () => {
|
||||
const input = {
|
||||
repoUrl: 'gitlab.com?repo=repo&owner=owner',
|
||||
title: 'Create my new MR',
|
||||
branchName: 'new-mr',
|
||||
description: 'This MR is really good',
|
||||
draft: true,
|
||||
targetPath: 'Subdirectory',
|
||||
};
|
||||
mockFs({
|
||||
[workspacePath]: {
|
||||
source: { 'foo.txt': 'Hello there!' },
|
||||
irrelevant: { 'bar.txt': 'Nothing to see here' },
|
||||
},
|
||||
});
|
||||
const ctx = {
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
output: jest.fn(),
|
||||
logger: getRootLogger(),
|
||||
logStream: new Writable(),
|
||||
input,
|
||||
workspacePath,
|
||||
};
|
||||
await instance.handler(ctx);
|
||||
|
||||
expect(mockGitlabClient.MergeRequests.create).toHaveBeenCalledWith(
|
||||
'owner/repo',
|
||||
'new-mr',
|
||||
'main',
|
||||
'Create my new MR',
|
||||
{ description: 'This MR is really good', removeSourceBranch: false },
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('createGitLabMergeRequestWithRemoveBranch', () => {
|
||||
it('removeSourceBranch is true when true is passed in options', async () => {
|
||||
const input = {
|
||||
repoUrl: 'gitlab.com?repo=repo&owner=owner',
|
||||
title: 'Create my new MR',
|
||||
branchName: 'new-mr',
|
||||
description: 'MR description',
|
||||
removeSourceBranch: true,
|
||||
draft: true,
|
||||
targetPath: 'Subdirectory',
|
||||
};
|
||||
mockFs({
|
||||
[workspacePath]: {
|
||||
source: { 'foo.txt': 'Hello there!' },
|
||||
irrelevant: { 'bar.txt': 'Nothing to see here' },
|
||||
},
|
||||
});
|
||||
|
||||
const ctx = {
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
output: jest.fn(),
|
||||
logger: getRootLogger(),
|
||||
logStream: new Writable(),
|
||||
input,
|
||||
workspacePath,
|
||||
};
|
||||
await instance.handler(ctx);
|
||||
|
||||
expect(mockGitlabClient.MergeRequests.create).toHaveBeenCalledWith(
|
||||
'owner/repo',
|
||||
'new-mr',
|
||||
'main',
|
||||
'Create my new MR',
|
||||
{ description: 'MR description', removeSourceBranch: true },
|
||||
);
|
||||
});
|
||||
|
||||
it('removeSourceBranch is false when false is passed in options', async () => {
|
||||
const input = {
|
||||
repoUrl: 'gitlab.com?repo=repo&owner=owner',
|
||||
title: 'Create my new MR',
|
||||
branchName: 'new-mr',
|
||||
description: 'other MR description',
|
||||
removeSourceBranch: false,
|
||||
draft: true,
|
||||
targetPath: 'Subdirectory',
|
||||
};
|
||||
mockFs({
|
||||
[workspacePath]: {
|
||||
source: { 'foo.txt': 'Hello there!' },
|
||||
irrelevant: { 'bar.txt': 'Nothing to see here' },
|
||||
},
|
||||
});
|
||||
|
||||
const ctx = {
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
output: jest.fn(),
|
||||
logger: getRootLogger(),
|
||||
logStream: new Writable(),
|
||||
input,
|
||||
workspacePath,
|
||||
};
|
||||
await instance.handler(ctx);
|
||||
|
||||
expect(mockGitlabClient.MergeRequests.create).toHaveBeenCalledWith(
|
||||
'owner/repo',
|
||||
'new-mr',
|
||||
'main',
|
||||
'Create my new MR',
|
||||
{
|
||||
description: 'other MR description',
|
||||
removeSourceBranch: false,
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
+13
-1
@@ -42,6 +42,7 @@ export const createPublishGitlabMergeRequestAction = (options: {
|
||||
token?: string;
|
||||
/** @deprecated Use projectPath instead */
|
||||
projectid?: string;
|
||||
removeSourceBranch?: boolean;
|
||||
}>({
|
||||
id: 'publish:gitlab:merge-request',
|
||||
schema: {
|
||||
@@ -85,6 +86,12 @@ export const createPublishGitlabMergeRequestAction = (options: {
|
||||
type: 'string',
|
||||
description: 'The token to use for authorization to GitLab',
|
||||
},
|
||||
removeSourceBranch: {
|
||||
title: 'Delete source branch',
|
||||
type: 'boolean',
|
||||
description:
|
||||
'Option to delete source branch once the MR has been merged. Default: false',
|
||||
},
|
||||
},
|
||||
},
|
||||
output: {
|
||||
@@ -187,7 +194,12 @@ export const createPublishGitlabMergeRequestAction = (options: {
|
||||
destinationBranch,
|
||||
String(defaultBranch),
|
||||
ctx.input.title,
|
||||
{ description: ctx.input.description },
|
||||
{
|
||||
description: ctx.input.description,
|
||||
removeSourceBranch: ctx.input.removeSourceBranch
|
||||
? ctx.input.removeSourceBranch
|
||||
: false,
|
||||
},
|
||||
).then((mergeRequest: { web_url: string }) => {
|
||||
return mergeRequest.web_url;
|
||||
});
|
||||
|
||||
@@ -153,6 +153,8 @@ export const OwnedEntityPickerFieldExtension: FieldExtensionComponent<
|
||||
|
||||
// @public
|
||||
export interface OwnedEntityPickerUiOptions {
|
||||
// (undocumented)
|
||||
allowArbitraryValues?: boolean;
|
||||
// (undocumented)
|
||||
allowedKinds?: string[];
|
||||
// (undocumented)
|
||||
@@ -193,6 +195,8 @@ export interface RepoUrlPickerUiOptions {
|
||||
// (undocumented)
|
||||
allowedOwners?: string[];
|
||||
// (undocumented)
|
||||
allowedRepos?: string[];
|
||||
// (undocumented)
|
||||
requestUserCredentials?: {
|
||||
secretsKey: string;
|
||||
additionalScopes?: {
|
||||
|
||||
@@ -37,6 +37,7 @@ import { FieldExtensionComponentProps } from '../../../extensions';
|
||||
export interface OwnedEntityPickerUiOptions {
|
||||
allowedKinds?: string[];
|
||||
defaultKind?: string;
|
||||
allowArbitraryValues?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,6 +61,8 @@ export const OwnedEntityPicker = (
|
||||
|
||||
const allowedKinds = uiSchema['ui:options']?.allowedKinds;
|
||||
const defaultKind = uiSchema['ui:options']?.defaultKind;
|
||||
const allowArbitraryValues =
|
||||
uiSchema['ui:options']?.allowArbitraryValues ?? true;
|
||||
const { ownedEntities, loading } = useOwnedEntities(allowedKinds);
|
||||
|
||||
const entityRefs = ownedEntities?.items
|
||||
@@ -83,7 +86,7 @@ export const OwnedEntityPicker = (
|
||||
onChange={onSelect}
|
||||
options={entityRefs || []}
|
||||
autoSelect
|
||||
freeSolo
|
||||
freeSolo={allowArbitraryValues}
|
||||
renderInput={params => (
|
||||
<TextField
|
||||
{...params}
|
||||
|
||||
@@ -19,14 +19,14 @@ import { AzureRepoPicker } from './AzureRepoPicker';
|
||||
import { render, fireEvent } from '@testing-library/react';
|
||||
|
||||
describe('AzureRepoPicker', () => {
|
||||
it('renders the three input fields', async () => {
|
||||
it('renders the two input fields', async () => {
|
||||
const { getAllByRole } = render(
|
||||
<AzureRepoPicker onChange={jest.fn()} rawErrors={[]} state={{}} />,
|
||||
);
|
||||
|
||||
const allInputs = getAllByRole('textbox');
|
||||
|
||||
expect(allInputs).toHaveLength(3);
|
||||
expect(allInputs).toHaveLength(2);
|
||||
});
|
||||
|
||||
describe('org field', () => {
|
||||
@@ -58,19 +58,4 @@ describe('AzureRepoPicker', () => {
|
||||
expect(onChange).toHaveBeenCalledWith({ owner: 'owner' });
|
||||
});
|
||||
});
|
||||
|
||||
describe('repoName field', () => {
|
||||
it('calls onChange when the repoName changes', () => {
|
||||
const onChange = jest.fn();
|
||||
const { getAllByRole } = render(
|
||||
<AzureRepoPicker onChange={onChange} rawErrors={[]} state={{}} />,
|
||||
);
|
||||
|
||||
const repoNameInput = getAllByRole('textbox')[2];
|
||||
|
||||
fireEvent.change(repoNameInput, { target: { value: 'repoName' } });
|
||||
|
||||
expect(onChange).toHaveBeenCalledWith({ repoName: 'repoName' });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -27,7 +27,7 @@ export const AzureRepoPicker = (props: {
|
||||
rawErrors: string[];
|
||||
}) => {
|
||||
const { rawErrors, state, onChange } = props;
|
||||
const { organization, repoName, owner } = state;
|
||||
const { organization, owner } = state;
|
||||
return (
|
||||
<>
|
||||
<FormControl
|
||||
@@ -58,19 +58,6 @@ export const AzureRepoPicker = (props: {
|
||||
/>
|
||||
<FormHelperText>The Owner that this repo will belong to</FormHelperText>
|
||||
</FormControl>
|
||||
<FormControl
|
||||
margin="normal"
|
||||
required
|
||||
error={rawErrors?.length > 0 && !repoName}
|
||||
>
|
||||
<InputLabel htmlFor="repoNameInput">Repository</InputLabel>
|
||||
<Input
|
||||
id="repoNameInput"
|
||||
onChange={e => onChange({ repoName: e.target.value })}
|
||||
value={repoName}
|
||||
/>
|
||||
<FormHelperText>The name of the repository</FormHelperText>
|
||||
</FormControl>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
+2
-21
@@ -26,7 +26,7 @@ describe('BitbucketRepoPicker', () => {
|
||||
<BitbucketRepoPicker onChange={jest.fn()} rawErrors={[]} state={state} />,
|
||||
);
|
||||
|
||||
expect(getAllByRole('textbox')).toHaveLength(3);
|
||||
expect(getAllByRole('textbox')).toHaveLength(2);
|
||||
expect(getAllByRole('textbox')[0]).toHaveValue('lolsWorkspace');
|
||||
});
|
||||
|
||||
@@ -39,7 +39,7 @@ describe('BitbucketRepoPicker', () => {
|
||||
<BitbucketRepoPicker onChange={jest.fn()} rawErrors={[]} state={state} />,
|
||||
);
|
||||
|
||||
expect(getAllByRole('textbox')).toHaveLength(2);
|
||||
expect(getAllByRole('textbox')).toHaveLength(1);
|
||||
});
|
||||
describe('workspace field', () => {
|
||||
it('calls onChange when the workspace changes', () => {
|
||||
@@ -78,23 +78,4 @@ describe('BitbucketRepoPicker', () => {
|
||||
expect(onChange).toHaveBeenCalledWith({ project: 'test-project' });
|
||||
});
|
||||
});
|
||||
|
||||
describe('repoName field', () => {
|
||||
it('calls onChange when the repoName changes', () => {
|
||||
const onChange = jest.fn();
|
||||
const { getAllByRole } = render(
|
||||
<BitbucketRepoPicker
|
||||
onChange={onChange}
|
||||
rawErrors={[]}
|
||||
state={{ host: 'bitbucket.org' }}
|
||||
/>,
|
||||
);
|
||||
|
||||
const repoNameInput = getAllByRole('textbox')[2];
|
||||
|
||||
fireEvent.change(repoNameInput, { target: { value: 'test-repo' } });
|
||||
|
||||
expect(onChange).toHaveBeenCalledWith({ repoName: 'test-repo' });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -26,7 +26,7 @@ export const BitbucketRepoPicker = (props: {
|
||||
rawErrors: string[];
|
||||
}) => {
|
||||
const { onChange, rawErrors, state } = props;
|
||||
const { host, workspace, project, repoName } = state;
|
||||
const { host, workspace, project } = state;
|
||||
return (
|
||||
<>
|
||||
{host === 'bitbucket.org' && (
|
||||
@@ -61,19 +61,6 @@ export const BitbucketRepoPicker = (props: {
|
||||
The Project that this repo will belong to
|
||||
</FormHelperText>
|
||||
</FormControl>
|
||||
<FormControl
|
||||
margin="normal"
|
||||
required
|
||||
error={rawErrors?.length > 0 && !repoName}
|
||||
>
|
||||
<InputLabel htmlFor="repoNameInput">Repository</InputLabel>
|
||||
<Input
|
||||
id="repoNameInput"
|
||||
onChange={e => onChange({ repoName: e.target.value })}
|
||||
value={repoName}
|
||||
/>
|
||||
<FormHelperText>The name of the repository</FormHelperText>
|
||||
</FormControl>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -56,23 +56,4 @@ describe('BitbucketRepoPicker', () => {
|
||||
expect(onChange).toHaveBeenCalledWith({ workspace: 'test-parent' });
|
||||
});
|
||||
});
|
||||
|
||||
describe('repoName field', () => {
|
||||
it('calls onChange when the repoName changes', () => {
|
||||
const onChange = jest.fn();
|
||||
const { getAllByRole } = render(
|
||||
<GerritRepoPicker
|
||||
onChange={onChange}
|
||||
rawErrors={[]}
|
||||
state={{ host: 'gerrithost.org' }}
|
||||
/>,
|
||||
);
|
||||
|
||||
const repoNameInput = getAllByRole('textbox')[2];
|
||||
|
||||
fireEvent.change(repoNameInput, { target: { value: 'test-repo' } });
|
||||
|
||||
expect(onChange).toHaveBeenCalledWith({ repoName: 'test-repo' });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -26,7 +26,7 @@ export const GerritRepoPicker = (props: {
|
||||
rawErrors: string[];
|
||||
}) => {
|
||||
const { onChange, rawErrors, state } = props;
|
||||
const { workspace, repoName, owner } = state;
|
||||
const { workspace, owner } = state;
|
||||
return (
|
||||
<>
|
||||
<FormControl
|
||||
@@ -57,19 +57,6 @@ export const GerritRepoPicker = (props: {
|
||||
The project parent that the repo will belong to
|
||||
</FormHelperText>
|
||||
</FormControl>
|
||||
<FormControl
|
||||
margin="normal"
|
||||
required
|
||||
error={rawErrors?.length > 0 && !repoName}
|
||||
>
|
||||
<InputLabel htmlFor="repoNameInput">Repository</InputLabel>
|
||||
<Input
|
||||
id="repoNameInput"
|
||||
onChange={e => onChange({ repoName: e.target.value })}
|
||||
value={repoName}
|
||||
/>
|
||||
<FormHelperText>The name of the repository</FormHelperText>
|
||||
</FormControl>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -84,24 +84,4 @@ describe('GithubRepoPicker', () => {
|
||||
expect(onChange).toHaveBeenCalledWith({ owner: 'my-mock-owner' });
|
||||
});
|
||||
});
|
||||
|
||||
describe('repo name', () => {
|
||||
it('should render free text field for input of repo name', () => {
|
||||
const onChange = jest.fn();
|
||||
const { getAllByRole } = render(
|
||||
<GithubRepoPicker
|
||||
onChange={onChange}
|
||||
rawErrors={[]}
|
||||
state={{ repoName: 'repo' }}
|
||||
/>,
|
||||
);
|
||||
|
||||
const repoNameField = getAllByRole('textbox')[1];
|
||||
fireEvent.change(repoNameField, {
|
||||
target: { value: 'my-mock-repo-name' },
|
||||
});
|
||||
|
||||
expect(onChange).toHaveBeenCalledWith({ repoName: 'my-mock-repo-name' });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -32,7 +32,7 @@ export const GithubRepoPicker = (props: {
|
||||
? allowedOwners.map(i => ({ label: i, value: i }))
|
||||
: [{ label: 'Loading...', value: 'loading' }];
|
||||
|
||||
const { owner, repoName } = state;
|
||||
const { owner } = state;
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -66,19 +66,6 @@ export const GithubRepoPicker = (props: {
|
||||
The organization, user or project that this repo will belong to
|
||||
</FormHelperText>
|
||||
</FormControl>
|
||||
<FormControl
|
||||
margin="normal"
|
||||
required
|
||||
error={rawErrors?.length > 0 && !repoName}
|
||||
>
|
||||
<InputLabel htmlFor="repoNameInput">Repository</InputLabel>
|
||||
<Input
|
||||
id="repoNameInput"
|
||||
onChange={e => onChange({ repoName: e.target.value })}
|
||||
value={repoName}
|
||||
/>
|
||||
<FormHelperText>The name of the repository</FormHelperText>
|
||||
</FormControl>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -84,24 +84,4 @@ describe('GitlabRepoPicker', () => {
|
||||
expect(onChange).toHaveBeenCalledWith({ owner: 'my-mock-owner' });
|
||||
});
|
||||
});
|
||||
|
||||
describe('repo name', () => {
|
||||
it('should render free text field for input of repo name', () => {
|
||||
const onChange = jest.fn();
|
||||
const { getAllByRole } = render(
|
||||
<GitlabRepoPicker
|
||||
onChange={onChange}
|
||||
rawErrors={[]}
|
||||
state={{ repoName: 'repo' }}
|
||||
/>,
|
||||
);
|
||||
|
||||
const repoNameField = getAllByRole('textbox')[1];
|
||||
fireEvent.change(repoNameField, {
|
||||
target: { value: 'my-mock-repo-name' },
|
||||
});
|
||||
|
||||
expect(onChange).toHaveBeenCalledWith({ repoName: 'my-mock-repo-name' });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -23,16 +23,17 @@ import { RepoUrlPickerState } from './types';
|
||||
|
||||
export const GitlabRepoPicker = (props: {
|
||||
allowedOwners?: string[];
|
||||
allowedRepos?: string[];
|
||||
state: RepoUrlPickerState;
|
||||
onChange: (state: RepoUrlPickerState) => void;
|
||||
rawErrors: string[];
|
||||
}) => {
|
||||
const { allowedOwners = [], rawErrors, state, onChange } = props;
|
||||
const { allowedOwners = [], state, onChange, rawErrors } = props;
|
||||
const ownerItems: SelectItem[] = allowedOwners
|
||||
? allowedOwners.map(i => ({ label: i, value: i }))
|
||||
: [{ label: 'Loading...', value: 'loading' }];
|
||||
|
||||
const { owner, repoName } = state;
|
||||
const { owner } = state;
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -69,19 +70,6 @@ export const GitlabRepoPicker = (props: {
|
||||
namespaces in gitlab), that this repo will belong to
|
||||
</FormHelperText>
|
||||
</FormControl>
|
||||
<FormControl
|
||||
margin="normal"
|
||||
required
|
||||
error={rawErrors?.length > 0 && !repoName}
|
||||
>
|
||||
<InputLabel htmlFor="repoNameInput">Repository</InputLabel>
|
||||
<Input
|
||||
id="repoNameInput"
|
||||
onChange={e => onChange({ repoName: e.target.value })}
|
||||
value={repoName}
|
||||
/>
|
||||
<FormHelperText>The name of the repository</FormHelperText>
|
||||
</FormControl>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -26,6 +26,7 @@ import { BitbucketRepoPicker } from './BitbucketRepoPicker';
|
||||
import { GerritRepoPicker } from './GerritRepoPicker';
|
||||
import { FieldExtensionComponentProps } from '../../../extensions';
|
||||
import { RepoUrlPickerHost } from './RepoUrlPickerHost';
|
||||
import { RepoUrlPickerRepoName } from './RepoUrlPickerRepoName';
|
||||
import { parseRepoPickerUrl, serializeRepoPickerUrl } from './utils';
|
||||
import { RepoUrlPickerState } from './types';
|
||||
import useDebounce from 'react-use/lib/useDebounce';
|
||||
@@ -40,6 +41,7 @@ import { useTemplateSecrets } from '../../secrets';
|
||||
export interface RepoUrlPickerUiOptions {
|
||||
allowedHosts?: string[];
|
||||
allowedOwners?: string[];
|
||||
allowedRepos?: string[];
|
||||
requestUserCredentials?: {
|
||||
secretsKey: string;
|
||||
additionalScopes?: {
|
||||
@@ -76,6 +78,10 @@ export const RepoUrlPicker = (
|
||||
() => uiSchema?.['ui:options']?.allowedOwners ?? [],
|
||||
[uiSchema],
|
||||
);
|
||||
const allowedRepos = useMemo(
|
||||
() => uiSchema?.['ui:options']?.allowedRepos ?? [],
|
||||
[uiSchema],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
onChange(serializeRepoPickerUrl(state));
|
||||
@@ -87,6 +93,11 @@ export const RepoUrlPicker = (
|
||||
setState(prevState => ({ ...prevState, owner: allowedOwners[0] }));
|
||||
}
|
||||
}, [setState, allowedOwners]);
|
||||
useEffect(() => {
|
||||
if (allowedRepos.length === 1) {
|
||||
setState(prevState => ({ ...prevState, repoName: allowedRepos[0] }));
|
||||
}
|
||||
}, [setState, allowedRepos]);
|
||||
|
||||
const updateLocalState = useCallback(
|
||||
(newState: RepoUrlPickerState) => {
|
||||
@@ -179,6 +190,14 @@ export const RepoUrlPicker = (
|
||||
onChange={updateLocalState}
|
||||
/>
|
||||
)}
|
||||
<RepoUrlPickerRepoName
|
||||
repoName={state.repoName}
|
||||
allowedRepos={allowedRepos}
|
||||
onChange={repoName =>
|
||||
setState(prevState => ({ ...prevState, repoName }))
|
||||
}
|
||||
rawErrors={rawErrors}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright 2022 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import React from 'react';
|
||||
import { RepoUrlPickerRepoName } from './RepoUrlPickerRepoName';
|
||||
import { render, fireEvent } from '@testing-library/react';
|
||||
|
||||
describe('RepoUrlPickerRepoName', () => {
|
||||
it('should call onChange with the first allowed repo if there is none set already', async () => {
|
||||
const onChange = jest.fn();
|
||||
|
||||
render(
|
||||
<RepoUrlPickerRepoName
|
||||
onChange={onChange}
|
||||
allowedRepos={['foo', 'bar']}
|
||||
rawErrors={[]}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(onChange).toHaveBeenCalledWith('foo');
|
||||
});
|
||||
|
||||
it('should render a dropdown of all the options', async () => {
|
||||
const allowedRepos = ['foo', 'bar'];
|
||||
|
||||
const onChange = jest.fn();
|
||||
|
||||
const { getByRole } = render(
|
||||
<RepoUrlPickerRepoName
|
||||
onChange={onChange}
|
||||
allowedRepos={allowedRepos}
|
||||
rawErrors={[]}
|
||||
/>,
|
||||
);
|
||||
|
||||
const select = getByRole('combobox');
|
||||
await fireEvent.click(select);
|
||||
|
||||
for (const option of allowedRepos) {
|
||||
const element = getByRole('option', { name: option });
|
||||
expect(element).toBeVisible();
|
||||
}
|
||||
});
|
||||
|
||||
it('should render a normal text area when no options are passed', async () => {
|
||||
const onChange = jest.fn();
|
||||
|
||||
const { getByRole } = render(
|
||||
<RepoUrlPickerRepoName
|
||||
onChange={onChange}
|
||||
allowedRepos={[]}
|
||||
rawErrors={[]}
|
||||
/>,
|
||||
);
|
||||
|
||||
const textArea = getByRole('textbox');
|
||||
|
||||
expect(textArea).toBeVisible();
|
||||
|
||||
fireEvent.change(textArea, { target: { value: 'foo' } });
|
||||
|
||||
expect(onChange).toHaveBeenCalledWith('foo');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright 2021 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import React, { useEffect } from 'react';
|
||||
import { Select, SelectItem } from '@backstage/core-components';
|
||||
import FormControl from '@material-ui/core/FormControl';
|
||||
import FormHelperText from '@material-ui/core/FormHelperText';
|
||||
import Input from '@material-ui/core/Input';
|
||||
import InputLabel from '@material-ui/core/InputLabel';
|
||||
|
||||
export const RepoUrlPickerRepoName = (props: {
|
||||
repoName?: string;
|
||||
allowedRepos?: string[];
|
||||
onChange: (host: string) => void;
|
||||
rawErrors: string[];
|
||||
}) => {
|
||||
const { repoName, allowedRepos, onChange, rawErrors } = props;
|
||||
|
||||
useEffect(() => {
|
||||
// If there is no repoName chosen currently
|
||||
if (!repoName) {
|
||||
// Set the first of the allowedRepos option if that available
|
||||
if (allowedRepos?.length) {
|
||||
onChange(allowedRepos[0]);
|
||||
}
|
||||
}
|
||||
}, [allowedRepos, repoName, onChange]);
|
||||
|
||||
const repoItems: SelectItem[] = allowedRepos
|
||||
? allowedRepos.map(i => ({ label: i, value: i }))
|
||||
: [{ label: 'Loading...', value: 'loading' }];
|
||||
|
||||
return (
|
||||
<>
|
||||
<FormControl
|
||||
margin="normal"
|
||||
required
|
||||
error={rawErrors?.length > 0 && !repoName}
|
||||
>
|
||||
{allowedRepos?.length ? (
|
||||
<Select
|
||||
native
|
||||
label="Repositories Available"
|
||||
onChange={selected =>
|
||||
String(Array.isArray(selected) ? selected[0] : selected)
|
||||
}
|
||||
disabled={allowedRepos.length === 1}
|
||||
selected={repoName}
|
||||
items={repoItems}
|
||||
/>
|
||||
) : (
|
||||
<>
|
||||
<InputLabel htmlFor="repoNameInput">Repository</InputLabel>
|
||||
<Input
|
||||
id="repoNameInput"
|
||||
onChange={e => onChange(String(e.target.value))}
|
||||
value={repoName}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
<FormHelperText>The name of the repository</FormHelperText>
|
||||
</FormControl>
|
||||
</>
|
||||
);
|
||||
};
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user