Skip to content

Commit f76f8d7

Browse files
committedDec 9, 2024·
Emable to trigger GitAuto by checking the checkbox
1 parent 11e36fb commit f76f8d7

File tree

4 files changed

+68
-10
lines changed

4 files changed

+68
-10
lines changed
 

‎README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ For development, you can do the following:
3939

4040
```shell
4141
forge variables list -e development
42-
forge variables set --encrypt SUPABASE_URL <value>
43-
forge variables set --encrypt SUPABASE_API_KEY <value>
42+
forge variables set --environment development --encrypt SUPABASE_URL <value>
43+
forge variables set --environment development --encrypt SUPABASE_API_KEY <value>
4444
```
4545

4646
For production, you have to do the following:

‎manifest.yml

+16-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
modules:
2-
# 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.
2+
# Trigger is used to invoke a function when a Jira issue event is fired.
33
# https://developer.atlassian.com/platform/forge/manifest-reference/modules/trigger/
44
# trigger:
5-
# - key: app-lifecycle-trigger
6-
# function: lifecycleHandler
5+
# - key: issue-trigger
6+
# function: webhook
7+
# # https://developer.atlassian.com/platform/forge/events-reference/jira/#issue-events
78
# events:
8-
# - installed # https://developer.atlassian.com/platform/forge/events-reference/life-cycle/
9-
# - uninstalled
9+
# - avi:jira:created:issue
10+
# - avi:jira:updated:issue
11+
# filter:
12+
# ignoreSelf: true # Prevents infinite loops by ignoring self-generated events
13+
# # expression: event.issue.fields.issuetype.name == 'Bug' # Optional: example filter for bug issues only
14+
# onError: IGNORE_AND_LOG # Will invoke function and log errors
1015

1116
# The jira module provides functionality for Jira products.
1217
jira:issuePanel:
@@ -22,6 +27,8 @@ modules:
2227
function:
2328
- key: resolver
2429
handler: index.handler
30+
# - key: webhook
31+
# handler: webhook.handler
2532

2633
resources:
2734
- key: main
@@ -33,6 +40,7 @@ app:
3340

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

4656
# https://developer.atlassian.com/platform/forge/manifest-reference/variables/
4757
environment:
4858
variables:
4959
- SUPABASE_URL
5060
- SUPABASE_API_KEY
61+
- GITAUTO_URL

‎src/frontend/index.jsx

+28-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useEffect, useState } from "react";
22
import { invoke } from "@forge/bridge";
3-
import ForgeReconciler, { Select, Text, useProductContext } from "@forge/react";
3+
import ForgeReconciler, { Select, Text, useProductContext, Checkbox, Stack } from "@forge/react";
44

55
const App = () => {
66
// Get Jira cloud ID (== workspace ID)
@@ -75,8 +75,26 @@ const App = () => {
7575
}
7676
};
7777

78+
// Handle checkbox
79+
const [isChecked, setIsChecked] = useState(false);
80+
const [isTriggering, setIsTriggering] = useState(false);
81+
const handleCheckboxChange = async (event) => {
82+
const checked = event.target.checked;
83+
setIsChecked(checked);
84+
if (!checked || !selectedRepo) return;
85+
setIsTriggering(true);
86+
try {
87+
await invoke("triggerGitAuto", { cloudId, projectId, issueId, selectedRepo });
88+
} catch (error) {
89+
console.error("Error triggering GitAuto:", error);
90+
} finally {
91+
setIsTriggering(false);
92+
}
93+
};
94+
7895
return (
79-
<>
96+
// https://developer.atlassian.com/platform/forge/ui-kit-2/stack/
97+
<Stack space="space.075">
8098
<Text>Target GitHub Repository:</Text>
8199
<Select
82100
value={selectedRepo}
@@ -85,7 +103,14 @@ const App = () => {
85103
isDisabled={isLoading}
86104
placeholder="Select a repository"
87105
/>
88-
</>
106+
<Checkbox
107+
label="Trigger GitAuto to open a pull request"
108+
onChange={handleCheckboxChange}
109+
value={isChecked}
110+
isDisabled={!selectedRepo || isTriggering}
111+
/>
112+
{isTriggering && <Text>Triggering GitAuto...</Text>}
113+
</Stack>
89114
);
90115
};
91116

‎src/resolvers/index.js

+22
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,26 @@ resolver.define("storeRepo", async ({ payload }) => {
5151
return await storage.set(key, value);
5252
});
5353

54+
resolver.define("triggerGitAuto", async ({ payload }) => {
55+
const { cloudId, projectId, issueId, selectedRepo } = payload;
56+
57+
// Determine the API endpoint based on environment
58+
const endpoint = process.env.GITAUTO_URL + "/webhook";
59+
console.log("Endpoint", endpoint);
60+
const response = await forge.fetch(endpoint, {
61+
method: "POST",
62+
headers: { "Content-Type": "application/json" },
63+
body: JSON.stringify({
64+
cloudId,
65+
projectId,
66+
issueId,
67+
repository: selectedRepo,
68+
}),
69+
});
70+
71+
if (!response.ok) throw new Error(`Failed to trigger GitAuto: ${response.status}`);
72+
73+
return await response.json();
74+
});
75+
5476
export const handler = resolver.getDefinitions();

0 commit comments

Comments
 (0)
Please sign in to comment.