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

Commit a32eb28

Browse files
committed
fix(platform): 在 get 请求中添加用户 token 配置
- 在 get 方法中增加了对用户 token 的检查和配置
1 parent e90fc87 commit a32eb28

File tree

8 files changed

+272
-49
lines changed

8 files changed

+272
-49
lines changed

src/models/platform/github/base.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type { App } from '@/models/platform/github/app'
99
import type { Auth } from '@/models/platform/github/auth'
1010
import type { Commit } from '@/models/platform/github/commit'
1111
import type { Issue } from '@/models/platform/github/issue'
12+
import type { Org } from '@/models/platform/github/org'
1213
import type { Repo } from '@/models/platform/github/repo'
1314
import type { User } from '@/models/platform/github/user'
1415
import type { WebHook } from '@/models/platform/github/webhook'
@@ -51,6 +52,7 @@ export class Base {
5152
declare user: User
5253
declare webhook: WebHook
5354
declare issue: Issue
55+
declare org: Org
5456
public BaseUrl: string
5557
public ApiUrl: string
5658
public jwtToken: string
@@ -196,6 +198,20 @@ export class Base {
196198
return this.user
197199
}
198200

201+
/**
202+
* 获取Org实例
203+
* @returns Org实例
204+
* @example
205+
* ```ts
206+
* const org = await base.get_org()
207+
* ```
208+
*/
209+
public async get_org (): Promise<Org> {
210+
const { Org } = await import('@/models/platform/github/org')
211+
this.org = new Org(this)
212+
return this.org
213+
}
214+
199215
/**
200216
* 获取WebHook实例
201217
* @returns WebHook实例
@@ -307,6 +323,11 @@ export class Base {
307323
*/
308324
public async get (path: string, parms?: any, customHeaders?: Record<string, string>): Promise<ApiResponseType> {
309325
try {
326+
if (this.userToken) {
327+
this.setRequestConfig({
328+
token: this.userToken
329+
})
330+
}
310331
const request = this.createRequest()
311332
const req = await request.get(path, parms, customHeaders)
312333
if (req.statusCode === 403 && req.data.message.includes('API rate limit exceeded')) {

src/models/platform/github/org.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { NotParamMsg } from '@/common'
2+
import { Base } from '@/models/platform/github/base'
3+
import {
4+
ApiResponseType,
5+
OrganizationInfoType,
6+
OrganizationNameParamType
7+
} from '@/types'
8+
9+
/**
10+
* Base 组织操作类
11+
*
12+
* 提供对GitHub组织的CRUD操作,包括:
13+
* - 获取组织信息
14+
*/
15+
export class Org extends Base {
16+
constructor (base: Base) {
17+
super(base)
18+
this.userToken = base.userToken
19+
this.ApiUrl = base.ApiUrl
20+
this.BaseUrl = base.BaseUrl
21+
}
22+
23+
public async get_org_info (options: OrganizationNameParamType): Promise<ApiResponseType<OrganizationInfoType>> {
24+
try {
25+
if (!options.org) {
26+
throw new Error(NotParamMsg)
27+
}
28+
this.setRequestConfig({
29+
token: this.userToken
30+
})
31+
const req = await this.get(`/orgs/${options.org}`)
32+
return req
33+
} catch (error) {
34+
throw new Error(`获取组织信息失败: ${(error as Error).message}`)
35+
}
36+
}
37+
}

src/models/platform/github/user.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import {
1313
ApiResponseType,
1414
ContributionResult,
1515
UserIdParamType,
16-
UserNameParamType,
17-
UserResponseType
16+
UserInfoResponseType,
17+
UserNameParamType
1818
} from '@/types'
1919

2020
/**
@@ -39,7 +39,7 @@ export class User extends Base {
3939
* @param options.username - 用户名或组织名
4040
*/
4141
public async get_user_info (options: UserNameParamType):
42-
Promise<ApiResponseType<UserResponseType>> {
42+
Promise<ApiResponseType<UserInfoResponseType>> {
4343
try {
4444
if (!options.username) {
4545
throw new Error(NotOrgOrUserParamMsg)
@@ -71,7 +71,7 @@ export class User extends Base {
7171
* @returns 用户信息
7272
*/
7373
public async get_user_info_by_user_id (options: UserIdParamType):
74-
Promise<ApiResponseType<UserResponseType>> {
74+
Promise<ApiResponseType<UserInfoResponseType>> {
7575
try {
7676
if (!options.user_id) {
7777
throw new Error(NotUserParamMsg)
@@ -99,7 +99,7 @@ export class User extends Base {
9999
* 通过访问令牌获取用户信息
100100
*/
101101
public async get_user_info_by_token ():
102-
Promise<ApiResponseType<UserResponseType>> {
102+
Promise<ApiResponseType<UserInfoResponseType>> {
103103
try {
104104
this.setRequestConfig({
105105
token: this.userToken

src/types/platform/github/base.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ export interface UserNameParamType {
1414
/** 用户名 */
1515
username: string;
1616
}
17+
export interface OrganizationNameParamType {
18+
/** 组织登录名 */
19+
org: string;
20+
}
1721
export interface UserIdParamType {
1822
/** 用户id */
1923
user_id: number;

src/types/platform/github/commit.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { RepoNameParamType, RepoOwnerParamType, RepoUrlParamType, ShaParamType } from '@/types/platform/github/base'
2-
import { UserBaseType } from '@/types/platform/github/user'
2+
import { AccountBaseType } from '@/types/platform/github/user'
33

44
export interface CommitInfoCommonParamType {
55
/** 提交SHA */
@@ -134,9 +134,9 @@ export interface CommitInfoResponseType {
134134
/** 提交信息 */
135135
commit: Commit;
136136
/** 提交作者 */
137-
author: UserBaseType | null;
137+
author: AccountBaseType | null;
138138
/** 提交者 */
139-
committer: UserBaseType | null;
139+
committer: AccountBaseType | null;
140140
/** 父提交列表 */
141141
parents: ParentCommit[];
142142
/** 提交统计信息 */

src/types/platform/github/issue.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { RepoUrlParamType } from '@/types/platform/github/base'
22
import { RepoBaseParamType } from '@/types/platform/github/repo'
3-
import { UserResponseType } from '@/types/platform/github/user'
3+
import { UserInfoResponseType } from '@/types/platform/github/user'
44

55
/** 议题信息参数类型 */
66
export type IssueInfoParamType = (RepoBaseParamType | RepoUrlParamType) & {
@@ -73,7 +73,7 @@ export interface MilestoneType {
7373
/** 里程碑描述 */
7474
description: string | null;
7575
/** 里程碑创建者 */
76-
creator: UserResponseType | null;
76+
creator: UserInfoResponseType | null;
7777
/** 开放议题数 */
7878
open_issues: number;
7979
/** 关闭议题数 */
@@ -131,13 +131,13 @@ export interface IssueInfoResponseType {
131131
/** 议题正文内容 */
132132
body: string | null;
133133
/** 议题创建者用户信息 */
134-
user: UserResponseType
134+
user: UserInfoResponseType
135135
/** 议题标签 */
136136
labels: Array<IssueLabelType | string>;
137137
/** 议题指派人 */
138-
assignee: UserResponseType | null;
138+
assignee: UserInfoResponseType | null;
139139
/** 议题所有指派人列表 */
140-
assignees: Array<UserResponseType> | null;
140+
assignees: Array<UserInfoResponseType> | null;
141141
/** 议题所属里程碑 */
142142
milestone: MilestoneType | null;
143143
/** 是否锁定 */
@@ -157,7 +157,7 @@ export interface IssueInfoResponseType {
157157
/** 是否是草稿 */
158158
draft?: boolean;
159159
/** 关闭者信息 */
160-
closed_by?: UserResponseType | null;
160+
closed_by?: UserInfoResponseType | null;
161161
}
162162

163163
/** 议题列表响应类型 */

src/types/platform/github/org.ts

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { RepoOwnerParamType } from '@/types/platform/github/base'
2+
import { AccountBaseType } from '@/types/platform/github/user'
23

34
/** 创建组织仓库请求参数 */
45
export interface OrgRepoCreateParamType extends RepoOwnerParamType {
@@ -49,3 +50,160 @@ export interface OrgRepoCreateParamType extends RepoOwnerParamType {
4950
/** 新存储库的自定义属性 */
5051
custom_properties?: { [key: string]: string };
5152
}
53+
54+
/**
55+
* @description 组织的基本信息
56+
*/
57+
export interface OrganizationBaseType extends AccountBaseType {
58+
/** 组织的名称 */
59+
name?: string;
60+
/** 组织的描述 */
61+
description: string | null;
62+
/** 组织的公司名称 */
63+
company?: string;
64+
/** 组织的博客 URL */
65+
blog: string | null;
66+
/** 组织的所在地 */
67+
location?: string;
68+
/** 组织的邮箱地址 */
69+
email?: string;
70+
/** 组织的 Twitter 用户名 */
71+
twitter_username?: string | null;
72+
/** 组织是否已验证 */
73+
is_verified?: boolean;
74+
/** 账户类型(例如 "Organization") */
75+
type: string;
76+
/** 创建时间 */
77+
created_at: string;
78+
/** 更新时间 */
79+
updated_at: string;
80+
/** 归档时间 */
81+
archived_at: string | null;
82+
}
83+
/**
84+
* @description 组织的计划信息
85+
*/
86+
export interface OrganizationPlanType {
87+
name: string;
88+
space: number;
89+
private_repos: number;
90+
filled_seats?: number;
91+
seats?: number;
92+
}
93+
94+
/**
95+
* @description 组织的 API URL 信息
96+
*/
97+
export interface OrganizationUrlType {
98+
/** 组织的 Webhook 列表 API URL */
99+
hooks_url: string;
100+
/** 组织的 Issues 列表 API URL */
101+
issues_url: string;
102+
/** 组织的成员列表 API URL 模板 */
103+
members_url: string;
104+
/** 组织的公开成员列表 API URL 模板 */
105+
public_members_url: string;
106+
}
107+
108+
/**
109+
* @description 组织的仓库和 Gists 信息
110+
*/
111+
export interface OrganizationRepositoryAndGistsType {
112+
/** 组织的公开仓库数量 */
113+
public_repos: number;
114+
/** 组织的公开 Gists 数量 */
115+
public_gists: number;
116+
/** 组织的总私有仓库数量 */
117+
total_private_repos?: number;
118+
/** 组织拥有的私有仓库数量 */
119+
owned_private_repos?: number;
120+
/** 组织的私有 Gists 数量 */
121+
private_gists?: number | null;
122+
/** 组织的磁盘使用量 */
123+
disk_usage?: number | null;
124+
}
125+
126+
/**
127+
* @description 组织的成员信息
128+
*/
129+
export interface OrganizationMemberType {
130+
/** 组织的关注者数量 */
131+
followers: number;
132+
/** 组织关注的数量 */
133+
following: number;
134+
/** 私有仓库中的协作者数量 */
135+
collaborators?: number | null;
136+
}
137+
138+
/**
139+
* @description 组织的权限和配置信息
140+
*/
141+
export interface OrganizationPermissionsAndConfigType {
142+
/** 组织是否启用了组织项目 */
143+
has_organization_projects: boolean;
144+
/** 组织是否启用了仓库项目 */
145+
has_repository_projects: boolean;
146+
/** 组织的账单邮箱地址 */
147+
billing_email?: string | null;
148+
/** 组织的计划信息 */
149+
plan?: OrganizationPlanType;
150+
/** 默认的仓库权限 */
151+
default_repository_permission?: string | null;
152+
/** 成员是否可以创建仓库 */
153+
members_can_create_repositories?: boolean | null;
154+
/** 是否启用了两因素认证要求 */
155+
two_factor_requirement_enabled?: boolean | null;
156+
/** 成员允许的仓库创建类型 */
157+
members_allowed_repository_creation_type?: string;
158+
/** 成员是否可以创建公开仓库 */
159+
members_can_create_public_repositories?: boolean;
160+
/** 成员是否可以创建私有仓库 */
161+
members_can_create_private_repositories?: boolean;
162+
/** 成员是否可以创建内部仓库 */
163+
members_can_create_internal_repositories?: boolean;
164+
/** 成员是否可以创建 Pages */
165+
members_can_create_pages?: boolean;
166+
/** 成员是否可以创建公开 Pages */
167+
members_can_create_public_pages?: boolean;
168+
/** 成员是否可以创建私有 Pages */
169+
members_can_create_private_pages?: boolean;
170+
/** 成员是否可以 Fork 私有仓库 */
171+
members_can_fork_private_repositories?: boolean | null;
172+
/** 是否要求 Web 提交签名 */
173+
web_commit_signoff_required?: boolean;
174+
/** 控制是否允许为组织中的仓库添加和使用部署密钥 */
175+
deploy_keys_enabled_for_repositories?: boolean;
176+
}
177+
178+
/**
179+
* @description 组织的安全配置信息
180+
*/
181+
export interface OrganizationSecurityConfigType {
182+
/** 对于新仓库和转移到此组织的仓库,是否启用了 GitHub Advanced Security */
183+
advanced_security_enabled_for_new_repositories?: boolean;
184+
/** 对于新仓库和转移到此组织的仓库,是否自动启用了 Dependabot alerts */
185+
dependabot_alerts_enabled_for_new_repositories?: boolean;
186+
/** 对于新仓库和转移到此组织的仓库,是否自动启用了 Dependabot security updates */
187+
dependabot_security_updates_enabled_for_new_repositories?: boolean;
188+
/** 对于新仓库和转移到此组织的仓库,是否自动启用了 dependency graph */
189+
dependency_graph_enabled_for_new_repositories?: boolean;
190+
/** 对于新仓库和转移到此组织的仓库,是否自动启用了 secret scanning */
191+
secret_scanning_enabled_for_new_repositories?: boolean;
192+
/** 对于新仓库和转移到此组织的仓库,是否自动启用了 secret scanning push protection */
193+
secret_scanning_push_protection_enabled_for_new_repositories?: boolean;
194+
/** 是否向因 push protection 而被阻止推送 secret 的贡献者显示自定义链接 */
195+
secret_scanning_push_protection_custom_link_enabled?: boolean;
196+
/** 显示给因 push protection 而被阻止推送 secret 的贡献者 */
197+
secret_scanning_push_protection_custom_link?: string | null;
198+
}
199+
200+
/**
201+
* @description GitHub 组织的完整信息
202+
*/
203+
export interface OrganizationInfoType
204+
extends OrganizationBaseType,
205+
OrganizationUrlType,
206+
OrganizationRepositoryAndGistsType,
207+
OrganizationMemberType,
208+
OrganizationPermissionsAndConfigType,
209+
OrganizationSecurityConfigType {}

0 commit comments

Comments
 (0)