Skip to content

Commit

Permalink
Get and display integrated repositories on a Jira ticket
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroshinishio committed Dec 7, 2024
1 parent 83259f1 commit 3cf1274
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 8 deletions.
27 changes: 27 additions & 0 deletions manifest.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -7,16 +17,33 @@ 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
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
40 changes: 36 additions & 4 deletions src/frontend/index.jsx
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -14,17 +16,47 @@ 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 (
<>
<Text>Target GitHub Repository:</Text>
<Select
value={selectedRepo}
onChange={setSelectedRepo}
options={repositories.map((repo) => ({ label: repo, value: repo }))}
options={githubRepos.map((repo) => ({ label: repo, value: repo }))}
/>
</>
);
Expand Down
33 changes: 29 additions & 4 deletions src/resolvers/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
import Resolver from '@forge/resolver';
import Resolver from "@forge/resolver";
import forge from "@forge/api";

const resolver = new Resolver();

resolver.define('getText', (req) => {
console.log(req);
return 'Hello, world!';
// https://developer.atlassian.com/platform/forge/runtime-reference/forge-resolver/
resolver.define("getGithubRepos", async ({ payload }) => {
const { cloudId, projectId } = payload;

// https://supabase.com/docs/guides/api/sql-to-rest
const queryParams = new URLSearchParams({
select: "*",
jira_site_id: `eq.${cloudId}`,
jira_project_id: `eq.${projectId}`,
}).toString();
const url = `${process.env.SUPABASE_URL}/rest/v1/jira_github_links?${queryParams}`;
console.log(url);

const response = await forge.fetch(url, {
method: "GET",
headers: {
apikey: process.env.SUPABASE_API_KEY,
Authorization: `Bearer ${process.env.SUPABASE_API_KEY}`,
"Content-Type": "application/json",
},
});

if (!response.ok) throw new Error(`Failed to fetch repositories: ${response.status}`);

const data = await response.json();
console.log(data);
return data;
});

export const handler = resolver.getDefinitions();

0 comments on commit 3cf1274

Please sign in to comment.