外观
Repo
约 3888 字大约 13 分钟
2025-08-01
@candriajs/git-neko-kit / github / Repo
类: Repo
定义于: models/platform/github/repo.ts:63
GitHub 仓库操作类
提供对GitHub仓库的完整CRUD操作接口,包括:
- 组织/用户仓库的查询、创建、删除
- 仓库详细信息的获取
- 仓库可见性检查
- 支持通过URL或owner/repo两种方式操作仓库
继承
构造函数
构造函数
new Repo(
base
):Repo
定义于: models/platform/github/repo.ts:64
参数
base
返回
Repo
重写了
属性
api_url
api_url:
string
定义于: models/platform/github/client.ts:79
继承自
app
app:
App
定义于: models/platform/github/client.ts:67
继承自
auth
auth:
Auth
定义于: models/platform/github/client.ts:68
继承自
base_url
base_url:
string
定义于: models/platform/github/client.ts:78
继承自
Client_ID?
readonly
optional
Client_ID:null
|string
定义于: models/platform/github/client.ts:83
继承自
Client_Secret?
readonly
optional
Client_Secret:null
|string
定义于: models/platform/github/client.ts:84
继承自
commit
commit:
Commit
定义于: models/platform/github/client.ts:69
继承自
format
readonly
format:boolean
定义于: models/platform/github/client.ts:86
继承自
issue
issue:
Issue
定义于: models/platform/github/client.ts:73
继承自
jwtToken
jwtToken:
string
定义于: models/platform/github/client.ts:80
继承自
org
org:
Org
定义于: models/platform/github/client.ts:74
继承自
Private_Key?
readonly
optional
Private_Key:null
|string
定义于: models/platform/github/client.ts:82
继承自
pull_request
pull_request:
Pull_Request
定义于: models/platform/github/client.ts:75
继承自
repo
repo:
Repo
定义于: models/platform/github/client.ts:70
继承自
search
search:
Search
定义于: models/platform/github/client.ts:77
继承自
user
user:
User
定义于: models/platform/github/client.ts:71
继承自
userToken?
optional
userToken:null
|string
定义于: models/platform/github/client.ts:81
继承自
webhook
webhook:
WebHook
定义于: models/platform/github/client.ts:72
继承自
WebHook_Secret?
readonly
optional
WebHook_Secret:null
|string
定义于: models/platform/github/client.ts:85
继承自
workflow
workflow:
Workflow
定义于: models/platform/github/client.ts:76
继承自
访问器
is_app_client
Getter 签名
get is_app_client():
boolean
定义于: models/platform/github/client.ts:130
是否是App客户端
示例
const isAppClient = await client.is_app_client
-> true
返回
boolean
是否是App客户端
继承自
type
Getter 签名
get type():
GitType
定义于: models/platform/github/client.ts:117
获取Git平台类型
示例
const type = await client.type
-> 'github'
返回
Git平台类型,如: github,gitee
继承自
方法
add_collaborator()
add_collaborator(
options
):Promise
<ApiResponseType
<AddCollaboratorResponseType
>>
定义于: models/platform/github/repo.ts:739
邀请协作者 权限:
- Administration: Read and write
参数
options
邀请协作者对象
- owner: 仓库拥有者
- repo: 仓库名称
- url: 仓库地址 owner和repo或者url选择一个即可
- username: 要邀请协作者用户名
- permission: 协作者权限,可选pull,triage, push, maintain, admin,默认为pull
返回
Promise
<ApiResponseType
<AddCollaboratorResponseType
>>
返回邀请协作者结果
示例
const result = await collaborator.add_collaborator({
owner: 'owner',
repo: 'repo',
username: 'username',
permission: 'pull'
})
-> 邀请仓库协作者信息对象
create_org_repo()
create_org_repo(
options
):Promise
<ApiResponseType
<RepoInfoResponseType
>>
定义于: models/platform/github/repo.ts:493
创建组织仓库 权限:
- Administration: Read and write
参数
options
创建组织仓库参数
- org: 组织名称
- name: 仓库名称
- description: 仓库描述
- homepage: 仓库主页URL
- visibility: 仓库可见性,可选值:'public' | 'private', 默认值:'public'
- has_issues: 是否启用issues功能, 默认值:true
- has_wiki: 是否启用wiki功能, 默认值:true
- auto_init: 是否自动初始化仓库 默认值:false
返回
Promise
<ApiResponseType
<RepoInfoResponseType
>>
返回创建成功的仓库信息
示例
const repoInfo = await org.create_org_repo({org: 'loli', repo: 'git-neko-kit'})
-> 创建组织仓库信息对象
create_repo()
create_repo(
options
):Promise
<ApiResponseType
<RepoInfoResponseType
>>
定义于: models/platform/github/repo.ts:653
创建用户仓库
参数
options
创建组织仓库参数
- owner: 仓库拥有者,用户名称
- name: 仓库名称
- description: 仓库描述
- homepage: 仓库主页URL
- visibility: 仓库可见性,可选值:'public' | 'private', 默认值:'public'
- has_issues: 是否启用issues功能, 默认值:true
- has_wiki: 是否启用wiki功能, 默认值:true
- auto_init: 是否自动初始化仓库 默认值:false
返回
Promise
<ApiResponseType
<RepoInfoResponseType
>>
返回创建成功的仓库信息
已被弃用
请使用create_user_repo方法 权限:
- Administration: Read and write
create_user_repo()
create_user_repo(
options
):Promise
<ApiResponseType
<RepoInfoResponseType
>>
定义于: models/platform/github/repo.ts:575
创建用户仓库 权限:
- Administration: Read and write
参数
options
创建组织仓库参数
- owner: 仓库拥有者,用户名称
- name: 仓库名称
- description: 仓库描述
- homepage: 仓库主页URL
- visibility: 仓库可见性,可选值:'public' | 'private', 默认值:'public'
- has_issues: 是否启用issues功能, 默认值:true
- has_wiki: 是否启用wiki功能, 默认值:true
- auto_init: 是否自动初始化仓库 默认值:false
返回
Promise
<ApiResponseType
<RepoInfoResponseType
>>
返回创建成功的仓库信息
示例
const repoInfo = await repo.create_user_repo({org: 'loli', repo: 'git-neko-kit'})
-> 创建用户仓库信息对象
delete()
delete(
path
,params
,data?
,customHeaders?
):Promise
<ApiResponseType
<any
>>
定义于: models/platform/github/client.ts:602
Github DELETE 请求方法
参数
path
string
请求路径
params
URL查询参数
null
| Record
<string
, string
>
data?
any
请求体数据
customHeaders?
Record
<string
, string
>
请求头,选项
返回
Promise
<ApiResponseType
<any
>>
请求结果
继承自
delete_collaborator()
delete_collaborator(
options
):Promise
<ApiResponseType
<RemoveCollaboratorResponseType
>>
定义于: models/platform/github/repo.ts:838
删除协作者
参数
options
删除协作者对象
返回
Promise
<ApiResponseType
<RemoveCollaboratorResponseType
>>
返回删除协作者结果
已被弃用
请使用remove_collaborator方法
get()
get(
path
,parms?
,customHeaders?
):Promise
<ApiResponseType
<any
>>
定义于: models/platform/github/client.ts:455
Github GET 请求方法
参数
path
string
请求路径
parms?
any
请求参数
customHeaders?
Record
<string
, string
>
请求头,选项
返回
Promise
<ApiResponseType
<any
>>
请求结果
继承自
get_app()
get_app():
Promise
<App
>
定义于: models/platform/github/client.ts:177
获取App实例
返回
Promise
<App
>
App实例
示例
const app = await GitHubClient.get_app()
继承自
get_auth()
get_auth():
Promise
<Auth
>
定义于: models/platform/github/client.ts:191
获取Auth实例
返回
Promise
<Auth
>
Auth实例
示例
const auth = await GitHubClient.get_auth()
继承自
get_collaborators_list()
get_collaborators_list(
options
):Promise
<ApiResponseType
<GetCollaboratorListResponseType
>>
定义于: models/platform/github/repo.ts:679
获取协作者列表 权限:
- Metadata: Read
参数
options
获取协作者列表对象
- owner: 仓库拥有者
- repo: 仓库名称
- url: 仓库地址 url和owner、repo参数传入其中的一种
- affiliation: 协作者类型,可选outside, direct, all,默认为all
- permission: 协作者权限,可选pull,triage, push, maintain, admin,默认为pull
- per_page: 每页数量,默认为30
- page: 页码,默认为1
返回
Promise
<ApiResponseType
<GetCollaboratorListResponseType
>>
返回获取协作者列表结果
示例
const result = await collaborator.get_collaborators_list(options)
-> 仓库协作者信息对象列表
get_commit()
get_commit():
Promise
<Commit
>
定义于: models/platform/github/client.ts:205
获取Commit实例
返回
Promise
<Commit
>
Commit实例
示例
const commit = await GitHubClient.get_commit()
继承自
get_issue()
get_issue():
Promise
<Issue
>
定义于: models/platform/github/client.ts:219
获取Issue实例
返回
Promise
<Issue
>
Issue实例
示例
const issue = await GitHubClient.get_issue()
继承自
get_org()
get_org():
Promise
<Org
>
定义于: models/platform/github/client.ts:261
获取Org实例
返回
Promise
<Org
>
Org实例
示例
const org = await GitHubClient.get_org()
继承自
get_org_repos_list()
get_org_repos_list(
options
):Promise
<ApiResponseType
<OrgRepoListResponseType
>>
定义于: models/platform/github/repo.ts:88
获取组织仓库列表 权限: Metadata - Read-only , 如果获取公开仓库可无需此权限
参数
options
请求参数对象
- org - 组织名称
- type - 仓库类型,可选值:'all' | 'public' | 'private' | 'forks' | 'sources' | 'member', 默认值:'all'
- sort - 排序字段,可选值:'created' | 'updated' | 'pushed' | 'full_name', 默认值:'created'
- direction - 排序方向,可选值:'asc' | 'desc', 默认值:'desc'
- per_page - 每页数量(1-100), 默认值:30
- page - 页码 默认值:1
返回
Promise
<ApiResponseType
<OrgRepoListResponseType
>>
组织仓库列表
示例
const repos = await repo.get_org_repos_list({ org: 'org' })
-> 组织仓库信息对象列表
get_pull_request()
get_pull_request():
Promise
<Pull_Request
>
定义于: models/platform/github/client.ts:289
获取Pull_request实例
返回
Promise
<Pull_Request
>
Pull_request实例
示例
const pull_request = await GitHubClient.get_pull_request()
继承自
get_repo()
get_repo():
Promise
<Repo
>
定义于: models/platform/github/client.ts:233
获取Repo实例
返回
Promise
<Repo
>
Repo实例
示例
const repo = await GitHubClient.get_repo()
继承自
get_repo_default_branch()
get_repo_default_branch(
options
):Promise
<null
|string
>
定义于: models/platform/github/repo.ts:889
获取仓库默认分支 权限:
- Metadata: Read-only, 如果只获取公开仓库可无需此权限
参数
options
owner 仓库拥有者
- repo 仓库名称
返回
Promise
<null
| string
>
示例
const defaultBranch = await repo.get_repo_default_branch({owner: CandriaJS, repo: meme-plugin)}
-> 'main'
```ts
***
### get\_repo\_info()
> **get\_repo\_info**(`options`): `Promise`\<[`ApiResponseType`](../../../../interfaces/ApiResponseType.md)\<[`RepoInfoResponseType`](../../../../interfaces/RepoInfoResponseType.md)\>\>
定义于: [models/platform/github/repo.ts:362](https://github.com/CandriaJS/git-neko-kit/blob/68e1dc12fd1bcb6fcbe1a2aa6869f49f3640b1b1/src/models/platform/github/repo.ts#L362)
获取仓库信息
权限:
- Metadata: Read-only, 如果只获取公开仓库可无需此权限
#### 参数
##### options
[`RepoBaseParamType`](../../../../type-aliases/RepoBaseParamType.md)
仓库信息参数对象,必须包含以下两种组合之一:
- owner 仓库拥有者
- repo 仓库名称
#### 返回
`Promise`\<[`ApiResponseType`](../../../../interfaces/ApiResponseType.md)\<[`RepoInfoResponseType`](../../../../interfaces/RepoInfoResponseType.md)\>\>
#### 示例
```ts
const repo = await repo.get_repo_info({ owner: 'owner', repo: 'repo' })
-> 仓库信息对象
get_repo_languages_list()
get_repo_languages_list(
options
):Promise
<ApiResponseType
<RepoLanguagesListResponseType
>>
定义于: models/platform/github/repo.ts:436
获取仓库语言列表 权限:
- Metadata: Read-only, 如果只获取公开仓库可无需此权限
参数
options
仓库信息参数对象,必须包含以下两种组合之一:
- owner 仓库拥有者
- repo 仓库名称
返回
Promise
<ApiResponseType
<RepoLanguagesListResponseType
>>
示例
const repo = await repo.get_repo_languages_list({ owner: 'owner', repo: 'repo' })
-> 仓库语言对象列表
get_repo_main_language()
get_repo_main_language(
options
):Promise
<null
|string
>
定义于: models/platform/github/repo.ts:925
获取仓库主要语言 权限:
- Metadata: Read-only, 如果只获取公开仓库可无需此权限
参数
options
url 仓库URL地址
- owner 仓库拥有者
- repo 仓库名称 url参数和owner、repo参数传入其中的一种
返回
Promise
<null
| string
>
示例
const language = await repo.get_repo_language({url: 'URL_ADDRESS.com/CandriaJS/meme-plugin')}
-> 'JavaScript'
```ts
***
### get\_repo\_visibility()
> **get\_repo\_visibility**(`options`): `Promise`\<`"public"` \| `"private"`\>
定义于: [models/platform/github/repo.ts:865](https://github.com/CandriaJS/git-neko-kit/blob/68e1dc12fd1bcb6fcbe1a2aa6869f49f3640b1b1/src/models/platform/github/repo.ts#L865)
快速获取仓库可见性
权限:
- Metadata: Read-only, 如果只获取公开仓库可无需此权限
#### 参数
##### options
[`RepoBaseParamType`](../../../../type-aliases/RepoBaseParamType.md)
url 仓库URL地址
- owner 仓库拥有者
- repo 仓库名称
url参数和owner、repo参数传入其中的一种
#### 返回
`Promise`\<`"public"` \| `"private"`\>
仓库可见性,
#### 备注
优先使用url参数,若url参数不存在则使用owner和repo参数
#### 示例
```ts
// 公开仓库
const visibility = await repo.get_repo_visibility({url: 'https://github.com/CandriaJS/git-neko-kit'})
-> 'public'
// 私有仓库
const visibility = await repo.get_repo_visibility({url: 'https://github.com/CandriaJS/git-neko-kit'})
-> 'private'
get_search()
get_search():
Promise
<Search
>
定义于: models/platform/github/client.ts:317
获取Search实例
返回
Promise
<Search
>
Search实例
示例
const search = await GitHubClient.get_search()
继承自
get_user()
get_user():
Promise
<User
>
定义于: models/platform/github/client.ts:247
获取User实例
返回
Promise
<User
>
User实例
示例
const user = await GitHubClient.get_user()
继承自
get_user_repos_list()
get_user_repos_list(
options
):Promise
<ApiResponseType
<UserRepoListType
>>
定义于: models/platform/github/repo.ts:272
获取用户仓库列表 权限:
- Metadata: Read-only, 如果只获取公开仓库可无需此权限
参数
options
请求参数对象
- username - 用户名 优先获取授权用户仓库列表,若授权用户不存在则获取指定用户仓库列表
- type - 仓库类型,可选值:all, owner, member,, 默认值:'all'
- sort - 排序字段,可选值:'created' | 'updated' | 'pushed' | 'full_name', 默认值:'created'
- direction - 排序方向,可选值:'asc' | 'desc', 默认值:'desc'
- per_page - 每页数量(1-100), 默认值:30
- page - 页码 默认值:1
返回
Promise
<ApiResponseType
<UserRepoListType
>>
用户仓库列表
示例
const repos = await github.get_user_repos_list({ username: 'loli' })
-> 用户仓库信息对象列表
get_user_repos_list_by_token()
get_user_repos_list_by_token(
options?
):Promise
<ApiResponseType
<UserRepoListType
>>
定义于: models/platform/github/repo.ts:178
通过授权用户查询仓库列表 权限: Metadata - read-only , 如果获取公开仓库可无需此权限
参数
options?
请求参数对象
- type - 仓库类型,可选值:可选all, public, private
- visibility - 仓库可见性,可选值:'public' | 'private' | 'internal', 默认值:'all'
- affiliation - 仓库关联,可选值:'owner' | 'collaborator' | 'organization_member', 默认值:'owner,collaborator,organization_member'
- sort - 排序字段,可选值:'created' | 'updated' | 'pushed' | 'full_name', 默认值:'created'
- direction - 排序方向,可选值:'asc' | 'desc', 默认值:'desc'
- per_page - 每页数量(1-100), 默认值:30
- page - 页码 默认值:1
返回
Promise
<ApiResponseType
<UserRepoListType
>>
仓库详细信息
示例
const repos = await repo.get_repos_list({ username: 'username' })
-> 用户仓库信息对象列表
get_webhook()
get_webhook():
Promise
<WebHook
>
定义于: models/platform/github/client.ts:275
获取WebHook实例
返回
Promise
<WebHook
>
WebHook实例
示例
const webhook = await GitHubClient.get_webhook()
继承自
get_workflow()
get_workflow():
Promise
<Workflow
>
定义于: models/platform/github/client.ts:303
获取Workflow实例
返回
Promise
<Workflow
>
Workflow实例
示例
const workflow = await GitHubClient.get_workflow()
继承自
patch()
patch(
path
,params
,data
,customHeaders?
):Promise
<ApiResponseType
<any
>>
定义于: models/platform/github/client.ts:528
Github PATCH 请求方法
参数
path
string
请求路径
params
URL查询参数
null
| Record
<string
, string
>
data
any
请求数据
customHeaders?
Record
<string
, string
>
请求头,选项
返回
Promise
<ApiResponseType
<any
>>
请求结果
继承自
post()
post(
path
,data
,customHeaders?
):Promise
<ApiResponseType
<any
>>
定义于: models/platform/github/client.ts:491
Github POST 请求方法
参数
path
string
请求路径
data
any
请求数据
customHeaders?
Record
<string
, string
>
请求头,选项
返回
Promise
<ApiResponseType
<any
>>
请求结果
继承自
put()
put(
path
,data
,customHeaders?
):Promise
<ApiResponseType
<any
>>
定义于: models/platform/github/client.ts:565
Github PUT 请求方法
参数
path
string
请求路径
data
any
请求数据
customHeaders?
Record
<string
, string
>
请求头,选项
返回
Promise
<ApiResponseType
<any
>>
请求结果
继承自
remove_collaborator()
remove_collaborator(
options
):Promise
<ApiResponseType
<RemoveCollaboratorResponseType
>>
定义于: models/platform/github/repo.ts:802
删除协作者 权限:
- Administration: Read and write
参数
options
删除协作者对象
- owner: 仓库拥有者
- repo: 仓库名称
- username: 要删除协作者用户名
返回
Promise
<ApiResponseType
<RemoveCollaboratorResponseType
>>
返回删除协作者结果
示例
const result = await collaborator.remove_collaborator({
owner: 'owner',
repo:'repo',
username: 'username'
})
-> 移除仓库协作者信息对象
setProxy()
setProxy(
proxy
):void
定义于: models/platform/github/client.ts:343
设置请求代理
参数
proxy
代理参数
返回
void
示例
setProxy({
type: 'http',
address: 'http://127.0.0.1:7890'
})
继承自
setRequestConfig()
protected
setRequestConfig(config
):void
定义于: models/platform/github/client.ts:428
设置当前请求的配置
- 仅在父类与子类中方法中可访问
参数
config
配置对象,包含以下属性:
- url: 请求的URL
- token: 认证令牌
- tokenType: 认证令牌类型,默认为 'Bearer'
返回
void
继承自
setToken()
setToken(
token
):void
定义于: models/platform/github/client.ts:390
设置 token 传入的 token 必须以 ghu_ 或 ghp_ 或 ghs_ 开头,否则会抛出错误
参数
token
string
传入的 token
返回
void
示例
setToken('ghu_xxxx')