|
1 | 1 | import { Body } from '@tauri-apps/api/http' |
2 | 2 | import { HttpClient } from '../http-client/http-client' |
3 | | -import { ApplicationDto, BranchDto } from './appcenter-api.type' |
| 3 | +import { ApplicationDto, BranchDto, BranchWithCommitDto, CommitLiteDto } from './appcenter-api.type' |
4 | 4 |
|
5 | 5 | export class AppcenterApi { |
6 | 6 | private readonly _http: HttpClient |
@@ -45,19 +45,29 @@ export class AppcenterApi { |
45 | 45 | ownerName: string, |
46 | 46 | applicationName: string, |
47 | 47 | token: string |
48 | | - ): Promise<Array<BranchDto>> { |
| 48 | + ): Promise<Array<BranchWithCommitDto>> { |
49 | 49 | return this._http |
50 | 50 | .get<Array<BranchDto>>(`apps/${ownerName}/${applicationName}/branches`, { |
51 | 51 | headers: { |
52 | 52 | 'Content-Type': 'application/json', |
53 | 53 | 'X-API-Token': token |
54 | 54 | } |
55 | 55 | }) |
56 | | - .then((res) => { |
| 56 | + .then(async (res) => { |
57 | 57 | if (!res.ok) { |
58 | 58 | return [] |
59 | 59 | } |
60 | | - return res.data |
| 60 | + const commits = await this.getCommitsBatch( |
| 61 | + ownerName, |
| 62 | + applicationName, |
| 63 | + res.data.map((b) => b.branch.commit.sha), |
| 64 | + token |
| 65 | + ) |
| 66 | + |
| 67 | + return res.data.map((b, index) => ({ |
| 68 | + ...b, |
| 69 | + commit: commits[index] |
| 70 | + })) |
61 | 71 | }) |
62 | 72 | } |
63 | 73 |
|
@@ -125,4 +135,30 @@ export class AppcenterApi { |
125 | 135 | ) |
126 | 136 | console.log(res) |
127 | 137 | } |
| 138 | + |
| 139 | + async getCommitsBatch( |
| 140 | + ownerName: string, |
| 141 | + applicationName: string, |
| 142 | + hashes: Array<string>, |
| 143 | + token: string |
| 144 | + ): Promise<Array<CommitLiteDto>> { |
| 145 | + return this._http |
| 146 | + .get<Array<CommitLiteDto>>(`apps/${ownerName}/${applicationName}/commits/batch`, { |
| 147 | + headers: { |
| 148 | + 'Content-Type': 'application/json', |
| 149 | + 'X-API-Token': token |
| 150 | + }, |
| 151 | + query: { |
| 152 | + form: 'lite', |
| 153 | + hashes: hashes.join(',') |
| 154 | + } |
| 155 | + }) |
| 156 | + .then((res) => { |
| 157 | + if (!res.ok) { |
| 158 | + return [] |
| 159 | + } |
| 160 | + |
| 161 | + return res.data |
| 162 | + }) |
| 163 | + } |
128 | 164 | } |
0 commit comments