This is an automated email from the ASF dual-hosted git repository.

lynwee pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/main by this push:
     new ee7a29307 fix: bitbucket server search not working (#7418)
ee7a29307 is described below

commit ee7a29307bf053b51913f18d31b449e5c34b1956
Author: Klesh Wong <[email protected]>
AuthorDate: Tue Apr 30 17:31:30 2024 +0800

    fix: bitbucket server search not working (#7418)
---
 backend/plugins/bitbucket_server/api/remote_api.go | 29 ++--------------------
 1 file changed, 2 insertions(+), 27 deletions(-)

diff --git a/backend/plugins/bitbucket_server/api/remote_api.go 
b/backend/plugins/bitbucket_server/api/remote_api.go
index 218eafda6..754309086 100644
--- a/backend/plugins/bitbucket_server/api/remote_api.go
+++ b/backend/plugins/bitbucket_server/api/remote_api.go
@@ -20,7 +20,6 @@ package api
 import (
        "fmt"
        "net/url"
-       "strings"
 
        "github.com/apache/incubator-devlake/core/errors"
        "github.com/apache/incubator-devlake/core/plugin"
@@ -197,17 +196,10 @@ func searchBitbucketServerRepos(apiClient 
plugin.ApiClient, params *dsmodels.DsR
                Start: 0,
                Limit: 1,
        })
-       s := params.Search
-       gid, searchName := getSearch(s)
-
-       queryString := fmt.Sprintf("name=%s", searchName)
-       if len(gid) > 0 {
-               queryString = fmt.Sprintf("&projectkey=%s", gid)
-       }
-       query.Set("q", queryString)
+       query.Set("name", params.Search)
 
        // list repos part
-       res, err := apiClient.Get("rest/api/1.0/repos", query, nil)
+       res, err := apiClient.Get("rest/api/latest/repos", query, nil)
        if err != nil {
                return nil, err
        }
@@ -233,23 +225,6 @@ func searchBitbucketServerRepos(apiClient 
plugin.ApiClient, params *dsmodels.DsR
        return children, nil
 }
 
-func getSearch(s string) (string, string) {
-       gid := ""
-       if strings.Contains(s, "/") {
-               parts := strings.Split(s, "/")
-               if len(parts) == 2 {
-                       // KEY/repo
-                       gid = parts[0]
-                       s = strings.Join(parts[1:], "/")
-               } else if len(parts) >= 3 {
-                       // KEY/repos/repo
-                       gid = parts[0]
-                       s = strings.Join(parts[2:], "/")
-               }
-       }
-       return gid, s
-}
-
 func initialQuery(page BitBucketServerRemotePagination) url.Values {
        query := url.Values{}
        query.Set("start", fmt.Sprintf("%v", page.Start))

Reply via email to