dosubot[bot] commented on issue #7524:
URL: 
https://github.com/apache/incubator-devlake/issues/7524#issuecomment-2134503466

   <!-- Answer -->
   To add a GitLab project with sub-projects to your scope in DevLake when you 
receive a "no data to select" message, you need to ensure that the `PutScopes` 
function is correctly creating or updating the GitLab project data. Here is the 
relevant part of the code:
   
   ```go
   package api
   
   import (
        "github.com/apache/incubator-devlake/core/errors"
        "github.com/apache/incubator-devlake/core/plugin"
        "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
        "github.com/apache/incubator-devlake/plugins/gitlab/models"
   )
   
   type PutScopesReqBody api.PutScopesReqBody[models.GitlabProject]
   type ScopeDetail api.ScopeDetail[models.GitlabProject, 
models.GitlabScopeConfig]
   
   // PutScopes create or update gitlab project
   // @Summary create or update gitlab project
   // @Description Create or update gitlab project
   // @Tags plugins/gitlab
   // @Accept application/json
   // @Param connectionId path int false "connection ID"
   // @Param scope body PutScopesReqBody true "json"
   // @Success 200  {object} []models.GitlabProject
   // @Failure 400  {object} shared.ApiBody "Bad Request"
   // @Failure 500  {object} shared.ApiBody "Internal Error"
   // @Router /plugins/gitlab/connections/{connectionId}/scopes [PUT]
   func PutScopes(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, 
errors.Error) {
        return dsHelper.ScopeApi.PutMultiple(input)
   }
   ```
   
   Ensure that the `PutScopes` function is correctly set up to create or update 
the GitLab project data. If the data is not being fetched correctly, you might 
need to check the connection settings and the project ID being used.
   
   Additionally, you can use the `GetScopeList` function to retrieve the list 
of GitLab projects and ensure they are being correctly fetched:
   
   ```go
   // GetScopeList get Gitlab projects
   // @Summary get Gitlab projects
   // @Description get Gitlab projects
   // @Tags plugins/gitlab
   // @Param connectionId path int false "connection ID"
   // @Param searchTerm query string false "search term for scope name"
   // @Param blueprints query bool false "also return blueprints using these 
scopes as part of the payload"
   // @Success 200  {object} []ScopeDetail
   // @Failure 400  {object} shared.ApiBody "Bad Request"
   // @Failure 500  {object} shared.ApiBody "Internal Error"
   // @Router /plugins/gitlab/connections/{connectionId}/scopes/ [GET]
   func GetScopeList(input *plugin.ApiResourceInput) 
(*plugin.ApiResourceOutput, errors.Error) {
        return dsHelper.ScopeApi.GetPage(input)
   }
   ```
   
   Ensure that your configuration in the UI is set up correctly. The 
