Skip to content
This repository was archived by the owner on Nov 12, 2025. It is now read-only.

Commit aa2cd03

Browse files
committed
fix(repo): 修复获取组织仓库列表逻辑
- 优化参数设置逻辑,仅当参数存在时才添加到请求 URL
1 parent f83081d commit aa2cd03

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/models/github/repo.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,17 @@ export class Repo {
6565
if (!options.org) {
6666
throw new Error(NotParamMsg)
6767
}
68-
const params = {
69-
type: options?.type,
70-
sort: options?.sort,
71-
direction: options?.direction,
72-
per_page: options?.per_page,
73-
page: options?.page
74-
}
75-
const req = await this.get(`/orgs/${options.org}/repos`, params)
68+
const queryParams = new URLSearchParams()
69+
if (options?.type) queryParams.set('type', options.type)
70+
if (options?.sort) queryParams.set('sort', options.sort)
71+
if (options?.direction) queryParams.set('direction', options.direction)
72+
if (options?.per_page) queryParams.set('per_page', options.per_page.toString())
73+
if (options?.page) queryParams.set('page', options.page.toString())
74+
const queryString = queryParams.toString()
75+
const url = queryString
76+
? `/orgs/${options.org}/repos?${queryString}`
77+
: `/orgs/${options.org}/repos`
78+
const req = await this.get(url)
7679
if (req.statusCode === 404) {
7780
throw new Error(NotOrgMsg)
7881
} else if (req.statusCode === 401) {
@@ -117,7 +120,9 @@ export class Repo {
117120
if (options?.page) queryParams.set('page', options.page.toString())
118121

119122
const queryString = queryParams.toString()
120-
const url = queryString ? `/user/repos?${queryString}` : '/uses/repos'
123+
const url = queryString
124+
? `/user/repos?${queryString}`
125+
: '/uses/repos'
121126
const req = await this.get(url)
122127
if (req.statusCode === 401) {
123128
throw new Error(NotPerrmissionMsg)
@@ -165,7 +170,9 @@ export class Repo {
165170
if (options?.page) queryParams.set('page', options.page.toString())
166171

167172
const queryString = queryParams.toString()
168-
const url = queryString ? `/users/${options.username}/repos?${queryString}` : `/users/${options.username}/repos`
173+
const url = queryString
174+
? `/users/${options.username}/repos?${queryString}`
175+
: `/users/${options.username}/repos`
169176
const req = await this.get(url)
170177
if (req.statusCode === 404) {
171178
throw new Error(NotUserMsg)

0 commit comments

Comments
 (0)