@@ -8,33 +8,29 @@ import (
8
8
9
9
// listUserRepos - List the repositories owned by the given user.
10
10
func listUserRepos (ctx * context.APIContext , u * models.User ) {
11
- userID := u .ID
12
- showPrivateRepos := ctx .IsSigned && (ctx .User .ID == userID || ctx .User .IsAdmin )
13
- ownRepos , err := models .GetUserRepositories (userID , showPrivateRepos , 1 , u .NumRepos , "" )
11
+ showPrivateRepos := ctx .IsSigned && (ctx .User .ID == u .ID || ctx .User .IsAdmin )
12
+ repos , err := models .GetUserRepositories (u .ID , showPrivateRepos , 1 , u .NumRepos , "" )
14
13
if err != nil {
15
14
ctx .Error (500 , "GetUserRepositories" , err )
16
15
return
17
16
}
18
- var accessibleRepos []* api.Repository
17
+ apiRepos := make ([]* api.Repository , len (repos ))
18
+ var ctxUserID int64
19
19
if ctx .User != nil {
20
- accessibleRepos , err = getAccessibleRepos (ctx )
20
+ ctxUserID = ctx .User .ID
21
+ }
22
+ for i := range repos {
23
+ access , err := models .AccessLevel (ctxUserID , repos [i ])
21
24
if err != nil {
22
- ctx .Error (500 , "GetAccessibleRepos" , err )
25
+ ctx .Error (500 , "AccessLevel" , err )
26
+ return
23
27
}
24
- }
25
- apiRepos := make ([]* api.Repository , len (ownRepos )+ len (accessibleRepos ))
26
- // Set owned repositories.
27
- for i := range ownRepos {
28
- apiRepos [i ] = ownRepos [i ].APIFormat (models .AccessModeOwner )
29
- }
30
- // Set repositories user has access to.
31
- for i := 0 ; i < len (accessibleRepos ); i ++ {
32
- apiRepos [i + len (ownRepos )] = accessibleRepos [i ]
28
+ apiRepos [i ] = repos [i ].APIFormat (access )
33
29
}
34
30
ctx .JSON (200 , & apiRepos )
35
31
}
36
32
37
- // ListUserRepos - list the repos owned and accessible by the given user.
33
+ // ListUserRepos - list the repos owned by the given user.
38
34
func ListUserRepos (ctx * context.APIContext ) {
39
35
// swagger:route GET /users/{username}/repos userListRepos
40
36
//
@@ -52,7 +48,7 @@ func ListUserRepos(ctx *context.APIContext) {
52
48
listUserRepos (ctx , user )
53
49
}
54
50
55
- // ListMyRepos - list the repositories owned by you .
51
+ // ListMyRepos - list the repositories you own or have access to .
56
52
func ListMyRepos (ctx * context.APIContext ) {
57
53
// swagger:route GET /user/repos userCurrentListRepos
58
54
//
@@ -62,21 +58,25 @@ func ListMyRepos(ctx *context.APIContext) {
62
58
// Responses:
63
59
// 200: RepositoryList
64
60
// 500: error
65
-
66
- listUserRepos (ctx , ctx .User )
67
- }
68
-
69
- // getAccessibleRepos - Get the repositories a user has access to.
70
- func getAccessibleRepos (ctx * context.APIContext ) ([]* api.Repository , error ) {
71
- accessibleRepos , err := ctx .User .GetRepositoryAccesses ()
61
+ ownRepos , err := models .GetUserRepositories (ctx .User .ID , true , 1 , ctx .User .NumRepos , "" )
62
+ if err != nil {
63
+ ctx .Error (500 , "GetUserRepositories" , err )
64
+ return
65
+ }
66
+ accessibleReposMap , err := ctx .User .GetRepositoryAccesses ()
72
67
if err != nil {
73
- return nil , err
68
+ ctx .Error (500 , "GetRepositoryAccesses" , err )
69
+ return
74
70
}
75
- i := 0
76
- repos := make ([]* api.Repository , len (accessibleRepos ))
77
- for repo , access := range accessibleRepos {
78
- repos [i ] = repo .APIFormat (access )
71
+
72
+ apiRepos := make ([]* api.Repository , len (ownRepos )+ len (accessibleReposMap ))
73
+ for i := range ownRepos {
74
+ apiRepos [i ] = ownRepos [i ].APIFormat (models .AccessModeOwner )
75
+ }
76
+ i := len (ownRepos )
77
+ for repo , access := range accessibleReposMap {
78
+ apiRepos [i ] = repo .APIFormat (access )
79
79
i ++
80
80
}
81
- return repos , nil
81
+ ctx . JSON ( 200 , & apiRepos )
82
82
}
0 commit comments