paperclip-github-plugin 0.17.4 → 0.17.6

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/README.md CHANGED
@@ -278,6 +278,8 @@ The plugin exposes GitHub workflow tools to Paperclip agents, including:
278
278
 
279
279
  Branch publication uses an isolated temporary bare repository backed by the selected trusted-workspace checkout's object database. It does not execute repository hooks, accept arbitrary refspecs, or honor repository-local remotes. An optional checkout path must resolve inside the issue execution workspace, while the selected target repository must be a canonical GitHub `owner/repo` reference. Publication rejects owner-qualified heads, base-branch targets, non-fast-forward updates, cross-project issues, mismatched local branch tips, and remote SHA mismatches.
280
280
 
281
+ Optional `labels`, `userReviewers`, and `teamReviewers` are applied right after the pull request exists (for example the approved `type:` label and the linked issue author as reviewer). Those follow-up calls never undo the pull request: their outcome is reported in the result as `labels`, `requestedReviewers`, `requestedTeams`, or `warnings`. The tool also appends the new pull request to the issue's GitHub link record immediately, so the Paperclip issue card shows the linked pull request without waiting for the next sync. `update_pull_request` accepts a replacement `labels` set, and `get_issue` returns the issue `author`, all `participants` (author and distinct commenters with their repository association), and `reviewerCandidates` (non-bot owners, members, and collaborators among them) so agents can request the reporter and the maintainers who joined the discussion as reviewers.
282
+
281
283
  The call is ordered and retry-safe rather than a cross-system transaction: a published branch may remain if GitHub PR creation or Paperclip link persistence fails. On retry, the tool re-verifies and republishes the exact SHA, then recovers an already-open PR only when repository, head, base, and head SHA all match before repairing the link and metric. It never deletes a branch or closes a PR as automatic compensation.
282
284
 
283
285
  After that durable link is written, pull-request tools can use the same `paperclipIssueId` to read or update the PR immediately, even when the Paperclip issue was created natively and has no linked GitHub issue. If one Paperclip issue has same-number PRs in different repositories, the caller must also supply the repository so the worker can reject ambiguous or unlinked selections.
