Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

Display linked project repository on the vcs detail page

天舟07a928b65f55
diff --git a/backend/api/repository.go b/backend/api/repository.go
index 4c073dcf88..7ab9f988ee 100644
--- a/backend/api/repository.go
+++ b/backend/api/repository.go
@@ -17,8 +17,9 @@ type Repository struct {
UpdatedTs int64 `jsonapi:"attr,updatedTs"`
// Related fields
- VCSId int64
- ProjectId int64
+ VCSId int
+ ProjectId int
+ Project *Project `jsonapi:"relation,project"`
// Domain specific fields
Name string `jsonapi:"attr,name"`
diff --git a/backend/server/repository.go b/backend/server/repository.go
index 1d77dc0119..71e6cb8991 100644
--- a/backend/server/repository.go
+++ b/backend/server/repository.go
@@ -19,5 +19,10 @@ func (s *Server) ComposeRepositoryRelationship(ctx context.Context, repository *
return err
}
+ repository.Project, err = s.ComposeProjectlById(context.Background(), repository.ProjectId, includeList)
+ if err != nil {
+ return err
+ }
+
return nil
}
diff --git a/backend/store/seed/0170_repo.sql b/backend/store/seed/0170_repo.sql
index c37251f717..d00116b529 100644
--- a/backend/store/seed/0170_repo.sql
+++ b/backend/store/seed/0170_repo.sql
@@ -18,11 +18,11 @@ VALUES
1001,
16001,
3001,
+ "project1",
+ "bytebase-test/project1",
+ "http://gitlab.bytebase.com/bytebase-test/project1",
-- Refers to the bytebase-test/project1
"7",
-- Refers to the webhook in bytebase-test/project1
- "5",
- "project1",
- "bytebase-test/project1",
- "http://gitlab.bytebase.com/bytebase-test/project1"
+ "5"
);
\ No newline at end of file
diff --git a/frontend/src/components/RepositoryTable.vue b/frontend/src/components/RepositoryTable.vue
new file mode 100644
index 0000000000..a7556a2fd1
--- /dev/null
+++ b/frontend/src/components/RepositoryTable.vue
@@ -0,0 +1,75 @@
+<template>
+ <BBTable
+ :columnList="columnList"
+ :dataSource="repositoryList"
+ :showHeader="true"
+ :leftBordered="true"
+ :rightBordered="true"
+ @click-row="clickRepository"
+ >
+ <template v-slot:body="{ rowData: repository }">
+ <BBTableCell :leftPadding="4" class="w-16">
+ {{ projectName(repository.project) }}
+ </BBTableCell>
+ <BBTableCell class="w-32">
+ {{ repository.fullPath }}
+ </BBTableCell>
+ <BBTableCell class="w-16">
+ <div class="flex flex-row items-center">
+ <BBAvatar :size="'small'" :username="repository.creator.name" />
+ <span class="ml-2">{{ repository.creator.name }}</span>
+ </div>
+ </BBTableCell>
+ <BBTableCell class="w-16">
+ {{ humanizeTs(repository.createdTs) }}
+ </BBTableCell>
+ </template>
+ </BBTable>
+</template>
+
+<script lang="ts">
+import { PropType } from "vue";
+import { useRouter } from "vue-router";
+import { BBTableColumn } from "../bbkit/types";
+import { projectSlug } from "../utils";
+import { Repository } from "../types";
+
+const columnList: BBTableColumn[] = [
+ {
+ title: "Project",
+ },
+ {
+ title: "Repository",
+ },
+ {
+ title: "Creator",
+ },
+ {
+ title: "Created",
+ },
+];
+
+export default {
+ name: "RepositoryTable",
+ components: {},
+ props: {
+ repositoryList: {
+ required: true,
+ type: Object as PropType<Repository[]>,
+ },
+ },
+ setup(props, ctx) {
+ const router = useRouter();
+
+ const clickRepository = function (section: number, row: number) {
+ const repository = props.repositoryList[row];
+ router.push(`/project/${projectSlug(repository.project)}`);
+ };
+
+ return {
+ columnList,
+ clickRepository,
+ };
+ },
+};
+</script>
diff --git a/frontend/src/components/VCSSetupWizard.vue b/frontend/src/components/VCSSetupWizard.vue
index cbe8a44957..474a0579de 100644
--- a/frontend/src/components/VCSSetupWizard.vue
+++ b/frontend/src/components/VCSSetupWizard.vue
@@ -128,7 +128,7 @@ export default {
const attentionText = computed((): string => {
if (state.config.type == "GITLAB_SELF_HOST") {
- return "You need to be an Admin of your chosen GitLab instance to configure this. Otherwise, you need to ask your GitLab instance Admin to register Bytebase as a system OAuth application in GitLab, then provide you that Application ID and Secret to fill in the 'OAuth application info' step.";
+ return "You need to be an Admin of your chosen GitLab instance to configure this. Otherwise, you need to ask your GitLab instance Admin to register Bytebase as a system OAuth application in GitLab, then provide you that Application ID and Secret to fill at the 'OAuth application info' step.";
}
return "";
});
diff --git a/frontend/src/store/modules/vcs.ts b/frontend/src/store/modules/vcs.ts
index bd3cee1765..629452d003 100644
--- a/frontend/src/store/modules/vcs.ts
+++ b/frontend/src/store/modules/vcs.ts
@@ -5,26 +5,45 @@ import {
VCSCreate,
VCSState,
ResourceObject,
+ ResourceIdentifier,
unknown,
VCSPatch,
empty,
EMPTY_ID,
Principal,
- VCSTokenCreate,
Repository,
+ Project,
} from "../../types";
-function convertRepository(respository: ResourceObject): Repository {
+function convertRepository(
+ respository: ResourceObject,
+ includedList: ResourceObject[],
+ rootGetters: any
+): Repository {
const creator = respository.attributes.creator as Principal;
const updater = respository.attributes.updater as Principal;
+
+ const projectId = (
+ respository.relationships!.project.data as ResourceIdentifier
+ ).id;
+ let project: Project = unknown("PROJECT") as Project;
+ project.id = parseInt(projectId);
+
+ for (const item of includedList || []) {
+ if (item.type == "project" && item.id == projectId) {
+ project = rootGetters["project/convert"](item, includedList);
+ }
+ }
+
return {
...(respository.attributes as Omit<
Repository,
- "id" | "creator" | "updater"
+ "id" | "creator" | "updater" | "project"
>),
id: parseInt(respository.id),
creator,
updater,
+ project,
};
}
@@ -153,14 +172,12 @@ const actions = {
commit("deleteVCSById", vcsId);
},
- async fetchRepositoryListByVCS({ commit }: any, vcs: VCS) {
- const repositoryList = (
- await axios.get(`/api/vcs/${vcs.id}/repository`)
- ).data.data.map((repository: ResourceObject) => {
- return convertRepository(repository);
- });
+ async fetchRepositoryListByVCS({ commit, rootGetters }: any, vcs: VCS) {
+ const data = (await axios.get(`/api/vcs/${vcs.id}/repository`)).data;
- console.log("repo", repositoryList);
+ const repositoryList = data.data.map((repository: ResourceObject) => {
+ return convertRepository(repository, data.included, rootGetters);
+ });
commit("setRepositoryListByVCSId", { vcsId: vcs.id, repositoryList });
return repositoryList;
diff --git a/frontend/src/types/common.ts b/frontend/src/types/common.ts
index 1776ca2484..c8a3236806 100644
--- a/frontend/src/types/common.ts
+++ b/frontend/src/types/common.ts
@@ -324,6 +324,7 @@ export const unknown = (
updater: UNKNOWN_PRINCIPAL,
createdTs: 0,
updatedTs: 0,
+ project: UNKNOWN_PROJECT,
externalId: UNKNOWN_ID.toString(),
name: "",
fullPath: "",
@@ -597,6 +598,7 @@ export const empty = (
updater: EMPTY_PRINCIPAL,
createdTs: 0,
updatedTs: 0,
+ project: EMPTY_PROJECT,
externalId: EMPTY_ID.toString(),
name: "",
fullPath: "",
diff --git a/frontend/src/types/repository.ts b/frontend/src/types/repository.ts
index bffa1d8f14..b4b917cee9 100644
--- a/frontend/src/types/repository.ts
+++ b/frontend/src/types/repository.ts
@@ -1,5 +1,6 @@
import { RepositoryId } from "./id";
import { Principal } from "./principal";
+import { Project } from "./project";
export type Repository = {
id: RepositoryId;
@@ -10,6 +11,9 @@ export type Repository = {
updater: Principal;
updatedTs: number;
+ // Related fields
+ project: Project;
+
// Domain specific fields
// e.g. In GitLab, this is the corresponding project id.
externalId: string;
diff --git a/frontend/src/views/SettingWorkspaceVCSDetail.vue b/frontend/src/views/SettingWorkspaceVCSDetail.vue
index e90a8738cf..b40f34ee2d 100644
--- a/frontend/src/views/SettingWorkspaceVCSDetail.vue
+++ b/frontend/src/views/SettingWorkspaceVCSDetail.vue
@@ -13,34 +13,34 @@
</div>
<div>
- <label for="name" class="textlabel"> Display name </label>
+ <label for="instanceurl" class="textlabel"> Instance URL </label>
<p class="mt-1 textinfolabel">
- An optional display name to help identifying among different configs
- using the same Git provider.
+ <template v-if="vcs.type == 'GITLAB_SELF_HOST'">
+ Your GitLab instance location.
+ </template>
</p>
<input
- id="name"
- name="name"
+ id="instanceurl"
+ name="instanceurl"
type="text"
class="textfield mt-1 w-full"
- v-model="state.name"
+ disabled="true"
+ :value="vcs.instanceURL"
/>
</div>
<div>
- <label for="instanceurl" class="textlabel"> Instance URL </label>
+ <label for="name" class="textlabel"> Display name </label>
<p class="mt-1 textinfolabel">
- <template v-if="vcs.type == 'GITLAB_SELF_HOST'">
- Your GitLab instance location.
- </template>
+ An optional display name to help identifying among different configs
+ using the same Git provider.
</p>
<input
- id="instanceurl"
- name="instanceurl"
+ id="name"
+ name="name"
type="text"
class="textfield mt-1 w-full"
- disabled="true"
- :value="vcs.instanceURL"
+ v-model="state.name"
/>
</div>
@@ -80,22 +80,48 @@
/>
</div>
- <div class="pt-4 flex border-t justify-end">
- <button
- type="button"
- class="btn-normal py-2 px-4"
- @click.prevent="cancel"
- >
- Cancel
- </button>
- <button
- type="button"
- class="btn-primary ml-3 inline-flex justify-center py-2 px-4"
- :disabled="!allowUpdate"
- @click.prevent="doUpdate"
- >
- Update
- </button>
+ <div class="pt-4 flex border-t justify-between">
+ <template v-if="repositoryList.length == 0">
+ <BBButtonConfirm
+ :style="'DELETE'"
+ :buttonText="'Delete this Git provider'"
+ :okText="'Delete'"
+ :confirmTitle="`Delete Git provider '${vcs.name}'?`"
+ :requireConfirm="true"
+ @confirm="deleteVCS"
+ />
+ </template>
+ <template v-else>
+ <div class="mt-1 textinfolabel">
+ To delete this provider, unlink all repositories first.
+ </div>
+ </template>
+ <div>
+ <button
+ type="button"
+ class="btn-normal py-2 px-4"
+ @click.prevent="cancel"
+ >
+ Cancel
+ </button>
+ <button
+ type="button"
+ class="btn-primary ml-3 inline-flex justify-center py-2 px-4"
+ :disabled="!allowUpdate"
+ @click.prevent="doUpdate"
+ >
+ Update
+ </button>
+ </div>
+ </div>
+ </div>
+
+ <div class="py-6">
+ <div class="text-lg leading-6 font-medium text-main">
+ {{ `Linked repositories (${repositoryList.length})` }}
+ </div>
+ <div class="mt-4">
+ <RepositoryTable :repositoryList="repositoryList" />
</div>
</div>
</template>
@@ -104,6 +130,7 @@
import { reactive, computed, watchEffect } from "vue";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
+import RepositoryTable from "../components/RepositoryTable.vue";
import isEmpty from "lodash-es/isEmpty";
import { idFromSlug } from "../utils";
import {
@@ -131,7 +158,7 @@ export default {
type: String,
},
},
- components: {},
+ components: { RepositoryTable },
setup(props, ctx) {
const store = useStore();
const router = useRouter();
@@ -278,6 +305,20 @@ export default {
});
};
+ const deleteVCS = () => {
+ const name = vcs.value.name;
+ store.dispatch("vcs/deleteVCSById", vcs.value.id).then(() => {
+ store.dispatch("notification/pushNotification", {
+ module: "bytebase",
+ style: "SUCCESS",
+ title: `Successfully deleted '${name}'`,
+ });
+ router.push({
+ name: "setting.workspace.version-control",
+ });
+ });
+ };
+
return {
state,
vcs,
@@ -286,6 +327,7 @@ export default {
allowUpdate,
doUpdate,
cancel,
+ deleteVCS,
};
},
};