Skip to content

Commit

Permalink
Merge pull request backstage#5381 from msamad/msamad/add-repourlpicke…
Browse files Browse the repository at this point in the history
…r-for-bitbucketcloud

Add repourlpicker and publisher for bitbucket cloud
  • Loading branch information
freben authored Aug 11, 2021
2 parents ff9222a + 9ecb8a5 commit 89b9447
Show file tree
Hide file tree
Showing 20 changed files with 630 additions and 102 deletions.
6 changes: 6 additions & 0 deletions .changeset/perfect-seals-burn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@backstage/plugin-scaffolder': minor
'@backstage/plugin-scaffolder-backend': minor
---

Add Bitbucket workspace and project fields to RepoUrlPicker to support Bitbucket cloud and server
1 change: 1 addition & 0 deletions .github/styles/vocab.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Avro
backrub
Bigtable
Billett
Bitbucket
Bitrise
Blackbox
bool
Expand Down
5 changes: 5 additions & 0 deletions app-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ integrations:
- host: bitbucket.org
username: ${BITBUCKET_USERNAME}
appPassword: ${BITBUCKET_APP_PASSWORD}
### Example for how to add your bitbucket server instance using the API:
# - host: server.bitbucket.com
# apiBaseUrl: server.bitbucket.com
# username: ${BITBUCKET_SERVER_USERNAME}
# appPassword: ${BITBUCKET_SERVER_APP_PASSWORD}
azure:
- host: dev.azure.com
token: ${AZURE_TOKEN}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
apiVersion: backstage.io/v1beta2
kind: Template
metadata:
name: bitbucket-demo
title: Test Bitbucket RepoUrlPicker template
description: scaffolder v1beta2 template demo publishing to bitbucket
spec:
owner: backstage/techdocs-core
type: service

parameters:
- title: Choose a location
required:
- repoUrl
properties:
repoUrl:
title: Repository Location
type: string
ui:field: RepoUrlPicker
ui:options:
allowedHosts:
- bitbucket.org
- server.bitbucket.com
- title: Fill in some steps
required:
- name
- owner
properties:
name:
title: Name
type: string
description: Unique name of the component
ui:autofocus: true
ui:options:
rows: 5
owner:
title: Owner
type: string
description: Owner of the component
ui:field: OwnerPicker
ui:options:
allowedKinds:
- Group

steps:
- id: fetch-base
name: Fetch Base
action: fetch:cookiecutter
input:
url: ./template
values:
name: '{{ parameters.name }}'
owner: '{{ parameters.owner }}'

- id: fetch-docs
name: Fetch Docs
action: fetch:plain
input:
targetPath: ./community
url: https://github.com/backstage/community/tree/main/backstage-community-sessions

- id: publish
name: Publish
action: publish:bitbucket
input:
description: 'This is {{ parameters.name }}'
repoUrl: '{{ parameters.repoUrl }}'

- id: register
name: Register
action: catalog:register
input:
repoContentsUrl: '{{ steps.publish.output.repoContentsUrl }}'
catalogInfoPath: '/catalog-info.yaml'

output:
remoteUrl: '{{ steps.publish.output.remoteUrl }}'
entityRef: '{{ steps.register.output.entityRef }}'
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
name: {{cookiecutter.name | jsonify}}
spec:
type: website
lifecycle: experimental
owner: {{cookiecutter.owner | jsonify}}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,13 @@ export function createGithubActionsDispatchAction(options: {
async handler(ctx) {
const { repoUrl, workflowId, branchOrTagName } = ctx.input;

const { owner, repo, host } = parseRepoUrl(repoUrl);
const { owner, repo, host } = parseRepoUrl(repoUrl, integrations);

if (!owner) {
throw new InputError(
`No owner provided for host: ${host}, and repo ${repo}`,
);
}

ctx.logger.info(
`Dispatching workflow ${workflowId} for repo ${repoUrl} on ${branchOrTagName}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,21 @@ describe('publish:azure', () => {
await expect(
action.handler({
...mockContext,
input: { repoUrl: 'azure.com?repo=bob' },
input: { repoUrl: 'dev.azure.com?repo=bob' },
}),
).rejects.toThrow(/missing owner/);

await expect(
action.handler({
...mockContext,
input: { repoUrl: 'azure.com?owner=owner' },
input: { repoUrl: 'dev.azure.com?owner=owner' },
}),
).rejects.toThrow(/missing repo/);

await expect(
action.handler({
...mockContext,
input: { repoUrl: 'azure.com?owner=owner&repo=repo' },
input: { repoUrl: 'dev.azure.com?owner=owner&repo=repo' },
}),
).rejects.toThrow(/missing organization/);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ export function createPublishAzureAction(options: {
async handler(ctx) {
const { repoUrl, defaultBranch = 'master' } = ctx.input;

const { owner, repo, host, organization } = parseRepoUrl(repoUrl);
const { owner, repo, host, organization } = parseRepoUrl(
repoUrl,
integrations,
);

if (!organization) {
throw new InputError(
Expand Down
Loading

0 comments on commit 89b9447

Please sign in to comment.