UNPKG

@roadiehq/backstage-plugin-bitbucket-pullrequest

Version:

42 lines (39 loc) 1.19 kB
import fetch from 'cross-fetch'; import { createApiRef } from '@backstage/core-plugin-api'; const bitbucketApiRef = createApiRef({ id: "plugin.bitbucket.service" }); const DEFAULT_PROXY_PATH = "/bitbucket/api"; class BitbucketApi { discoveryApi; constructor(options) { this.discoveryApi = options.discoveryApi; } async fetchPullRequestList(project, repo, state) { const proxyUrl = await this.discoveryApi.getBaseUrl("proxy"); const response = await fetch( `${proxyUrl}${DEFAULT_PROXY_PATH}/projects/${project}/repos/${repo}/pull-requests?state=${state || ""}`, { headers: { "Content-Type": "application/json" } } ); if (!response.ok) { throw new Error("Failed to fetch pull requests"); } const data = await response.json(); return data.values.map((pr) => ({ id: pr.id, title: pr.title, author: pr.author.user.name, created_on: pr.createdDate, updated_on: pr.updatedDate, state: pr.state, url: pr.links.self[0].href, description: pr.description })); } } export { BitbucketApi, bitbucketApiRef }; //# sourceMappingURL=BitbucketApi.esm.js.map