paperclip-github-plugin 0.7.4 → 0.7.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/manifest.js CHANGED
@@ -520,7 +520,7 @@ var COMPANY_METRIC_API_ROUTE_URL_PATH = `/api/plugins/${GITHUB_SYNC_PLUGIN_ID}/a
520
520
  var require2 = createRequire(import.meta.url);
521
521
  var packageJson = require2("../package.json");
522
522
  var SCHEDULE_TICK_CRON = "* * * * *";
523
- var MANIFEST_VERSION = "0.7.4"?.trim() || typeof packageJson.version === "string" && packageJson.version.trim() || process.env.npm_package_version?.trim() || "0.0.0-dev";
523
+ var MANIFEST_VERSION = "0.7.5"?.trim() || typeof packageJson.version === "string" && packageJson.version.trim() || process.env.npm_package_version?.trim() || "0.0.0-dev";
524
524
  var manifest = {
525
525
  id: GITHUB_SYNC_PLUGIN_ID,
526
526
  apiVersion: 1,
package/dist/worker.js CHANGED
@@ -2304,6 +2304,18 @@ async function resolvePaperclipIssueGitHubLink(ctx, issueId, companyId, options
2304
2304
  };
2305
2305
  return await hydrateRecoveredPaperclipIssueGitHubLink(ctx, issueId, fallbackLink) ?? fallbackLink;
2306
2306
  }
2307
+ async function resolvePaperclipIssueGitHubPullRequestLink(ctx, issueId, companyId) {
2308
+ const links = await listGitHubPullRequestLinkRecords(ctx, {
2309
+ paperclipIssueId: issueId
2310
+ });
2311
+ return links.filter((record) => !record.data.companyId || record.data.companyId === companyId).sort((left, right) => {
2312
+ const rightTimestamp = Date.parse(right.updatedAt ?? right.createdAt ?? "");
2313
+ const leftTimestamp = Date.parse(left.updatedAt ?? left.createdAt ?? "");
2314
+ const safeRightTimestamp = Number.isFinite(rightTimestamp) ? rightTimestamp : 0;
2315
+ const safeLeftTimestamp = Number.isFinite(leftTimestamp) ? leftTimestamp : 0;
2316
+ return safeRightTimestamp - safeLeftTimestamp;
2317
+ })[0] ?? null;
2318
+ }
2307
2319
  async function hydrateRecoveredPaperclipIssueGitHubLink(ctx, issueId, fallbackLink) {
2308
2320
  const repository = parseRepositoryReference(fallbackLink.repositoryUrl);
2309
2321
  if (!repository) {
@@ -2379,21 +2391,33 @@ async function resolveManualSyncTarget(ctx, settings, input) {
2379
2391
  }
2380
2392
  const link = await resolvePaperclipIssueGitHubLink(ctx, input.issueId, companyId2);
2381
2393
  if (!link) {
2382
- throw new Error("This Paperclip issue is not linked to a GitHub issue yet. Run a broader sync first.");
2383
- }
2384
- const candidateMappings = getSyncableMappingsForTarget(settings.mappings, {
2385
- kind: "issue",
2386
- companyId: companyId2,
2387
- projectId: link.paperclipProjectId,
2388
- repositoryUrl: link.repositoryUrl,
2389
- issueId: input.issueId,
2390
- githubIssueId: link.githubIssueId,
2391
- githubIssueNumber: link.githubIssueNumber,
2392
- githubIssueUrl: link.githubIssueUrl,
2393
- displayLabel: `issue #${link.githubIssueNumber}`
2394
- });
2395
- if (candidateMappings.length === 0) {
2396
- throw new Error("No saved GitHub repository mapping matches this Paperclip issue.");
2394
+ const pullRequestLink = await resolvePaperclipIssueGitHubPullRequestLink(ctx, input.issueId, companyId2);
2395
+ if (!pullRequestLink) {
2396
+ throw new Error("This Paperclip issue is not linked to a GitHub issue or pull request yet. Run a broader sync first.");
2397
+ }
2398
+ const candidateMappings = getSyncableMappingsForTarget(settings.mappings, {
2399
+ kind: "issue",
2400
+ companyId: companyId2,
2401
+ projectId: pullRequestLink.data.paperclipProjectId,
2402
+ repositoryUrl: pullRequestLink.data.repositoryUrl,
2403
+ issueId: input.issueId,
2404
+ githubPullRequestNumber: pullRequestLink.data.githubPullRequestNumber,
2405
+ githubPullRequestUrl: pullRequestLink.data.githubPullRequestUrl,
2406
+ displayLabel: `pull request #${pullRequestLink.data.githubPullRequestNumber}`
2407
+ });
2408
+ if (candidateMappings.length === 0) {
2409
+ throw new Error("No saved GitHub repository mapping matches this Paperclip issue.");
2410
+ }
2411
+ return {
2412
+ kind: "issue",
2413
+ companyId: companyId2,
2414
+ projectId: pullRequestLink.data.paperclipProjectId,
2415
+ issueId: input.issueId,
2416
+ repositoryUrl: pullRequestLink.data.repositoryUrl,
2417
+ githubPullRequestNumber: pullRequestLink.data.githubPullRequestNumber,
2418
+ githubPullRequestUrl: pullRequestLink.data.githubPullRequestUrl,
2419
+ displayLabel: `pull request #${pullRequestLink.data.githubPullRequestNumber}`
2420
+ };
2397
2421
  }
