"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadRelatedPullRequest = loadRelatedPullRequest;
const types_1 = require("../platform/ticket-tracker/types");
const default_issue_workspace_manager_1 = require("../workspaces/default-issue-workspace-manager");
async function loadRelatedPullRequest(clients, issue, options = {}) {
    if (options.includePullRequestTarget === true &&
        issue.kind === types_1.TRACKER_ITEM_KINDS.pullRequest &&
        issue.pullRequestNumber !== undefined) {
        return clients.repositoryHost.getPullRequest(issue.pullRequestNumber);
    }
    if (issue.kind !== types_1.TRACKER_ITEM_KINDS.issue) {
        return null;
    }
    return clients.repositoryHost.findPullRequestByBranch((0, default_issue_workspace_manager_1.resolveIssueBranchName)(clients.config.branchPrefix, issue));
}
