@@ -36,6 +36,46 @@ func (q *Queries) CountForksOfRepo(ctx context.Context, db DBTX, forkOfRepoID pg |
| 36 | 36 | return count, err |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | +const countPublicReposForOwnerOrg = `-- name: CountPublicReposForOwnerOrg :one |
| 40 | +SELECT count(*) FROM repos |
| 41 | +WHERE owner_org_id = $1 |
| 42 | + AND visibility = 'public' |
| 43 | + AND deleted_at IS NULL |
| 44 | +` |
| 45 | + |
| 46 | +func (q *Queries) CountPublicReposForOwnerOrg(ctx context.Context, db DBTX, ownerOrgID pgtype.Int8) (int64, error) { |
| 47 | + row := db.QueryRow(ctx, countPublicReposForOwnerOrg, ownerOrgID) |
| 48 | + var count int64 |
| 49 | + err := row.Scan(&count) |
| 50 | + return count, err |
| 51 | +} |
| 52 | + |
| 53 | +const countPublicReposForOwnerUser = `-- name: CountPublicReposForOwnerUser :one |
| 54 | +SELECT count(*) FROM repos |
| 55 | +WHERE owner_user_id = $1 |
| 56 | + AND visibility = 'public' |
| 57 | + AND deleted_at IS NULL |
| 58 | +` |
| 59 | + |
| 60 | +func (q *Queries) CountPublicReposForOwnerUser(ctx context.Context, db DBTX, ownerUserID pgtype.Int8) (int64, error) { |
| 61 | + row := db.QueryRow(ctx, countPublicReposForOwnerUser, ownerUserID) |
| 62 | + var count int64 |
| 63 | + err := row.Scan(&count) |
| 64 | + return count, err |
| 65 | +} |
| 66 | + |
| 67 | +const countReposForOwnerOrg = `-- name: CountReposForOwnerOrg :one |
| 68 | +SELECT count(*) FROM repos |
| 69 | +WHERE owner_org_id = $1 AND deleted_at IS NULL |
| 70 | +` |
| 71 | + |
| 72 | +func (q *Queries) CountReposForOwnerOrg(ctx context.Context, db DBTX, ownerOrgID pgtype.Int8) (int64, error) { |
| 73 | + row := db.QueryRow(ctx, countReposForOwnerOrg, ownerOrgID) |
| 74 | + var count int64 |
| 75 | + err := row.Scan(&count) |
| 76 | + return count, err |
| 77 | +} |
| 78 | + |
| 39 | 79 | const countReposForOwnerUser = `-- name: CountReposForOwnerUser :one |
| 40 | 80 | SELECT count(*) FROM repos |
| 41 | 81 | WHERE owner_user_id = $1 AND deleted_at IS NULL |
@@ -918,6 +958,152 @@ func (q *Queries) ListPublicContributionRepos(ctx context.Context, db DBTX, limi |
| 918 | 958 | return items, nil |
| 919 | 959 | } |
| 920 | 960 | |
| 961 | +const listPublicReposForOwnerOrg = `-- name: ListPublicReposForOwnerOrg :many |
| 962 | +SELECT id, owner_user_id, owner_org_id, name, description, visibility, |
| 963 | + default_branch, is_archived, archived_at, deleted_at, |
| 964 | + disk_used_bytes, fork_of_repo_id, license_key, primary_language, |
| 965 | + has_issues, has_pulls, created_at, updated_at, default_branch_oid, |
| 966 | + allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method, |
| 967 | + star_count, watcher_count, fork_count, init_status, |
| 968 | + last_indexed_oid |
| 969 | +FROM repos |
| 970 | +WHERE owner_org_id = $1 |
| 971 | + AND visibility = 'public' |
| 972 | + AND deleted_at IS NULL |
| 973 | +ORDER BY updated_at DESC |
| 974 | +LIMIT $2 OFFSET $3 |
| 975 | +` |
| 976 | + |
| 977 | +type ListPublicReposForOwnerOrgParams struct { |
| 978 | + OwnerOrgID pgtype.Int8 |
| 979 | + Limit int32 |
| 980 | + Offset int32 |
| 981 | +} |
| 982 | + |
| 983 | +// Public-only org repo listing for non-member callers (and the no-auth |
| 984 | +// public-discovery REST view). |
| 985 | +func (q *Queries) ListPublicReposForOwnerOrg(ctx context.Context, db DBTX, arg ListPublicReposForOwnerOrgParams) ([]Repo, error) { |
| 986 | + rows, err := db.Query(ctx, listPublicReposForOwnerOrg, arg.OwnerOrgID, arg.Limit, arg.Offset) |
| 987 | + if err != nil { |
| 988 | + return nil, err |
| 989 | + } |
| 990 | + defer rows.Close() |
| 991 | + items := []Repo{} |
| 992 | + for rows.Next() { |
| 993 | + var i Repo |
| 994 | + if err := rows.Scan( |
| 995 | + &i.ID, |
| 996 | + &i.OwnerUserID, |
| 997 | + &i.OwnerOrgID, |
| 998 | + &i.Name, |
| 999 | + &i.Description, |
| 1000 | + &i.Visibility, |
| 1001 | + &i.DefaultBranch, |
| 1002 | + &i.IsArchived, |
| 1003 | + &i.ArchivedAt, |
| 1004 | + &i.DeletedAt, |
| 1005 | + &i.DiskUsedBytes, |
| 1006 | + &i.ForkOfRepoID, |
| 1007 | + &i.LicenseKey, |
| 1008 | + &i.PrimaryLanguage, |
| 1009 | + &i.HasIssues, |
| 1010 | + &i.HasPulls, |
| 1011 | + &i.CreatedAt, |
| 1012 | + &i.UpdatedAt, |
| 1013 | + &i.DefaultBranchOid, |
| 1014 | + &i.AllowSquashMerge, |
| 1015 | + &i.AllowRebaseMerge, |
| 1016 | + &i.AllowMergeCommit, |
| 1017 | + &i.DefaultMergeMethod, |
| 1018 | + &i.StarCount, |
| 1019 | + &i.WatcherCount, |
| 1020 | + &i.ForkCount, |
| 1021 | + &i.InitStatus, |
| 1022 | + &i.LastIndexedOid, |
| 1023 | + ); err != nil { |
| 1024 | + return nil, err |
| 1025 | + } |
| 1026 | + items = append(items, i) |
| 1027 | + } |
| 1028 | + if err := rows.Err(); err != nil { |
| 1029 | + return nil, err |
| 1030 | + } |
| 1031 | + return items, nil |
| 1032 | +} |
| 1033 | + |
| 1034 | +const listPublicReposForOwnerUser = `-- name: ListPublicReposForOwnerUser :many |
| 1035 | +SELECT id, owner_user_id, owner_org_id, name, description, visibility, |
| 1036 | + default_branch, is_archived, archived_at, deleted_at, |
| 1037 | + disk_used_bytes, fork_of_repo_id, license_key, primary_language, |
| 1038 | + has_issues, has_pulls, created_at, updated_at, default_branch_oid, |
| 1039 | + allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method, |
| 1040 | + star_count, watcher_count, fork_count, init_status, |
| 1041 | + last_indexed_oid |
| 1042 | +FROM repos |
| 1043 | +WHERE owner_user_id = $1 |
| 1044 | + AND visibility = 'public' |
| 1045 | + AND deleted_at IS NULL |
| 1046 | +ORDER BY updated_at DESC |
| 1047 | +LIMIT $2 OFFSET $3 |
| 1048 | +` |
| 1049 | + |
| 1050 | +type ListPublicReposForOwnerUserParams struct { |
| 1051 | + OwnerUserID pgtype.Int8 |
| 1052 | + Limit int32 |
| 1053 | + Offset int32 |
| 1054 | +} |
| 1055 | + |
| 1056 | +// Public-only view of a user's repos for the "list another user's repos" |
| 1057 | +// REST endpoint. Hidden behind the same updated_at ordering. |
| 1058 | +func (q *Queries) ListPublicReposForOwnerUser(ctx context.Context, db DBTX, arg ListPublicReposForOwnerUserParams) ([]Repo, error) { |
| 1059 | + rows, err := db.Query(ctx, listPublicReposForOwnerUser, arg.OwnerUserID, arg.Limit, arg.Offset) |
| 1060 | + if err != nil { |
| 1061 | + return nil, err |
| 1062 | + } |
| 1063 | + defer rows.Close() |
| 1064 | + items := []Repo{} |
| 1065 | + for rows.Next() { |
| 1066 | + var i Repo |
| 1067 | + if err := rows.Scan( |
| 1068 | + &i.ID, |
| 1069 | + &i.OwnerUserID, |
| 1070 | + &i.OwnerOrgID, |
| 1071 | + &i.Name, |
| 1072 | + &i.Description, |
| 1073 | + &i.Visibility, |
| 1074 | + &i.DefaultBranch, |
| 1075 | + &i.IsArchived, |
| 1076 | + &i.ArchivedAt, |
| 1077 | + &i.DeletedAt, |
| 1078 | + &i.DiskUsedBytes, |
| 1079 | + &i.ForkOfRepoID, |
| 1080 | + &i.LicenseKey, |
| 1081 | + &i.PrimaryLanguage, |
| 1082 | + &i.HasIssues, |
| 1083 | + &i.HasPulls, |
| 1084 | + &i.CreatedAt, |
| 1085 | + &i.UpdatedAt, |
| 1086 | + &i.DefaultBranchOid, |
| 1087 | + &i.AllowSquashMerge, |
| 1088 | + &i.AllowRebaseMerge, |
| 1089 | + &i.AllowMergeCommit, |
| 1090 | + &i.DefaultMergeMethod, |
| 1091 | + &i.StarCount, |
| 1092 | + &i.WatcherCount, |
| 1093 | + &i.ForkCount, |
| 1094 | + &i.InitStatus, |
| 1095 | + &i.LastIndexedOid, |
| 1096 | + ); err != nil { |
| 1097 | + return nil, err |
| 1098 | + } |
| 1099 | + items = append(items, i) |
| 1100 | + } |
| 1101 | + if err := rows.Err(); err != nil { |
| 1102 | + return nil, err |
| 1103 | + } |
| 1104 | + return items, nil |
| 1105 | +} |
| 1106 | + |
| 921 | 1107 | const listRepoTopics = `-- name: ListRepoTopics :many |
| 922 | 1108 | |
| 923 | 1109 | SELECT topic FROM repo_topics WHERE repo_id = $1 ORDER BY topic ASC |
@@ -1006,6 +1192,77 @@ func (q *Queries) ListReposForOwnerOrg(ctx context.Context, db DBTX, ownerOrgID |
| 1006 | 1192 | return items, nil |
| 1007 | 1193 | } |
| 1008 | 1194 | |
| 1195 | +const listReposForOwnerOrgPaged = `-- name: ListReposForOwnerOrgPaged :many |
| 1196 | +SELECT id, owner_user_id, owner_org_id, name, description, visibility, |
| 1197 | + default_branch, is_archived, archived_at, deleted_at, |
| 1198 | + disk_used_bytes, fork_of_repo_id, license_key, primary_language, |
| 1199 | + has_issues, has_pulls, created_at, updated_at, default_branch_oid, |
| 1200 | + allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method, |
| 1201 | + star_count, watcher_count, fork_count, init_status, |
| 1202 | + last_indexed_oid |
| 1203 | +FROM repos |
| 1204 | +WHERE owner_org_id = $1 AND deleted_at IS NULL |
| 1205 | +ORDER BY updated_at DESC |
| 1206 | +LIMIT $2 OFFSET $3 |
| 1207 | +` |
| 1208 | + |
| 1209 | +type ListReposForOwnerOrgPagedParams struct { |
| 1210 | + OwnerOrgID pgtype.Int8 |
| 1211 | + Limit int32 |
| 1212 | + Offset int32 |
| 1213 | +} |
| 1214 | + |
| 1215 | +// Paginated mirror of ListReposForOwnerOrg for the REST list endpoint |
| 1216 | +// when the viewer is an org member and may see private repos. |
| 1217 | +func (q *Queries) ListReposForOwnerOrgPaged(ctx context.Context, db DBTX, arg ListReposForOwnerOrgPagedParams) ([]Repo, error) { |
| 1218 | + rows, err := db.Query(ctx, listReposForOwnerOrgPaged, arg.OwnerOrgID, arg.Limit, arg.Offset) |
| 1219 | + if err != nil { |
| 1220 | + return nil, err |
| 1221 | + } |
| 1222 | + defer rows.Close() |
| 1223 | + items := []Repo{} |
| 1224 | + for rows.Next() { |
| 1225 | + var i Repo |
| 1226 | + if err := rows.Scan( |
| 1227 | + &i.ID, |
| 1228 | + &i.OwnerUserID, |
| 1229 | + &i.OwnerOrgID, |
| 1230 | + &i.Name, |
| 1231 | + &i.Description, |
| 1232 | + &i.Visibility, |
| 1233 | + &i.DefaultBranch, |
| 1234 | + &i.IsArchived, |
| 1235 | + &i.ArchivedAt, |
| 1236 | + &i.DeletedAt, |
| 1237 | + &i.DiskUsedBytes, |
| 1238 | + &i.ForkOfRepoID, |
| 1239 | + &i.LicenseKey, |
| 1240 | + &i.PrimaryLanguage, |
| 1241 | + &i.HasIssues, |
| 1242 | + &i.HasPulls, |
| 1243 | + &i.CreatedAt, |
| 1244 | + &i.UpdatedAt, |
| 1245 | + &i.DefaultBranchOid, |
| 1246 | + &i.AllowSquashMerge, |
| 1247 | + &i.AllowRebaseMerge, |
| 1248 | + &i.AllowMergeCommit, |
| 1249 | + &i.DefaultMergeMethod, |
| 1250 | + &i.StarCount, |
| 1251 | + &i.WatcherCount, |
| 1252 | + &i.ForkCount, |
| 1253 | + &i.InitStatus, |
| 1254 | + &i.LastIndexedOid, |
| 1255 | + ); err != nil { |
| 1256 | + return nil, err |
| 1257 | + } |
| 1258 | + items = append(items, i) |
| 1259 | + } |
| 1260 | + if err := rows.Err(); err != nil { |
| 1261 | + return nil, err |
| 1262 | + } |
| 1263 | + return items, nil |
| 1264 | +} |
| 1265 | + |
| 1009 | 1266 | const listReposForOwnerUser = `-- name: ListReposForOwnerUser :many |
| 1010 | 1267 | SELECT id, owner_user_id, owner_org_id, name, description, visibility, |
| 1011 | 1268 | default_branch, is_archived, archived_at, deleted_at, |
@@ -1068,6 +1325,79 @@ func (q *Queries) ListReposForOwnerUser(ctx context.Context, db DBTX, ownerUserI |
| 1068 | 1325 | return items, nil |
| 1069 | 1326 | } |
| 1070 | 1327 | |
| 1328 | +const listReposForOwnerUserPaged = `-- name: ListReposForOwnerUserPaged :many |
| 1329 | +SELECT id, owner_user_id, owner_org_id, name, description, visibility, |
| 1330 | + default_branch, is_archived, archived_at, deleted_at, |
| 1331 | + disk_used_bytes, fork_of_repo_id, license_key, primary_language, |
| 1332 | + has_issues, has_pulls, created_at, updated_at, default_branch_oid, |
| 1333 | + allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method, |
| 1334 | + star_count, watcher_count, fork_count, init_status, |
| 1335 | + last_indexed_oid |
| 1336 | +FROM repos |
| 1337 | +WHERE owner_user_id = $1 AND deleted_at IS NULL |
| 1338 | +ORDER BY updated_at DESC |
| 1339 | +LIMIT $2 OFFSET $3 |
| 1340 | +` |
| 1341 | + |
| 1342 | +type ListReposForOwnerUserPagedParams struct { |
| 1343 | + OwnerUserID pgtype.Int8 |
| 1344 | + Limit int32 |
| 1345 | + Offset int32 |
| 1346 | +} |
| 1347 | + |
| 1348 | +// Paginated mirror of ListReposForOwnerUser. Used by the REST surface |
| 1349 | +// where the caller is the owner (or a site admin) and is allowed to see |
| 1350 | +// private repos. Order matches the un-paginated form so callers can |
| 1351 | +// swap between them without observing a reshuffle. |
| 1352 | +func (q *Queries) ListReposForOwnerUserPaged(ctx context.Context, db DBTX, arg ListReposForOwnerUserPagedParams) ([]Repo, error) { |
| 1353 | + rows, err := db.Query(ctx, listReposForOwnerUserPaged, arg.OwnerUserID, arg.Limit, arg.Offset) |
| 1354 | + if err != nil { |
| 1355 | + return nil, err |
| 1356 | + } |
| 1357 | + defer rows.Close() |
| 1358 | + items := []Repo{} |
| 1359 | + for rows.Next() { |
| 1360 | + var i Repo |
| 1361 | + if err := rows.Scan( |
| 1362 | + &i.ID, |
| 1363 | + &i.OwnerUserID, |
| 1364 | + &i.OwnerOrgID, |
| 1365 | + &i.Name, |
| 1366 | + &i.Description, |
| 1367 | + &i.Visibility, |
| 1368 | + &i.DefaultBranch, |
| 1369 | + &i.IsArchived, |
| 1370 | + &i.ArchivedAt, |
| 1371 | + &i.DeletedAt, |
| 1372 | + &i.DiskUsedBytes, |
| 1373 | + &i.ForkOfRepoID, |
| 1374 | + &i.LicenseKey, |
| 1375 | + &i.PrimaryLanguage, |
| 1376 | + &i.HasIssues, |
| 1377 | + &i.HasPulls, |
| 1378 | + &i.CreatedAt, |
| 1379 | + &i.UpdatedAt, |
| 1380 | + &i.DefaultBranchOid, |
| 1381 | + &i.AllowSquashMerge, |
| 1382 | + &i.AllowRebaseMerge, |
| 1383 | + &i.AllowMergeCommit, |
| 1384 | + &i.DefaultMergeMethod, |
| 1385 | + &i.StarCount, |
| 1386 | + &i.WatcherCount, |
| 1387 | + &i.ForkCount, |
| 1388 | + &i.InitStatus, |
| 1389 | + &i.LastIndexedOid, |
| 1390 | + ); err != nil { |
| 1391 | + return nil, err |
| 1392 | + } |
| 1393 | + items = append(items, i) |
| 1394 | + } |
| 1395 | + if err := rows.Err(); err != nil { |
| 1396 | + return nil, err |
| 1397 | + } |
| 1398 | + return items, nil |
| 1399 | +} |
| 1400 | + |
| 1071 | 1401 | const listReposNeedingReindex = `-- name: ListReposNeedingReindex :many |
| 1072 | 1402 | SELECT id, name, default_branch, default_branch_oid |
| 1073 | 1403 | FROM repos |