I am trying to fetch the open PR for a repo and render them as a dropdown in my forge app.
The API to fetch the repo details works fine but the repo to fetch the open PR’s gives me a 403 and specifically a REQUEST_EGRESS_ALLOWLIST_ERR
My JSX and Manifest.yaml looks something like this :
import ForgeUI, {
render,
Fragment,
Text,
useState,
Select,
Option,
Form,
useProductContext
} from "@forge/ui";
import api, { route } from "@forge/api";
import PrModal from "./modal";
const fetchRepository = async (workspaceId, repositoryId) => {
const res = await api
.asApp()
.requestBitbucket(route`/2.0/repositories/${workspaceId}/${repositoryId}`);
const data = await res.json();
return data;
};
const App = () => {
const [formState, setFormState] = useState(undefined);
const [modalState, setModalState] = useState(false);
const [status,setStatus]=useState("Init")
const context = useProductContext();
const [repository] = useState(
async () =>
await fetchRepository(
context.workspaceId,
context.extensionContext.repository.uuid
)
);
const fetchData = async () => {
try {
const workspace = "aristo42";
const repoSlug = "javascript-node-repo";
setStatus("Pre fetch for ")
const response = await api.asApp().requestBitbucket(route`/2.0/repositories/${workspace}/${repoSlug}/pullrequests`);
setStatus("Post fetch")
if (response.status === 200) {
setStatus("200")
const data = await response.json();
const extractedData = data.values.slice(0, 15).map((pr) => {
return {
id: pr.id,
title: pr.title,
description: pr.description,
};
});
return extractedData
} else {
console.log("Failed to fetch data as "+response.status);
}
} catch (error) {
console.error("Error fetching PRs:", error);
}
};
const [prList, setPrList] = useState(async () => await fetchData()); // State for PR list
const onSubmit = async (formData) => {
setModalState(false);
setFormState(formData);
setModalState(true);
};
return (
<Fragment>
<Text>Hello, I am Aristo!</Text>
<Text>{repository.full_name}</Text>
<Text>{status}</Text>
<Text>Please choose a PR request that you want me to review!</Text>
<Form onSubmit={onSubmit}>
{prList &&
<Select label="Select a PR" name="PrListDropdown">
{prList.map((pr) => (
<Option
key={pr.id.toString()} // Set a unique identifier as the key
label={pr.title}
value={pr.id.toString()} // Set a unique identifier as the value
/>
))}
</Select>
}
</Form>
{modalState && <PrModal modal={modalState} pr={formState} />}
</Fragment>
);
};
export const run = render(<App />);
Manifest file :
modules:
'bitbucket:repoCodeOverviewCard':
- key: hello-world-app-hello-world-panel
function: main
title: Forge app for Aristo
function:
- key: main
handler: index.run
permissions:
scopes:
- "write:repository:bitbucket"
- "read:pullrequest:bitbucket"
- "write:pullrequest:bitbucket"
app:
id: ari:cloud:ecosystem::app/993ad354-6f8d-4a84-8400-ae4f390c7d27
This is what I see in the logs :
Error fetching PRs: { “message”: “URL not allowed: /2.0/repositories/aristo42/javascript-node-repo/pullrequests.”, “name”: “REQUEST_EGRESS_ALLOWLIST_ERR”, “status”: 403 }