1
1
import React , { useEffect , useState } from "react" ;
2
2
import ForgeReconciler , { Select , Text , useProductContext } from "@forge/react" ;
3
- import { requestJira } from "@forge/bridge" ;
3
+ import { invoke } from "@forge/bridge" ;
4
4
5
5
const App = ( ) => {
6
6
// Get Jira cloud ID (== workspace ID)
7
7
const context = useProductContext ( ) ;
8
+
9
+ // Get Jira cloud ID
8
10
const [ cloudId , setCloudId ] = useState ( null ) ;
9
11
useEffect ( ( ) => {
10
12
if ( context ) {
@@ -14,17 +16,47 @@ const App = () => {
14
16
}
15
17
} , [ context ] ) ;
16
18
19
+ // Get Jira project ID
20
+ const [ projectId , setProjectId ] = useState ( null ) ;
21
+ useEffect ( ( ) => {
22
+ if ( context ) setProjectId ( context . extension . project . id ) ;
23
+ } , [ context ] ) ;
24
+
25
+ // Get corresponding GitHub repositories from Supabase
26
+ const [ githubRepos , setGithubRepos ] = useState ( [ ] ) ;
27
+ useEffect ( ( ) => {
28
+ const fetchRepositories = async ( ) => {
29
+ if ( cloudId && projectId ) {
30
+ try {
31
+ const response = await invoke ( "getGithubRepos" , {
32
+ cloudId,
33
+ projectId,
34
+ } ) ;
35
+
36
+ // response will be an array of repositories from Supabase
37
+ setGithubRepos (
38
+ response . map ( ( repo ) => `${ repo . github_owner_name } /${ repo . github_repo_name } ` )
39
+ ) ;
40
+ } catch ( error ) {
41
+ console . error ( "Error fetching repositories:" , error ) ;
42
+ setGithubRepos ( [ ] ) ;
43
+ }
44
+ }
45
+ } ;
46
+
47
+ fetchRepositories ( ) ;
48
+ } , [ cloudId , projectId ] ) ;
49
+
17
50
// Get repository list where GitAuto is installed
18
- const repositories = [ "gitautoai/gitauto" , "gitautoai/gitauto-jira" ] ;
19
- const [ selectedRepo , setSelectedRepo ] = useState ( repositories [ 0 ] ) ;
51
+ const [ selectedRepo , setSelectedRepo ] = useState ( githubRepos [ 0 ] ) ;
20
52
21
53
return (
22
54
< >
23
55
< Text > Target GitHub Repository:</ Text >
24
56
< Select
25
57
value = { selectedRepo }
26
58
onChange = { setSelectedRepo }
27
- options = { repositories . map ( ( repo ) => ( { label : repo , value : repo } ) ) }
59
+ options = { githubRepos . map ( ( repo ) => ( { label : repo , value : repo } ) ) }
28
60
/>
29
61
</ >
30
62
) ;
0 commit comments