Skip to main content

示例

映射软件源、文件内容和拉取请求

在下面的示例中,您将把 Bitbucket 仓库、其 README.md 文件内容和拉取请求引用到 Port,您可以使用以下 Port 蓝图定义和 port-app-config.yml:

Repository blueprint
{
"identifier": "bitbucketRepository",
"title": "Repository",
"icon": "Microservice",
"schema": {
"properties": {
"readme": {
"title": "README",
"type": "string",
"format": "markdown"
},
"url": {
"title": "Repository URL",
"type": "string",
"format": "url"
},
"defaultBranch": {
"title": "Default branch",
"type": "string"
}
},
"required": []
},
"mirrorProperties": {},
"calculationProperties": {},
"relations": {}
}
Pull request blueprint
{
"identifier": "bitbucketPullRequest",
"title": "Pull Request",
"icon": "GitVersion",
"schema": {
"properties": {
"creator": {
"title": "Creator",
"type": "string",
"format": "user"
},
"assignees": {
"title": "Assignees",
"type": "array"
},
"reviewers": {
"title": "Reviewers",
"type": "array"
},
"status": {
"title": "Status",
"type": "string",
"enum": ["MERGED", "OPEN", "DECLINED"],
"enumColors": {
"MERGED": "purple",
"OPEN": "green",
"DECLINED": "red"
}
},
"createdAt": {
"title": "Create At",
"type": "string",
"format": "date-time"
},
"updatedAt": {
"title": "Updated At",
"type": "string",
"format": "date-time"
},
"link": {
"title": "Link",
"format": "url",
"type": "string"
}
},
"required": []
},
"mirrorProperties": {},
"calculationProperties": {},
"relations": {
"repository": {
"title": "Repository",
"target": "bitbucketRepository",
"required": false,
"many": false
}
}
}
Port port-app-config.yml
resources:
- kind: repository
selector:
query: "true" # JQ boolean query. If evaluated to false - skip syncing the object.
port:
entity:
mappings:
identifier: ".name" # The Entity identifier will be the repository name. After the Entity is created, the exporter will send `PATCH` requests to update this microservice within Port.
title: ".name"
blueprint: '"bitbucketRepository"'
properties:
readme: file://README.md # fetching the README.md file that is within the root folder of the repository and ingesting its contents as a markdown property
url: ".links.html.href"
defaultBranch: .main_branch
- kind: pull-request
selector:
query: "true" # JQ boolean query. If evaluated to false - skip syncing the object.
port:
entity:
mappings:
identifier: ".destination.repository.name + (.id|tostring)" # The Entity identifier will be the repository name + the pull request ID. After the Entity is created, the exporter will send `PATCH` requests to update this pull request within Port.
title: ".title"
blueprint: '"bitbucketPullRequest"'
properties:
creator: ".author.display_name"
assignees: "[.participants[].user.display_name]"
reviewers: "[.reviewers[].user.display_name]"
status: ".state"
updatedAt: ".updated_on"
link: ".links.html.href"
relations:
repository: ".destination.repository.name"
tip
  • 请参阅setup 部分,了解有关 port-app-config.yml 设置过程的更多信息;
  • 我们利用JQ JSON processor 将 Bitbucket 对象映射和转换为 Port 实体;
  • 点击Here 查看 Bitbucket 版本库对象结构。
  • 点击Here 查看 Bitbucket 拉取请求对象结构。

创建蓝图并提交port-app-config.yml文件到.bitbucket-private或特定版本库后,您将在版本库中看到与您的版本库相匹配的新实体,以及它们的 README.md 文件内容和拉取请求(请记住,port-app-config.yml文件必须位于版本库的默认分支中才能生效)。

映射软件源和单核处理器

在下面的示例中,您将把 Bitbucket 资源库及其文件夹引用到 Port。 按照这个示例,您可以将不同的服务、包和库从 monorepo 映射到 Port 中的不同实体。您可以使用下面的 Port 蓝图定义和 port-app-config.yml:

Repository blueprint
{
"identifier": "bitbucketRepository",
"title": "Repository",
"icon": "Microservice",
"schema": {
"properties": {
"readme": {
"title": "README",
"type": "string",
"format": "markdown"
},
"url": {
"title": "Repository URL",
"type": "string",
"format": "url"
},
"defaultBranch": {
"title": "Default branch",
"type": "string"
}
},
"required": []
},
"mirrorProperties": {},
"calculationProperties": {},
"relations": {}
}
Port port-app-config.yml
resources:
- kind: folder
selector:
query: "true" # JQ boolean query. If evaluated to false - skip syncing the object.
folders: # Specify the repositories and folders to include under this relative path.
- path: apps/* # Relative path to the folders within the repositories.
repos: # List of repositories to include folders from.
- backend-service
- frontend-service
port:
entity:
mappings:
identifier: .folder.name
blueprint: '"bitbucketRepository"'
properties:
url: .repo.links.html.href + "/src/" + .repo.mainbranch.name + "/" + .folder.path
readme: file://README.md
tip
  • 请参阅setup 部分,了解有关 port-app-config.yml 设置过程的更多信息;
  • 我们利用JQ JSON processor 将 GitHub 对象映射和转换为 Port 实体;
  • 点击Here 查看 Bitbucket 仓库对象结构。
  • 点击Here 查看 Bitbucket 文件夹对象结构。

映射支持的资源

上面的示例展示了一个特定的用例,但 Port 的 Bitbucket 应用程序支持摄取许多其他 Bitbucket 对象,要调整上面的示例,请使用 Bitbucket API 参考资料了解不同支持对象的可用字段:

Available Bitbucket resources

在添加其他资源的摄取时,请记得在 resources 数组中添加一个条目,并相应更改提供给 kind 键的值。