Skip to content

Commit e1b23cf

Browse files
committed
rettriev and display last commi
1 parent a0840f8 commit e1b23cf

File tree

6 files changed

+97
-26
lines changed

6 files changed

+97
-26
lines changed

src/app/screens/application-list/ApplicationList.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {
1010
IColumn,
1111
IGroup,
1212
Image,
13+
Persona,
14+
PersonaSize,
1315
ProgressIndicator,
1416
SelectionMode,
1517
Stack,
@@ -68,15 +70,29 @@ export const ApplicationList = observer(() => {
6870
}
6971
return appName
7072
},
71-
minWidth: 100,
73+
minWidth: 150,
7274
maxWidth: 250
7375
},
7476
{
7577
key: 'branch',
7678
name: 'Branch',
7779
onRender: (item: Branch) => item.name,
7880
minWidth: 50,
79-
maxWidth: 100
81+
maxWidth: 80
82+
},
83+
{
84+
key: 'commit',
85+
name: 'Commit',
86+
onRender: ({ lastCommit }: Branch) => (
87+
<Persona
88+
size={PersonaSize.size32}
89+
showSecondaryText
90+
imageUrl={lastCommit.author.avatar_url}
91+
text={lastCommit.commit.message}
92+
secondaryText={lastCommit.commit.author.name}
93+
/>
94+
),
95+
minWidth: 150
8096
},
8197
{
8298
key: 'build',
@@ -88,7 +104,7 @@ export const ApplicationList = observer(() => {
88104
return <BuildStatusIndicator status={lastBuild.status} result={lastBuild.result} />
89105
}
90106
},
91-
minWidth: 50
107+
minWidth: 40
92108
},
93109
{
94110
key: 'actions',

src/models/application-store/application/application.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
SnapshotOut,
1111
types
1212
} from 'mobx-state-tree'
13-
import { ApplicationDto, BranchDto } from '../../../services'
13+
import { ApplicationDto, BranchWithCommitDto } from '../../../services'
1414
import { Branch, BranchModel } from '../../branch-store'
1515
import { withEnvironment } from '../../extensions/with-environment'
1616
import { withRootStore } from '../../extensions/with-root-store'
@@ -77,18 +77,19 @@ export const ApplicationModel: ApplicationRunType = ApplicationModel$1.props({
7777
.actions((self) => ({
7878
fetchBranches: flow(function* () {
7979
self.isLoading = true
80-
const [applicationDto, branchesDto]: [ApplicationDto, Array<BranchDto>] = yield Promise.all([
81-
self.environment.appcenterApi.getApplication(
82-
self.owner.displayName,
83-
self.name,
84-
self.token.token
85-
),
86-
self.environment.appcenterApi.getBranches(
87-
self.owner.displayName,
88-
self.name,
89-
self.token.token
90-
)
91-
])
80+
const [applicationDto, branchesDto]: [ApplicationDto, Array<BranchWithCommitDto>] =
81+
yield Promise.all([
82+
self.environment.appcenterApi.getApplication(
83+
self.owner.displayName,
84+
self.name,
85+
self.token.token
86+
),
87+
self.environment.appcenterApi.getBranches(
88+
self.owner.displayName,
89+
self.name,
90+
self.token.token
91+
)
92+
])
9293

9394
// update self properties
9495
self.name = applicationDto.name

src/models/branch-store/branch-store.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Instance, SnapshotOut, types } from 'mobx-state-tree'
2-
import { BranchDto } from '../../services'
2+
import { BranchWithCommitDto } from '../../services'
33
import { Build } from '../build-store'
44
import { withEnvironment, withRootStore } from '../extensions/extensions'
55
import { BranchModel } from './branch'
@@ -21,7 +21,7 @@ export const BranchStoreModel = types
2121
.extend(withRootStore)
2222
.actions((self) => ({
2323
putBranchDdto: (
24-
branchDto: BranchDto,
24+
branchDto: BranchWithCommitDto,
2525
appId: string,
2626
applicationName: string,
2727
ownerName: string
@@ -35,7 +35,7 @@ export const BranchStoreModel = types
3535
id: `${ownerName}_${applicationName}_${branchDto.branch.name}`,
3636
name: branchDto.branch.name,
3737
configured: branchDto.configured,
38-
lastCommit: branchDto.branch.commit.sha,
38+
lastCommit: branchDto.commit,
3939
application: appId,
4040
lastBuild: lastBuild?.id
4141
})

src/models/branch-store/branch/branch.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { IObjectWithKey } from '@fluentui/react'
22
import { flow, Instance, SnapshotOut, types } from 'mobx-state-tree'
3-
import { BuildDto } from '../../../services'
3+
import { BuildDto, CommitLiteDto } from '../../../services'
44
import { ApplicationModel, ApplicationRunType } from '../../application-store'
55
import { BuildModel } from '../../build-store'
66
import { withEnvironment } from '../../extensions/with-environment'
@@ -15,7 +15,7 @@ export const BranchModel = types
1515
id: types.identifier,
1616
name: types.string,
1717
configured: types.boolean,
18-
lastCommit: types.string,
18+
lastCommit: types.frozen<CommitLiteDto>(),
1919
lastBuild: types.safeReference(BuildModel),
2020
application: types.reference(types.late((): ApplicationRunType => ApplicationModel))
2121
})
@@ -40,7 +40,7 @@ export const BranchModel = types
4040
ownerName: self.application.owner.displayName,
4141
applicationName: self.application.name,
4242
branchName: self.name,
43-
commit: self.lastCommit,
43+
commit: self.lastCommit.sha,
4444
token: self.application.token.token
4545
})
4646
}),

src/services/appcenter-api/appcenter-api.ts

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Body } from '@tauri-apps/api/http'
22
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'
44

55
export class AppcenterApi {
66
private readonly _http: HttpClient
@@ -45,19 +45,29 @@ export class AppcenterApi {
4545
ownerName: string,
4646
applicationName: string,
4747
token: string
48-
): Promise<Array<BranchDto>> {
48+
): Promise<Array<BranchWithCommitDto>> {
4949
return this._http
5050
.get<Array<BranchDto>>(`apps/${ownerName}/${applicationName}/branches`, {
5151
headers: {
5252
'Content-Type': 'application/json',
5353
'X-API-Token': token
5454
}
5555
})
56-
.then((res) => {
56+
.then(async (res) => {
5757
if (!res.ok) {
5858
return []
5959
}
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+
}))
6171
})
6272
}
6373

@@ -125,4 +135,30 @@ export class AppcenterApi {
125135
)
126136
console.log(res)
127137
}
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+
}
128164
}

src/services/appcenter-api/appcenter-api.type.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,20 @@ export interface CommitDto {
4141
sha: string
4242
}
4343

44+
export interface CommitLiteDto extends CommitDto {
45+
author: {
46+
avatar_url?: string
47+
}
48+
commit: {
49+
message: string
50+
author: {
51+
name: string
52+
email: string
53+
date: string
54+
}
55+
}
56+
}
57+
4458
export interface BuildDto {
4559
id: number
4660
buildNumber: string
@@ -68,3 +82,7 @@ export interface BranchDto {
6882
lastBuild?: BuildDto
6983
trigger?: string
7084
}
85+
86+
export interface BranchWithCommitDto extends BranchDto {
87+
commit: CommitLiteDto
88+
}

0 commit comments

Comments
 (0)