package/dist/manifest.js CHANGED
@@ -123,7 +123,7 @@ var GITHUB_AGENT_TOOLS = [
123
123
  {
124
124
  name: "get_issue",
125
125
  displayName: "Get Issue",
126
- description: "Read one GitHub issue with its metadata, assignees, labels, milestone, and linked pull requests.",
126
+ description: "Read one GitHub issue with its metadata, author, participants (author plus distinct commenters with their repository association), reviewerCandidates (non-bot owners, members, and collaborators among them, for pull request reviewer routing), assignees, labels, milestone, and linked pull requests.",
127
127
  parametersSchema: {
128
128
  type: "object",
129
129
  additionalProperties: false,
@@ -268,7 +268,7 @@ var GITHUB_AGENT_TOOLS = [
268
268
  {
269
269
  name: "create_pull_request",
270
270
  displayName: "Create Pull Request",
271
- description: "Publish the local branch at the exact requested commit, verify the remote branch, then create and link a GitHub pull request in one operation. The GitHub credential remains inside the trusted plugin worker. When a non-empty body is provided, the plugin appends an AI-authorship footer and includes llmModel when supplied.",
271
+ description: "Publish the local branch at the exact requested commit, verify the remote branch, then create and link a GitHub pull request in one operation. Optional labels and reviewer requests are applied right after creation and reported back; a failure in those follow-up steps does not undo the pull request. The GitHub credential remains inside the trusted plugin worker. When a non-empty body is provided, the plugin appends an AI-authorship footer and includes llmModel when supplied.",
272
272
  parametersSchema: {
273
273
  type: "object",
274
274
  additionalProperties: false,
@@ -310,6 +310,27 @@ var GITHUB_AGENT_TOOLS = [
310
310
  llmModel: llmModelProperty,
311
311
  draft: {
312
312
  type: "boolean"
313
+ },
314
+ labels: {
315
+ type: "array",
316
+ items: {
317
+ type: "string"
318
+ },
319
+ description: "Optional GitHub labels to add to the new pull request, for example the approved `type:` label. Labels are applied after the pull request is created; failures are returned as warnings."
320
+ },
321
+ userReviewers: {
322
+ type: "array",
323
+ items: {
324
+ type: "string"
325
+ },
326
+ description: "Optional GitHub user logins to request as reviewers right after creation, for example the linked issue author when they are not the pull request author. Failures are returned as warnings."
327
+ },
328
+ teamReviewers: {
329
+ type: "array",
330
+ items: {
331
+ type: "string"
332
+ },
333
+ description: "Optional GitHub team slugs to request as reviewers right after creation. Failures are returned as warnings."
313
334
  }
314
335
  }
315
336
  }
@@ -332,7 +353,7 @@ var GITHUB_AGENT_TOOLS = [
332
353
  {
333
354
  name: "update_pull_request",
334
355
  displayName: "Update Pull Request",
335
- description: "Edit pull request title, body, base branch, open or close it, or convert between draft and ready for review. When a non-empty body is provided, the plugin appends an AI-authorship footer and includes llmModel when supplied.",
356
+ description: "Edit pull request title, body, base branch, labels, open or close it, or convert between draft and ready for review. When a non-empty body is provided, the plugin appends an AI-authorship footer and includes llmModel when supplied.",
336
357
  parametersSchema: {
337
358
  type: "object",
338
359
  additionalProperties: false,
@@ -359,6 +380,13 @@ var GITHUB_AGENT_TOOLS = [
359
380
  isDraft: {
360
381
  type: "boolean",
361
382
  description: "True converts the pull request to draft. False marks it ready for review."
383
+ },
384
+ labels: {
385
+ type: "array",
386
+ items: {
387
+ type: "string"
388
+ },
389
+ description: "Optional replacement label set for the pull request. When provided, the pull request ends up with exactly these labels."
362
390
  }
363
391
  }
364
392
  }
@@ -691,7 +719,7 @@ var COMPANY_METRIC_API_ROUTE_URL_PATH = `/api/plugins/${GITHUB_SYNC_PLUGIN_ID}/a
691
719
  var require2 = createRequire(import.meta.url);
692
720
  var packageJson = require2("../package.json");
693
721
  var SCHEDULE_TICK_CRON = "* * * * *";
694
- var MANIFEST_VERSION = "0.17.4"?.trim() || typeof packageJson.version === "string" && packageJson.version.trim() || process.env.npm_package_version?.trim() || "0.0.0-dev";
722
+ var MANIFEST_VERSION = "0.17.6"?.trim() || typeof packageJson.version === "string" && packageJson.version.trim() || process.env.npm_package_version?.trim() || "0.0.0-dev";
695
723
  var COMPANY_SECRET_REF_VALUE_SCHEMA = {
696
724
  anyOf: [
697
725
  { type: "string" },
package/dist/worker.js CHANGED
@@ -134,7 +134,7 @@ var GITHUB_AGENT_TOOLS = [
134
134
  {
135
135
  name: "get_issue",
136
136
  displayName: "Get Issue",
137
- description: "Read one GitHub issue with its metadata, assignees, labels, milestone, and linked pull requests.",
137
+ description: "Read one GitHub issue with its metadata, author, participants (author plus distinct commenters with their repository association), reviewerCandidates (non-bot owners, members, and collaborators among them, for pull request reviewer routing), assignees, labels, milestone, and linked pull requests.",
138
138
  parametersSchema: {
139
139
  type: "object",
140
140
  additionalProperties: false,
@@ -279,7 +279,7 @@ var GITHUB_AGENT_TOOLS = [
279
279
  {
280
280
  name: "create_pull_request",
281
281
  displayName: "Create Pull Request",
282
- description: "Publish the local branch at the exact requested commit, verify the remote branch, then create and link a GitHub pull request in one operation. The GitHub credential remains inside the trusted plugin worker. When a non-empty body is provided, the plugin appends an AI-authorship footer and includes llmModel when supplied.",
282
+ description: "Publish the local branch at the exact requested commit, verify the remote branch, then create and link a GitHub pull request in one operation. Optional labels and reviewer requests are applied right after creation and reported back; a failure in those follow-up steps does not undo the pull request. The GitHub credential remains inside the trusted plugin worker. When a non-empty body is provided, the plugin appends an AI-authorship footer and includes llmModel when supplied.",
283
283
  parametersSchema: {
284
284
  type: "object",
285
285
  additionalProperties: false,
@@ -321,6 +321,27 @@ var GITHUB_AGENT_TOOLS = [
321
321
  llmModel: llmModelProperty,
322
322
  draft: {
323
323
  type: "boolean"
324
+ },
325
+ labels: {
326
+ type: "array",
327
+ items: {
328
+ type: "string"
329
+ },
330
+ description: "Optional GitHub labels to add to the new pull request, for example the approved `type:` label. Labels are applied after the pull request is created; failures are returned as warnings."
331
+ },
332
+ userReviewers: {
333
+ type: "array",
334
+ items: {
335
+ type: "string"
336
+ },
337
+ description: "Optional GitHub user logins to request as reviewers right after creation, for example the linked issue author when they are not the pull request author. Failures are returned as warnings."
338
+ },
339
+ teamReviewers: {
340
+ type: "array",
341
+ items: {
342
+ type: "string"
343
+ },
344
+ description: "Optional GitHub team slugs to request as reviewers right after creation. Failures are returned as warnings."
324
345
  }
325
346
  }
326
347
  }
@@ -343,7 +364,7 @@ var GITHUB_AGENT_TOOLS = [
343
364
  {
344
365
  name: "update_pull_request",
345
366
  displayName: "Update Pull Request",
346
- description: "Edit pull request title, body, base branch, open or close it, or convert between draft and ready for review. When a non-empty body is provided, the plugin appends an AI-authorship footer and includes llmModel when supplied.",
367
+ description: "Edit pull request title, body, base branch, labels, open or close it, or convert between draft and ready for review. When a non-empty body is provided, the plugin appends an AI-authorship footer and includes llmModel when supplied.",
347
368
  parametersSchema: {
348
369
  type: "object",
349
370
  additionalProperties: false,
@@ -370,6 +391,13 @@ var GITHUB_AGENT_TOOLS = [
370
391
  isDraft: {
371
392
  type: "boolean",
372
393
  description: "True converts the pull request to draft. False marks it ready for review."
394
+ },
395
+ labels: {
396
+ type: "array",
397
+ items: {
398
+ type: "string"
399
+ },
400
+ description: "Optional replacement label set for the pull request. When provided, the pull request ends up with exactly these labels."
373
401
  }
374
402
  }
375
403
  }
@@ -5778,6 +5806,7 @@ function normalizeGitHubIssueRecord(issue) {
5778
5806
  ...authorUrl ? { authorUrl } : {},
5779
5807
  ...authorAvatarUrl ? { authorAvatarUrl } : {},
5780
5808
  ...normalizeGitHubLowercaseString(issue.author_association) ? { authorAssociation: normalizeGitHubLowercaseString(issue.author_association) } : {},
5809
+ ...issue.user?.type === "Bot" ? { authorIsBot: true } : {},
5781
5810
  labels: normalizeGitHubIssueLabels(issue.labels),
5782
5811
  state: issue.state === "closed" ? "closed" : "open",
5783
5812
  stateReason: normalizeGitHubIssueStateReason(issue.state_reason),
@@ -8560,15 +8589,18 @@ function buildGitHubIssueLinkRecord(target, issueId, githubIssue, linkedPullRequ
8560
8589
  }
8561
8590
  async function upsertGitHubIssueLinkRecord(ctx, target, issueId, githubIssue, linkedPullRequests) {
8562
8591
  const record = buildGitHubIssueLinkRecord(target, issueId, githubIssue, linkedPullRequests);
8563
- await ctx.entities.upsert({
8564
- entityType: ISSUE_LINK_ENTITY_TYPE,
8565
- scopeKind: "issue",
8566
- scopeId: issueId,
8567
- externalId: record.data.githubIssueUrl,
8568
- ...record.title ? { title: record.title } : {},
8569
- ...record.status ? { status: record.status } : {},
8570
- data: record.data
8571
- });
8592
+ await withPullRequestLinkMutationLock(
8593
+ issueLinkMutationLockKey(target.companyId, issueId),
8594
+ () => ctx.entities.upsert({
8595
+ entityType: ISSUE_LINK_ENTITY_TYPE,
8596
+ scopeKind: "issue",
8597
+ scopeId: issueId,
8598
+ externalId: record.data.githubIssueUrl,
8599
+ ...record.title ? { title: record.title } : {},
8600
+ ...record.status ? { status: record.status } : {},
8601
+ data: record.data
8602
+ })
8603
+ );
8572
8604
  }
8573
8605
  var pullRequestLinkMutationTails = /* @__PURE__ */ new Map();
8574
8606
  async function withPullRequestLinkMutationLock(key, mutation) {
@@ -8589,6 +8621,48 @@ async function withPullRequestLinkMutationLock(key, mutation) {
8589
8621
  }
8590
8622
  }
8591
8623
  }
8624
+ async function appendPullRequestToGitHubIssueLinkRecords(ctx, input) {
8625
+ return withPullRequestLinkMutationLock(issueLinkMutationLockKey(input.companyId, input.issueId), async () => {
8626
+ const repositoryUrl = parseRepositoryReference(input.repositoryUrl)?.url ?? input.repositoryUrl.trim();
8627
+ const records = await listGitHubIssueLinkRecords(ctx, { paperclipIssueId: input.issueId });
8628
+ let changed = false;
8629
+ for (const record of records) {
8630
+ if (record.data.companyId && record.data.companyId !== input.companyId) {
8631
+ continue;
8632
+ }
8633
+ const alreadyLinked = record.data.linkedPullRequests.some(
8634
+ (pullRequest) => pullRequest.number === input.pullRequestNumber && (parseRepositoryReference(pullRequest.repositoryUrl)?.url ?? pullRequest.repositoryUrl) === repositoryUrl
8635
+ );
8636
+ if (alreadyLinked) {
8637
+ continue;
8638
+ }
8639
+ const linkedPullRequests = normalizeLinkedPullRequestReferences(
8640
+ [...record.data.linkedPullRequests, { number: input.pullRequestNumber, repositoryUrl }],
8641
+ record.data.repositoryUrl
8642
+ );
8643
+ await ctx.entities.upsert({
8644
+ entityType: ISSUE_LINK_ENTITY_TYPE,
8645
+ scopeKind: "issue",
8646
+ scopeId: input.issueId,
8647
+ externalId: record.data.githubIssueUrl,
8648
+ ...record.title ? { title: record.title } : {},
8649
+ ...record.status ? { status: record.status } : {},
8650
+ data: {
8651
+ ...record.data,
8652
+ linkedPullRequestNumbers: normalizeLinkedPullRequestNumbers(
8653
+ linkedPullRequests.map((pullRequest) => pullRequest.number)
8654
+ ),
8655
+ linkedPullRequests
8656
+ }
8657
+ });
8658
+ changed = true;
8659
+ }
8660
+ return changed;
8661
+ });
8662
+ }
8663
+ function issueLinkMutationLockKey(companyId, issueId) {
8664
+ return `issue-link:${companyId ?? ""}:${issueId}`;
8665
+ }
8592
8666
  async function upsertGitHubPullRequestLinkRecord(ctx, params) {
8593
8667
  const repositoryUrl = getNormalizedMappingRepositoryUrl({ repositoryUrl: params.repositoryUrl });
8594
8668
  const referenceKey = buildGitHubPullRequestReferenceKey({
@@ -10074,6 +10148,21 @@ function isPaperclipIssuePatchApplied(params) {
10074
10148
  )) return false;
10075
10149
  return true;
10076
10150
  }
10151
+ function findSettledNoopAttempt(events, attemptPrefix) {
10152
+ const resultSuffix = ":result:noop";
10153
+ const settled = events.filter((candidate) => {
10154
+ if (!candidate.dedupeKey.startsWith(attemptPrefix)) return false;
10155
+ return /^[^:]+:result:noop$/.test(candidate.dedupeKey.slice(attemptPrefix.length));
10156
+ }).sort(
10157
+ (left, right) => right.occurredAt.localeCompare(left.occurredAt) || right.dedupeKey.localeCompare(left.dedupeKey)
10158
+ );
10159
+ for (const event of settled) {
10160
+ const dedupeBase = event.dedupeKey.slice(0, -resultSuffix.length);
10161
+ const intent = events.find((candidate) => candidate.dedupeKey === `${dedupeBase}:intent`);
10162
+ if (intent) return { dedupeBase, occurredAt: intent.occurredAt };
10163
+ }
10164
+ return void 0;
10165
+ }
10077
10166
  async function updatePaperclipIssueState(ctx, params) {
10078
10167
  const {
10079
10168
  companyId,
@@ -10198,8 +10287,15 @@ async function updatePaperclipIssueState(ctx, params) {
10198
10287
  reconciliationAttemptId = interactionDedupeBase.slice(attemptPrefix.length);
10199
10288
  interactionOccurredAt = latestOpenAttemptIntent.occurredAt;
10200
10289
  } else {
10201
- reconciliationAttemptId = randomUUID();
10202
- interactionDedupeBase = `${attemptPrefix}${reconciliationAttemptId}`;
10290
+ const settledNoopAttempt = !statusWillChange && issuePatchAlreadyApplied ? findSettledNoopAttempt(existingInteractionEvents, attemptPrefix) : void 0;
10291
+ if (settledNoopAttempt) {
10292
+ interactionDedupeBase = settledNoopAttempt.dedupeBase;
10293
+ reconciliationAttemptId = interactionDedupeBase.slice(attemptPrefix.length);
10294
+ interactionOccurredAt = settledNoopAttempt.occurredAt;
10295
+ } else {
10296
+ reconciliationAttemptId = randomUUID();
10297
+ interactionDedupeBase = `${attemptPrefix}${reconciliationAttemptId}`;
10298
+ }
10203
10299
  }
10204
10300
  }
10205
10301
  const mutationPatchBase = `${mutationFamilyBase}${reconciliationAttemptId ? `:attempt:${reconciliationAttemptId}` : ""}:patch:${createHash("sha256").update(JSON.stringify(issuePatch)).digest("hex").slice(0, 32)}:applied:${mutationExpectedStateFingerprint}`;
@@ -13106,6 +13202,37 @@ function appendOptionalAiAuthorshipFooter(body, subject, llmModel) {
13106
13202
  }
13107
13203
  return `${trimmedBody}${formatAiAuthorshipFooter(subject, llmModel)}`;
13108
13204
  }
13205
+ var REVIEWER_CANDIDATE_ASSOCIATIONS = /* @__PURE__ */ new Set(["owner", "member", "collaborator"]);
13206
+ function buildGitHubIssueParticipants(issue, comments) {
13207
+ const participants = [];
13208
+ const seen = /* @__PURE__ */ new Set();
13209
+ if (issue.authorLogin) {
13210
+ participants.push({
13211
+ login: issue.authorLogin,
13212
+ role: "author",
13213
+ ...issue.authorAssociation ? { association: issue.authorAssociation } : {},
13214
+ isBot: issue.authorIsBot === true,
13215
+ ...issue.authorUrl ? { url: issue.authorUrl } : {}
13216
+ });
13217
+ seen.add(issue.authorLogin.toLowerCase());
13218
+ }
13219
+ for (const comment of comments) {
13220
+ const login = comment.authorLogin;
13221
+ if (!login || seen.has(login.toLowerCase())) {
13222
+ continue;
13223
+ }
13224
+ seen.add(login.toLowerCase());
13225
+ participants.push({
13226
+ login,
13227
+ role: "commenter",
13228
+ ...comment.authorAssociation ? { association: comment.authorAssociation } : {},
13229
+ isBot: comment.authorIsBot === true,
13230
+ ...comment.authorUrl ? { url: comment.authorUrl } : {}
13231
+ });
13232
+ }
13233
+ const reviewerCandidates = participants.filter((participant) => !participant.isBot && participant.association !== void 0 && REVIEWER_CANDIDATE_ASSOCIATIONS.has(participant.association)).map((participant) => participant.login);
13234
+ return { participants, reviewerCandidates };
13235
+ }
13109
13236
  async function listAllGitHubIssueComments(octokit, repository, issueNumber) {
13110
13237
  const comments = [];
13111
13238
  for await (const response of octokit.paginate.iterator(octokit.rest.issues.listComments, {
@@ -13124,6 +13251,7 @@ async function listAllGitHubIssueComments(octokit, repository, issueNumber) {
13124
13251
  url: comment.html_url ?? void 0,
13125
13252
  authorLogin: normalizeGitHubUserLogin(comment.user?.login),
13126
13253
  ...normalizeGitHubLowercaseString(comment.author_association) ? { authorAssociation: normalizeGitHubLowercaseString(comment.author_association) } : {},
13254
+ ...comment.user?.type === "Bot" ? { authorIsBot: true } : {},
13127
13255
  authorUrl: comment.user?.html_url ?? void 0,
13128
13256
  authorAvatarUrl: comment.user?.avatar_url ?? void 0,
13129
13257
  createdAt: comment.created_at ?? void 0,
@@ -17062,6 +17190,14 @@ function registerGitHubAgentTools(ctx) {
17062
17190
  });
17063
17191
  const issue = normalizeGitHubIssueRecord(response.data);
17064
17192
  const linkedPullRequests = await listLinkedPullRequestsForIssue(octokit, target.repository, target.issueNumber);
17193
+ let issueComments = [];
17194
+ let participantsWarning;
17195
+ try {
17196
+ issueComments = await listAllGitHubIssueComments(octokit, target.repository, target.issueNumber);
17197
+ } catch (error) {
17198
+ participantsWarning = `Issue comments could not be listed, so participants only include the author: ${getErrorMessage(error)}`;
17199
+ }
17200
+ const { participants, reviewerCandidates } = buildGitHubIssueParticipants(issue, issueComments);
17065
17201
  const assignees = (response.data.assignees ?? []).map((assignee) => assignee?.login ?? "").filter(Boolean);
17066
17202
  const milestone = response.data.milestone ? {
17067
17203
  number: response.data.milestone.number,
@@ -17082,6 +17218,15 @@ function registerGitHubAgentTools(ctx) {
17082
17218
  url: issue.htmlUrl,
17083
17219
  state: issue.state,
17084
17220
  stateReason: issue.stateReason,
17221
+ author: issue.authorLogin ? {
17222
+ login: issue.authorLogin,
17223
+ ...issue.authorUrl ? { url: issue.authorUrl } : {},
17224
+ ...issue.authorAssociation ? { association: issue.authorAssociation } : {},
17225
+ isBot: issue.authorIsBot === true
17226
+ } : null,
17227
+ participants,
17228
+ reviewerCandidates,
17229
+ ...participantsWarning ? { participantsWarning } : {},
17085
17230
  labels: issue.labels,
17086
17231
  assignees,
17087
17232
  milestone,
@@ -17442,6 +17587,7 @@ function registerGitHubAgentTools(ctx) {
17442
17587
  }
17443
17588
  pullRequestData = existingPullRequest;
17444
17589
  }
17590
+ const postCreationWarnings = [];
17445
17591
  let persistedFollowThroughAssigneeAgentId = followThroughAssigneeAgentId ?? void 0;
17446
17592
  let persistedFollowThroughAssigneeUpdatedAt;
17447
17593
  if (paperclipIssueId) {
@@ -17467,6 +17613,62 @@ function registerGitHubAgentTools(ctx) {
17467
17613
  projectId: issueProjectId,
17468
17614
  repository
17469
17615
  });
17616
+ try {
17617
+ await appendPullRequestToGitHubIssueLinkRecords(ctx, {
17618
+ companyId: runCtx.companyId,
17619
+ issueId: paperclipIssueId,
17620
+ repositoryUrl: repository.url,
17621
+ pullRequestNumber: pullRequestData.number
17622
+ });
17623
+ } catch (error) {
17624
+ postCreationWarnings.push(
17625
+ `Pull request #${pullRequestData.number} was created, but the Paperclip issue link could not be refreshed yet: ${getErrorMessage(error)}`
17626
+ );
17627
+ }
17628
+ }
17629
+ const requestedLabels = normalizeToolStringArray(input.labels);
17630
+ let appliedLabels;
17631
+ if (requestedLabels.length > 0) {
17632
+ try {
17633
+ const labelResponse = await octokit.rest.issues.addLabels({
17634
+ owner: repository.owner,
17635
+ repo: repository.repo,
17636
+ issue_number: pullRequestData.number,
17637
+ labels: requestedLabels,
17638
+ headers: {
17639
+ "X-GitHub-Api-Version": GITHUB_API_VERSION
17640
+ }
17641
+ });
17642
+ appliedLabels = (labelResponse.data ?? []).map((label) => typeof label === "string" ? label : label?.name ?? "").filter(Boolean);
17643
+ } catch (error) {
17644
+ postCreationWarnings.push(
17645
+ `Pull request #${pullRequestData.number} was created, but labels could not be applied: ${getErrorMessage(error)}`
17646
+ );
17647
+ }
17648
+ }
17649
+ const requestedUserReviewers = normalizeToolStringArray(input.userReviewers);
17650
+ const requestedTeamReviewers = normalizeToolStringArray(input.teamReviewers);
17651
+ let requestedReviewers;
17652
+ let requestedTeams;
17653
+ if (requestedUserReviewers.length > 0 || requestedTeamReviewers.length > 0) {
17654
+ try {
17655
+ const reviewerResponse = await octokit.rest.pulls.requestReviewers({
17656
+ owner: repository.owner,
17657
+ repo: repository.repo,
17658
+ pull_number: pullRequestData.number,
17659
+ reviewers: requestedUserReviewers,
17660
+ team_reviewers: requestedTeamReviewers,
17661
+ headers: {
17662
+ "X-GitHub-Api-Version": GITHUB_API_VERSION
17663
+ }
17664
+ });
17665
+ requestedReviewers = (reviewerResponse.data.requested_reviewers ?? []).map((reviewer) => reviewer?.login ?? "").filter(Boolean);
17666
+ requestedTeams = (reviewerResponse.data.requested_teams ?? []).map((team) => team?.slug ?? "").filter(Boolean);
17667
+ } catch (error) {
17668
+ postCreationWarnings.push(
17669
+ `Pull request #${pullRequestData.number} was created, but reviewers could not be requested: ${getErrorMessage(error)}`
17670
+ );
17671
+ }
17470
17672
  }
17471
17673
  await persistCompanyActivityMetricEvent(
17472
17674
  ctx,
@@ -17482,9 +17684,13 @@ function registerGitHubAgentTools(ctx) {
17482
17684
  }
17483
17685
  );
17484
17686
  return buildToolSuccessResult(
17485
- `Created pull request #${pullRequestData.number} in ${formatRepositoryLabel(repository)}.`,
17687
+ postCreationWarnings.length > 0 ? `Created pull request #${pullRequestData.number} in ${formatRepositoryLabel(repository)} with follow-up warnings: ${postCreationWarnings.join(" ")}` : `Created pull request #${pullRequestData.number} in ${formatRepositoryLabel(repository)}.`,
17486
17688
  {
17487
17689
  repository: repository.url,
17690
+ ...appliedLabels ? { labels: appliedLabels } : {},
17691
+ ...requestedReviewers ? { requestedReviewers } : {},
17692
+ ...requestedTeams ? { requestedTeams } : {},
17693
+ ...postCreationWarnings.length > 0 ? { warnings: postCreationWarnings } : {},
17488
17694
  publishedBranch: {
17489
17695
  name: publishedBranch.branchName,
17490
17696
  commitSha: publishedBranch.commitSha,
@@ -17611,6 +17817,26 @@ function registerGitHubAgentTools(ctx) {
17611
17817
  }
17612
17818
  });
17613
17819
  }
17820
+ let labels;
17821
+ if (Array.isArray(input.labels)) {
17822
+ const requestedLabels = normalizeToolStringArray(input.labels);
17823
+ const currentLabels = (currentResponse.data.labels ?? []).map((label) => typeof label === "string" ? label : label?.name ?? "").filter(Boolean);
17824
+ if ([...requestedLabels].sort().join("\n") !== [...currentLabels].sort().join("\n")) {
17825
+ const labelResponse = await octokit.rest.issues.setLabels({
17826
+ owner: target.repository.owner,
17827
+ repo: target.repository.repo,
17828
+ issue_number: target.pullRequestNumber,
17829
+ labels: requestedLabels,
17830
+ headers: {
17831
+ "X-GitHub-Api-Version": GITHUB_API_VERSION
17832
+ }
17833
+ });
17834
+ labels = (labelResponse.data ?? []).map((label) => typeof label === "string" ? label : label?.name ?? "").filter(Boolean);
17835
+ changed = true;
17836
+ } else {
17837
+ labels = currentLabels;
17838
+ }
17839
+ }
17614
17840
  return buildToolSuccessResult(
17615
17841
  changed ? `Updated pull request #${currentResponse.data.number} in ${formatRepositoryLabel(target.repository)}.` : `No GitHub pull request changes were requested for #${currentResponse.data.number} in ${formatRepositoryLabel(target.repository)}.`,
17616
17842
  {
@@ -17622,7 +17848,8 @@ function registerGitHubAgentTools(ctx) {
17622
17848
  url: currentResponse.data.html_url,
17623
17849
  state: currentResponse.data.state,
17624
17850
  isDraft: currentResponse.data.draft,
17625
- baseRefName: currentResponse.data.base.ref
17851
+ baseRefName: currentResponse.data.base.ref,
17852
+ ...labels ? { labels } : {}
17626
17853
  }
17627
17854
  }
17628
17855
  );
@@ -18072,6 +18299,7 @@ var __testing = {
18072
18299
  hasUnresolvedPaperclipIssueBlocker,
18073
18300
  isHealthyMaintainerWaitTransition,
18074
18301
  isPaperclipIssuePatchApplied,
18302
+ findSettledNoopAttempt,
18075
18303
  listTrustedNewLinkedPullRequestCommentSources,
18076
18304
  normalizePaperclipIssueAssigneePrincipal,
18077
18305
  normalizeImportRegistry,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "paperclip-github-plugin",
3
- "version": "0.17.4",
3
+ "version": "0.17.6",
4
4
  "description": "Paperclip plugin for synchronizing GitHub issues into Paperclip projects.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",