Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: remove unused code for group member sync (#4615)
Joe Chen90d225c79abb
diff --git a/backend/plugin/vcs/github/github.go b/backend/plugin/vcs/github/github.goindex 3f499f09cb..98927af7cb 100644--- a/backend/plugin/vcs/github/github.go+++ b/backend/plugin/vcs/github/github.go@@ -65,25 +65,6 @@ func (*Provider) APIURL(instanceURL string) string {return fmt.Sprintf("%s/api/v3", instanceURL)}-// RepositoryRole is the role of the repository collaborator.-type RepositoryRole string--// The list of GitHub roles.-const (- RepositoryRoleAdmin RepositoryRole = "admin"- RepositoryRoleMaintain RepositoryRole = "maintain"- RepositoryRoleWrite RepositoryRole = "write"- RepositoryRoleTriage RepositoryRole = "triage"- RepositoryRoleRead RepositoryRole = "read"-)--// RepositoryCollaborator represents a GitHub API response for a repository-// collaborator.-type RepositoryCollaborator struct {- Login string `json:"login"`- RoleName string `json:"role_name"`-}-// User represents a GitHub API response for a user.type User struct {Name string `json:"name"`@@ -378,126 +359,6 @@ func (p *Provider) GetDiffFileList(ctx context.Context, oauthCtx common.OauthConreturn ret, nil}-// FetchUserInfo fetches user info of given user ID.-func (p *Provider) FetchUserInfo(ctx context.Context, oauthCtx common.OauthContext, instanceURL, username string) (*vcs.UserInfo, error) {- return p.fetchUserInfoImpl(ctx, oauthCtx, instanceURL, fmt.Sprintf("users/%s", username))-}--func getRoleAndMappedRole(roleName string) (githubRole RepositoryRole, bytebaseRole common.ProjectRole) {- // Please refer to https://docs.github.com/en/organizations/managing-access-to-your-organizations-repositories/repository-roles-for-an-organization#repository-roles-for-organizations- // for the detailed role descriptions of GitHub.- switch roleName {- case "admin":- return RepositoryRoleAdmin, common.ProjectOwner- case "maintain":- return RepositoryRoleMaintain, common.ProjectOwner- case "write":- return RepositoryRoleWrite, common.ProjectOwner- case "triage":- return RepositoryRoleTriage, common.ProjectDeveloper- case "read":- return RepositoryRoleRead, common.ProjectDeveloper- }- return "", ""-}--// FetchRepositoryActiveMemberList fetch all active members of a repository-//-// Docs: https://docs.github.com/en/rest/collaborators/collaborators#list-repository-collaborators-func (p *Provider) FetchRepositoryActiveMemberList(ctx context.Context, oauthCtx common.OauthContext, instanceURL, repositoryID string) ([]*vcs.RepositoryMember, error) {- var allCollaborators []RepositoryCollaborator- page := 1- for {- collaborators, hasNextPage, err := p.fetchPaginatedRepositoryCollaborators(ctx, oauthCtx, instanceURL, repositoryID, page)- if err != nil {- return nil, errors.Wrap(err, "fetch paginated list")- }- allCollaborators = append(allCollaborators, collaborators...)-- if !hasNextPage {- break- }- page++- }-- var emptyEmailUserList []string- var allMembers []*vcs.RepositoryMember- for _, c := range allCollaborators {- userInfo, err := p.FetchUserInfo(ctx, oauthCtx, githubComURL, c.Login)- if err != nil {- return nil, errors.Wrapf(err, "fetch user info, login: %s", c.Login)- }-- if userInfo.PublicEmail == "" {- emptyEmailUserList = append(emptyEmailUserList, userInfo.Name)- continue- }-- githubRole, bytebaseRole := getRoleAndMappedRole(c.RoleName)- allMembers = append(allMembers,- &vcs.RepositoryMember{- Name: userInfo.Name,- Email: userInfo.PublicEmail,- Role: bytebaseRole,- VCSRole: string(githubRole),- State: vcs.StateActive,- },- )- }-- if len(emptyEmailUserList) != 0 {- return nil, errors.Errorf("[ %v ] did not configure their public email in GitHub, please make sure every members' public email is configured before syncing, see https://docs.github.com/en/account-and-profile", strings.Join(emptyEmailUserList, ", "))- }-- return allMembers, nil-}--// fetchPaginatedRepositoryCollaborators fetches collaborators of a repository-// in given page. It return the paginated results along with a boolean-// indicating whether the next page exists.-func (p *Provider) fetchPaginatedRepositoryCollaborators(ctx context.Context, oauthCtx common.OauthContext, instanceURL, repositoryID string, page int) (collaborators []RepositoryCollaborator, hasNextPage bool, err error) {- url := fmt.Sprintf("%s/repos/%s/collaborators?page=%d&per_page=%d", p.APIURL(instanceURL), repositoryID, page, apiPageSize)- code, _, body, err := oauth.Get(- ctx,- p.client,- url,- &oauthCtx.AccessToken,- tokenRefresher(- instanceURL,- oauthContext{- ClientID: oauthCtx.ClientID,- ClientSecret: oauthCtx.ClientSecret,- RefreshToken: oauthCtx.RefreshToken,- },- oauthCtx.Refresher,- ),- )- if err != nil {- return nil, false, errors.Wrapf(err, "GET %s", url)- }-- if code == http.StatusNotFound {- return nil, false, common.Errorf(common.NotFound, "failed to fetch repository collaborators from URL %s", url)- } else if code >= 300 {- return nil, false,- errors.Errorf("failed to read repository collaborators from URL %s, status code: %d, body: %s",- url,- code,- body,- )- }-- if err := json.Unmarshal([]byte(body), &collaborators); err != nil {- return nil, false, errors.Wrap(err, "unmarshal body")- }-- // NOTE: We deliberately choose to not use the Link header for checking the next- // page to avoid introducing a new dependency, see- // https://github.com/bytebase/bytebase/pull/1423#discussion_r884278534 for the- // discussion.- return collaborators, len(collaborators) >= apiPageSize, nil-}-// oauthResponse is a GitHub OAuth response.type oauthResponse struct {AccessToken string `json:"access_token" `diff --git a/backend/plugin/vcs/github/github_test.go b/backend/plugin/vcs/github/github_test.goindex ff251dba7f..b6ca34d15b 100644--- a/backend/plugin/vcs/github/github_test.go+++ b/backend/plugin/vcs/github/github_test.go@@ -16,301 +16,6 @@ import ("github.com/bytebase/bytebase/backend/plugin/vcs/internal/oauth")-func TestProvider_FetchUserInfo(t *testing.T) {- p := newMockProvider(func(r *http.Request) (*http.Response, error) {- assert.Equal(t, "/users/octocat", r.URL.Path)- return &http.Response{- StatusCode: http.StatusOK,- // Example response taken from https://docs.github.com/en/rest/reference/users#get-a-user- Body: io.NopCloser(strings.NewReader(`-{- "login": "octocat",- "id": 1,- "node_id": "MDQ6VXNlcjE=",- "avatar_url": "https://github.com/images/error/octocat_happy.gif",- "gravatar_id": "",- "url": "https://api.github.com/users/octocat",- "html_url": "https://github.com/octocat",- "followers_url": "https://api.github.com/users/octocat/followers",- "following_url": "https://api.github.com/users/octocat/following{/other_user}",- "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",- "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",- "subscriptions_url": "https://api.github.com/users/octocat/subscriptions",- "organizations_url": "https://api.github.com/users/octocat/orgs",- "repos_url": "https://api.github.com/users/octocat/repos",- "events_url": "https://api.github.com/users/octocat/events{/privacy}",- "received_events_url": "https://api.github.com/users/octocat/received_events",- "type": "User",- "site_admin": false,- "name": "monalisa octocat",- "company": "GitHub",- "blog": "https://github.com/blog",- "location": "San Francisco",- "email": "[email protected]",- "hireable": false,- "bio": "There once was...",- "twitter_username": "monatheoctocat",- "public_repos": 2,- "public_gists": 1,- "followers": 20,- "following": 0,- "created_at": "2008-01-14T04:33:35Z",- "updated_at": "2008-01-14T04:33:35Z",- "private_gists": 81,- "total_private_repos": 100,- "owned_private_repos": 100,- "disk_usage": 10000,- "collaborators": 8,- "two_factor_authentication": true,- "plan": {- "name": "Medium",- "space": 400,- "private_repos": 20,- "collaborators": 0- }-}-`)),- }, nil- },- )-- ctx := context.Background()- got, err := p.FetchUserInfo(ctx, common.OauthContext{}, githubComURL, "octocat")- require.NoError(t, err)-- want := &vcs.UserInfo{- PublicEmail: "[email protected]",- Name: "monalisa octocat",- State: vcs.StateActive,- }- assert.Equal(t, want, got)-}--func TestProvider_FetchRepositoryActiveMemberList(t *testing.T) {- t.Run("missing public email", func(t *testing.T) {- p := newProvider(- vcs.ProviderConfig{- Client: &http.Client{- Transport: &common.MockRoundTripper{- MockRoundTrip: func(r *http.Request) (*http.Response, error) {- switch r.URL.Path {- case "/repos/octocat/Hello-World/collaborators":- return &http.Response{- StatusCode: http.StatusOK,- // Example response taken from https://docs.github.com/en/rest/collaborators/collaborators#list-repository-collaborators- Body: io.NopCloser(strings.NewReader(`-[- {- "login": "octocat",- "id": 1,- "node_id": "MDQ6VXNlcjE=",- "avatar_url": "https://github.com/images/error/octocat_happy.gif",- "gravatar_id": "",- "url": "https://api.github.com/users/octocat",- "html_url": "https://github.com/octocat",- "followers_url": "https://api.github.com/users/octocat/followers",- "following_url": "https://api.github.com/users/octocat/following{/other_user}",- "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",- "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",- "subscriptions_url": "https://api.github.com/users/octocat/subscriptions",- "organizations_url": "https://api.github.com/users/octocat/orgs",- "repos_url": "https://api.github.com/users/octocat/repos",- "events_url": "https://api.github.com/users/octocat/events{/privacy}",- "received_events_url": "https://api.github.com/users/octocat/received_events",- "type": "User",- "site_admin": false,- "permissions": {- "pull": true,- "triage": true,- "push": true,- "maintain": false,- "admin": false- },- "role_name": "write"- }-]-`)),- }, nil- case "/users/octocat":- return &http.Response{- StatusCode: http.StatusOK,- // Example response derived from https://docs.github.com/en/rest/reference/users#get-a-user- Body: io.NopCloser(strings.NewReader(`-{- "login": "octocat",- "id": 1,- "node_id": "MDQ6VXNlcjE=",- "avatar_url": "https://github.com/images/error/octocat_happy.gif",- "gravatar_id": "",- "url": "https://api.github.com/users/octocat",- "html_url": "https://github.com/octocat",- "followers_url": "https://api.github.com/users/octocat/followers",- "following_url": "https://api.github.com/users/octocat/following{/other_user}",- "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",- "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",- "subscriptions_url": "https://api.github.com/users/octocat/subscriptions",- "organizations_url": "https://api.github.com/users/octocat/orgs",- "repos_url": "https://api.github.com/users/octocat/repos",- "events_url": "https://api.github.com/users/octocat/events{/privacy}",- "received_events_url": "https://api.github.com/users/octocat/received_events",- "type": "User",- "site_admin": false,- "name": "monalisa octocat",- "company": "GitHub",- "blog": "https://github.com/blog",- "location": "San Francisco",- "email": "",- "hireable": false,- "bio": "There once was...",- "twitter_username": "monatheoctocat",- "public_repos": 2,- "public_gists": 1,- "followers": 20,- "following": 0,- "created_at": "2008-01-14T04:33:35Z",- "updated_at": "2008-01-14T04:33:35Z",- "private_gists": 81,- "total_private_repos": 100,- "owned_private_repos": 100,- "disk_usage": 10000,- "collaborators": 8,- "two_factor_authentication": true,- "plan": {- "name": "Medium",- "space": 400,- "private_repos": 20,- "collaborators": 0- }-}-`)),- }, nil- }- return nil, errors.Errorf("unexpected request path: %s", r.URL.Path)- },- },- },- },- )-- ctx := context.Background()- _, got := p.FetchRepositoryActiveMemberList(ctx, common.OauthContext{}, githubComURL, "octocat/Hello-World")- want := "[ monalisa octocat ] did not configure their public email in GitHub, please make sure every members' public email is configured before syncing, see https://docs.github.com/en/account-and-profile"- assert.EqualError(t, got, want)- })-- p := newMockProvider(func(r *http.Request) (*http.Response, error) {- switch r.URL.Path {- case "/repos/octocat/Hello-World/collaborators":- return &http.Response{- StatusCode: http.StatusOK,- // Example response taken from https://docs.github.com/en/rest/collaborators/collaborators#list-repository-collaborators- Body: io.NopCloser(strings.NewReader(`-[- {- "login": "octocat",- "id": 1,- "node_id": "MDQ6VXNlcjE=",- "avatar_url": "https://github.com/images/error/octocat_happy.gif",- "gravatar_id": "",- "url": "https://api.github.com/users/octocat",- "html_url": "https://github.com/octocat",- "followers_url": "https://api.github.com/users/octocat/followers",- "following_url": "https://api.github.com/users/octocat/following{/other_user}",- "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",- "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",- "subscriptions_url": "https://api.github.com/users/octocat/subscriptions",- "organizations_url": "https://api.github.com/users/octocat/orgs",- "repos_url": "https://api.github.com/users/octocat/repos",- "events_url": "https://api.github.com/users/octocat/events{/privacy}",- "received_events_url": "https://api.github.com/users/octocat/received_events",- "type": "User",- "site_admin": false,- "permissions": {- "pull": true,- "triage": true,- "push": true,- "maintain": false,- "admin": false- },- "role_name": "write"- }-]-`)),- }, nil- case "/users/octocat":- return &http.Response{- StatusCode: http.StatusOK,- // Example response taken from https://docs.github.com/en/rest/reference/users#get-a-user- Body: io.NopCloser(strings.NewReader(`-{- "login": "octocat",- "id": 1,- "node_id": "MDQ6VXNlcjE=",- "avatar_url": "https://github.com/images/error/octocat_happy.gif",- "gravatar_id": "",- "url": "https://api.github.com/users/octocat",- "html_url": "https://github.com/octocat",- "followers_url": "https://api.github.com/users/octocat/followers",- "following_url": "https://api.github.com/users/octocat/following{/other_user}",- "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",- "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",- "subscriptions_url": "https://api.github.com/users/octocat/subscriptions",- "organizations_url": "https://api.github.com/users/octocat/orgs",- "repos_url": "https://api.github.com/users/octocat/repos",- "events_url": "https://api.github.com/users/octocat/events{/privacy}",- "received_events_url": "https://api.github.com/users/octocat/received_events",- "type": "User",- "site_admin": false,- "name": "monalisa octocat",- "company": "GitHub",- "blog": "https://github.com/blog",- "location": "San Francisco",- "email": "[email protected]",- "hireable": false,- "bio": "There once was...",- "twitter_username": "monatheoctocat",- "public_repos": 2,- "public_gists": 1,- "followers": 20,- "following": 0,- "created_at": "2008-01-14T04:33:35Z",- "updated_at": "2008-01-14T04:33:35Z",- "private_gists": 81,- "total_private_repos": 100,- "owned_private_repos": 100,- "disk_usage": 10000,- "collaborators": 8,- "two_factor_authentication": true,- "plan": {- "name": "Medium",- "space": 400,- "private_repos": 20,- "collaborators": 0- }-}-`)),- }, nil- }- return nil, errors.Errorf("unexpected request path: %s", r.URL.Path)- },- )-- ctx := context.Background()- got, err := p.FetchRepositoryActiveMemberList(ctx, common.OauthContext{}, githubComURL, "octocat/Hello-World")- require.NoError(t, err)-- want := []*vcs.RepositoryMember{- {- Email: "[email protected]",- Name: "monalisa octocat",- State: vcs.StateActive,- Role: common.ProjectOwner,- VCSRole: string(RepositoryRoleWrite),- },- }- assert.Equal(t, want, got)-}-func TestProvider_FetchCommitByID(t *testing.T) {p := newMockProvider(func(r *http.Request) (*http.Response, error) {assert.Equal(t, "/repos/octocat/Hello-World/git/commits/7638417db6d59f3c431d3e1f261cc637155684cd", r.URL.Path)diff --git a/backend/plugin/vcs/gitlab/gitlab.go b/backend/plugin/vcs/gitlab/gitlab.goindex 259ebd923c..06b7f86c50 100644--- a/backend/plugin/vcs/gitlab/gitlab.go+++ b/backend/plugin/vcs/gitlab/gitlab.go@@ -131,29 +131,6 @@ type CommitsDiff struct {FileDiffList []MergeRequestFile `json:"diffs"`}-// ProjectRole is the role of the project member.-type ProjectRole string--// The list of GitLab roles.-const (- ProjectRoleOwner ProjectRole = "Owner"- ProjectRoleMaintainer ProjectRole = "Maintainer"- ProjectRoleDeveloper ProjectRole = "Developer"- ProjectRoleReporter ProjectRole = "Reporter"- ProjectRoleGuest ProjectRole = "Guest"- ProjectRoleMinimalAccess ProjectRole = "MinimalAccess"- ProjectRoleNoAccess ProjectRole = "NoAccess"-)--// RepositoryMember represents a GitLab API response for a repository member.-type RepositoryMember struct {- ID int `json:"id"`- Email string `json:"email"`- Name string `json:"name"`- State vcs.State `json:"state"`- AccessLevel int32 `json:"access_level"`-}-// gitLabRepository represents a GitLab API response for a repository.type gitLabRepository struct {ID int64 `json:"id"`@@ -478,146 +455,6 @@ func (p *Provider) GetDiffFileList(ctx context.Context, oauthCtx common.OauthConreturn ret, nil}-// FetchUserInfo fetches user info of given user ID.-func (p *Provider) FetchUserInfo(ctx context.Context, oauthCtx common.OauthContext, instanceURL, userID string) (*vcs.UserInfo, error) {- return p.fetchUserInfoImpl(ctx, oauthCtx, instanceURL, fmt.Sprintf("users/%s", userID))-}--func getRoleAndMappedRole(accessLevel int32) (gitLabRole ProjectRole, bytebaseRole common.ProjectRole) {- // Please refer to https://docs.gitlab.com/ee/api/members.html for the detailed role descriptions of GitLab.- switch accessLevel {- case 50 /* Owner */ :- return ProjectRoleOwner, common.ProjectOwner- case 40 /* Maintainer */ :- return ProjectRoleMaintainer, common.ProjectOwner- case 30 /* Developer */ :- return ProjectRoleDeveloper, common.ProjectDeveloper- case 20 /* Reporter */ :- return ProjectRoleReporter, common.ProjectDeveloper- case 10 /* Guest */ :- return ProjectRoleGuest, common.ProjectDeveloper- case 5 /* Minimal access */ :- return ProjectRoleMinimalAccess, common.ProjectDeveloper- case 0 /* No access */ :- return ProjectRoleNoAccess, common.ProjectDeveloper- }-- return "", ""-}--// FetchRepositoryActiveMemberList fetches all active members of a repository.-//-// Docs: https://docs.gitlab.com/ee/api/members.html#list-all-members-of-a-group-or-project-func (p *Provider) FetchRepositoryActiveMemberList(ctx context.Context, oauthCtx common.OauthContext, instanceURL, repositoryID string) ([]*vcs.RepositoryMember, error) {- var allMembers []RepositoryMember- page := 1- for {- members, hasNextPage, err := p.fetchPaginatedRepositoryActiveMemberList(ctx, oauthCtx, instanceURL, repositoryID, page)- if err != nil {- return nil, errors.Wrap(err, "fetch paginated list")- }- allMembers = append(allMembers, members...)-- if !hasNextPage {- break- }- page++- }-- var emptyEmailUserList []string- var activeMembers []*vcs.RepositoryMember- for _, m := range allMembers {- // We only want active member (both state and membership_state is active)- if m.State != vcs.StateActive {- continue- }-- // The email field is only returned if the caller credential is associated with- // a GitLab admin account. We'll try getting the email by fetching the info of- // individual users.- if m.Email == "" {- // TODO: need to work around this if the user does not set public email. For now, we just return an error listing users not having public emails.- // TODO: if the number of the member is too large, fetching sequentially may cause performance issue- userInfo, err := p.FetchUserInfo(ctx, oauthCtx, instanceURL, strconv.Itoa(m.ID))- if err != nil {- return nil, errors.Wrapf(err, "fetch user info, id: %d", m.ID)- }- m.Email = userInfo.PublicEmail- }-- if m.Email == "" {- emptyEmailUserList = append(emptyEmailUserList, m.Name)- continue- }-- gitlabRole, bytebaseRole := getRoleAndMappedRole(m.AccessLevel)- activeMembers = append(- activeMembers,- &vcs.RepositoryMember{- Name: m.Name,- Email: m.Email,- Role: bytebaseRole,- VCSRole: string(gitlabRole),- State: vcs.StateActive,- },- )- }-- if len(emptyEmailUserList) != 0 {- return nil, errors.Errorf("[ %v ] did not configure their public email in GitLab, please make sure every members' public email is configured before syncing, see https://docs.gitlab.com/ee/user/profile", strings.Join(emptyEmailUserList, ", "))- }-- return activeMembers, nil-}--// fetchPaginatedRepositoryActiveMemberList fetches active members of a-// repository in given page. It return the paginated results along with a-// boolean indicating whether the next page exists.-func (p *Provider) fetchPaginatedRepositoryActiveMemberList(ctx context.Context, oauthCtx common.OauthContext, instanceURL, repositoryID string, page int) (members []RepositoryMember, hasNextPage bool, err error) {- // The "state" filter only available in GitLab Premium self-managed, GitLab- // Premium SaaS, and higher tiers, but worth a try for less abandoned results.- url := fmt.Sprintf("%s/projects/%s/members/all?state=active&page=%d&per_page=%d", p.APIURL(instanceURL), repositoryID, page, apiPageSize)- code, _, body, err := oauth.Get(- ctx,- p.client,- url,- &oauthCtx.AccessToken,- tokenRefresher(- instanceURL,- oauthContext{- ClientID: oauthCtx.ClientID,- ClientSecret: oauthCtx.ClientSecret,- RefreshToken: oauthCtx.RefreshToken,- },- oauthCtx.Refresher,- ),- )- if err != nil {- return nil, false, errors.Wrapf(err, "GET %s", url)- }-- if code == http.StatusNotFound {- return nil, false, common.Errorf(common.NotFound, "failed to fetch repository members from URL %s", url)- } else if code >= 300 {- return nil, false,- errors.Errorf("failed to fetch repository members from URL %s, status code: %d, body: %s",- url,- code,- body,- )- }-- if err := json.Unmarshal([]byte(body), &members); err != nil {- return nil, false, errors.Wrap(err, "unmarshal body")- }-- // NOTE: We deliberately choose to not use the Link header for checking the next- // page to avoid introducing a new dependency, see- // https://github.com/bytebase/bytebase/pull/1423#discussion_r884278534 for the- // discussion.- return members, len(members) >= apiPageSize, nil-}-// FetchRepositoryFileList fetches the all files from the given repository tree// recursively.//diff --git a/backend/plugin/vcs/gitlab/gitlab_test.go b/backend/plugin/vcs/gitlab/gitlab_test.goindex 5d61c090be..37facb8ebf 100644--- a/backend/plugin/vcs/gitlab/gitlab_test.go+++ b/backend/plugin/vcs/gitlab/gitlab_test.go@@ -16,239 +16,6 @@ import ("github.com/bytebase/bytebase/backend/plugin/vcs/internal/oauth")-func TestProvider_FetchUserInfo(t *testing.T) {- p := newMockProvider(func(r *http.Request) (*http.Response, error) {- assert.Equal(t, "/api/v4/users/1", r.URL.Path)- return &http.Response{- StatusCode: http.StatusOK,- // Example response taken from https://docs.gitlab.com/ee/api/users.html#single-user- Body: io.NopCloser(strings.NewReader(`-{- "id": 1,- "username": "john_smith",- "name": "John Smith",- "state": "active",- "avatar_url": "http://localhost:3000/uploads/user/avatar/1/cd8.jpeg",- "web_url": "http://localhost:3000/john_smith",- "created_at": "2012-05-23T08:00:58Z",- "bio": "",- "bot": false,- "location": null,- "public_email": "[email protected]",- "skype": "",- "linkedin": "",- "twitter": "",- "website_url": "",- "organization": "",- "job_title": "Operations Specialist",- "followers": 1,- "following": 1-}-`)),- }, nil- },- )-- ctx := context.Background()- got, err := p.FetchUserInfo(ctx, common.OauthContext{}, "", "1")- require.NoError(t, err)-- want := &vcs.UserInfo{- PublicEmail: "[email protected]",- Name: "John Smith",- State: vcs.StateActive,- }- assert.Equal(t, want, got)-}--func TestProvider_FetchRepositoryActiveMemberList(t *testing.T) {- t.Run("missing public email", func(t *testing.T) {- p := newProvider(- vcs.ProviderConfig{- Client: &http.Client{- Transport: &common.MockRoundTripper{- MockRoundTrip: func(r *http.Request) (*http.Response, error) {- switch r.URL.Path {- case "/api/v4/projects/1/members/all":- return &http.Response{- StatusCode: http.StatusOK,- // Example response derived from https://docs.gitlab.com/ee/api/members.html#list-all-members-of-a-group-or-project-including-inherited-and-invited-members- Body: io.NopCloser(strings.NewReader(`-[- {- "id": 1,- "username": "raymond_smith",- "name": "Raymond Smith",- "state": "active",- "avatar_url": "https://www.gravatar.com/avatar/c2525a7f58ae3776070e44c106c48e15?s=80&d=identicon",- "web_url": "http://192.168.1.8:3000/root",- "created_at": "2012-09-22T14:13:35Z",- "created_by": {- "id": 2,- "username": "john_doe",- "name": "John Doe",- "state": "active",- "avatar_url": "https://www.gravatar.com/avatar/c2525a7f58ae3776070e44c106c48e15?s=80&d=identicon",- "web_url": "http://192.168.1.8:3000/root"- },- "expires_at": "2012-10-22T14:13:35Z",- "access_level": 30,- "group_saml_identity": null,- "membership_state": "active"- }-]-`)),- }, nil- case "/api/v4/users/1":- return &http.Response{- StatusCode: http.StatusOK,- // Example response derived from https://docs.gitlab.com/ee/api/users.html#single-user- Body: io.NopCloser(strings.NewReader(`-{- "id": 1,- "username": "john_smith",- "name": "John Smith",- "state": "active",- "avatar_url": "http://localhost:3000/uploads/user/avatar/1/cd8.jpeg",- "web_url": "http://localhost:3000/john_smith",- "created_at": "2012-05-23T08:00:58Z",- "bio": "",- "bot": false,- "location": null,- "public_email": "",- "skype": "",- "linkedin": "",- "twitter": "",- "website_url": "",- "organization": "",- "job_title": "Operations Specialist",- "followers": 1,- "following": 1-}-`)),- }, nil- }- return nil, errors.Errorf("unexpected request path: %s", r.URL.Path)- },- },- },- },- )-- ctx := context.Background()- _, got := p.FetchRepositoryActiveMemberList(ctx, common.OauthContext{}, "", "1")- want := "[ Raymond Smith ] did not configure their public email in GitLab, please make sure every members' public email is configured before syncing, see https://docs.gitlab.com/ee/user/profile"- assert.EqualError(t, got, want)- })-- p := newMockProvider(func(r *http.Request) (*http.Response, error) {- switch r.URL.Path {- case "/api/v4/projects/1/members/all":- return &http.Response{- StatusCode: http.StatusOK,- // Example response derived from https://docs.gitlab.com/ee/api/members.html#list-all-members-of-a-group-or-project-including-inherited-and-invited-members- Body: io.NopCloser(strings.NewReader(`-[- {- "id": 1,- "username": "raymond_smith",- "name": "Raymond Smith",- "state": "active",- "avatar_url": "https://www.gravatar.com/avatar/c2525a7f58ae3776070e44c106c48e15?s=80&d=identicon",- "web_url": "http://192.168.1.8:3000/root",- "created_at": "2012-09-22T14:13:35Z",- "created_by": {- "id": 2,- "username": "john_doe",- "name": "John Doe",- "state": "active",- "avatar_url": "https://www.gravatar.com/avatar/c2525a7f58ae3776070e44c106c48e15?s=80&d=identicon",- "web_url": "http://192.168.1.8:3000/root"- },- "expires_at": "2012-10-22T14:13:35Z",- "access_level": 30,- "group_saml_identity": null,- "membership_state": "active"- },- {- "id": 2,- "username": "john_doe",- "name": "John Doe",- "state": "archived",- "avatar_url": "https://www.gravatar.com/avatar/c2525a7f58ae3776070e44c106c48e15?s=80&d=identicon",- "web_url": "http://192.168.1.8:3000/root",- "created_at": "2012-09-22T14:13:35Z",- "created_by": {- "id": 1,- "username": "raymond_smith",- "name": "Raymond Smith",- "state": "active",- "avatar_url": "https://www.gravatar.com/avatar/c2525a7f58ae3776070e44c106c48e15?s=80&d=identicon",- "web_url": "http://192.168.1.8:3000/root"- },- "expires_at": "2012-10-22T14:13:35Z",- "access_level": 30,- "email": "[email protected]",- "group_saml_identity": {- "extern_uid":"ABC-1234567890",- "provider": "group_saml",- "saml_provider_id": 10- },- "membership_state": "active"- }-]-`)),- }, nil- case "/api/v4/users/1":- return &http.Response{- StatusCode: http.StatusOK,- // Example response taken from https://docs.gitlab.com/ee/api/users.html#single-user- Body: io.NopCloser(strings.NewReader(`-{- "id": 1,- "username": "john_smith",- "name": "John Smith",- "state": "active",- "avatar_url": "http://localhost:3000/uploads/user/avatar/1/cd8.jpeg",- "web_url": "http://localhost:3000/john_smith",- "created_at": "2012-05-23T08:00:58Z",- "bio": "",- "bot": false,- "location": null,- "public_email": "[email protected]",- "skype": "",- "linkedin": "",- "twitter": "",- "website_url": "",- "organization": "",- "job_title": "Operations Specialist",- "followers": 1,- "following": 1-}-`)),- }, nil- }- return nil, errors.Errorf("unexpected request path: %s", r.URL.Path)- },- )-- ctx := context.Background()- got, err := p.FetchRepositoryActiveMemberList(ctx, common.OauthContext{}, "", "1")- require.NoError(t, err)-- // Non-active member should be excluded- want := []*vcs.RepositoryMember{- {- Email: "[email protected]",- Name: "Raymond Smith",- State: vcs.StateActive,- Role: common.ProjectDeveloper,- VCSRole: string(ProjectRoleDeveloper),- },- }- assert.Equal(t, want, got)-}-func TestProvider_FetchCommitByID(t *testing.T) {p := newMockProvider(func(r *http.Request) (*http.Response, error) {assert.Equal(t, "/api/v4/projects/5/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6", r.URL.Path)diff --git a/backend/plugin/vcs/vcs.go b/backend/plugin/vcs/vcs.goindex 2df497514d..4fe3e26af9 100644--- a/backend/plugin/vcs/vcs.go+++ b/backend/plugin/vcs/vcs.go@@ -144,15 +144,6 @@ type UserInfo struct {State State `json:"state"`}-// RepositoryMember is the API message for repository member info.-type RepositoryMember struct {- Email string `json:"email"`- Name string `json:"name"`- State State `json:"state"`- Role common.ProjectRole `json:"role"`- VCSRole string `json:"vcsRole"`-}-// Repository is the API message for repository info.type Repository struct {ID int64 `json:"id"`@@ -221,18 +212,6 @@ type Provider interface {// beforeCommit: the previous commit// afterCommit: the current commitGetDiffFileList(ctx context.Context, oauthCtx common.OauthContext, instanceURL, repositoryID, beforeCommit, afterCommit string) ([]FileDiff, error)- // Fetch the user info of the given userID- //- // oauthCtx: OAuth context to write the file content- // instanceURL: VCS instance URL- // user: the ID or username of the desired user- FetchUserInfo(ctx context.Context, oauthCtx common.OauthContext, instanceURL string, user string) (*UserInfo, error)- // Fetch all active members of a given repository- //- // oauthCtx: OAuth context to write the file content- // instanceURL: VCS instance URL- // repositoryID: the repository ID from the external VCS system (note this is NOT the ID of Bytebase's own repository resource)- FetchRepositoryActiveMemberList(ctx context.Context, oauthCtx common.OauthContext, instanceURL, repositoryID string) ([]*RepositoryMember, error)// Fetch all repository within a given user's scope//