From 3cf12742606d047ebbc8cacf3efa287dbd7373da Mon Sep 17 00:00:00 2001 From: Hiroshi Nishio Date: Sat, 7 Dec 2024 20:27:33 +0900 Subject: [PATCH] Get and display integrated repositories on a Jira ticket --- manifest.yml | 27 +++++++++++++++++++++++++++ src/frontend/index.jsx | 40 ++++++++++++++++++++++++++++++++++++---- src/resolvers/index.js | 33 +++++++++++++++++++++++++++++---- 3 files changed, 92 insertions(+), 8 deletions(-) diff --git a/manifest.yml b/manifest.yml index 28571ab..fdc4e2f 100644 --- a/manifest.yml +++ b/manifest.yml @@ -1,4 +1,14 @@ modules: + # The trigger module invokes a function or calls a remote backend when a product event, app lifecycle event, or data security policy event is fired. + # https://developer.atlassian.com/platform/forge/manifest-reference/modules/trigger/ + # trigger: + # - key: app-lifecycle-trigger + # function: lifecycleHandler + # events: + # - installed # https://developer.atlassian.com/platform/forge/events-reference/life-cycle/ + # - uninstalled + + # The jira module provides functionality for Jira products. jira:issuePanel: - key: gitauto-jira-hello-world-issue-panel resource: main @@ -7,9 +17,12 @@ modules: render: native title: GitAuto icon: https://developer.atlassian.com/platform/forge/images/icons/issue-panel-icon.svg + + # https://developer.atlassian.com/platform/forge/runtime-reference/forge-resolver/ function: - key: resolver handler: index.handler + resources: - key: main path: src/frontend/index.jsx @@ -17,6 +30,20 @@ app: runtime: name: nodejs20.x # Has to be 'sandbox', 'nodejs18.x', 'nodejs20.x' id: ari:cloud:ecosystem::app/f434bcc5-834f-45e5-ba1d-62e2ee8952cd + +# Environment variables are not supported in the manifest.yml file. +# https://developer.atlassian.com/platform/forge/manifest-reference/permissions/ permissions: scopes: - read:jira-work + external: + fetch: + backend: + - https://dkrxtcbaqzrodvsagwwn.supabase.co + - https://awegqusxzsmlgxaxyyrq.supabase.co + +# https://developer.atlassian.com/platform/forge/manifest-reference/variables/ +environment: + variables: + - SUPABASE_URL + - SUPABASE_API_KEY diff --git a/src/frontend/index.jsx b/src/frontend/index.jsx index 4ff5b34..4575c77 100644 --- a/src/frontend/index.jsx +++ b/src/frontend/index.jsx @@ -1,10 +1,12 @@ import React, { useEffect, useState } from "react"; import ForgeReconciler, { Select, Text, useProductContext } from "@forge/react"; -import { requestJira } from "@forge/bridge"; +import { invoke } from "@forge/bridge"; const App = () => { // Get Jira cloud ID (== workspace ID) const context = useProductContext(); + + // Get Jira cloud ID const [cloudId, setCloudId] = useState(null); useEffect(() => { if (context) { @@ -14,9 +16,39 @@ const App = () => { } }, [context]); + // Get Jira project ID + const [projectId, setProjectId] = useState(null); + useEffect(() => { + if (context) setProjectId(context.extension.project.id); + }, [context]); + + // Get corresponding GitHub repositories from Supabase + const [githubRepos, setGithubRepos] = useState([]); + useEffect(() => { + const fetchRepositories = async () => { + if (cloudId && projectId) { + try { + const response = await invoke("getGithubRepos", { + cloudId, + projectId, + }); + + // response will be an array of repositories from Supabase + setGithubRepos( + response.map((repo) => `${repo.github_owner_name}/${repo.github_repo_name}`) + ); + } catch (error) { + console.error("Error fetching repositories:", error); + setGithubRepos([]); + } + } + }; + + fetchRepositories(); + }, [cloudId, projectId]); + // Get repository list where GitAuto is installed - const repositories = ["gitautoai/gitauto", "gitautoai/gitauto-jira"]; - const [selectedRepo, setSelectedRepo] = useState(repositories[0]); + const [selectedRepo, setSelectedRepo] = useState(githubRepos[0]); return ( <> @@ -24,7 +56,7 @@ const App = () => {