@@ -73,7 +73,7 @@ export default function () {
73
73
const [ prebuildInstance , setPrebuildInstance ] = useState < WorkspaceInstance | undefined > ( ) ;
74
74
const { isDark } = useContext ( ThemeContext ) ;
75
75
76
- const [ showAuthBanner , setShowAuthBanner ] = useState < { host : string } | undefined > ( undefined ) ;
76
+ const [ showAuthBanner , setShowAuthBanner ] = useState < { host : string , scope ?: string } | undefined > ( undefined ) ;
77
77
78
78
useEffect ( ( ) => {
79
79
// Disable editing while loading, or when the config comes from Git.
@@ -99,7 +99,11 @@ export default function () {
99
99
try {
100
100
await detectProjectConfiguration ( project ) ;
101
101
} catch ( error ) {
102
- if ( error && error . code === ErrorCodes . NOT_AUTHENTICATED ) {
102
+ if ( error && error . message && error . message . includes ( "NotFound" ) ) {
103
+ const host = new URL ( project . cloneUrl ) . hostname ;
104
+ const scope : string | undefined = host === "github.com" ? "repo" : undefined ;
105
+ setShowAuthBanner ( { host : new URL ( project . cloneUrl ) . hostname , scope } ) ;
106
+ } else if ( error && error . code === ErrorCodes . NOT_AUTHENTICATED ) {
103
107
setShowAuthBanner ( { host : new URL ( project . cloneUrl ) . hostname } ) ;
104
108
} else {
105
109
console . error ( 'Getting project configuration failed' , error ) ;
@@ -135,12 +139,12 @@ export default function () {
135
139
setGitpodYml ( TASKS . Other ) ;
136
140
}
137
141
138
- // @ts -ignore
139
- const tryAuthorize = async ( host : string , onSuccess : ( ) => void ) => {
142
+ const tryAuthorize = async ( params : { host : string , scope ?: string , onSuccess : ( ) => void } ) => {
140
143
try {
141
144
await openAuthorizeWindow ( {
142
- host,
143
- onSuccess,
145
+ host : params . host ,
146
+ onSuccess : params . onSuccess ,
147
+ scopes : params . scope ? [ params . scope ] : undefined ,
144
148
onError : ( error ) => {
145
149
console . log ( error ) ;
146
150
}
@@ -150,17 +154,17 @@ export default function () {
150
154
}
151
155
} ;
152
156
153
- const onConfirmShowAuthModal = async ( host : string ) => {
157
+ const onConfirmShowAuthModal = async ( host : string , scope ?: string ) => {
154
158
setShowAuthBanner ( undefined ) ;
155
- await tryAuthorize ( host , async ( ) => {
159
+ await tryAuthorize ( { host, onSuccess : async ( ) => {
156
160
// update remote session
157
161
await getGitpodService ( ) . reconnect ( ) ;
158
162
159
163
// retry fetching branches
160
164
if ( project ) {
161
165
detectProjectConfiguration ( project ) ;
162
166
}
163
- } ) ;
167
+ } } ) ;
164
168
} ;
165
169
166
170
const buildProject = async ( event : React . MouseEvent ) => {
@@ -215,9 +219,9 @@ export default function () {
215
219
No Access
216
220
</ div >
217
221
< div className = "text-center dark:text-gray-400 pb-3" >
218
- Authorize { showAuthBanner . host } < br /> to access project configuration.
222
+ Authorize { showAuthBanner . host } < br /> { showAuthBanner . scope ? ( < > and grant < strong > { showAuthBanner . scope } </ strong > permission </ > ) : "" } to access project configuration.
219
223
</ div >
220
- < button className = { `primary mr-2 py-2` } onClick = { ( ) => onConfirmShowAuthModal ( showAuthBanner . host ) } > Authorize Provider</ button >
224
+ < button className = { `primary mr-2 py-2` } onClick = { ( ) => onConfirmShowAuthModal ( showAuthBanner . host , showAuthBanner . scope ) } > Authorize Provider</ button >
221
225
</ div >
222
226
</ div >
223
227
) : ( < >
0 commit comments