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" ;
16
14
import { useCurrentProject } from "./project-context" ;
17
15
import { shortCommitMessage } from "./render-utils" ;
16
+ import { prebuildClient , watchPrebuild } from "../service/public-api" ;
17
+ import { Prebuild , PrebuildPhase_Phase } from "@gitpod/public-api/lib/gitpod/v1/prebuild_pb" ;
18
18
19
19
export default function PrebuildPage ( ) {
20
20
const history = useHistory ( ) ;
21
21
const { project, loading } = useCurrentProject ( ) ;
22
22
23
23
const { prebuildId } = useParams < { prebuildId : string } > ( ) ;
24
24
25
- const [ prebuild , setPrebuild ] = useState < PrebuildWithStatus | undefined > ( ) ;
25
+ const [ prebuild , setPrebuild ] = useState < Prebuild | undefined > ( ) ;
26
26
const [ isRerunningPrebuild , setIsRerunningPrebuild ] = useState < boolean > ( false ) ;
27
27
const [ isCancellingPrebuild , setIsCancellingPrebuild ] = useState < boolean > ( false ) ;
28
28
29
29
useEffect ( ( ) => {
30
30
if ( ! project || ! prebuildId ) {
31
31
return ;
32
32
}
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 ;
33
+ return watchPrebuild ( { prebuildIds : [ prebuildId ] } , ( prebuild ) => setPrebuild ( prebuild ) ) ;
50
34
} , [ prebuildId , project ] ) ;
51
35
52
36
const title = useMemo ( ( ) => {
53
37
if ( ! prebuild ) {
54
38
return "unknown prebuild" ;
55
39
}
56
- return prebuild . info . branch ;
40
+ return prebuild . ref ;
57
41
} , [ prebuild ] ) ;
58
42
59
43
const renderSubtitle = ( ) => {
60
44
if ( ! prebuild ) {
61
45
return "" ;
62
46
}
63
- const startedByAvatar = prebuild . info . startedByAvatar && (
64
- < img
65
- className = "rounded-full w-4 h-4 inline-block align-text-bottom mr-2"
66
- src = { prebuild . info . startedByAvatar || "" }
67
- alt = { prebuild . info . startedBy }
68
- />
69
- ) ;
70
47
return (
71
48
< div className = "flex" >
72
49
< div className = "my-auto" >
73
- < Subheading >
74
- { startedByAvatar } Triggered { dayjs ( prebuild . info . startedAt ) . fromNow ( ) }
75
- </ Subheading >
50
+ < Subheading > Triggered { dayjs ( prebuild . status ?. startTime ?. toDate ( ) ) . fromNow ( ) } </ Subheading >
76
51
</ div >
77
52
< p className = "mx-2 my-auto" > ·</ p >
78
53
< div className = "my-auto" >
79
- < p className = "text-gray-500 dark:text-gray-50" > { shortCommitMessage ( prebuild . info . changeTitle ) } </ p >
54
+ < p className = "text-gray-500 dark:text-gray-50" >
55
+ { shortCommitMessage ( prebuild . commit ?. message || "" ) }
56
+ </ p >
80
57
</ div >
81
- { ! ! prebuild . info . basedOnPrebuildId && (
58
+ { ! ! prebuild . basedOnPrebuildId && (
82
59
< >
83
60
< p className = "mx-2 my-auto" > ·</ p >
84
61
< div className = "my-auto" >
85
62
< p className = "text-gray-500 dark:text-gray-50" >
86
63
Incremental Prebuild (
87
64
< a
88
65
className = "gp-link"
89
- title = { prebuild . info . basedOnPrebuildId }
90
- href = { `./${ prebuild . info . basedOnPrebuildId } ` }
66
+ title = { prebuild . basedOnPrebuildId }
67
+ href = { `./${ prebuild . basedOnPrebuildId } ` }
91
68
>
92
69
base
93
70
</ a >
@@ -106,7 +83,10 @@ export default function PrebuildPage() {
106
83
}
107
84
try {
108
85
setIsRerunningPrebuild ( true ) ;
109
- await getGitpodService ( ) . server . triggerPrebuild ( prebuild . info . projectId , prebuild . info . branch ) ;
86
+ await prebuildClient . startPrebuild ( {
87
+ configurationId : prebuild . configurationId ,
88
+ gitRef : prebuild . ref ,
89
+ } ) ;
110
90
// TODO: Open a Prebuilds page that's specific to `prebuild.info.branch`?
111
91
if ( project ) {
112
92
history . push ( `/projects/${ project . id } /prebuilds` ) ;
@@ -124,7 +104,9 @@ export default function PrebuildPage() {
124
104
}
125
105
try {
126
106
setIsCancellingPrebuild ( true ) ;
127
- await getGitpodService ( ) . server . cancelPrebuild ( prebuild . info . projectId , prebuild . info . id ) ;
107
+ await prebuildClient . cancelPrebuild ( {
108
+ prebuildId : prebuild . id ,
109
+ } ) ;
128
110
} catch ( error ) {
129
111
console . error ( "Could not cancel prebuild" , error ) ;
130
112
} finally {
@@ -140,8 +122,10 @@ export default function PrebuildPage() {
140
122
< >
141
123
< Header title = { title } subtitle = { renderSubtitle ( ) } />
142
124
< div className = "app-container mt-8" >
143
- < PrebuildLogs workspaceId = { prebuild ?. info ?. buildWorkspaceId } >
144
- { [ "building" , "queued" ] . includes ( prebuild ?. status || "" ) ? (
125
+ < PrebuildLogs workspaceId = { prebuild ?. buildWorkspaceId } >
126
+ { [ PrebuildPhase_Phase . BUILDING , PrebuildPhase_Phase . QUEUED ] . includes (
127
+ prebuild ?. status ?. phase ?. name || PrebuildPhase_Phase . UNSPECIFIED ,
128
+ ) ? (
145
129
< button
146
130
className = "danger flex items-center space-x-2"
147
131
disabled = { isCancellingPrebuild }
@@ -162,20 +146,8 @@ export default function PrebuildPage() {
162
146
{ isRerunningPrebuild && (
163
147
< img alt = "" className = "h-4 w-4 animate-spin filter brightness-150" src = { Spinner } />
164
148
) }
165
- < span > Rerun Prebuild ({ prebuild ?. info . branch } )</ span >
149
+ < span > Rerun Prebuild ({ prebuild ?. ref } )</ span >
166
150
</ button >
167
- { prebuild ?. status === "available" ? (
168
- < a
169
- className = "my-auto"
170
- href = { gitpodHostUrl
171
- . withContext ( `open-prebuild/${ prebuild ?. info . id } /${ prebuild ?. info . changeUrl } ` )
172
- . toString ( ) }
173
- >
174
- < button > New Workspace (with this prebuild)</ button >
175
- </ a >
176
- ) : (
177
- < button disabled = { true } > New Workspace (with this prebuild)</ button >
178
- ) }
179
151
</ >
180
152
) }
181
153
</ PrebuildLogs >
0 commit comments