Split verification of GitHub
Background
Section titled BackgroundVerify the GitHub setting on config page, there is some data redundancy. Besides, users will reset the verify status when modifying the date, resulting in a bad user experience.
Expect
Section titled ExpectReduce the granularity of the step of verification and enables a new API for target resource verification.
Solutions
Section titled SolutionsThrough two-stage verification of GitHub tokens, the first stage verifies the validity of the token, and the second stage verifies that the token can read the target branch.
1. Verify the validity of the token
Section titled 1. Verify the validity of the token- Request timing
Triggered after clicking GitHub’s verify on the config page.
- Api Design
paths: /api/v1/source-control/{sourceType}/verify
method: post
request: {
token: "..."
}
responses:
Status Code: 204
- GitHub Api for verification
paths: "https://api.github.com/octocat"
method: get
header: "Authorization: Bearer YOUR-TOKEN"
- Exception Handler
status | message | hintInfo |
400 | Token cannot be empty. | |
Token’s pattern is incorrect. | ||
Source type is incorrect. | ||
401 | Failed to get GitHub info_status: 401, reason: Bad credentials | Token is incorrect |
500 | Internal Server Error |
- Sequence Diagram
2. Verify token can read target branch
Section titled 2. Verify token can read target branch- Request timing
Triggered when the user selects a branch in the Pipeline settings module of the Metrics page.
- Api Design
paths: /api/v1/source-control/{sourceType}/repos/branches/verify
method: post
request: {
repository: "git@github.com:XXXX/XXXX.git",
token: "...",
branch: "main"
}
responses:
Status Code: 204
Note:Since the branch name may contain special characters, which will cause the URL to be unsafe, put it in the request body.
- GitHub Api for verification
paths: https://api.github.com/repos/{owner}/{repo}/branches/{branch}
method: get
header: "Authorization: Bearer <YOUR-TOKEN>"
- Exception Handler
status | message | hintInfo |
400 | Token cannot be empty. | |
Token’s pattern is incorrect. | ||
Repository cannot be empty. | ||
Source type is incorrect. | ||
Branch cannot be empty. | ||
Unable to read target branch: main, with token error | Please reconfirm the input | |
401 | Unable to read target organization | Token is incorrect |
404 | Unable to read target branch | Not found |
500 | Internal Server Error |
- Sequence Diagram