`GitLabConfig` in the `config-ui/src/plugins/register/gitlab/config.tsx` file 
should be properly configured to handle GitLab connections and data scopes:
   
   ```tsx
   import { ExternalLink } from '@/components';
   import { DOC_URL } from '@/release';
   import { IPluginConfig } from '@/types';
   
   import Icon from './assets/icon.svg?react';
   
   export const GitLabConfig: IPluginConfig = {
     plugin: 'gitlab',
     name: 'GitLab',
     icon: ({ color }) => <Icon fill={color} />,
     sort: 6,
     connection: {
       docLink: DOC_URL.PLUGIN.GITLAB.BASIS,
       initialValues: {
         endpoint: 'https://gitlab.com/api/v4/',
       },
       fields: [
         'name',
         {
           key: 'endpoint',
           multipleVersions: {
             cloud: 'https://gitlab.com/api/v4/',
             server: '(v11+)',
           },
           subLabel:
             'If you are using GitLab Server, please enter the endpoint URL. 
E.g. https://gitlab.your-company.com/api/v4/',
         },
         {
           key: 'token',
           label: 'Personal Access Token',
           subLabel: (
             <ExternalLink link={DOC_URL.PLUGIN.GITLAB.AUTH_TOKEN}>
               Learn how to create a personal access token
             </ExternalLink>
           ),
         },
         'proxy',
         {
           key: 'rateLimitPerHour',
           subLabel:
             'By default, DevLake uses dynamic rate limit around 12,000 
requests/hour for optimized data collection for GitLab. But you can adjust the 
collection speed by entering a fixed value.',
           learnMore: DOC_URL.PLUGIN.GITLAB.RATE_LIMIT,
           externalInfo:
             'The maximum rate limit for GitLab Cloud is 120,000 requests/hour. 
Tokens under the same IP address share the rate limit, so the actual rate limit 
for your token will be lower than this number.',
           defaultValue: 12000,
         },
       ],
     },
     dataScope: {
       searchPlaceholder: 'Please enter at least 3 characters to search',
       title: 'Projects',
       millerColumn: {
         columnCount: 2.5,
         firstColumnTitle: 'Subgroups/Projects',
       },
     },
     scopeConfig: {
       entities: ['CODE', 'TICKET', 'CODEREVIEW', 'CROSS', 'CICD'],
       transformation: {
         envNamePattern: '(?i)prod(.*)',
         deploymentPattern: '',
         productionPattern: '',
       },
     },
   };
   ```
   
   Furthermore, the `listGitlabRemoteScopes` function in the backend code is 
responsible for listing GitLab projects and sub-projects. Ensure this function 
is correctly implemented to fetch the necessary data:
   
   ```go
   func listGitlabRemoteScopes(
        connection *models.GitlabConnection,
        apiClient plugin.ApiClient,
        groupId string,
        page GitlabRemotePagination,
   ) (
        children []dsmodels.DsRemoteApiScopeListEntry[models.GitlabProject],
        nextPage *GitlabRemotePagination,
        err errors.Error,
   ) {
        if page.Page == 0 {
                page.Page = 1
        }
        if page.PerPage == 0 {
                page.PerPage = 100
        }
        if page.Step == "" {
                page.Step = "group"
        }
   
        // load all groups unless groupId is user's own account
        if page.Step == "group" && !strings.HasPrefix(groupId, USERS_PREFIX) {
                children, nextPage, err = listGitlabRemoteGroups(connection, 
apiClient, groupId, page)
                if err != nil {
                        return
                }
        }
        if groupId == "" || nextPage != nil {
                return
        }
        // no more groups, start to load projects under the group
        var moreChild []dsmodels.DsRemoteApiScopeListEntry[models.GitlabProject]
        moreChild, nextPage, err = listGitlabRemoteProjects(connection, 
apiClient, groupId, GitlabRemotePagination{
                Page:    1,
                PerPage: page.PerPage,
                Step:    "project",
        })
        if err != nil {
                return
        }
        children = append(children, moreChild...)
        return
   }
   ```
   
   By ensuring these functions and configurations are correctly implemented and 
the connection settings are accurate, you should be able to add a GitLab 
project with sub-projects to your scope in DevLake 
<sup>[[1]](https://github.com/apache/incubator-devlake/blob/main/backend/plugins/gitlab/tasks/project_convertor.go)</sup><sup>[[2]](https://github.com/apache/incubator-devlake/blob/main/backend/plugins/gitlab/api/scope_api.go)</sup><sup>[[3]](https://github.com/apache/incubator-devlake/blob/main/config-ui/src/plugins/register/gitlab/config.tsx)</sup><sup>[[4]](https://github.com/apache/incubator-devlake/blob/main/backend/plugins/gitlab/api/remote_api.go)</sup>.
   
   
   <!-- Dosu Comment Footer -->
   <details>
   <summary>
   
   #### Details
   </summary>
   
   **About Dosu**
   This response is meant to be useful and save you time. It is **not meant to 
be a precise solution**, but rather a starting point for your own research.
   
   Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is 
irrelevant.
   </details>
   
   *To continue the conversation, mention @dosu.*
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@devlake.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to