2398
2422
  return {
2399
2423
  kind: "issue",
@@ -2517,23 +2541,46 @@ async function buildToolbarSyncState(ctx, input) {
2517
2541
  }
2518
2542
  if (entityType === "issue" && entityId && companyId) {
2519
2543
  const link = await resolvePaperclipIssueGitHubLink(ctx, entityId, companyId);
2520
- const mappings = link ? getSyncableMappingsForTarget(settings.mappings, {
2544
+ if (link) {
2545
+ const mappings2 = getSyncableMappingsForTarget(settings.mappings, {
2546
+ kind: "issue",
2547
+ companyId,
2548
+ projectId: link.paperclipProjectId,
2549
+ issueId: entityId,
2550
+ repositoryUrl: link.repositoryUrl,
2551
+ githubIssueId: link.githubIssueId,
2552
+ githubIssueNumber: link.githubIssueNumber,
2553
+ githubIssueUrl: link.githubIssueUrl,
2554
+ displayLabel: `issue #${link.githubIssueNumber}`
2555
+ });
2556
+ return {
2557
+ kind: "issue",
2558
+ visible: false,
2559
+ canRun: githubTokenConfigured && mappings2.length > 0,
2560
+ label: `Sync #${link.githubIssueNumber}`,
2561
+ message: `Sync ${link.repositoryUrl.replace(/^https:\/\/github\.com\//, "")} issue #${link.githubIssueNumber}.`,
2562
+ syncState: settings.syncState,
2563
+ githubTokenConfigured,
2564
+ savedMappingCount
2565
+ };
2566
+ }
2567
+ const pullRequestLink = await resolvePaperclipIssueGitHubPullRequestLink(ctx, entityId, companyId);
2568
+ const mappings = pullRequestLink ? getSyncableMappingsForTarget(settings.mappings, {
2521
2569
  kind: "issue",
2522
2570
  companyId,
2523
- projectId: link.paperclipProjectId,
2571
+ projectId: pullRequestLink.data.paperclipProjectId,
2524
2572
  issueId: entityId,
2525
- repositoryUrl: link.repositoryUrl,
2526
- githubIssueId: link.githubIssueId,
2527
- githubIssueNumber: link.githubIssueNumber,
2528
- githubIssueUrl: link.githubIssueUrl,
2529
- displayLabel: `issue #${link.githubIssueNumber}`
2573
+ repositoryUrl: pullRequestLink.data.repositoryUrl,
2574
+ githubPullRequestNumber: pullRequestLink.data.githubPullRequestNumber,
2575
+ githubPullRequestUrl: pullRequestLink.data.githubPullRequestUrl,
2576
+ displayLabel: `pull request #${pullRequestLink.data.githubPullRequestNumber}`
2530
2577
  }) : [];
2531
2578
  return {
2532
2579
  kind: "issue",
2533
2580
  visible: false,
2534
2581
  canRun: githubTokenConfigured && mappings.length > 0,
2535
- label: link?.githubIssueNumber ? `Sync #${link.githubIssueNumber}` : "Sync issue",
2536
- message: link ? `Sync ${link.repositoryUrl.replace(/^https:\/\/github\.com\//, "")} issue #${link.githubIssueNumber}.` : "This Paperclip issue is not linked to GitHub yet.",
2582
+ label: pullRequestLink?.data.githubPullRequestNumber ? `Sync PR #${pullRequestLink.data.githubPullRequestNumber}` : "Sync issue",
2583
+ message: pullRequestLink ? `Sync ${pullRequestLink.data.repositoryUrl.replace(/^https:\/\/github\.com\//, "")} pull request #${pullRequestLink.data.githubPullRequestNumber}.` : "This Paperclip issue is not linked to GitHub yet.",
2537
2584
  syncState: settings.syncState,
2538
2585
  githubTokenConfigured,
2539
2586
  savedMappingCount
@@ -8040,6 +8087,40 @@ async function listRepositoryIssues(octokit, repository, state = "open", options
8040
8087
  }
8041
8088
  return normalizedIssues;
8042
8089
  }
8090
+ async function listRepositoryIssuesForSyncTarget(octokit, repository, state, target, options = {}) {
8091
+ if (target?.kind !== "issue") {
8092
+ return listRepositoryIssues(octokit, repository, state, options);
8093
+ }
8094
+ if (target.githubIssueNumber === void 0) {
8095
+ if (options.onProgress) {
8096
+ await options.onProgress({
8097
+ loadedIssueCount: 0
8098
+ });
8099
+ }
8100
+ return [];
8101
+ }
8102
+ const response = await octokit.rest.issues.get({
8103
+ owner: repository.owner,
8104
+ repo: repository.repo,
8105
+ issue_number: target.githubIssueNumber,
8106
+ headers: {
8107
+ accept: "application/vnd.github+json",
8108
+ "X-GitHub-Api-Version": GITHUB_API_VERSION
8109
+ }
8110
+ });
8111
+ const issue = response.data;
8112
+ if ("pull_request" in issue) {
8113
+ return [];
8114
+ }
8115
+ const normalizedIssue = normalizeGitHubIssueRecord(issue);
8116
+ const issues = state === "open" && normalizedIssue.state !== "open" ? [] : [normalizedIssue];
8117
+ if (options.onProgress) {
8118
+ await options.onProgress({
8119
+ loadedIssueCount: issues.length
8120
+ });
8121
+ }
8122
+ return issues;
8123
+ }
8043
8124
  async function listRepositoryIssuesForImport(allIssues) {
8044
8125
  return sortIssuesForImport(allIssues.filter((issue) => issue.state === "open"));
8045
8126
  }
@@ -12301,10 +12382,11 @@ async function performSync(ctx, trigger, options = {}) {
12301
12382
  updateSyncFailureContext(failureContext, {
12302
12383
  phase: "listing_github_issues"
12303
12384
  });
12304
- const allIssues = await listRepositoryIssues(
12385
+ const allIssues = await listRepositoryIssuesForSyncTarget(
12305
12386
  octokit,
12306
12387
  repository,
12307
12388
  shouldLoadClosedIssues ? "all" : "open",
12389
+ options.target,
12308
12390
  {
12309
12391
  onProgress: async (progress) => {
12310
12392
  currentProgress = {
@@ -12427,7 +12509,7 @@ async function performSync(ctx, trigger, options = {}) {
12427
12509
  };
12428
12510
  await persistRunningProgress(true);
12429
12511
  try {
12430
- const warmedLinkedPullRequests = await loadLinkedPullRequestsForOpenIssues(octokit, repository);
12512
+ const warmedLinkedPullRequests = options.target?.kind === "issue" ? /* @__PURE__ */ new Map() : await loadLinkedPullRequestsForOpenIssues(octokit, repository);
12431
12513
  for (const [issueNumber, linkedPullRequests] of warmedLinkedPullRequests.entries()) {
12432
12514
  linkedPullRequestsByIssueNumber.set(issueNumber, linkedPullRequests);
12433
12515
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "paperclip-github-plugin",
3
- "version": "0.7.4",
3
+ "version": "0.7.5",
4
4
  "description": "Paperclip plugin for synchronizing GitHub issues into Paperclip projects.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",