-
Notifications
You must be signed in to change notification settings - Fork 402
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1665 from florinnania/add-sign-in-button-in-entit…
…y-github-related-cards Add sign in button in entity GitHub related cards
- Loading branch information
Showing
15 changed files
with
252 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@roadiehq/backstage-plugin-github-pull-requests': minor | ||
'@roadiehq/backstage-plugin-security-insights': minor | ||
'@roadiehq/backstage-plugin-github-insights': minor | ||
--- | ||
|
||
Add SignIn button to all Github related cards from entity overwiew page. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
plugins/frontend/backstage-plugin-github-insights/src/hooks/useGithubLoggedIn.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright 2024 Larder Software Limited | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import React, { useEffect, useState } from 'react'; | ||
import { | ||
useApi, | ||
githubAuthApiRef, | ||
SessionState, | ||
} from '@backstage/core-plugin-api'; | ||
import { Grid, Tooltip, Button, Typography } from '@material-ui/core'; | ||
|
||
export const GithubNotAuthorized = () => { | ||
const githubApi = useApi(githubAuthApiRef); | ||
return ( | ||
<Grid container> | ||
<Grid item xs={8}> | ||
<Typography> | ||
You are not logged into github. You need to be signed in to see the | ||
content of this card. | ||
</Typography> | ||
</Grid> | ||
<Grid item xs={4} container justifyContent="flex-end"> | ||
<Tooltip placement="top" arrow title="Sign in to Github"> | ||
<Button | ||
variant="outlined" | ||
color="primary" | ||
// Calling getAccessToken instead of a plain signIn because we are going to get the correct scopes right away. No need to second request | ||
onClick={() => githubApi.getAccessToken('repo')} | ||
> | ||
Sign in | ||
</Button> | ||
</Tooltip> | ||
</Grid> | ||
</Grid> | ||
); | ||
}; | ||
|
||
export const useGithubLoggedIn = () => { | ||
const githubApi = useApi(githubAuthApiRef); | ||
const [isLoggedIn, setIsLoggedIn] = useState(false); | ||
|
||
useEffect(() => { | ||
githubApi.getAccessToken('repo', { optional: true }); | ||
const authSubscription = githubApi.sessionState$().subscribe(state => { | ||
if (state === SessionState.SignedIn) { | ||
setIsLoggedIn(true); | ||
} | ||
}); | ||
return () => { | ||
authSubscription.unsubscribe(); | ||
}; | ||
}, [githubApi]); | ||
|
||
return isLoggedIn; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.