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.
- Loading branch information
Showing
14 changed files
with
1,256 additions
and
2 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
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,5 @@ | ||
# @internal/backstage-plugin-catalog-backend-module-gitea | ||
|
||
The gitea backend module for the catalog plugin. | ||
|
||
_This plugin was created through the Backstage CLI_ |
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,37 @@ | ||
{ | ||
"name": "@internal/backstage-plugin-catalog-backend-module-gitea", | ||
"description": "The gitea backend module for the catalog plugin.", | ||
"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-module" | ||
}, | ||
"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.24.0", | ||
"@backstage/backend-plugin-api": "^0.8.0" | ||
}, | ||
"devDependencies": { | ||
"@backstage/backend-test-utils": "^0.5.0", | ||
"@backstage/cli": "^0.27.0" | ||
}, | ||
"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,8 @@ | ||
/***/ | ||
/** | ||
* The gitea backend module for the catalog plugin. | ||
* | ||
* @packageDocumentation | ||
*/ | ||
|
||
export { catalogModuleGitea as default } from './module'; |
21 changes: 21 additions & 0 deletions
21
plugins/catalog-backend-module-gitea/src/lib/annotation.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,21 @@ | ||
/** | ||
* The value of this annotation is the so-called login that identifies a user on | ||
* [GitHub](https://github.com) (either the public one, or a private GitHub | ||
* Enterprise installation) that is related to this entity. It is on the format | ||
* `<username>`, and is the same as can be seen in the URL location bar of the | ||
* browser when viewing that user. | ||
* | ||
* @public | ||
*/ | ||
export const ANNOTATION_GITHUB_USER_LOGIN = 'github.com/user-login'; | ||
|
||
/** | ||
* The value of this annotation is the so-called slug that identifies a team on | ||
* [GitHub](https://github.com) (either the public one, or a private GitHub | ||
* Enterprise installation) that is related to this entity. It is on the format | ||
* `<organization>/<team>`, and is the same as can be seen in the URL location | ||
* bar of the browser when viewing that team. | ||
* | ||
* @public | ||
*/ | ||
export const ANNOTATION_GITHUB_TEAM_SLUG = 'github.com/team-slug'; |
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 @@ | ||
import { | ||
getGiteaRequestOptions, | ||
GiteaIntegrationConfig, | ||
} from '@backstage/integration'; | ||
import axios from 'axios'; | ||
|
||
// client for Gitea API using axios | ||
const createGiteaClient = async ( | ||
config: GiteaIntegrationConfig | ||
) => { | ||
const options = getGiteaRequestOptions(config); | ||
const client = axios.create(options); | ||
|
||
return client; | ||
} | ||
|
||
export default createGiteaClient; |
128 changes: 128 additions & 0 deletions
128
plugins/catalog-backend-module-gitea/src/lib/defaultTransformers.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 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
import { Entity, GroupEntity, UserEntity } from '@backstage/catalog-model'; | ||
import { AxiosInstance } from 'axios'; | ||
import { | ||
ANNOTATION_GITHUB_TEAM_SLUG, | ||
ANNOTATION_GITHUB_USER_LOGIN, | ||
} from './annotation'; | ||
import { GiteaOrganization, GiteaUser } from './gitea'; | ||
|
||
/** | ||
* Context passed to Transformers | ||
* | ||
* @public | ||
*/ | ||
export interface TransformerContext { | ||
client: AxiosInstance; | ||
org: string; | ||
} | ||
|
||
/** | ||
* Transformer for Gitea users to an Entity | ||
* | ||
* @public | ||
*/ | ||
export type UserTransformer = ( | ||
item: GiteaUser, | ||
ctx: TransformerContext, | ||
) => Promise<Entity | undefined>; | ||
|
||
/** | ||
* Transformer for Gitea Organization to an Entity | ||
* | ||
* @public | ||
*/ | ||
export type OrganizationTransformer = ( | ||
item: GiteaOrganization, | ||
ctx: TransformerContext, | ||
) => Promise<Entity | undefined>; | ||
|
||
/** | ||
* Default transformer for Gitea users to UserEntity | ||
* | ||
* @public | ||
*/ | ||
export const defaultUserTransformer = async ( | ||
item: GiteaUser, | ||
_ctx: TransformerContext, | ||
): Promise<UserEntity | undefined> => { | ||
const entity: UserEntity = { | ||
apiVersion: 'backstage.io/v1alpha1', | ||
kind: 'User', | ||
metadata: { | ||
name: item.username, | ||
annotations: { | ||
[ANNOTATION_GITHUB_USER_LOGIN]: item.html_url, | ||
}, | ||
}, | ||
spec: { | ||
profile: {}, | ||
memberOf: [], | ||
}, | ||
}; | ||
|
||
if (item.description) entity.metadata.description = item.description; | ||
if (item.full_name) entity.spec.profile!.displayName = item.full_name; | ||
if (item.email) entity.spec.profile!.email = item.email; | ||
if (item.avatar_url) entity.spec.profile!.picture = item.avatar_url; | ||
return entity; | ||
}; | ||
|
||
/** | ||
* Default transformer for Gitea Organization to GroupEntity | ||
* | ||
* @public | ||
*/ | ||
export const defaultOrganizationTransformer: OrganizationTransformer = | ||
async org => { | ||
const annotations: { [annotationName: string]: string } = { | ||
[ANNOTATION_GITHUB_TEAM_SLUG]: org.full_path, | ||
}; | ||
|
||
if (org.edit_url) { | ||
annotations['backstage.io/edit-url'] = org.edit_url; | ||
} | ||
|
||
const entity: GroupEntity = { | ||
apiVersion: 'backstage.io/v1alpha1', | ||
kind: 'Group', | ||
metadata: { | ||
name: org.name, | ||
annotations, | ||
}, | ||
spec: { | ||
type: 'org', | ||
profile: {}, | ||
children: [], | ||
}, | ||
}; | ||
|
||
if (org.description) { | ||
entity.metadata.description = org.description; | ||
} | ||
if (org.full_name) { | ||
entity.spec.profile!.displayName = org.full_name; | ||
} | ||
if (org.avatar_url) { | ||
entity.spec.profile!.picture = org.avatar_url; | ||
} | ||
|
||
entity.spec.members = org.members.map(user => user.username); | ||
|
||
return entity; | ||
}; |
Oops, something went wrong.