-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7825dd8
commit 48532d2
Showing
12 changed files
with
422 additions
and
10 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
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 |
---|---|---|
|
@@ -61,6 +61,7 @@ | |
] | ||
}, | ||
"volta": { | ||
"node": "14.20.0" | ||
"node": "14.20.0", | ||
"yarn": "1.22.19" | ||
} | ||
} |
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 @@ | ||
module.exports = require('@backstage/cli/config/eslint-factory')(__dirname); |
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,2 @@ | ||
src/providers/GitHub* | ||
src/lib |
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,14 @@ | ||
# sourcegraph-entity-provider-backend | ||
|
||
Welcome to the sourcegraph-entity-provider-backend backend plugin! | ||
|
||
_This plugin was created through the Backstage CLI_ | ||
|
||
## Getting started | ||
|
||
Your plugin has been added to the example app in this repository, meaning you'll be able to access it by running `yarn | ||
start` in the root directory, and then navigating to [/sourcegraph-entity-provider-backend](http://localhost:3000/sourcegraph-entity-provider-backend). | ||
|
||
You can also serve the plugin in isolation by running `yarn start` in the plugin directory. | ||
This method of serving the plugin provides quicker iteration speed and a faster startup and hot reloads. | ||
It is only meant for local development, and the setup for it can be found inside the [/dev](/dev) directory. |
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,46 @@ | ||
{ | ||
"name": "@frontside/backstage-plugin-sourcegraph-entity-provider", | ||
"version": "0.1.0", | ||
"main": "src/index.ts", | ||
"types": "src/index.ts", | ||
"license": "Apache-2.0", | ||
"private": true, | ||
"publishConfig": { | ||
"access": "public", | ||
"main": "dist/index.cjs.js", | ||
"types": "dist/index.d.ts" | ||
}, | ||
"backstage": { | ||
"role": "backend-plugin" | ||
}, | ||
"scripts": { | ||
"start": "backstage-cli package start", | ||
"build": "backstage-cli package build", | ||
"lint": "backstage-cli package lint", | ||
"test": "backstage-cli package test", | ||
"clean": "backstage-cli package clean", | ||
"prepack": "backstage-cli package prepack", | ||
"postpack": "backstage-cli package postpack" | ||
}, | ||
"dependencies": { | ||
"@backstage/backend-common": "^0.15.1", | ||
"@backstage/backend-tasks": "^0.3.6-next.2", | ||
"@backstage/config": "^1.0.2", | ||
"@types/express": "*", | ||
"express": "^4.17.1", | ||
"express-promise-router": "^4.1.0", | ||
"graphql-request": "^5.0.0", | ||
"node-fetch": "^2.6.7", | ||
"winston": "^3.2.1", | ||
"yn": "^4.0.0" | ||
}, | ||
"devDependencies": { | ||
"@backstage/cli": "^0.19.0", | ||
"@types/supertest": "^2.0.8", | ||
"msw": "^0.46.0", | ||
"supertest": "^4.0.2" | ||
}, | ||
"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,17 @@ | ||
/* | ||
* Copyright 2020 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 * from './providers/SourcegraphEntityProvider'; |
128 changes: 128 additions & 0 deletions
128
plugins/sourcegraph-entity-provider-backend/src/providers/SourcegraphEntityProvider.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 |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import { | ||
EntityProvider, | ||
EntityProviderConnection, | ||
parseEntityYaml | ||
} from '@backstage/plugin-catalog-backend'; | ||
import { Config } from '@backstage/config'; | ||
import { Logger } from 'winston'; | ||
import { GraphQLClient, gql } from "graphql-request"; | ||
|
||
interface SourcegraphSearch { | ||
search: { | ||
results: { | ||
results: [{ | ||
repository: { | ||
name: string; | ||
}; | ||
file: { | ||
url: string; | ||
content: string; | ||
} | ||
}] | ||
} | ||
} | ||
} | ||
|
||
export class SourcegraphEntityProvider implements EntityProvider { | ||
private readonly config: Config; | ||
private connection?: EntityProviderConnection; | ||
private readonly logger: Logger; | ||
private graphQLClient: GraphQLClient; | ||
|
||
static create({ config, logger }: { config: Config, logger: Logger }) { | ||
return new SourcegraphEntityProvider({ config, logger }) | ||
} | ||
|
||
private constructor(options: { | ||
config: Config, | ||
logger: Logger, | ||
}) { | ||
this.config = options.config; | ||
this.logger = options.logger.child({ | ||
target: this.getProviderName(), | ||
}); | ||
this.graphQLClient = new GraphQLClient(""); | ||
} | ||
|
||
getProviderName(): string { | ||
return `sourcegraph-provider:${this.config.getString("sourcegraph.orgId")}`; | ||
} | ||
|
||
async connect(connection: EntityProviderConnection): Promise<void> { | ||
this.connection = connection; | ||
const endpoint = `https://${this.config.getString("sourcegraph.orgId")}.sourcegraph.com/.api/graphql` | ||
this.graphQLClient = new GraphQLClient(endpoint, { | ||
headers: { | ||
authorization: `token ${this.config.getString("sourcegraph.token")}` | ||
} | ||
}); | ||
await this.test(); | ||
} | ||
|
||
async test_old() { | ||
if (!this.connection) { | ||
throw new Error('Not initialized'); | ||
} | ||
const query = gql` | ||
{ | ||
currentUser { | ||
username | ||
} | ||
} | ||
`; | ||
const data = await this.graphQLClient.request(query); | ||
this.logger.info(`🚨 HELLO ${JSON.stringify(data, null, 2)}`) | ||
} | ||
async test() { | ||
if (!this.connection) { | ||
throw new Error('Not initialized'); | ||
} | ||
const query = gql` | ||
query ($query: String!) { | ||
search(query: $query) { | ||
results { | ||
matchCount | ||
results { | ||
__typename | ||
... on FileMatch { | ||
repository { | ||
name | ||
} | ||
file { | ||
url | ||
content | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`; | ||
const data: SourcegraphSearch = await this.graphQLClient.request(query, { | ||
query: "file:^catalog-info.yaml" | ||
}); | ||
data.search.results.results.forEach((result) => { | ||
const location = { | ||
type: "url", | ||
target: result.file.url | ||
}; | ||
this.logger.info(`✅ ${result.repository.name}`) | ||
|
||
// const content = Buffer.from(data, "utf8"); | ||
// for (const parseResult of parseEntityYaml(content, location)) { | ||
// parseResults.push(parseResult) | ||
// } | ||
}) | ||
} | ||
|
||
async full(logger: Logger) { | ||
logger.info(`🚨 FULL}`) | ||
// full mutation on schedule | ||
} | ||
|
||
async delta(logger: Logger) { | ||
logger.info(`🚨 DELTA}`) | ||
// delta mutation from webhooks | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
plugins/sourcegraph-entity-provider-backend/src/setupTests.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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright 2020 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 {}; |
Oops, something went wrong.