Repository: kubesphere/ks-devops
Pull request #671 (2022-06-14 05:24:25)

[release-3.3] Using a new API to fetch both public and private repos of a user
This is an automated cherry-pick of #670

```release-note
None
```

ks-ci-bot: [APPROVALNOTIFIER] This PR is **NOT APPROVED**

This pull-request has been approved by:
To complete the [pull request process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process), please assign **linuxsuren** after the PR has been reviewed.
You can assign the PR to them by writing `/assign @linuxsuren` in a comment when ready.

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=kubesphere%2Fks-devops).

<details open>
Needs approval from an approver in each of these files:

- **[OWNERS](https://github.com/kubesphere/ks-devops/blob/release-3.3/OWNERS)**

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":["linuxsuren"]} -->
ks-ci-bot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/kubesphere/ks-devops/pull/671#pullrequestreview-1005246082" title="Approved">LinuxSuRen</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=kubesphere%2Fks-devops).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[OWNERS](https://github.com/kubesphere/ks-devops/blob/release-3.3/OWNERS)~~ [LinuxSuRen]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->

Patch:
diff --git a/pkg/kapis/devops/v1alpha3/scm/scmhandler.go b/pkg/kapis/devops/v1alpha3/scm/scmhandler.go
index 9c70b00..5cd2f63 100644
--- a/pkg/kapis/devops/v1alpha3/scm/scmhandler.go
+++ b/pkg/kapis/devops/v1alpha3/scm/scmhandler.go
@@ -101,7 +101,9 @@ func (h *handler) getRepositories(scm, server, org, secret, namespace string, pa
 		var listRepositoryFunc listRepository
 		if user, err = h.getCurrentUsername(c); err == nil {
 			if user == org && !strings.HasPrefix(scm, "bitbucket") {
-				listRepositoryFunc = c.Repositories.ListUser
+				listRepositoryFunc = func(ctx context.Context, s string, options goscm.ListOptions) ([]*goscm.Repository, *goscm.Response, error) {
+					return c.Repositories.List(ctx, options)
+				}
 			} else {
 				listRepositoryFunc = c.Repositories.ListOrganisation
 			}


Test patch:
diff --git a/pkg/kapis/devops/v1alpha3/scm/scmhandler_test.go b/pkg/kapis/devops/v1alpha3/scm/scmhandler_test.go
index 4611d3d..0c29df4 100644
--- a/pkg/kapis/devops/v1alpha3/scm/scmhandler_test.go
+++ b/pkg/kapis/devops/v1alpha3/scm/scmhandler_test.go
@@ -278,9 +278,11 @@ func TestSCMAPI(t *testing.T) {
 			}
 
 			gock.New("https://api.github.com").
-				Get("users/octocat/repos").
+				Get("/user/repos").
 				MatchParam("per_page", "1").
 				MatchParam("page", "1").
+				MatchParam("visibility", "all").
+				MatchParam("affiliation", "owner").
 				Reply(200).
 				Type("application/json").
 				SetHeaders(mockHeaders).