44 GitlabIcon ,
55} from "@/components/icons/data-tools-icons" ;
66import { DialogAction } from "@/components/shared/dialog-action" ;
7- import { Button } from "@/components/ui/button" ;
7+ import { Button , buttonVariants } from "@/components/ui/button" ;
88import {
99 Card ,
1010 CardContent ,
@@ -13,8 +13,16 @@ import {
1313 CardTitle ,
1414} from "@/components/ui/card" ;
1515import { api } from "@/utils/api" ;
16+ import { useUrl } from "@/utils/hooks/use-url" ;
1617import { formatDate } from "date-fns" ;
17- import { GitBranch , Loader2 , Trash2 } from "lucide-react" ;
18+ import {
19+ ExternalLinkIcon ,
20+ GitBranch ,
21+ ImportIcon ,
22+ Loader2 ,
23+ Trash2 ,
24+ } from "lucide-react" ;
25+ import Link from "next/link" ;
1826import { toast } from "sonner" ;
1927import { AddBitbucketProvider } from "./bitbucket/add-bitbucket-provider" ;
2028import { EditBitbucketProvider } from "./bitbucket/edit-bitbucket-provider" ;
@@ -27,7 +35,20 @@ export const ShowGitProviders = () => {
2735 const { data, isLoading, refetch } = api . gitProvider . getAll . useQuery ( ) ;
2836 const { mutateAsync, isLoading : isRemoving } =
2937 api . gitProvider . remove . useMutation ( ) ;
38+ const url = useUrl ( ) ;
39+ const getGitlabUrl = (
40+ clientId : string ,
41+ gitlabId : string ,
42+ gitlabUrl : string ,
43+ ) => {
44+ const redirectUri = `${ url } /api/providers/gitlab/callback?gitlabId=${ gitlabId } ` ;
45+
46+ const scope = "api read_user read_repository" ;
47+
48+ const authUrl = `${ gitlabUrl } /oauth/authorize?client_id=${ clientId } &redirect_uri=${ encodeURIComponent ( redirectUri ) } &response_type=code&scope=${ encodeURIComponent ( scope ) } ` ;
3049
50+ return authUrl ;
51+ } ;
3152 return (
3253 < div className = "w-full" >
3354 < Card className = "h-full bg-sidebar p-2.5 rounded-xl max-w-5xl mx-auto" >
@@ -128,6 +149,51 @@ export const ShowGitProviders = () => {
128149 </ div >
129150
130151 < div className = "flex flex-row gap-1" >
152+ { ! haveGithubRequirements && isGithub && (
153+ < div className = "flex flex-col gap-1" >
154+ < Link
155+ href = { `${ gitProvider ?. github ?. githubAppName } /installations/new?state=gh_setup:${ gitProvider ?. github . githubId } ` }
156+ className = { buttonVariants ( {
157+ size : "icon" ,
158+ variant : "ghost" ,
159+ } ) }
160+ >
161+ < ImportIcon className = "size-4 text-primary" />
162+ </ Link >
163+ </ div >
164+ ) }
165+ { haveGithubRequirements && isGithub && (
166+ < div className = "flex flex-col gap-1" >
167+ < Link
168+ href = { `${ gitProvider ?. github ?. githubAppName } ` }
169+ target = "_blank"
170+ className = { buttonVariants ( {
171+ size : "icon" ,
172+ variant : "ghost" ,
173+ } ) }
174+ >
175+ < ExternalLinkIcon className = "size-4 text-primary" />
176+ </ Link >
177+ </ div >
178+ ) }
179+ { ! haveGitlabRequirements && isGitlab && (
180+ < div className = "flex flex-col gap-1" >
181+ < Link
182+ href = { getGitlabUrl (
183+ gitProvider . gitlab ?. applicationId || "" ,
184+ gitProvider . gitlab ?. gitlabId || "" ,
185+ gitProvider . gitlab ?. gitlabUrl ,
186+ ) }
187+ target = "_blank"
188+ className = { buttonVariants ( {
189+ size : "icon" ,
190+ variant : "ghost" ,
191+ } ) }
192+ >
193+ < ImportIcon className = "size-4 text-primary" />
194+ </ Link >
195+ </ div >
196+ ) }
131197 { isGithub && haveGithubRequirements && (
132198 < EditGithubProvider
133199 githubId = { gitProvider . github . githubId }
0 commit comments