-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
4.3 github github integration layer
Relevant source files
- app/src/main/java/com/abk/kernel/data/api/GitHubApiService.kt
- app/src/main/java/com/abk/kernel/data/api/GitHubAuthService.kt
- app/src/main/java/com/abk/kernel/data/api/NetworkClient.kt
- app/src/main/java/com/abk/kernel/data/model/Models.kt
- app/src/main/java/com/abk/kernel/data/repository/GitHubRepository.kt
- app/src/main/java/com/abk/kernel/ui/screens/ModuleRepositoryScreen.kt
- app/src/main/java/com/abk/kernel/viewmodel/MainViewModel.kt
本页面详细介绍了 ABK Manager 与 GitHub API 交互的架构实现,包括身份验证、仓库管理、工作流调度及模块目录获取。
This page details the architectural implementation of ABK Manager's interaction with the GitHub API, covering authentication, repository management, workflow dispatching, and module catalog fetching.
GitHub 集成层是 ABK Manager 的核心通信枢纽。它负责将 Android 端的构建请求转换为 GitHub Actions 工作流任务,并实时监控远程构建状态。该层主要由 GitHubRepository 封装业务逻辑,通过 GitHubApiService 和 GitHubAuthService 进行 RESTful 调用。
ABK 采用 GitHub OAuth 设备流(Device Flow),允许用户在不直接输入密码的情况下授权应用访问仓库和工作流权限。
-
请求设备码 :通过
GitHubAuthService.requestDeviceCode获取用户验证码。 -
轮询令牌 :使用
pollToken持续检查用户是否已在浏览器中完成授权。 -
作用域 :请求
repo和workflow权限以确保能触发构建和下载制品。
为了在用户的个人账户中运行构建,应用需要确保存在一个 ABK 的 Fork。
-
Fork 检测 :
getUserFork检查当前用户是否已 Fork 指定的 ABK 仓库 app/src/main/java/com/abk/kernel/data/repository/GitHubRepository.kt#L158-L172。 -
自动 Fork :如果不存在,则调用
forkRepo创建 app/src/main/java/com/abk/kernel/data/api/GitHubApiService.kt#L21-L26。 -
上游同步 :通过
syncFork接口将上游 ABK 仓库的最新代码同步到用户的 Fork app/src/main/java/com/abk/kernel/data/api/GitHubApiService.kt#L36-L41。
这是应用最复杂的部分,涉及构建的触发、日志获取和制品下载。
-
触发构建 :
dispatchWorkflow发送带有自定义输入参数(如内核版本、KSU 选项等)的 POST 请求 app/src/main/java/com/abk/kernel/data/api/GitHubApiService.kt#L50-L56。 -
状态轮询 :应用通过
listWorkflowRuns监控构建进度,并使用listRunJobs获取具体步骤(Steps)的成功或失败状态 app/src/main/java/com/abk/kernel/data/api/GitHubApiService.kt#L95-L101。 -
日志流 :支持通过
downloadRunLogs下载整个运行过程的压缩日志 app/src/main/java/com/abk/kernel/data/api/GitHubApiService.kt#L113-L117。
应用支持从第三方仓库获取内核模块定义。
-
元数据获取 :
fetchExternalModuleMetadata会尝试从 GitHub 链接中寻找module.conf文件 app/src/main/java/com/abk/kernel/data/repository/GitHubRepository.kt#L62-L97。 -
目录解析 :
fetchModuleCatalog下载 JSON 索引,解析并展示可用的内核扩展模块 app/src/main/java/com/abk/kernel/data/repository/GitHubRepository.kt#L99-L143。
"GitHub 集成层数据流 / GitHub Integration Layer Data Flow"
DeepWiki client-side-rendered block omitted in static export.
Sources: app/src/main/java/com/abk/kernel/data/repository/GitHubRepository.kt#L1-L29 app/src/main/java/com/abk/kernel/data/api/GitHubApiService.kt#L8-L160 app/src/main/java/com/abk/kernel/viewmodel/MainViewModel.kt#L158-L172
The GitHub Integration Layer serves as the central communication hub for ABK Manager. It is responsible for translating build requests from the Android client into GitHub Actions workflow tasks and providing real-time monitoring of remote build statuses. This layer is primarily encapsulated in GitHubRepository, which performs RESTful calls via GitHubApiService and GitHubAuthService.
ABK utilizes the GitHub OAuth Device Flow, allowing users to authorize the app's access to repositories and workflows without entering passwords directly into the app.
-
Device Code Request : Fetches the user verification code via
GitHubAuthService.requestDeviceCode. -
Token Polling : Uses
pollTokento continuously check if the user has completed authorization in their browser. -
Scopes : Requests
repoandworkflowscopes to ensure it can trigger builds and download artifacts.
To run builds within the user's personal account, the app ensures a fork of the ABK repository exists.
-
Fork Detection :
getUserForkchecks if the current user has already forked the designated ABK repository app/src/main/java/com/abk/kernel/data/repository/GitHubRepository.kt#L158-L172 -
Automated Forking : If not found, it calls
forkRepoto create one app/src/main/java/com/abk/kernel/data/api/GitHubApiService.kt#L21-L26 -
Upstream Sync : Synchronizes the user's fork with the latest code from the upstream ABK repository using the
syncForkinterface app/src/main/java/com/abk/kernel/data/api/GitHubApiService.kt#L36-L41
This is the most complex part of the integration, involving build triggering, log retrieval, and artifact downloading.
-
Triggering Builds :
dispatchWorkflowsends a POST request with custom input parameters (e.g., kernel version, KSU options) app/src/main/java/com/abk/kernel/data/api/GitHubApiService.kt#L50-L56 -
Status Polling : The app monitors build progress via
listWorkflowRunsand useslistRunJobsto get success/failure status for specific steps app/src/main/java/com/abk/kernel/data/api/GitHubApiService.kt#L95-L101 -
Log Streaming : Supports downloading compressed logs for the entire run via
downloadRunLogsapp/src/main/java/com/abk/kernel/data/api/GitHubApiService.kt#L113-L117
The app supports fetching kernel module definitions from third-party repositories.
-
Metadata Fetching :
fetchExternalModuleMetadataattempts to locatemodule.conffiles from GitHub URLs app/src/main/java/com/abk/kernel/data/repository/GitHubRepository.kt#L62-L97 -
Catalog Parsing :
fetchModuleCatalogdownloads a JSON index, parses it, and displays available kernel extension modules app/src/main/java/com/abk/kernel/data/repository/GitHubRepository.kt#L99-L143
"从自然语言到代码实体的映射 / Mapping Natural Language to Code Entities"
| 功能 / Feature | 代码类与方法 / Code Class & Method | API 终点 / API Endpoint |
|---|---|---|
| 设备授权 / Device Auth | GitHubAuthService.requestDeviceCode |
POST /login/device/code |
| 创建 Fork / Create Fork | GitHubApiService.forkRepo |
POST /repos/{o}/{r}/forks |
| 启动构建 / Start Build | GitHubApiService.dispatchWorkflow |
POST .../dispatches |
| 下载制品 / Download Artifact | GitHubApiService.downloadArtifact |
GET .../artifacts/{id}/zip |
| 解析模块 / Parse Module | GitHubRepository.parseExternalModuleConf |
N/A (Internal Logic) |
"GitHub OAuth 设备流实现 / GitHub OAuth Device Flow Implementation"
DeepWiki client-side-rendered block omitted in static export.
Sources: app/src/main/java/com/abk/kernel/data/api/GitHubAuthService.kt#L8-L24 app/src/main/java/com/abk/kernel/data/repository/GitHubRepository.kt#L36-L58 app/src/main/java/com/abk/kernel/data/api/NetworkClient.kt#L36-L43
null