forked from backstage/backstage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce @backstage/integration-react and its scmIntegrationsApiRef
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
- Loading branch information
Showing
36 changed files
with
476 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
'@backstage/create-app': patch | ||
--- | ||
|
||
Supply a `scmIntegrationsApiRef` from the new `@backstage/integration-react`. | ||
|
||
This is a new facility that plugins will start to use. You will have to add it to your local `packages/app` as described below. If this is not done, runtime errors will be seen in the frontend, on the form `No API factory available for dependency apiRef{integration.scmintegrations}`. | ||
|
||
In `packages/app/package.json`: | ||
|
||
```diff | ||
"dependencies": { | ||
+ "@backstage/integration-react": "^0.1.1", | ||
``` | ||
|
||
In `packages/app/src/apis.ts`: | ||
|
||
```diff | ||
+import { | ||
+ scmIntegrationsApiRef, | ||
+ ScmIntegrationsApi, | ||
+} from '@backstage/integration-react'; | ||
|
||
export const apis: AnyApiFactory[] = [ | ||
+ createApiFactory({ | ||
+ api: scmIntegrationsApiRef, | ||
+ deps: { configApi: configApiRef }, | ||
+ factory: ({ configApi }) => ScmIntegrationsApi.fromConfig(configApi), | ||
+ }), | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@backstage/plugin-catalog': patch | ||
'@backstage/plugin-catalog-import': patch | ||
'@backstage/plugin-scaffolder': patch | ||
--- | ||
|
||
Use `scmIntegrationsApiRef` from the new `@backstage/integration-react`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 14 additions & 1 deletion
15
packages/create-app/templates/default-app/packages/app/src/apis.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,14 @@ | ||
export const apis = []; | ||
import { | ||
AnyApiFactory, configApiRef, createApiFactory | ||
} from '@backstage/core'; | ||
import { | ||
ScmIntegrationsApi, scmIntegrationsApiRef | ||
} from '@backstage/integration-react'; | ||
|
||
export const apis: AnyApiFactory[] = [ | ||
createApiFactory({ | ||
api: scmIntegrationsApiRef, | ||
deps: { configApi: configApiRef }, | ||
factory: ({ configApi }) => ScmIntegrationsApi.fromConfig(configApi), | ||
}), | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
extends: [require.resolve('@backstage/cli/config/eslint')], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Integrations React-specific functionality | ||
|
||
Exposes a frontend API for interacting with configured integrations (as added | ||
under the `integrations` root config key). Most of the actual code is in the | ||
`@backstage/integration` package. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright 2021 Spotify AB | ||
* | ||
* 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 { Content, useApi } from '@backstage/core'; | ||
import { ScmIntegration, ScmIntegrationsGroup } from '@backstage/integration'; | ||
import { Typography } from '@material-ui/core'; | ||
import React from 'react'; | ||
import { scmIntegrationsApiRef } from '../src/ScmIntegrationsApi'; | ||
|
||
const Integrations = (props: { | ||
group: ScmIntegrationsGroup<ScmIntegration>; | ||
}) => { | ||
const integrations = props.group.list(); | ||
if (!integrations) { | ||
return ( | ||
<Typography color="textSecondary"> | ||
No integrations of this type | ||
</Typography> | ||
); | ||
} | ||
|
||
return ( | ||
<Typography variant="caption"> | ||
<pre>{JSON.stringify(integrations, undefined, 2)}</pre> | ||
</Typography> | ||
); | ||
}; | ||
|
||
export const DevPage = () => { | ||
const integrations = useApi(scmIntegrationsApiRef); | ||
return ( | ||
<Content> | ||
<Typography paragraph variant="h2"> | ||
Azure | ||
</Typography> | ||
<Integrations group={integrations.azure} /> | ||
<Typography paragraph variant="h2"> | ||
Bitbucket | ||
</Typography> | ||
<Integrations group={integrations.bitbucket} /> | ||
<Typography paragraph variant="h2"> | ||
GitHub | ||
</Typography> | ||
<Integrations group={integrations.github} /> | ||
<Typography paragraph variant="h2"> | ||
GitLab | ||
</Typography> | ||
<Integrations group={integrations.gitlab} /> | ||
</Content> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2021 Spotify AB | ||
* | ||
* 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 { configApiRef, createApiFactory } from '@backstage/core'; | ||
import { createDevApp } from '@backstage/dev-utils'; | ||
import { ScmIntegrations } from '@backstage/integration'; | ||
import React from 'react'; | ||
import { scmIntegrationsApiRef } from '../src/ScmIntegrationsApi'; | ||
import { DevPage } from './DevPage'; | ||
|
||
createDevApp() | ||
.registerApi( | ||
createApiFactory({ | ||
api: scmIntegrationsApiRef, | ||
deps: { configApi: configApiRef }, | ||
factory: ({ configApi }) => ScmIntegrations.fromConfig(configApi), | ||
}), | ||
) | ||
.addPage({ | ||
element: <DevPage />, | ||
title: 'Root Page', | ||
}) | ||
.render(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{ | ||
"name": "@backstage/integration-react", | ||
"version": "0.1.1", | ||
"main": "src/index.ts", | ||
"types": "src/index.ts", | ||
"license": "Apache-2.0", | ||
"private": true, | ||
"publishConfig": { | ||
"access": "public", | ||
"main": "dist/index.esm.js", | ||
"types": "dist/index.d.ts" | ||
}, | ||
"scripts": { | ||
"build": "backstage-cli plugin:build", | ||
"start": "backstage-cli plugin:serve", | ||
"lint": "backstage-cli lint", | ||
"test": "backstage-cli test", | ||
"prepack": "backstage-cli prepack", | ||
"postpack": "backstage-cli postpack", | ||
"clean": "backstage-cli clean" | ||
}, | ||
"dependencies": { | ||
"@backstage/config": "^0.1.2", | ||
"@backstage/core": "^0.7.0", | ||
"@backstage/integration": "^0.5.0", | ||
"@backstage/theme": "^0.2.3", | ||
"@material-ui/core": "^4.11.0", | ||
"@material-ui/icons": "^4.9.1", | ||
"@material-ui/lab": "4.0.0-alpha.45", | ||
"react": "^16.13.1", | ||
"react-dom": "^16.13.1", | ||
"react-use": "^15.3.3" | ||
}, | ||
"devDependencies": { | ||
"@backstage/cli": "^0.6.3", | ||
"@backstage/dev-utils": "^0.1.13", | ||
"@backstage/test-utils": "^0.1.8", | ||
"@testing-library/jest-dom": "^5.10.1", | ||
"@testing-library/react": "^11.2.5", | ||
"@testing-library/user-event": "^12.0.7", | ||
"@types/jest": "^26.0.7", | ||
"@types/node": "^14.14.32", | ||
"msw": "^0.21.2", | ||
"cross-fetch": "^3.0.6" | ||
}, | ||
"files": [ | ||
"dist" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright 2021 Spotify AB | ||
* | ||
* 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 { ConfigReader } from '@backstage/config'; | ||
import { | ||
ScmIntegrationsApi, | ||
scmIntegrationsApiRef, | ||
} from './ScmIntegrationsApi'; | ||
|
||
describe('scmIntegrationsApiRef', () => { | ||
it('should export api', () => { | ||
expect(scmIntegrationsApiRef).toBeDefined(); | ||
}); | ||
|
||
it('should be instantiated', () => { | ||
const i = ScmIntegrationsApi.fromConfig(new ConfigReader({})); | ||
expect(i.list().length).toBe(4); // The default ones | ||
}); | ||
}); |
Oops, something went wrong.