Skip to content

Commit

Permalink
Merge pull request #22 from gitautoai/wes
Browse files Browse the repository at this point in the history
Emable to trigger GitAuto by checking the checkbox
  • Loading branch information
hiroshinishio authored Dec 9, 2024
2 parents 1f98809 + f76f8d7 commit b88e496
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ For development, you can do the following:

```shell
forge variables list -e development
forge variables set --encrypt SUPABASE_URL <value>
forge variables set --encrypt SUPABASE_API_KEY <value>
forge variables set --environment development --encrypt SUPABASE_URL <value>
forge variables set --environment development --encrypt SUPABASE_API_KEY <value>
```

For production, you have to do the following:
Expand Down
21 changes: 16 additions & 5 deletions manifest.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
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.
# Trigger is used to invoke a function when a Jira issue event is fired.
# https://developer.atlassian.com/platform/forge/manifest-reference/modules/trigger/
# trigger:
# - key: app-lifecycle-trigger
# function: lifecycleHandler
# - key: issue-trigger
# function: webhook
# # https://developer.atlassian.com/platform/forge/events-reference/jira/#issue-events
# events:
# - installed # https://developer.atlassian.com/platform/forge/events-reference/life-cycle/
# - uninstalled
# - avi:jira:created:issue
# - avi:jira:updated:issue
# filter:
# ignoreSelf: true # Prevents infinite loops by ignoring self-generated events
# # expression: event.issue.fields.issuetype.name == 'Bug' # Optional: example filter for bug issues only
# onError: IGNORE_AND_LOG # Will invoke function and log errors

# The jira module provides functionality for Jira products.
jira:issuePanel:
Expand All @@ -22,6 +27,8 @@ modules:
function:
- key: resolver
handler: index.handler
# - key: webhook
# handler: webhook.handler

resources:
- key: main
Expand All @@ -33,6 +40,7 @@ app:

# Environment variables are not supported in the manifest.yml file.
# https://developer.atlassian.com/platform/forge/manifest-reference/permissions/
# It takes a few hours to 1 day to update here: https://developer.atlassian.com/console/myapps/f434bcc5-834f-45e5-ba1d-62e2ee8952cd/manage/permissions
permissions:
scopes:
- storage:app
Expand All @@ -42,9 +50,12 @@ permissions:
backend:
- https://dkrxtcbaqzrodvsagwwn.supabase.co
- https://awegqusxzsmlgxaxyyrq.supabase.co
- https://5ze2tkqk7c27bpl5opy5sbilsi0vrdim.lambda-url.us-west-1.on.aws
- https://gitauto.ngrok.dev

# https://developer.atlassian.com/platform/forge/manifest-reference/variables/
environment:
variables:
- SUPABASE_URL
- SUPABASE_API_KEY
- GITAUTO_URL
31 changes: 28 additions & 3 deletions src/frontend/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from "react";
import { invoke } from "@forge/bridge";
import ForgeReconciler, { Select, Text, useProductContext } from "@forge/react";
import ForgeReconciler, { Select, Text, useProductContext, Checkbox, Stack } from "@forge/react";

const App = () => {
// Get Jira cloud ID (== workspace ID)
Expand Down Expand Up @@ -75,8 +75,26 @@ const App = () => {
}
};

// Handle checkbox
const [isChecked, setIsChecked] = useState(false);
const [isTriggering, setIsTriggering] = useState(false);
const handleCheckboxChange = async (event) => {
const checked = event.target.checked;
setIsChecked(checked);
if (!checked || !selectedRepo) return;
setIsTriggering(true);
try {
await invoke("triggerGitAuto", { cloudId, projectId, issueId, selectedRepo });
} catch (error) {
console.error("Error triggering GitAuto:", error);
} finally {
setIsTriggering(false);
}
};

return (
<>
// https://developer.atlassian.com/platform/forge/ui-kit-2/stack/
<Stack space="space.075">
<Text>Target GitHub Repository:</Text>
<Select
value={selectedRepo}
Expand All @@ -85,7 +103,14 @@ const App = () => {
isDisabled={isLoading}
placeholder="Select a repository"
/>
</>
<Checkbox
label="Trigger GitAuto to open a pull request"
onChange={handleCheckboxChange}
value={isChecked}
isDisabled={!selectedRepo || isTriggering}
/>
{isTriggering && <Text>Triggering GitAuto...</Text>}
</Stack>
);
};

Expand Down
22 changes: 22 additions & 0 deletions src/resolvers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,26 @@ resolver.define("storeRepo", async ({ payload }) => {
return await storage.set(key, value);
});

resolver.define("triggerGitAuto", async ({ payload }) => {
const { cloudId, projectId, issueId, selectedRepo } = payload;

// Determine the API endpoint based on environment
const endpoint = process.env.GITAUTO_URL + "/webhook";
console.log("Endpoint", endpoint);
const response = await forge.fetch(endpoint, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
cloudId,
projectId,
issueId,
repository: selectedRepo,
}),
});

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

return await response.json();
});

export const handler = resolver.getDefinitions();

0 comments on commit b88e496

Please sign in to comment.