4
4
* See License.AGPL.txt in the project root for license information.
5
5
*/
6
6
7
- import { PrebuildWithStatus } from "@gitpod/gitpod-protocol" ;
8
7
import dayjs from "dayjs" ;
9
8
import { useEffect , useMemo , useState } from "react" ;
10
9
import { Redirect , useHistory , useParams } from "react-router" ;
11
10
import Header from "../components/Header" ;
12
11
import PrebuildLogs from "../components/PrebuildLogs" ;
13
12
import { Subheading } from "../components/typography/headings" ;
14
13
import Spinner from "../icons/Spinner.svg" ;
15
- import { getGitpodService , gitpodHostUrl } from "../service/service" ;
14
+ import { gitpodHostUrl } from "../service/service" ;
16
15
import { useCurrentProject } from "./project-context" ;
17
16
import { shortCommitMessage } from "./render-utils" ;
17
+ import { prebuildClient , watchPrebuild } from "../service/public-api" ;
18
+ import { Prebuild , Prebuild_Status } from "@gitpod/public-api/lib/gitpod/v1/prebuild_pb" ;
18
19
19
20
export default function PrebuildPage ( ) {
20
21
const history = useHistory ( ) ;
21
22
const { project, loading } = useCurrentProject ( ) ;
22
23
23
24
const { prebuildId } = useParams < { prebuildId : string } > ( ) ;
24
25
25
- const [ prebuild , setPrebuild ] = useState < PrebuildWithStatus | undefined > ( ) ;
26
+ const [ prebuild , setPrebuild ] = useState < Prebuild | undefined > ( ) ;
26
27
const [ isRerunningPrebuild , setIsRerunningPrebuild ] = useState < boolean > ( false ) ;
27
28
const [ isCancellingPrebuild , setIsCancellingPrebuild ] = useState < boolean > ( false ) ;
28
29
29
30
useEffect ( ( ) => {
30
31
if ( ! project || ! prebuildId ) {
31
32
return ;
32
33
}
33
- ( async ( ) => {
34
- const prebuilds = await getGitpodService ( ) . server . findPrebuilds ( {
35
- projectId : project . id ,
36
- prebuildId,
37
- } ) ;
38
- setPrebuild ( prebuilds [ 0 ] ) ;
39
- } ) ( ) ;
40
-
41
- return getGitpodService ( ) . registerClient ( {
42
- onPrebuildUpdate ( update : PrebuildWithStatus ) {
43
- if ( update . info . id !== prebuildId ) {
44
- return ;
45
- }
46
-
47
- setPrebuild ( update ) ;
48
- } ,
49
- } ) . dispose ;
34
+ return watchPrebuild ( { prebuildId } , ( prebuild ) => setPrebuild ( prebuild ) ) ;
50
35
} , [ prebuildId , project ] ) ;
51
36
52
37
const title = useMemo ( ( ) => {
53
38
if ( ! prebuild ) {
54
39
return "unknown prebuild" ;
55
40
}
56
- return prebuild . info . branch ;
41
+ return prebuild . branch ;
57
42
} , [ prebuild ] ) ;
58
43
59
44
const renderSubtitle = ( ) => {
60
45
if ( ! prebuild ) {
61
46
return "" ;
62
47
}
63
- const startedByAvatar = prebuild . info . startedByAvatar && (
48
+ const startedByAvatar = prebuild . startedBy && (
64
49
< img
65
50
className = "rounded-full w-4 h-4 inline-block align-text-bottom mr-2"
66
- src = { prebuild . info . startedByAvatar || "" }
67
- alt = { prebuild . info . startedBy }
51
+ src = { prebuild . startedBy . avatarUrl }
52
+ alt = { prebuild . startedBy . name }
68
53
/>
69
54
) ;
70
55
return (
71
56
< div className = "flex" >
72
57
< div className = "my-auto" >
73
58
< Subheading >
74
- { startedByAvatar } Triggered { dayjs ( prebuild . info . startedAt ) . fromNow ( ) }
59
+ { startedByAvatar } Triggered { dayjs ( prebuild . startTime ?. toDate ( ) ) . fromNow ( ) }
75
60
</ Subheading >
76
61
</ div >
77
62
< p className = "mx-2 my-auto" > ·</ p >
78
63
< div className = "my-auto" >
79
- < p className = "text-gray-500 dark:text-gray-50" > { shortCommitMessage ( prebuild . info . changeTitle ) } </ p >
64
+ < p className = "text-gray-500 dark:text-gray-50" >
65
+ { shortCommitMessage ( prebuild . commit ?. message || "" ) }
66
+ </ p >
80
67
</ div >
81
- { ! ! prebuild . info . basedOnPrebuildId && (
68
+ { ! ! prebuild . basedOnPrebuildId && (
82
69
< >
83
70
< p className = "mx-2 my-auto" > ·</ p >
84
71
< div className = "my-auto" >
85
72
< p className = "text-gray-500 dark:text-gray-50" >
86
73
Incremental Prebuild (
87
74
< a
88
75
className = "gp-link"
89
- title = { prebuild . info . basedOnPrebuildId }
90
- href = { `./${ prebuild . info . basedOnPrebuildId } ` }
76
+ title = { prebuild . basedOnPrebuildId }
77
+ href = { `./${ prebuild . basedOnPrebuildId } ` }
91
78
>
92
79
base
93
80
</ a >
@@ -106,7 +93,10 @@ export default function PrebuildPage() {
106
93
}
107
94
try {
108
95
setIsRerunningPrebuild ( true ) ;
109
- await getGitpodService ( ) . server . triggerPrebuild ( prebuild . info . projectId , prebuild . info . branch ) ;
96
+ await prebuildClient . startPrebuild ( {
97
+ configurationId : prebuild . configurationId ,
98
+ branch : prebuild . branch ,
99
+ } ) ;
110
100
// TODO: Open a Prebuilds page that's specific to `prebuild.info.branch`?
111
101
if ( project ) {
112
102
history . push ( `/projects/${ project . id } /prebuilds` ) ;
@@ -124,7 +114,10 @@ export default function PrebuildPage() {
124
114
}
125
115
try {
126
116
setIsCancellingPrebuild ( true ) ;
127
- await getGitpodService ( ) . server . cancelPrebuild ( prebuild . info . projectId , prebuild . info . id ) ;
117
+ await prebuildClient . stopPrebuild ( {
118
+ prebuildId : prebuild . id ,
119
+ configurationId : prebuild . configurationId ,
120
+ } ) ;
128
121
} catch ( error ) {
129
122
console . error ( "Could not cancel prebuild" , error ) ;
130
123
} finally {
@@ -140,8 +133,10 @@ export default function PrebuildPage() {
140
133
< >
141
134
< Header title = { title } subtitle = { renderSubtitle ( ) } />
142
135
< div className = "app-container mt-8" >
143
- < PrebuildLogs workspaceId = { prebuild ?. info ?. buildWorkspaceId } >
144
- { [ "building" , "queued" ] . includes ( prebuild ?. status || "" ) ? (
136
+ < PrebuildLogs workspaceId = { prebuild ?. buildWorkspaceId } >
137
+ { [ Prebuild_Status . BUILDING , Prebuild_Status . QUEUED ] . includes (
138
+ prebuild ?. status || Prebuild_Status . UNSPECIFIED ,
139
+ ) ? (
145
140
< button
146
141
className = "danger flex items-center space-x-2"
147
142
disabled = { isCancellingPrebuild }
@@ -162,13 +157,13 @@ export default function PrebuildPage() {
162
157
{ isRerunningPrebuild && (
163
158
< img alt = "" className = "h-4 w-4 animate-spin filter brightness-150" src = { Spinner } />
164
159
) }
165
- < span > Rerun Prebuild ({ prebuild ?. info . branch } )</ span >
160
+ < span > Rerun Prebuild ({ prebuild ?. branch } )</ span >
166
161
</ button >
167
- { prebuild ?. status === "available" ? (
162
+ { prebuild ?. status === Prebuild_Status . AVAILABLE ? (
168
163
< a
169
164
className = "my-auto"
170
165
href = { gitpodHostUrl
171
- . withContext ( `open-prebuild/${ prebuild ?. info . id } /${ prebuild ?. info . changeUrl } ` )
166
+ . withContext ( `open-prebuild/${ prebuild ?. id } /${ prebuild ?. url } ` )
172
167
. toString ( ) }
173
168
>
174
169
< button > New Workspace (with this prebuild)</ button >
0 commit comments