Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
Backend repository API and frontend related support for fetching repository for a VCS
天舟9a397615a7cc
diff --git a/backend/api/repository.go b/backend/api/repository.gonew file mode 100644index 0000000000..4c073dcf88--- /dev/null+++ b/backend/api/repository.go@@ -0,0 +1,98 @@+package api++import (+ "context"+ "encoding/json"+)++type Repository struct {+ ID int `jsonapi:"primary,repository"`++ // Standard fields+ CreatorId int+ Creator *Principal `jsonapi:"attr,creator"`+ CreatedTs int64 `jsonapi:"attr,createdTs"`+ UpdaterId int+ Updater *Principal `jsonapi:"attr,updater"`+ UpdatedTs int64 `jsonapi:"attr,updatedTs"`++ // Related fields+ VCSId int64+ ProjectId int64++ // Domain specific fields+ Name string `jsonapi:"attr,name"`+ FullPath string `jsonapi:"attr,fullPath"`+ WebURL string `jsonapi:"attr,webURL"`+ BaseDirectory string `jsonapi:"attr,baseDirectory"`+ BranchFilter string `jsonapi:"attr,branchFilter"`+ ExternalId string `jsonapi:"attr,externalId"`+ WebhookId string `jsonapi:"attr,webhookId"`+ // Because we normalize the data, thus we fetch below info from vcs table.+ VCSName string `jsonapi:"attr,vcsName"`+ VCSType VCSType `jsonapi:"attr,vcsType"`+ InstanceURL string `jsonapi:"attr,instanceURL"`+}++type RepositoryCreate struct {+ // Standard fields+ // Value is assigned from the jwt subject field passed by the client.+ CreatorId int++ // Related fields+ VCSId int `jsonapi:"attr,vcsId"`+ ProjectId int `jsonapi:"attr,projectId"`++ // Domain specific fields+ Name string `jsonapi:"attr,name"`+ FullPath string `jsonapi:"attr,fullPath"`+ WebURL string `jsonapi:"attr,webURL"`+ BaseDirectory string `jsonapi:"attr,baseDirectory"`+ BranchFilter string `jsonapi:"attr,branchFilter"`+ ExternalId string `jsonapi:"attr,externalId"`+ WebhookId string `jsonapi:"attr,webhookId"`+}++type RepositoryFind struct {+ ID *int++ // Related fields+ VCSId *int+ ProjectId *int+}++func (find *RepositoryFind) String() string {+ str, err := json.Marshal(*find)+ if err != nil {+ return err.Error()+ }+ return string(str)+}++type RepositoryPatch struct {+ ID int++ // Standard fields+ // Value is assigned from the jwt subject field passed by the client.+ UpdaterId int++ // Domain specific fields+ BaseDirectory *string `jsonapi:"attr,baseDirectory"`+ BranchFilter *string `jsonapi:"attr,branchFilter"`+}++type RepositoryDelete struct {+ ID int++ // Standard fields+ // Value is assigned from the jwt subject field passed by the client.+ DeleterId int+}++type RepositoryService interface {+ CreateRepository(ctx context.Context, create *RepositoryCreate) (*Repository, error)+ FindRepositoryList(ctx context.Context, find *RepositoryFind) ([]*Repository, error)+ FindRepository(ctx context.Context, find *RepositoryFind) (*Repository, error)+ PatchRepository(ctx context.Context, patch *RepositoryPatch) (*Repository, error)+ DeleteRepository(ctx context.Context, delete *RepositoryDelete) error+}diff --git a/backend/cmd/echo/main.go b/backend/cmd/echo/main.goindex 583f2e7611..3f33a3cbd0 100644--- a/backend/cmd/echo/main.go+++ b/backend/cmd/echo/main.go@@ -60,6 +60,7 @@ func (m *Main) Run() error {server.ActivityService = store.NewActivityService(m.l, db)server.BookmarkService = store.NewBookmarkService(m.l, db)server.VCSService = store.NewVCSService(m.l, db)+ server.RepositoryService = store.NewRepositoryService(m.l, db)m.server = serverif err := server.Run(); err != nil {diff --git a/backend/server/acl_casbin_policy_dba.csv b/backend/server/acl_casbin_policy_dba.csvindex e79a1e4862..6e6467de2f 100644--- a/backend/server/acl_casbin_policy_dba.csv+++ b/backend/server/acl_casbin_policy_dba.csv@@ -40,4 +40,5 @@ p, DBA, /vcs, POSTp, DBA, /vcs, GETp, DBA, /vcs/{id}, GETp, DBA, /vcs/{id}, PATCH-p, DBA, /vcs/{id}, DELETE\ No newline at end of file+p, DBA, /vcs/{id}, DELETE+p, DBA, /vcs/{id}/repository, GET\ No newline at end of filediff --git a/backend/server/acl_casbin_policy_owner.csv b/backend/server/acl_casbin_policy_owner.csvindex 50f65b6edd..e7d1ac7a17 100644--- a/backend/server/acl_casbin_policy_owner.csv+++ b/backend/server/acl_casbin_policy_owner.csv@@ -47,3 +47,4 @@ p, OWNER, /vcs/{id}, GETp, OWNER, /vcs/{id}, PATCHp, OWNER, /vcs/{id}, DELETEp, OWNER, /vcs/{id}/token, POST+p, OWNER, /vcs/{id}/repository, GETdiff --git a/backend/server/repository.go b/backend/server/repository.gonew file mode 100644index 0000000000..1d77dc0119--- /dev/null+++ b/backend/server/repository.go@@ -0,0 +1,23 @@+package server++import (+ "context"++ "github.com/bytebase/bytebase/api"+)++func (s *Server) ComposeRepositoryRelationship(ctx context.Context, repository *api.Repository, includeList []string) error {+ var err error++ repository.Creator, err = s.ComposePrincipalById(context.Background(), repository.CreatorId, includeList)+ if err != nil {+ return err+ }++ repository.Updater, err = s.ComposePrincipalById(context.Background(), repository.UpdaterId, includeList)+ if err != nil {+ return err+ }++ return nil+}diff --git a/backend/server/server.go b/backend/server/server.goindex 097013db2f..85d0716ac0 100644--- a/backend/server/server.go+++ b/backend/server/server.go@@ -42,6 +42,7 @@ type Server struct {ActivityService api.ActivityServiceBookmarkService api.BookmarkServiceVCSService api.VCSService+ RepositoryService api.RepositoryServicee *echo.Echo}diff --git a/backend/server/vcs.go b/backend/server/vcs.goindex 042d8a7d75..2c91d4cdad 100644--- a/backend/server/vcs.go+++ b/backend/server/vcs.go@@ -54,7 +54,7 @@ func (s *Server) registerVCSRoutes(g *echo.Group) {for _, vcs := range list {if err := s.ComposeVCSRelationship(context.Background(), vcs, c.Get(getIncludeKey()).([]string)); err != nil {- return err+ return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch vcs relationship: %v", vcs.ID)).SetInternal(err)}}@@ -242,6 +242,33 @@ func (s *Server) registerVCSRoutes(g *echo.Group) {}return nil})++ g.GET("/vcs/:vcsId/repository", func(c echo.Context) error {+ id, err := strconv.Atoi(c.Param("vcsId"))+ if err != nil {+ return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("id"))).SetInternal(err)+ }++ repositoryFind := &api.RepositoryFind{+ VCSId: &id,+ }+ list, err := s.RepositoryService.FindRepositoryList(context.Background(), repositoryFind)+ if err != nil {+ return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch repository for vcs ID: %v", id)).SetInternal(err)+ }++ for _, repository := range list {+ if err := s.ComposeRepositoryRelationship(context.Background(), repository, c.Get(getIncludeKey()).([]string)); err != nil {+ return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch repository relationship: %v", repository.ID)).SetInternal(err)+ }+ }++ c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)+ if err := jsonapi.MarshalPayload(c.Response().Writer, list); err != nil {+ return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to marshal repository list response for vcs ID: %v", id)).SetInternal(err)+ }+ return nil+ })}func (s *Server) ComposeVCSRelationship(ctx context.Context, vcs *api.VCS, includeList []string) error {diff --git a/backend/store/migration/0001_init_schema.up.sql b/backend/store/migration/0001_init_schema.up.sqlindex a051e971a8..2ec8cbed54 100644--- a/backend/store/migration/0001_init_schema.up.sql+++ b/backend/store/migration/0001_init_schema.up.sql@@ -691,15 +691,26 @@ CREATE TABLE repo (updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),vcs_id INTEGER NOT NULL REFERENCES vcs (id),project_id INTEGER NOT NULL UNIQUE REFERENCES project (id),- -- Repo id for the corresponding VCS provider. For GitLab, this is the GitLab project id- external_id TEXT NOT NULL,- -- Push webhook id for the corresponding VCS provider.- webhook_id TEXT NOT NULL,+ -- Name from the corresponding VCS provider.+ -- For GitLab, this is the project name. e.g. project 1name TEXT NOT NULL,+ -- Full path from the corresponding VCS provider.+ -- For GitLab, this is the project full path. e.g. group1/project-1full_path TEXT NOT NULL,+ -- Web url from the corresponding VCS provider.+ -- For GitLab, this is the project web url. e.g. https://gitlab.example.com/group1/project-1web_url TEXT NOT NULL,+ -- Base working directory we are interested.base_directory TEXT NOT NULL DEFAULT '',- branch_filter TEXT NOT NULL DEFAULT ''+ -- Branch we are interested.+ -- For GitLab, this corresponds to webhook's push_events_branch_filter. Wildcard is supported+ branch_filter TEXT NOT NULL DEFAULT '',+ -- Repo id from the corresponding VCS provider.+ -- For GitLab, this is the project id. e.g. 123+ external_id TEXT NOT NULL,+ -- Push webhook id from the corresponding VCS provider.+ -- For GitLab, this is the project webhook id. e.g. 123+ webhook_id TEXT NOT NULL);INSERT INTOdiff --git a/backend/store/repository.go b/backend/store/repository.gonew file mode 100644index 0000000000..c370b91a35--- /dev/null+++ b/backend/store/repository.go@@ -0,0 +1,321 @@+package store++import (+ "context"+ "fmt"+ "strings"++ "github.com/bytebase/bytebase"+ "github.com/bytebase/bytebase/api"+ "go.uber.org/zap"+)++var (+ _ api.RepositoryService = (*RepositoryService)(nil)+)++// RepositoryService represents a service for managing repository.+type RepositoryService struct {+ l *zap.Logger+ db *DB+}++// NewRepositoryService returns a new instance of RepositoryService.+func NewRepositoryService(logger *zap.Logger, db *DB) *RepositoryService {+ return &RepositoryService{l: logger, db: db}+}++// CreateRepository creates a new repository.+func (s *RepositoryService) CreateRepository(ctx context.Context, create *api.RepositoryCreate) (*api.Repository, error) {+ tx, err := s.db.BeginTx(ctx, nil)+ if err != nil {+ return nil, FormatError(err)+ }+ defer tx.Rollback()++ repository, err := createRepository(ctx, tx, create)+ if err != nil {+ return nil, err+ }++ if err := tx.Commit(); err != nil {+ return nil, FormatError(err)+ }++ return repository, nil+}++// FindRepositoryList retrieves a list of repositorys based on find.+func (s *RepositoryService) FindRepositoryList(ctx context.Context, find *api.RepositoryFind) ([]*api.Repository, error) {+ tx, err := s.db.BeginTx(ctx, nil)+ if err != nil {+ return nil, FormatError(err)+ }+ defer tx.Rollback()++ list, err := findRepositoryList(ctx, tx, find)+ if err != nil {+ return []*api.Repository{}, err+ }++ return list, nil+}++// FindRepository retrieves a single repository based on find.+// Returns ENOTFOUND if no matching record.+// Returns the first matching one and prints a warning if finding more than 1 matching records.+func (s *RepositoryService) FindRepository(ctx context.Context, find *api.RepositoryFind) (*api.Repository, error) {+ tx, err := s.db.BeginTx(ctx, nil)+ if err != nil {+ return nil, FormatError(err)+ }+ defer tx.Rollback()++ list, err := findRepositoryList(ctx, tx, find)+ if err != nil {+ return nil, err+ } else if len(list) == 0 {+ return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("repository not found: %v", find)}+ } else if len(list) > 1 {+ s.l.Warn(fmt.Sprintf("found mulitple repositories: %d, expect 1", len(list)))+ }+ return list[0], nil+}++// PatchRepository updates an existing repository by ID.+// Returns ENOTFOUND if repository does not exist.+func (s *RepositoryService) PatchRepository(ctx context.Context, patch *api.RepositoryPatch) (*api.Repository, error) {+ tx, err := s.db.BeginTx(ctx, nil)+ if err != nil {+ return nil, FormatError(err)+ }+ defer tx.Rollback()++ repository, err := patchRepository(ctx, tx, patch)+ if err != nil {+ return nil, FormatError(err)+ }++ if err := tx.Commit(); err != nil {+ return nil, FormatError(err)+ }++ return repository, nil+}++// DeleteRepository deletes an existing repository by ID.+// Returns ENOTFOUND if repository does not exist.+func (s *RepositoryService) DeleteRepository(ctx context.Context, delete *api.RepositoryDelete) error {+ tx, err := s.db.BeginTx(ctx, nil)+ if err != nil {+ return FormatError(err)+ }+ defer tx.Rollback()++ err = deleteRepository(ctx, tx, delete)+ if err != nil {+ return FormatError(err)+ }++ if err := tx.Commit(); err != nil {+ return FormatError(err)+ }++ return nil+}++// createRepository creates a new repository.+func createRepository(ctx context.Context, tx *Tx, create *api.RepositoryCreate) (*api.Repository, error) {+ // Insert row into database.+ row, err := tx.QueryContext(ctx, `+ INSERT INTO repo (+ creator_id,+ updater_id,+ vcs_id,+ project_id,+ name,+ full_path,+ web_url,+ base_directory,+ branch_filter,+ external_id,+ webhook_id+ )+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)+ RETURNING id, creator_id, created_ts, updater_id, updated_ts, vcs_id, project_id, name, full_path, web_url, base_directory, branch_filter, external_id, webhook_id+ `,+ create.CreatorId,+ create.CreatorId,+ create.VCSId,+ create.ProjectId,+ create.Name,+ create.FullPath,+ create.WebURL,+ create.BaseDirectory,+ create.BranchFilter,+ create.ExternalId,+ create.WebhookId,+ )++ if err != nil {+ return nil, FormatError(err)+ }+ defer row.Close()++ row.Next()+ var repository api.Repository+ if err := row.Scan(+ &repository.ID,+ &repository.CreatorId,+ &repository.CreatedTs,+ &repository.UpdaterId,+ &repository.UpdatedTs,+ &repository.VCSId,+ &repository.ProjectId,+ &repository.Name,+ &repository.FullPath,+ &repository.WebURL,+ &repository.BaseDirectory,+ &repository.BranchFilter,+ &repository.ExternalId,+ &repository.WebhookId,+ ); err != nil {+ return nil, FormatError(err)+ }++ return &repository, nil+}++func findRepositoryList(ctx context.Context, tx *Tx, find *api.RepositoryFind) (_ []*api.Repository, err error) {+ // Build WHERE clause.+ where, args := []string{"1 = 1"}, []interface{}{}+ if v := find.ID; v != nil {+ where, args = append(where, "id = ?"), append(args, *v)+ }++ rows, err := tx.QueryContext(ctx, `+ SELECT+ id,+ creator_id,+ created_ts,+ updater_id,+ updated_ts,+ vcs_id,+ project_id,+ name,+ full_path,+ web_url,+ base_directory,+ branch_filter,+ external_id,+ webhook_id+ FROM repo+ WHERE `+strings.Join(where, " AND "),+ args...,+ )+ if err != nil {+ return nil, FormatError(err)+ }+ defer rows.Close()++ // Iterate over result set and deserialize rows into list.+ list := make([]*api.Repository, 0)+ for rows.Next() {+ var repository api.Repository+ if err := rows.Scan(+ &repository.ID,+ &repository.CreatorId,+ &repository.CreatedTs,+ &repository.UpdaterId,+ &repository.UpdatedTs,+ &repository.VCSId,+ &repository.ProjectId,+ &repository.Name,+ &repository.FullPath,+ &repository.WebURL,+ &repository.BaseDirectory,+ &repository.BranchFilter,+ &repository.ExternalId,+ &repository.WebhookId,+ ); err != nil {+ return nil, FormatError(err)+ }++ list = append(list, &repository)+ }+ if err := rows.Err(); err != nil {+ return nil, FormatError(err)+ }++ return list, nil+}++// patchRepository updates a repository by ID. Returns the new state of the repository after update.+func patchRepository(ctx context.Context, tx *Tx, patch *api.RepositoryPatch) (*api.Repository, error) {+ // Build UPDATE clause.+ set, args := []string{"updater_id = ?"}, []interface{}{patch.UpdaterId}+ if v := patch.BaseDirectory; v != nil {+ set, args = append(set, "base_directory = ?"), append(args, *v)+ }+ if v := patch.BranchFilter; v != nil {+ set, args = append(set, "branch_filter = ?"), append(args, *v)+ }++ args = append(args, patch.ID)++ // Execute update query with RETURNING.+ row, err := tx.QueryContext(ctx, `+ UPDATE repo+ SET `+strings.Join(set, ", ")+`+ WHERE id = ?+ RETURNING id, creator_id, created_ts, updater_id, updated_ts, vcs_id, project_id, name, full_path, web_url, base_directory, branch_filter, external_id, webhook_id+ `,+ args...,+ )+ if err != nil {+ return nil, FormatError(err)+ }+ defer row.Close()++ if row.Next() {+ var repository api.Repository+ if err := row.Scan(+ &repository.ID,+ &repository.CreatorId,+ &repository.CreatedTs,+ &repository.UpdaterId,+ &repository.UpdatedTs,+ &repository.VCSId,+ &repository.ProjectId,+ &repository.Name,+ &repository.FullPath,+ &repository.WebURL,+ &repository.BaseDirectory,+ &repository.BranchFilter,+ &repository.ExternalId,+ &repository.WebhookId,+ ); err != nil {+ return nil, FormatError(err)+ }++ return &repository, nil+ }++ return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("repository ID not found: %d", patch.ID)}+}++// deleteRepository permanently deletes a repository by ID.+func deleteRepository(ctx context.Context, tx *Tx, delete *api.RepositoryDelete) error {+ // Remove row from database.+ result, err := tx.ExecContext(ctx, `DELETE FROM repo WHERE id = ?`, delete.ID)+ if err != nil {+ return FormatError(err)+ }++ rows, _ := result.RowsAffected()+ if rows == 0 {+ return &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("repository ID not found: %d", delete.ID)}+ }++ return nil+}diff --git a/backend/store/seed/0170_repo.sql b/backend/store/seed/0170_repo.sqlindex 8a0ee87660..c37251f717 100644--- a/backend/store/seed/0170_repo.sql+++ b/backend/store/seed/0170_repo.sql@@ -5,11 +5,11 @@ INSERT INTOupdater_id,vcs_id,project_id,- external_id,- webhook_id,name,full_path,- web_url+ web_url,+ external_id,+ webhook_id)VALUES(diff --git a/frontend/src/components/RepositorySelectionPanel.vue b/frontend/src/components/RepositorySelectionPanel.vueindex dcce020404..7d8a037a99 100644--- a/frontend/src/components/RepositorySelectionPanel.vue+++ b/frontend/src/components/RepositorySelectionPanel.vue@@ -45,10 +45,10 @@import { reactive } from "@vue/reactivity";import { useStore } from "vuex";import { computed, PropType, watchEffect } from "@vue/runtime-core";-import { ProjectRepoConfig, Repository } from "../types";+import { ExternalRepository, ProjectRepoConfig } from "../types";interface LocalState {- repositoryList: Repository[];+ repositoryList: ExternalRepository[];searchText: string;}@@ -86,12 +86,12 @@ export default {if (state.searchText == "") {return state.repositoryList;}- return state.repositoryList.filter((repository: Repository) => {+ return state.repositoryList.filter((repository: ExternalRepository) => {return repository.fullPath.toLowerCase().includes(state.searchText);});});- const selectRepository = (repository: Repository) => {+ const selectRepository = (repository: ExternalRepository) => {props.config.repository = repository;emit("next");};diff --git a/frontend/src/store/modules/gitlab.ts b/frontend/src/store/modules/gitlab.tsindex d85e99d7ac..2f93e0dc0b 100644--- a/frontend/src/store/modules/gitlab.ts+++ b/frontend/src/store/modules/gitlab.ts@@ -1,12 +1,12 @@import axios from "axios";-import { Repository, VCS } from "../../types";+import { ExternalRepository, VCS } from "../../types";const GITLAB_API_PATH = "api/v4";const GITLAB_WEBHOOK_PATH = "hook/gitlab";const getters = {};-function convertGitLabProject(project: any): Repository {+function convertGitLabProject(project: any): ExternalRepository {return {externalId: project.id.toString(),name: project.name,@@ -35,7 +35,7 @@ const actions = {async fetchProjectList({}: any,{ vcs, token }: { vcs: VCS; token: string }- ): Promise<Repository[]> {+ ): Promise<ExternalRepository[]> {console.log("req",`${vcs.instanceURL}/${GITLAB_API_PATH}/projects?membership=true&simple=true`diff --git a/frontend/src/store/modules/vcs.ts b/frontend/src/store/modules/vcs.tsindex 6ae8028f4e..7cc26aee1d 100644--- a/frontend/src/store/modules/vcs.ts+++ b/frontend/src/store/modules/vcs.ts@@ -11,13 +11,24 @@ import {EMPTY_ID,Principal,VCSTokenCreate,+ Repository,} from "../../types";-function convert(- vcs: ResourceObject,- includedList: ResourceObject[],- rootGetters: any-): VCS {+function convertRepository(respository: ResourceObject): Repository {+ const creator = respository.attributes.creator as Principal;+ const updater = respository.attributes.updater as Principal;+ return {+ ...(respository.attributes as Omit<+ Repository,+ "id" | "creator" | "updater"+ >),+ id: parseInt(respository.id),+ creator,+ updater,+ };+}++function convert(vcs: ResourceObject): VCS {const creator = vcs.attributes.creator as Principal;const updater = vcs.attributes.updater as Principal;return {@@ -30,15 +41,10 @@ function convert(const state: () => VCSState = () => ({vcsById: new Map(),+ repositoryListByVCSId: new Map(),});const getters = {- convert:- (state: VCSState, getters: any, rootState: any, rootGetters: any) =>- (vcs: ResourceObject, includedList: ResourceObject[]): VCS => {- return convert(vcs, includedList, rootGetters);- },-vcsList: (state: VCSState) => (): VCS[] => {const list = [];for (const [_, vcs] of state.vcsById) {@@ -61,11 +67,11 @@ const getters = {};const actions = {- async fetchVCSList({ commit, rootGetters }: any) {+ async fetchVCSList({ commit }: any) {const path = "/api/vcs";const data = (await axios.get(path)).data;const vcsList = data.data.map((vcs: ResourceObject) => {- return convert(vcs, data.included, rootGetters);+ return convert(vcs);});commit("setVCSList", vcsList);@@ -73,10 +79,10 @@ const actions = {return vcsList;},- async fetchVCSById({ commit, rootGetters }: any, vcsId: VCSId) {+ async fetchVCSById({ commit }: any, vcsId: VCSId) {// include=secret to return username/password when requesting the specific vcs idconst data = (await axios.get(`/api/vcs/${vcsId}`)).data;- const vcs = convert(data.data, data.included, rootGetters);+ const vcs = convert(data.data);commit("setVCSById", {vcsId,@@ -85,7 +91,7 @@ const actions = {return vcs;},- async createVCS({ commit, rootGetters }: any, newVCS: VCSCreate) {+ async createVCS({ commit }: any, newVCS: VCSCreate) {const data = (await axios.post(`/api/vcs`, {data: {@@ -94,7 +100,7 @@ const actions = {},})).data;- const createdVCS = convert(data.data, data.included, rootGetters);+ const createdVCS = convert(data.data);commit("setVCSById", {vcsId: createdVCS.id,@@ -105,7 +111,7 @@ const actions = {},async patchVCS(- { commit, rootGetters }: any,+ { commit }: any,{vcsId,vcsPatch,@@ -122,7 +128,7 @@ const actions = {},})).data;- const updatedVCS = convert(data.data, data.included, rootGetters);+ const updatedVCS = convert(data.data);commit("setVCSById", {vcsId: updatedVCS.id,@@ -142,7 +148,7 @@ const actions = {},async createVCSToken(- { commit, rootGetters }: any,+ { commit }: any,{ vcsId, tokenCreate }: { vcsId: VCSId; tokenCreate: VCSTokenCreate }) {const data = (@@ -153,7 +159,7 @@ const actions = {},})).data;- const createdVCS = convert(data.data, data.included, rootGetters);+ const createdVCS = convert(data.data);commit("setVCSById", {vcsId: createdVCS.id,@@ -162,6 +168,19 @@ const actions = {return createdVCS;},++ async fetchRepositoryListByVCS({ commit }: any, vcs: VCS) {+ const repositoryList = (+ await axios.get(`/api/vcs/${vcs.id}/repository`)+ ).data.data.map((repository: ResourceObject) => {+ return convertRepository(repository);+ });++ console.log("repo", repositoryList);++ commit("setRepositoryListByVCSId", { vcsId: vcs.id, repositoryList });+ return repositoryList;+ },};const mutations = {@@ -187,6 +206,19 @@ const mutations = {deleteVCSById(state: VCSState, vcsId: VCSId) {state.vcsById.delete(vcsId);},++ setRepositoryListByVCSId(+ state: VCSState,+ {+ vcsId,+ repositoryList,+ }: {+ vcsId: VCSId;+ repositoryList: Repository[];+ }+ ) {+ state.repositoryListByVCSId.set(vcsId, repositoryList);+ },};export default {diff --git a/frontend/src/types/common.ts b/frontend/src/types/common.tsindex 430932dddb..75f4c1f94d 100644--- a/frontend/src/types/common.ts+++ b/frontend/src/types/common.ts@@ -318,6 +318,11 @@ export const unknown = (};const UNKONWN_REPOSITORY: Repository = {+ id: UNKNOWN_ID,+ creator: UNKNOWN_PRINCIPAL,+ updater: UNKNOWN_PRINCIPAL,+ createdTs: 0,+ updatedTs: 0,externalId: UNKNOWN_ID.toString(),name: "",fullPath: "",@@ -586,6 +591,11 @@ export const empty = (};const EMPTY_REPOSITORY: Repository = {+ id: EMPTY_ID,+ creator: EMPTY_PRINCIPAL,+ updater: EMPTY_PRINCIPAL,+ createdTs: 0,+ updatedTs: 0,externalId: EMPTY_ID.toString(),name: "",fullPath: "",diff --git a/frontend/src/types/id.ts b/frontend/src/types/id.tsindex 78d2b84d6d..8d29b7d007 100644--- a/frontend/src/types/id.ts+++ b/frontend/src/types/id.ts@@ -39,6 +39,8 @@ export type TableId = IdType;export type VCSId = IdType;+export type RepositoryId = IdType;+export type CommandId = IdType;export type CommandRegisterId = IdType;diff --git a/frontend/src/types/project.ts b/frontend/src/types/project.tsindex 9b4a59df06..491816de69 100644--- a/frontend/src/types/project.ts+++ b/frontend/src/types/project.ts@@ -1,7 +1,7 @@import { RowStatus } from "./common";import { MemberId, PrincipalId, ProjectId } from "./id";import { Principal } from "./principal";-import { Repository } from "./repository";+import { ExternalRepository, Repository } from "./repository";import { VCS } from "./vcs";export type ProjectRoleType = "OWNER" | "DEVELOPER";@@ -83,7 +83,7 @@ export type ProjectRepoConfig = {vcs: VCS;code: string;accessToken: string;- repository: Repository;+ repository: ExternalRepository;baseDirectory: string;branchFilter: string;};diff --git a/frontend/src/types/repository.ts b/frontend/src/types/repository.tsindex fa600df3c1..bffa1d8f14 100644--- a/frontend/src/types/repository.ts+++ b/frontend/src/types/repository.ts@@ -1,4 +1,16 @@+import { RepositoryId } from "./id";+import { Principal } from "./principal";+export type Repository = {+ id: RepositoryId;++ // Standard fields+ creator: Principal;+ createdTs: number;+ updater: Principal;+ updatedTs: number;++ // Domain specific fields// e.g. In GitLab, this is the corresponding project id.externalId: string;// e.g. sample-project@@ -8,3 +20,14 @@ export type Repository = {// e.g. http://gitlab.bytebase.com/bytebase/sample-projectwebURL: string;};++export type ExternalRepository = {+ // e.g. In GitLab, this is the corresponding project id. e.g. 123+ externalId: string;+ // e.g. sample-project+ name: string;+ // e.g. bytebase/sample-project+ fullPath: string;+ // e.g. http://gitlab.bytebase.com/bytebase/sample-project+ webURL: string;+};diff --git a/frontend/src/types/store.ts b/frontend/src/types/store.tsindex 6b67bac388..9c4714bbed 100644--- a/frontend/src/types/store.ts+++ b/frontend/src/types/store.ts@@ -24,6 +24,7 @@ import { Project } from "./project";import { Notification } from "./notification";import { Table } from "./table";import { VCS } from "./vcs";+import { Repository } from "./repository";export interface AuthState {currentUser: Principal;@@ -100,6 +101,7 @@ export interface TableState {export interface VCSState {vcsById: Map<VCSId, VCS>;+ repositoryListByVCSId: Map<VCSId, Repository[]>;}export interface NotificationState {