Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix(vcs): unable to load list of external repositories when enable GitOps (#6443)
Joe Chen04811ddaed71
diff --git a/frontend/src/components/RepositorySelectionPanel.vue b/frontend/src/components/RepositorySelectionPanel.vueindex c44a255405..ba856f0262 100644--- a/frontend/src/components/RepositorySelectionPanel.vue+++ b/frontend/src/components/RepositorySelectionPanel.vue@@ -22,7 +22,7 @@><div class="flex items-center px-4 py-3"><div class="min-w-0 flex-1 flex items-center">- {{ repository.fullPath }}+ {{ repository.fullpath }}</div><div><!-- Heroicon name: solid/chevron-right -->@@ -46,12 +46,15 @@ import {OAuthToken,ProjectRepositoryConfig,} from "../types";-import { useOAuthStore, useGitlabStore } from "@/store";-import { ExternalVersionControl_Type } from "@/types/proto/v1/externalvs_service";+import { useOAuthStore, useVCSV1Store } from "@/store";+import {+ ExternalVersionControl_Type,+ SearchExternalVersionControlProjectsResponse_Project,+} from "@/types/proto/v1/externalvs_service";import { getVCSUid } from "@/store/modules/v1/common";interface LocalState {- repositoryList: ExternalRepositoryInfo[];+ repositoryList: SearchExternalVersionControlProjectsResponse_Project[];searchText: string;}@@ -63,7 +66,7 @@ const emit = defineEmits<{(event: "set-repository", payload: ExternalRepositoryInfo): void;}>();-const gitlabStore = useGitlabStore();+const vcsV1Store = useVCSV1Store();const state = reactive<LocalState>({repositoryList: [],searchText: "",@@ -81,11 +84,12 @@ const prepareRepositoryList = () => {}).then((token: OAuthToken) => {emit("set-token", token);- gitlabStore- .fetchProjectList({- vcsId: getVCSUid(props.config.vcs.name),- token: token,- })+ vcsV1Store+ .listVCSExternalProjects(+ props.config.vcs.name,+ token.accessToken,+ token.refreshToken+ ).then((list) => {state.repositoryList = list;});@@ -93,25 +97,26 @@ const prepareRepositoryList = () => {};const refreshRepositoryList = () => {- if (props.config.vcs.type == ExternalVersionControl_Type.GITLAB) {- gitlabStore- .fetchProjectList({- vcsId: getVCSUid(props.config.vcs.name),- token: props.config.token,- })- .then((list) => {- state.repositoryList = list;- });- }+ vcsV1Store+ .listVCSExternalProjects(+ props.config.vcs.name,+ props.config.token.accessToken,+ props.config.token.refreshToken+ )+ .then((list) => {+ state.repositoryList = list;+ });};const repositoryList = computed(() => {if (state.searchText == "") {return state.repositoryList;}- return state.repositoryList.filter((repository: ExternalRepositoryInfo) => {- return repository.fullPath.toLowerCase().includes(state.searchText);- });+ return state.repositoryList.filter(+ (repository: SearchExternalVersionControlProjectsResponse_Project) => {+ return repository.fullpath.toLowerCase().includes(state.searchText);+ }+ );});const attentionText = computed((): string => {@@ -125,8 +130,15 @@ const attentionText = computed((): string => {return "";});-const selectRepository = (repository: ExternalRepositoryInfo) => {- emit("set-repository", repository);+const selectRepository = (+ repository: SearchExternalVersionControlProjectsResponse_Project+) => {+ emit("set-repository", {+ externalId: repository.id,+ name: repository.title,+ fullPath: repository.fullpath,+ webUrl: repository.webUrl,+ });emit("next");};diff --git a/frontend/src/store/modules/gitlab.ts b/frontend/src/store/modules/gitlab.tsdeleted file mode 100644index d6af9161ba..0000000000--- a/frontend/src/store/modules/gitlab.ts+++ /dev/null@@ -1,66 +0,0 @@-import { defineStore } from "pinia";-import axios from "axios";-import {- ExternalRepositoryInfo,- VCSId,- OAuthConfig,- OAuthToken,-} from "@/types";--function convertGitLabProject(project: any): ExternalRepositoryInfo {- const attributes = project.attributes;- return {- externalId: project.id.toString(),- name: attributes.name,- fullPath: attributes.fullPath,- webUrl: attributes.webUrl,- };-}--export const useGitlabStore = defineStore("gitlab", {- actions: {- // this actions is for initiating vcs ONLY- // after creation, the frontend should in no case access the secret.- async exchangeToken({- oAuthConfig,- code,- }: {- oAuthConfig: OAuthConfig;- code: string;- }): Promise<OAuthToken> {- const data = (- await axios.post(- `${oAuthConfig.endpoint}?client_id=${oAuthConfig.applicationId}&client_secret=${oAuthConfig.secret}&code=${code}&redirect_uri=${oAuthConfig.redirectUrl}&grant_type=authorization_code`- )- ).data;-- const oAuthToken: OAuthToken = {- accessToken: data.access_token,- refreshToken: data.refresh_token,- // For GitLab, as of 13.12, the default config won't expire the access token, thus this field is 0.- // see https://gitlab.com/gitlab-org/gitlab/-/issues/21745.- expiresTs: data.expires_in == 0 ? 0 : data.created_at + data.expires_in,- };- return oAuthToken;- },-- // TODO(zilong): here we still store the access token at the frontend, we may move this to the backend- async fetchProjectList({- vcsId,- token,- }: {- vcsId: VCSId;- token: OAuthToken;- }): Promise<ExternalRepositoryInfo[]> {- const data = (- await axios.get(`/api/vcs/${vcsId}/external-repository`, {- headers: {- accessToken: token.accessToken,- refreshToken: token.refreshToken,- },- })- ).data.data;- return data.map((item: any) => convertGitLabProject(item));- },- },-});diff --git a/frontend/src/store/modules/index.ts b/frontend/src/store/modules/index.tsindex db1bcf651f..b5b17ff3ca 100644--- a/frontend/src/store/modules/index.ts+++ b/frontend/src/store/modules/index.ts@@ -8,7 +8,6 @@ export * from "./command";export * from "./database";export * from "./dataSource";export * from "./environment";-export * from "./gitlab";export * from "./help";export * from "./issue";export * from "./issueSubscriber";diff --git a/frontend/src/store/modules/v1/vcs.ts b/frontend/src/store/modules/v1/vcs.tsindex ec280bf5bc..e236843aa2 100644--- a/frontend/src/store/modules/v1/vcs.ts+++ b/frontend/src/store/modules/v1/vcs.ts@@ -9,6 +9,22 @@ import { VCSId } from "@/types";export const useVCSV1Store = defineStore("vcs_v1", () => {const vcsMapByName = reactive(new Map<string, ExternalVersionControl>());+ const listVCSExternalProjects = async (+ vcsName: string,+ accessToken: string,+ refreshToken: string+ ) => {+ const resp =+ await externalVersionControlServiceClient.searchExternalVersionControlProjects(+ {+ name: vcsName,+ accessToken,+ refreshToken,+ }+ );+ return resp.projects;+ };+const fetchVCSList = async () => {const resp =await externalVersionControlServiceClient.listExternalVersionControls({});@@ -74,6 +90,7 @@ export const useVCSV1Store = defineStore("vcs_v1", () => {};return {+ listVCSExternalProjects,getVCSByUid,getVCSList,fetchVCSByName,