@sentry/junior-github 0.299.0 → 0.301.0
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/account-links.d.ts +8 -0
- package/dist/{chunk-O74CQGTZ.js → chunk-YUF5P5I7.js} +1 -1
- package/dist/configured-repository.d.ts +10 -0
- package/dist/images.d.ts +8 -0
- package/dist/index.js +384 -183
- package/dist/object-facts.d.ts +14 -3
- package/dist/reply-markdown.d.ts +18 -2
- package/dist/testing.js +1 -1
- package/dist/tool-support/github-api.d.ts +7 -0
- package/dist/tool-support/github-text.d.ts +8 -0
- package/dist/tools/clone-repository.d.ts +38 -2
- package/dist/tools/comment-on-issue.d.ts +38 -2
- package/dist/tools/comment-on-pull-request.d.ts +38 -2
- package/dist/tools/create-issue.d.ts +38 -2
- package/dist/tools/create-pull-request.d.ts +38 -2
- package/dist/tools/get-deployment.d.ts +38 -2
- package/dist/tools/get-issue.d.ts +38 -2
- package/dist/tools/get-pull-request.d.ts +38 -2
- package/dist/tools/get-release.d.ts +38 -2
- package/dist/tools/get-repository.d.ts +38 -2
- package/dist/tools/get-status.d.ts +38 -2
- package/dist/tools/react-to-issue.d.ts +38 -2
- package/dist/tools/resolve-pull-request-review-thread.d.ts +38 -2
- package/dist/tools/submit-pull-request-review.d.ts +38 -2
- package/dist/tools/update-issue-comment.d.ts +38 -2
- package/dist/tools/update-issue.d.ts +38 -2
- package/dist/tools/update-pull-request-feedback.d.ts +38 -2
- package/dist/tools/update-pull-request.d.ts +38 -2
- package/package.json +8 -4
package/dist/index.js
CHANGED
|
@@ -63,7 +63,65 @@ import {
|
|
|
63
63
|
readGrantPermissions,
|
|
64
64
|
requireEnv,
|
|
65
65
|
resolveUserAccount
|
|
66
|
-
} from "./chunk-
|
|
66
|
+
} from "./chunk-YUF5P5I7.js";
|
|
67
|
+
|
|
68
|
+
// src/account-links.ts
|
|
69
|
+
var GITHUB_LOGIN_PATTERN = /^[A-Za-z0-9][A-Za-z0-9_-]{0,38}$/;
|
|
70
|
+
var NON_ACCOUNT_PATHS = /* @__PURE__ */ new Set([
|
|
71
|
+
"about",
|
|
72
|
+
"apps",
|
|
73
|
+
"codespaces",
|
|
74
|
+
"collections",
|
|
75
|
+
"contact",
|
|
76
|
+
"copilot",
|
|
77
|
+
"dashboard",
|
|
78
|
+
"enterprise",
|
|
79
|
+
"events",
|
|
80
|
+
"explore",
|
|
81
|
+
"features",
|
|
82
|
+
"issues",
|
|
83
|
+
"login",
|
|
84
|
+
"logout",
|
|
85
|
+
"marketplace",
|
|
86
|
+
"new",
|
|
87
|
+
"notifications",
|
|
88
|
+
"organizations",
|
|
89
|
+
"pricing",
|
|
90
|
+
"pulls",
|
|
91
|
+
"search",
|
|
92
|
+
"security",
|
|
93
|
+
"settings",
|
|
94
|
+
"signup",
|
|
95
|
+
"sponsors",
|
|
96
|
+
"stars",
|
|
97
|
+
"topics",
|
|
98
|
+
"trending"
|
|
99
|
+
]);
|
|
100
|
+
function githubAccountCard(login2) {
|
|
101
|
+
return {
|
|
102
|
+
kind: "object",
|
|
103
|
+
objectType: "person",
|
|
104
|
+
key: `github:${login2.toLowerCase()}`,
|
|
105
|
+
label: `@${login2}`,
|
|
106
|
+
title: login2,
|
|
107
|
+
url: `https://github.com/${login2}`,
|
|
108
|
+
displayType: "GitHub account",
|
|
109
|
+
facts: { type: "person", githubHandle: login2 }
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
var githubAccountLinks = {
|
|
113
|
+
filters: [{ host: "github.com", pathPattern: "/*" }],
|
|
114
|
+
// A GitHub profile is public, and the card holds only the login.
|
|
115
|
+
canView: async () => true,
|
|
116
|
+
objectType: "person",
|
|
117
|
+
async resolve(ctx, url) {
|
|
118
|
+
const login2 = url.pathname.split("/")[1] ?? "";
|
|
119
|
+
if (!GITHUB_LOGIN_PATTERN.test(login2) || NON_ACCOUNT_PATHS.has(login2.toLowerCase())) {
|
|
120
|
+
return void 0;
|
|
121
|
+
}
|
|
122
|
+
return await ctx.findPerson({ provider: "github", handle: login2 }) ?? githubAccountCard(login2);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
67
125
|
|
|
68
126
|
// src/tool-support/attribution.ts
|
|
69
127
|
import * as z from "zod";
|
|
@@ -114,6 +172,16 @@ function redirectTarget(response, from) {
|
|
|
114
172
|
const target = new URL(location, from);
|
|
115
173
|
return target.origin === GITHUB_API_BASE ? target.href : void 0;
|
|
116
174
|
}
|
|
175
|
+
async function githubAttachmentLocation(egress, url) {
|
|
176
|
+
const response = await egress.fetch({
|
|
177
|
+
provider: "github",
|
|
178
|
+
operation: "github.attachment.get",
|
|
179
|
+
request: new Request(url, { redirect: "manual" })
|
|
180
|
+
});
|
|
181
|
+
await response.body?.cancel();
|
|
182
|
+
const location = REDIRECT_STATUSES.has(response.status) ? response.headers.get("location") : null;
|
|
183
|
+
return location ? new URL(location, url).href : void 0;
|
|
184
|
+
}
|
|
117
185
|
async function readBody(response) {
|
|
118
186
|
const text2 = await response.text();
|
|
119
187
|
if (!text2) return void 0;
|
|
@@ -158,10 +226,10 @@ function isRecord2(value) {
|
|
|
158
226
|
var GITHUB_REQUEST_ATTRIBUTION_START = "<!-- junior-request-attribution:start -->";
|
|
159
227
|
var GITHUB_REQUEST_ATTRIBUTION_END = "<!-- junior-request-attribution:end -->";
|
|
160
228
|
var SLACK_USER_ID_DISPLAY_PATTERN = /^[UW][A-Z0-9]{5,}$/;
|
|
161
|
-
var
|
|
229
|
+
var GITHUB_LOGIN_PATTERN2 = /^[A-Za-z0-9][A-Za-z0-9_-]{0,99}$/;
|
|
162
230
|
function parseGitHubLogin(value) {
|
|
163
231
|
const login2 = value?.trim().replace(/^@/, "");
|
|
164
|
-
return login2 &&
|
|
232
|
+
return login2 && GITHUB_LOGIN_PATTERN2.test(login2) ? login2 : void 0;
|
|
165
233
|
}
|
|
166
234
|
function linkedGitHubLogin(user) {
|
|
167
235
|
return parseGitHubLogin(
|
|
@@ -465,7 +533,7 @@ function createGitHubCloneRepositoryTool(ctx) {
|
|
|
465
533
|
openWorldHint: true,
|
|
466
534
|
readOnlyHint: true
|
|
467
535
|
},
|
|
468
|
-
description: "Clone a GitHub repository into the sandbox as an ad-hoc checkout. The destination must not already exist. In the default Sandbox, a matching Workspace is a tool input error: call switchWorkspace instead, or
|
|
536
|
+
description: "Clone a GitHub repository into the sandbox as an ad-hoc checkout. The destination must not already exist. In the default Sandbox, a matching Workspace is a tool input error: call switchWorkspace instead, or opt in to an intentional ad-hoc checkout. Inside a Workspace, the clone proceeds and the result notes matching Workspaces.",
|
|
469
537
|
describeProposal(input) {
|
|
470
538
|
const directory = typeof input.directory === "string" && input.directory.length > 0 ? input.directory : void 0;
|
|
471
539
|
const adHoc = input.allow_ad_hoc === true ? " as an intentional ad-hoc checkout" : "";
|
|
@@ -666,7 +734,7 @@ function createGitHubCommentOnPullRequestTool(egress) {
|
|
|
666
734
|
openWorldHint: true,
|
|
667
735
|
readOnlyHint: false
|
|
668
736
|
},
|
|
669
|
-
description: "Post a conversation comment on a GitHub pull request, or reply in an inline review thread
|
|
737
|
+
description: "Post a conversation comment on a GitHub pull request, or reply in an inline review thread. For issues, use github_commentOnIssue. Use it to answer a question asked in a pull request review or comment. Returns the comment id and URL.",
|
|
670
738
|
inputSchema: inputSchema4,
|
|
671
739
|
outputSchema: outputSchema4,
|
|
672
740
|
async execute(input) {
|
|
@@ -754,18 +822,23 @@ function htmlImageSources(html) {
|
|
|
754
822
|
visit2(parseFragment(html));
|
|
755
823
|
return sources;
|
|
756
824
|
}
|
|
757
|
-
|
|
825
|
+
var GITHUB_ATTACHMENT_PATH = /^\/user-attachments\/assets\/[0-9a-f-]{36}$/i;
|
|
826
|
+
function githubImageKind(url) {
|
|
827
|
+
if (url.username || url.password || url.href.length > 512) return void 0;
|
|
828
|
+
if (url.origin === "https://github.com" && !url.search && GITHUB_ATTACHMENT_PATH.test(url.pathname)) {
|
|
829
|
+
return "attachment";
|
|
830
|
+
}
|
|
758
831
|
const baseUrl = process.env.JUNIOR_BASE_URL?.trim().replace(/\/+$/, "");
|
|
759
|
-
if (!baseUrl
|
|
760
|
-
let url;
|
|
761
|
-
let prefix;
|
|
762
|
-
try {
|
|
763
|
-
url = new URL(value);
|
|
764
|
-
prefix = new URL(`${baseUrl}/public/artifacts/`);
|
|
765
|
-
} catch {
|
|
832
|
+
if (!baseUrl || !URL.canParse(`${baseUrl}/public/artifacts/`)) {
|
|
766
833
|
return void 0;
|
|
767
834
|
}
|
|
768
|
-
|
|
835
|
+
const prefix = new URL(`${baseUrl}/public/artifacts/`);
|
|
836
|
+
return (url.protocol === "https:" || url.protocol === "http:") && url.origin === prefix.origin && url.pathname.length > prefix.pathname.length && url.pathname.startsWith(prefix.pathname) ? "artifact" : void 0;
|
|
837
|
+
}
|
|
838
|
+
function previewImageUrl(value) {
|
|
839
|
+
if (!URL.canParse(value)) return void 0;
|
|
840
|
+
const url = new URL(value);
|
|
841
|
+
return githubImageKind(url) ? url.href : void 0;
|
|
769
842
|
}
|
|
770
843
|
function githubPreviewImageUrls(body) {
|
|
771
844
|
const sources = [];
|
|
@@ -775,7 +848,7 @@ function githubPreviewImageUrls(body) {
|
|
|
775
848
|
});
|
|
776
849
|
return [
|
|
777
850
|
...new Set(
|
|
778
|
-
sources.map(
|
|
851
|
+
sources.map(previewImageUrl).filter((url) => url !== void 0)
|
|
779
852
|
)
|
|
780
853
|
];
|
|
781
854
|
}
|
|
@@ -1593,10 +1666,12 @@ function createGitHubGetIssueTool(ctx) {
|
|
|
1593
1666
|
});
|
|
1594
1667
|
}
|
|
1595
1668
|
function issueRepoRef(repositoryUrl) {
|
|
1596
|
-
const
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1669
|
+
const url = repositoryUrl ? URL.parse(repositoryUrl) : null;
|
|
1670
|
+
if (url?.origin !== "https://api.github.com" || url.search || url.hash) {
|
|
1671
|
+
return void 0;
|
|
1672
|
+
}
|
|
1673
|
+
const [repos, owner, repo, ...rest] = url.pathname.slice(1).split("/");
|
|
1674
|
+
return repos === "repos" && owner && repo && rest.length === 0 ? `${owner}/${repo}` : void 0;
|
|
1600
1675
|
}
|
|
1601
1676
|
|
|
1602
1677
|
// src/tools/create-pull-request.ts
|
|
@@ -3628,12 +3703,14 @@ var REST_REACTION_CONTENT = new Map(
|
|
|
3628
3703
|
var inputSchema14 = z22.object({
|
|
3629
3704
|
repo: z22.string().describe('Repository in "owner/name" format.'),
|
|
3630
3705
|
comment_kind: z22.enum(["conversation", "review", "review_body"]).describe(
|
|
3631
|
-
'Comment kind: "conversation" for a pull request conversation comment, "review" for an inline review comment, "review_body" for the body of a submitted review.'
|
|
3706
|
+
'Comment kind: "conversation" for a pull request conversation comment, "review" for an inline review comment, "review_body" for the body of a submitted review. Use the exact value from the event.'
|
|
3632
3707
|
),
|
|
3633
3708
|
comment_id: z22.number().int().positive().describe(
|
|
3634
|
-
"GitHub comment id (conversation comment id, inline review comment id, or review id)."
|
|
3709
|
+
"GitHub comment id (conversation comment id, inline review comment id, or review id). Use the exact value from the event."
|
|
3710
|
+
),
|
|
3711
|
+
pull_request: z22.number().int().positive().describe(
|
|
3712
|
+
"Pull request number that the comment is on. Use the exact value from the event."
|
|
3635
3713
|
),
|
|
3636
|
-
pull_request: z22.number().int().positive().describe("Pull request number that the comment is on."),
|
|
3637
3714
|
status: z22.enum(["addressed", "declined"]).describe(
|
|
3638
3715
|
"Feedback outcome. Maps to a reaction: addressed -> +1, declined -> -1."
|
|
3639
3716
|
)
|
|
@@ -3801,7 +3878,7 @@ function createGitHubUpdatePullRequestFeedbackTool(ctx, botEmail) {
|
|
|
3801
3878
|
openWorldHint: true,
|
|
3802
3879
|
readOnlyHint: false
|
|
3803
3880
|
},
|
|
3804
|
-
description: "Set your outcome reaction on GitHub pull request feedback: addressed (+1) or declined (-1).
|
|
3881
|
+
description: "Set your outcome reaction on GitHub pull request feedback: addressed (+1) or declined (-1). Call it after acting on the feedback. Replaces only your prior status reaction on that comment. Only works on pull requests the bot authored.",
|
|
3805
3882
|
exposure: "direct",
|
|
3806
3883
|
inputSchema: inputSchema14,
|
|
3807
3884
|
outputSchema: outputSchema14,
|
|
@@ -4116,44 +4193,64 @@ function createGitHubSubmitPullRequestReviewTool(egress) {
|
|
|
4116
4193
|
});
|
|
4117
4194
|
}
|
|
4118
4195
|
|
|
4196
|
+
// src/tool-support/github-text.ts
|
|
4197
|
+
function withGitHubText(tools, users) {
|
|
4198
|
+
return Object.fromEntries(
|
|
4199
|
+
Object.entries(tools).map(([name, tool]) => {
|
|
4200
|
+
const execute = tool.execute;
|
|
4201
|
+
if (!execute) return [name, tool];
|
|
4202
|
+
const wrapped = Object.create(tool);
|
|
4203
|
+
wrapped.execute = async (input, options) => await execute.call(
|
|
4204
|
+
tool,
|
|
4205
|
+
await users.replaceSlackMentions(input, "github"),
|
|
4206
|
+
options
|
|
4207
|
+
);
|
|
4208
|
+
return [name, wrapped];
|
|
4209
|
+
})
|
|
4210
|
+
);
|
|
4211
|
+
}
|
|
4212
|
+
|
|
4119
4213
|
// src/tools.ts
|
|
4120
4214
|
function createGitHubTools(ctx, botEmail, pullRequestSubscription, experimental = {}) {
|
|
4121
4215
|
const descriptionDecider = experimental.pullRequestDescriptionChecks ? ctx.decider : void 0;
|
|
4122
|
-
return
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
|
|
4139
|
-
|
|
4140
|
-
|
|
4141
|
-
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
|
|
4145
|
-
|
|
4146
|
-
|
|
4147
|
-
|
|
4148
|
-
|
|
4149
|
-
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
|
|
4155
|
-
|
|
4156
|
-
|
|
4216
|
+
return withGitHubText(
|
|
4217
|
+
{
|
|
4218
|
+
reactToIssue: createGitHubReactToIssueTool(ctx.egress),
|
|
4219
|
+
cloneRepository: createGitHubCloneRepositoryTool(ctx),
|
|
4220
|
+
commentOnIssue: createGitHubCommentOnIssueTool(ctx.egress),
|
|
4221
|
+
commentOnPullRequest: createGitHubCommentOnPullRequestTool(ctx.egress),
|
|
4222
|
+
createIssue: createGitHubIssueTool(ctx),
|
|
4223
|
+
createPullRequest: createGitHubPullRequestTool(
|
|
4224
|
+
ctx,
|
|
4225
|
+
pullRequestSubscription,
|
|
4226
|
+
descriptionDecider
|
|
4227
|
+
),
|
|
4228
|
+
getDeployment: createGitHubGetDeploymentTool(ctx),
|
|
4229
|
+
getIssue: createGitHubGetIssueTool(ctx),
|
|
4230
|
+
getPullRequest: createGitHubGetPullRequestTool(ctx),
|
|
4231
|
+
getRelease: createGitHubGetReleaseTool(ctx),
|
|
4232
|
+
getRepository: createGitHubGetRepositoryTool(ctx),
|
|
4233
|
+
getStatus: createGitHubGetStatusTool(ctx),
|
|
4234
|
+
resolvePullRequestReviewThread: createGitHubResolvePullRequestReviewThreadTool(ctx, botEmail),
|
|
4235
|
+
submitPullRequestReview: createGitHubSubmitPullRequestReviewTool(
|
|
4236
|
+
ctx.egress
|
|
4237
|
+
),
|
|
4238
|
+
updateIssue: createGitHubUpdateIssueTool(ctx),
|
|
4239
|
+
updateIssueComment: createGitHubUpdateIssueCommentTool(
|
|
4240
|
+
ctx.egress,
|
|
4241
|
+
botEmail
|
|
4242
|
+
),
|
|
4243
|
+
updatePullRequest: createGitHubUpdatePullRequestTool(
|
|
4244
|
+
ctx,
|
|
4245
|
+
descriptionDecider
|
|
4246
|
+
),
|
|
4247
|
+
updatePullRequestFeedback: createGitHubUpdatePullRequestFeedbackTool(
|
|
4248
|
+
ctx,
|
|
4249
|
+
botEmail
|
|
4250
|
+
)
|
|
4251
|
+
},
|
|
4252
|
+
ctx.users
|
|
4253
|
+
);
|
|
4157
4254
|
}
|
|
4158
4255
|
|
|
4159
4256
|
// src/webhooks/handler.ts
|
|
@@ -6717,6 +6814,68 @@ async function classifyGitHubPullRequestCommitComposition(args) {
|
|
|
6717
6814
|
return foundCommit ? "junior_only" : void 0;
|
|
6718
6815
|
}
|
|
6719
6816
|
|
|
6817
|
+
// src/images.ts
|
|
6818
|
+
import {
|
|
6819
|
+
decodeObjectImageRef
|
|
6820
|
+
} from "@sentry/junior-plugin-api";
|
|
6821
|
+
import * as z44 from "zod";
|
|
6822
|
+
var OBJECT_KEY = /^([\w.-]+)\/([\w.-]+)#\d+$/;
|
|
6823
|
+
var ACCESS_TTL_MS = 10 * 60 * 1e3;
|
|
6824
|
+
var permissionSchema = z44.object({ permission: z44.string().min(1) });
|
|
6825
|
+
var AccessReadFailed = class extends Error {
|
|
6826
|
+
status;
|
|
6827
|
+
constructor(status) {
|
|
6828
|
+
super(`GitHub repository permission read failed with HTTP ${status}`);
|
|
6829
|
+
this.status = status;
|
|
6830
|
+
}
|
|
6831
|
+
};
|
|
6832
|
+
async function canSeeRepository(ctx, repository2, login2) {
|
|
6833
|
+
try {
|
|
6834
|
+
return await readRepositoryAccess(ctx, repository2, login2);
|
|
6835
|
+
} catch (error) {
|
|
6836
|
+
if (!(error instanceof AccessReadFailed)) throw error;
|
|
6837
|
+
ctx.log.warn("github.image_access.read_failed", {
|
|
6838
|
+
"http.response.status_code": error.status
|
|
6839
|
+
});
|
|
6840
|
+
return false;
|
|
6841
|
+
}
|
|
6842
|
+
}
|
|
6843
|
+
async function readRepositoryAccess(ctx, repository2, login2) {
|
|
6844
|
+
return await ctx.cache.getOrLoad(
|
|
6845
|
+
`image-access:${repository2.owner}/${repository2.name}:${login2}`.toLowerCase(),
|
|
6846
|
+
async () => {
|
|
6847
|
+
const response = await githubApi(ctx.egress, {
|
|
6848
|
+
operation: "github.repository.collaborator-permission.get",
|
|
6849
|
+
path: `${repoPath(repository2)}/collaborators/${encodeURIComponent(login2)}/permission`
|
|
6850
|
+
});
|
|
6851
|
+
if (!response.ok && response.status !== 404) {
|
|
6852
|
+
throw new AccessReadFailed(response.status);
|
|
6853
|
+
}
|
|
6854
|
+
const parsed = response.ok ? permissionSchema.safeParse(response.body) : void 0;
|
|
6855
|
+
return {
|
|
6856
|
+
value: parsed?.success === true && parsed.data.permission !== "none",
|
|
6857
|
+
ttlMs: ACCESS_TTL_MS
|
|
6858
|
+
};
|
|
6859
|
+
}
|
|
6860
|
+
);
|
|
6861
|
+
}
|
|
6862
|
+
var githubImageSource = {
|
|
6863
|
+
async resolve(ctx, ref) {
|
|
6864
|
+
const image = decodeObjectImageRef(ref);
|
|
6865
|
+
const key = image && OBJECT_KEY.exec(image.key);
|
|
6866
|
+
if (!image || !key || !URL.canParse(image.url)) return void 0;
|
|
6867
|
+
const kind = githubImageKind(new URL(image.url));
|
|
6868
|
+
const login2 = linkedGitHubLogin(ctx.viewer);
|
|
6869
|
+
if (!kind || !login2) return void 0;
|
|
6870
|
+
const repository2 = { name: key[2], owner: key[1] };
|
|
6871
|
+
if (!await canSeeRepository(ctx, repository2, login2)) return void 0;
|
|
6872
|
+
return kind === "artifact" ? { url: image.url } : {
|
|
6873
|
+
url: image.url,
|
|
6874
|
+
location: () => githubAttachmentLocation(ctx.egress, image.url)
|
|
6875
|
+
};
|
|
6876
|
+
}
|
|
6877
|
+
};
|
|
6878
|
+
|
|
6720
6879
|
// src/git-config.ts
|
|
6721
6880
|
function cleanIdentityPart(value) {
|
|
6722
6881
|
return String(value ?? "").replaceAll("\n", " ").replaceAll("\r", " ").replace(/[<>]/g, "").trim();
|
|
@@ -7098,133 +7257,162 @@ async function prepareSandboxGit(ctx) {
|
|
|
7098
7257
|
}
|
|
7099
7258
|
|
|
7100
7259
|
// src/reply-markdown.ts
|
|
7101
|
-
|
|
7102
|
-
|
|
7103
|
-
|
|
7104
|
-
|
|
7105
|
-
|
|
7106
|
-
function
|
|
7107
|
-
|
|
7108
|
-
|
|
7109
|
-
|
|
7110
|
-
|
|
7111
|
-
|
|
7112
|
-
}
|
|
7113
|
-
let markerLength = 1;
|
|
7114
|
-
while (text2[start + markerLength] === "`") {
|
|
7115
|
-
markerLength++;
|
|
7116
|
-
}
|
|
7117
|
-
const marker = "`".repeat(markerLength);
|
|
7118
|
-
const end = text2.indexOf(marker, start + markerLength);
|
|
7119
|
-
return end === -1 ? void 0 : end + markerLength;
|
|
7260
|
+
import { fromMarkdown } from "mdast-util-from-markdown";
|
|
7261
|
+
import { gfmFromMarkdown } from "mdast-util-gfm";
|
|
7262
|
+
import { gfm } from "micromark-extension-gfm";
|
|
7263
|
+
|
|
7264
|
+
// src/configured-repository.ts
|
|
7265
|
+
function configuredRepository(config) {
|
|
7266
|
+
const [first, second, ...extra] = (config.repo ?? "").trim().split("/");
|
|
7267
|
+
if (extra.length > 0) return void 0;
|
|
7268
|
+
const owner = second ? first : config.org?.trim();
|
|
7269
|
+
const name = second || first;
|
|
7270
|
+
return owner && name ? { owner, name } : void 0;
|
|
7120
7271
|
}
|
|
7121
|
-
|
|
7122
|
-
|
|
7123
|
-
|
|
7124
|
-
|
|
7125
|
-
|
|
7126
|
-
|
|
7127
|
-
|
|
7128
|
-
|
|
7129
|
-
|
|
7130
|
-
|
|
7272
|
+
|
|
7273
|
+
// src/reply-markdown.ts
|
|
7274
|
+
var OWNER = "[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?";
|
|
7275
|
+
var LOGIN = `${OWNER}(?:_[A-Za-z0-9]+)?`;
|
|
7276
|
+
var REPO = "[A-Za-z0-9._-]+";
|
|
7277
|
+
var SHA = "[0-9a-f]{7,40}";
|
|
7278
|
+
var START = "(?<![\\w.\\-/@&<\\\\])";
|
|
7279
|
+
var END = "(?![\\w-])";
|
|
7280
|
+
var TEXT_REFERENCE_PATTERN = new RegExp(
|
|
7281
|
+
[
|
|
7282
|
+
`${START}(?<issueOwner>${LOGIN})\\/(?<issueRepo>${REPO})#(?<issue>\\d+)${END}`,
|
|
7283
|
+
`${START}(?<commitOwner>${LOGIN})\\/(?<commitRepo>${REPO})@(?<commit>${SHA})${END}`,
|
|
7284
|
+
`${START}(?<user>${LOGIN})@(?<userCommit>[0-9a-f]{40})${END}`,
|
|
7285
|
+
`${START}(?:#|GH-)(?<bareIssue>\\d+)${END}`,
|
|
7286
|
+
// Not `@scope/name`, which is an npm package more often than a team.
|
|
7287
|
+
`${START}@(?<mention>${LOGIN})(?![\\w/-]|\\.\\w)`,
|
|
7288
|
+
// Only full SHAs: shorter hex runs are often other IDs, such as event IDs.
|
|
7289
|
+
`${START}(?<bareCommit>[0-9a-f]{40})${END}`
|
|
7290
|
+
].join("|"),
|
|
7291
|
+
"g"
|
|
7292
|
+
);
|
|
7293
|
+
var GITHUB_URL_BODY = `https?:\\/\\/(?:www\\.)?github\\.com\\/(?!(?:orgs|enterprises)\\/)(?<owner>${LOGIN})\\/(?<repo>${REPO})\\/(?:(?:issues|pull|discussions)\\/(?<issue>\\d+)|commit\\/(?<commit>${SHA}))`;
|
|
7294
|
+
var GITHUB_URL_PATTERN = new RegExp(`^${GITHUB_URL_BODY}$`, "i");
|
|
7295
|
+
var GITHUB_LINKED_URL_PATTERN = new RegExp(GITHUB_URL_BODY, "gi");
|
|
7296
|
+
var NON_ACCOUNT_MENTIONS = /* @__PURE__ */ new Set(["channel", "everyone", "here"]);
|
|
7297
|
+
function readSpans(text2) {
|
|
7298
|
+
const spans = [];
|
|
7299
|
+
const visit2 = (node) => {
|
|
7300
|
+
const start = node.position?.start.offset;
|
|
7301
|
+
const end = node.position?.end.offset;
|
|
7302
|
+
if (start === void 0 || end === void 0) return;
|
|
7303
|
+
if (node.type === "text") {
|
|
7304
|
+
spans.push({ kind: "text", start, end });
|
|
7305
|
+
} else if (node.type === "link" || node.type === "definition") {
|
|
7306
|
+
const bare = node.type === "link" && text2.slice(start, end) === node.url;
|
|
7307
|
+
spans.push({ kind: bare ? "url" : "link", start, end, url: node.url });
|
|
7308
|
+
} else if (node.type !== "linkReference" && "children" in node) {
|
|
7309
|
+
for (const child of node.children) visit2(child);
|
|
7310
|
+
}
|
|
7311
|
+
};
|
|
7312
|
+
visit2(
|
|
7313
|
+
fromMarkdown(text2, {
|
|
7314
|
+
extensions: [gfm()],
|
|
7315
|
+
mdastExtensions: [gfmFromMarkdown()]
|
|
7316
|
+
})
|
|
7317
|
+
);
|
|
7318
|
+
return spans;
|
|
7131
7319
|
}
|
|
7132
|
-
function
|
|
7133
|
-
|
|
7134
|
-
|
|
7135
|
-
|
|
7136
|
-
|
|
7137
|
-
|
|
7138
|
-
|
|
7139
|
-
|
|
7140
|
-
|
|
7141
|
-
|
|
7142
|
-
|
|
7320
|
+
function namedRepositories(text2, spans) {
|
|
7321
|
+
const repositories = /* @__PURE__ */ new Map();
|
|
7322
|
+
const add = (owner, name) => {
|
|
7323
|
+
if (owner && name) {
|
|
7324
|
+
repositories.set(`${owner}/${name}`.toLowerCase(), { owner, name });
|
|
7325
|
+
}
|
|
7326
|
+
};
|
|
7327
|
+
for (const span of spans) {
|
|
7328
|
+
if (span.url) {
|
|
7329
|
+
for (const { groups } of span.url.matchAll(GITHUB_LINKED_URL_PATTERN)) {
|
|
7330
|
+
add(groups?.owner, groups?.repo);
|
|
7331
|
+
}
|
|
7332
|
+
} else {
|
|
7333
|
+
const source = text2.slice(span.start, span.end);
|
|
7334
|
+
for (const { groups } of source.matchAll(TEXT_REFERENCE_PATTERN)) {
|
|
7335
|
+
add(groups?.issueOwner, groups?.issueRepo);
|
|
7336
|
+
add(groups?.commitOwner, groups?.commitRepo);
|
|
7337
|
+
}
|
|
7338
|
+
}
|
|
7143
7339
|
}
|
|
7144
|
-
|
|
7145
|
-
const closeParens = text2.indexOf(")", destStart);
|
|
7146
|
-
return closeParens === -1 ? void 0 : closeParens + 1;
|
|
7340
|
+
return [...repositories.values()];
|
|
7147
7341
|
}
|
|
7148
|
-
|
|
7149
|
-
|
|
7150
|
-
|
|
7342
|
+
var issueUrl = (owner, name, issue) => `https://github.com/${owner}/${name}/issues/${issue}`;
|
|
7343
|
+
var commitUrl = (owner, name, sha) => `https://github.com/${owner}/${name}/commit/${sha}`;
|
|
7344
|
+
function linkifyUrl(url) {
|
|
7345
|
+
const groups = GITHUB_URL_PATTERN.exec(url)?.groups;
|
|
7346
|
+
if (!groups?.owner || !groups.repo) {
|
|
7347
|
+
return url;
|
|
7151
7348
|
}
|
|
7152
|
-
const
|
|
7153
|
-
return
|
|
7349
|
+
const label = groups.issue ? `${groups.owner}/${groups.repo}#${groups.issue}` : `${groups.owner}/${groups.repo}@${groups.commit.slice(0, 7)}`;
|
|
7350
|
+
return `[${label}](${url})`;
|
|
7154
7351
|
}
|
|
7155
|
-
function
|
|
7156
|
-
|
|
7157
|
-
|
|
7158
|
-
|
|
7159
|
-
|
|
7160
|
-
|
|
7161
|
-
output += line.slice(index2, codeEnd);
|
|
7162
|
-
index2 = codeEnd;
|
|
7163
|
-
continue;
|
|
7352
|
+
function linkifyTextReferences(text2, context) {
|
|
7353
|
+
const { repository: repository2 } = context;
|
|
7354
|
+
return text2.replace(TEXT_REFERENCE_PATTERN, (reference, ...args) => {
|
|
7355
|
+
const groups = args.at(-1);
|
|
7356
|
+
if (groups.issue) {
|
|
7357
|
+
return `[${reference}](${issueUrl(groups.issueOwner, groups.issueRepo, groups.issue)})`;
|
|
7164
7358
|
}
|
|
7165
|
-
|
|
7166
|
-
|
|
7167
|
-
|
|
7168
|
-
index2 = markdownLinkEnd;
|
|
7169
|
-
continue;
|
|
7359
|
+
if (groups.commit) {
|
|
7360
|
+
const label = `${groups.commitOwner}/${groups.commitRepo}@${groups.commit.slice(0, 7)}`;
|
|
7361
|
+
return `[${label}](${commitUrl(groups.commitOwner, groups.commitRepo, groups.commit)})`;
|
|
7170
7362
|
}
|
|
7171
|
-
|
|
7172
|
-
|
|
7173
|
-
|
|
7174
|
-
|
|
7175
|
-
|
|
7363
|
+
if (groups.mention) {
|
|
7364
|
+
const login2 = groups.mention;
|
|
7365
|
+
if (NON_ACCOUNT_MENTIONS.has(login2.toLowerCase())) return reference;
|
|
7366
|
+
const known = context.mention(login2);
|
|
7367
|
+
if (known) return known;
|
|
7368
|
+
return context.linkProfiles ? `[${reference}](https://github.com/${login2})` : reference;
|
|
7176
7369
|
}
|
|
7177
|
-
if (
|
|
7178
|
-
|
|
7179
|
-
if (match) {
|
|
7180
|
-
output += match[0];
|
|
7181
|
-
index2 += match[0].length;
|
|
7182
|
-
continue;
|
|
7183
|
-
}
|
|
7370
|
+
if (!repository2) {
|
|
7371
|
+
return reference;
|
|
7184
7372
|
}
|
|
7185
|
-
if (
|
|
7186
|
-
|
|
7187
|
-
if (match) {
|
|
7188
|
-
const [reference, owner, repository2, number33] = match;
|
|
7189
|
-
output += `[${reference}](https://github.com/${owner}/${repository2}/issues/${number33})`;
|
|
7190
|
-
index2 += reference.length;
|
|
7191
|
-
continue;
|
|
7192
|
-
}
|
|
7373
|
+
if (groups.bareIssue) {
|
|
7374
|
+
return `[${reference}](${issueUrl(repository2.owner, repository2.name, groups.bareIssue)})`;
|
|
7193
7375
|
}
|
|
7194
|
-
|
|
7195
|
-
|
|
7196
|
-
|
|
7197
|
-
return output;
|
|
7198
|
-
}
|
|
7199
|
-
function linkifyGitHubReferences(text2) {
|
|
7200
|
-
let openFenceLength = 0;
|
|
7201
|
-
return text2.split("\n").map((line) => {
|
|
7202
|
-
const fenceLength = readFenceLength(line);
|
|
7203
|
-
if (fenceLength !== void 0) {
|
|
7204
|
-
if (openFenceLength === 0) {
|
|
7205
|
-
openFenceLength = fenceLength;
|
|
7206
|
-
} else if (fenceLength >= openFenceLength) {
|
|
7207
|
-
openFenceLength = 0;
|
|
7208
|
-
}
|
|
7209
|
-
return line;
|
|
7376
|
+
if (groups.userCommit) {
|
|
7377
|
+
const label = `${groups.user}@${groups.userCommit.slice(0, 7)}`;
|
|
7378
|
+
return `[${label}](${commitUrl(groups.user, repository2.name, groups.userCommit)})`;
|
|
7210
7379
|
}
|
|
7211
|
-
|
|
7212
|
-
|
|
7380
|
+
const sha = groups.bareCommit;
|
|
7381
|
+
return `[${sha.slice(0, 7)}](${commitUrl(repository2.owner, repository2.name, sha)})`;
|
|
7382
|
+
});
|
|
7383
|
+
}
|
|
7384
|
+
function linkifyGitHubReferences(text2, options = {}) {
|
|
7385
|
+
const spans = readSpans(text2);
|
|
7386
|
+
const named = namedRepositories(text2, spans);
|
|
7387
|
+
const context = {
|
|
7388
|
+
linkProfiles: options.githubText === true || named.length > 0,
|
|
7389
|
+
mention: options.mention ?? (() => void 0),
|
|
7390
|
+
repository: named.length === 0 ? configuredRepository(options.config ?? {}) : named.length === 1 ? named[0] : void 0
|
|
7391
|
+
};
|
|
7392
|
+
let result = "";
|
|
7393
|
+
let cursor = 0;
|
|
7394
|
+
for (const span of spans) {
|
|
7395
|
+
const source = text2.slice(span.start, span.end);
|
|
7396
|
+
result += text2.slice(cursor, span.start);
|
|
7397
|
+
result += span.kind === "text" ? linkifyTextReferences(source, context) : span.kind === "url" && !options.bareUrls ? linkifyUrl(source) : source;
|
|
7398
|
+
cursor = span.end;
|
|
7399
|
+
}
|
|
7400
|
+
return result + text2.slice(cursor);
|
|
7213
7401
|
}
|
|
7214
7402
|
|
|
7215
7403
|
// src/conversation-title-context.ts
|
|
7216
7404
|
var MAX_REFERENCES = 3;
|
|
7217
7405
|
var TITLE_MAX_LENGTH = 160;
|
|
7218
|
-
var
|
|
7219
|
-
var
|
|
7220
|
-
var
|
|
7406
|
+
var OWNER2 = String.raw`([A-Za-z0-9][A-Za-z0-9-]*)`;
|
|
7407
|
+
var REPO2 = String.raw`([\w.-]*\w)`;
|
|
7408
|
+
var SHA2 = String.raw`([0-9a-f]{7,40})`;
|
|
7221
7409
|
var NOT_AFTER_PATH = String.raw`(?<![\w/.-])`;
|
|
7222
|
-
var REPO_IN_PROSE = String.raw`(?:on|in|from|of|at)\s+${
|
|
7410
|
+
var REPO_IN_PROSE = String.raw`(?:on|in|from|of|at)\s+${OWNER2}\/${REPO2}`;
|
|
7223
7411
|
var repository = (owner, name) => owner && name ? { owner, name } : void 0;
|
|
7224
7412
|
var REFERENCE_PATTERNS = [
|
|
7225
7413
|
{
|
|
7226
7414
|
pattern: new RegExp(
|
|
7227
|
-
String.raw`https?:\/\/(?:www\.)?github\.com\/${
|
|
7415
|
+
String.raw`https?:\/\/(?:www\.)?github\.com\/${OWNER2}\/${REPO2}\/(issues|pull)\/(\d+)`,
|
|
7228
7416
|
"gi"
|
|
7229
7417
|
),
|
|
7230
7418
|
read: ([, owner, name, path, id]) => ({
|
|
@@ -7235,7 +7423,7 @@ var REFERENCE_PATTERNS = [
|
|
|
7235
7423
|
},
|
|
7236
7424
|
{
|
|
7237
7425
|
pattern: new RegExp(
|
|
7238
|
-
String.raw`https?:\/\/(?:www\.)?github\.com\/${
|
|
7426
|
+
String.raw`https?:\/\/(?:www\.)?github\.com\/${OWNER2}\/${REPO2}\/commit\/${SHA2}`,
|
|
7239
7427
|
"gi"
|
|
7240
7428
|
),
|
|
7241
7429
|
read: ([, owner, name, id]) => ({
|
|
@@ -7246,7 +7434,7 @@ var REFERENCE_PATTERNS = [
|
|
|
7246
7434
|
},
|
|
7247
7435
|
{
|
|
7248
7436
|
pattern: new RegExp(
|
|
7249
|
-
String.raw`${NOT_AFTER_PATH}${
|
|
7437
|
+
String.raw`${NOT_AFTER_PATH}${OWNER2}\/${REPO2}#(\d+)\b`,
|
|
7250
7438
|
"g"
|
|
7251
7439
|
),
|
|
7252
7440
|
read: ([, owner, name, id]) => ({
|
|
@@ -7257,7 +7445,7 @@ var REFERENCE_PATTERNS = [
|
|
|
7257
7445
|
},
|
|
7258
7446
|
{
|
|
7259
7447
|
pattern: new RegExp(
|
|
7260
|
-
String.raw`${NOT_AFTER_PATH}${
|
|
7448
|
+
String.raw`${NOT_AFTER_PATH}${OWNER2}\/${REPO2}@${SHA2}\b`,
|
|
7261
7449
|
"g"
|
|
7262
7450
|
),
|
|
7263
7451
|
read: ([, owner, name, id]) => ({
|
|
@@ -7282,11 +7470,6 @@ var REFERENCE_PATTERNS = [
|
|
|
7282
7470
|
read: ([, id]) => ({ id, kind: "issue" })
|
|
7283
7471
|
}
|
|
7284
7472
|
];
|
|
7285
|
-
function configuredRepository(config) {
|
|
7286
|
-
const [first, second, ...extra] = (config.repo ?? "").trim().split("/");
|
|
7287
|
-
if (extra.length > 0) return void 0;
|
|
7288
|
-
return second ? repository(first, second) : repository(config.org?.trim(), first);
|
|
7289
|
-
}
|
|
7290
7473
|
function parseGitHubReferences(text2, config) {
|
|
7291
7474
|
const matches = REFERENCE_PATTERNS.flatMap(
|
|
7292
7475
|
({ pattern, read }) => [...text2.matchAll(pattern)].map((match) => ({
|
|
@@ -7300,23 +7483,23 @@ function parseGitHubReferences(text2, config) {
|
|
|
7300
7483
|
const previous = accepted.at(-1);
|
|
7301
7484
|
if (!previous || match.start >= previous.end) accepted.push(match);
|
|
7302
7485
|
}
|
|
7303
|
-
const
|
|
7486
|
+
const namedRepositories2 = /* @__PURE__ */ new Map();
|
|
7304
7487
|
for (const match of accepted) {
|
|
7305
7488
|
if (match.repository) {
|
|
7306
7489
|
const key = `${match.repository.owner}/${match.repository.name}`;
|
|
7307
|
-
|
|
7490
|
+
namedRepositories2.set(key.toLowerCase(), match.repository);
|
|
7308
7491
|
}
|
|
7309
7492
|
}
|
|
7310
7493
|
for (const match of text2.matchAll(new RegExp(REPO_IN_PROSE, "gi"))) {
|
|
7311
7494
|
const named = repository(match[1], match[2]);
|
|
7312
7495
|
if (named) {
|
|
7313
|
-
|
|
7496
|
+
namedRepositories2.set(
|
|
7314
7497
|
`${named.owner}/${named.name}`.toLowerCase(),
|
|
7315
7498
|
named
|
|
7316
7499
|
);
|
|
7317
7500
|
}
|
|
7318
7501
|
}
|
|
7319
|
-
const fallback =
|
|
7502
|
+
const fallback = namedRepositories2.size === 1 ? [...namedRepositories2.values()][0] : configuredRepository(config);
|
|
7320
7503
|
const references = /* @__PURE__ */ new Map();
|
|
7321
7504
|
for (const match of accepted) {
|
|
7322
7505
|
const target = match.repository ?? fallback;
|
|
@@ -7328,9 +7511,9 @@ function parseGitHubReferences(text2, config) {
|
|
|
7328
7511
|
}
|
|
7329
7512
|
return [...references.values()];
|
|
7330
7513
|
}
|
|
7331
|
-
function objectTitle(kind,
|
|
7332
|
-
if (!isRecord(
|
|
7333
|
-
const raw = kind === "commit" ? isRecord(
|
|
7514
|
+
function objectTitle(kind, object44) {
|
|
7515
|
+
if (!isRecord(object44)) return void 0;
|
|
7516
|
+
const raw = kind === "commit" ? isRecord(object44.commit) && typeof object44.commit.message === "string" ? object44.commit.message.split("\n")[0] : void 0 : typeof object44.title === "string" ? object44.title : void 0;
|
|
7334
7517
|
return raw?.replace(/\s+/g, " ").trim() || void 0;
|
|
7335
7518
|
}
|
|
7336
7519
|
async function loadGitHubConversationTitleContext(args) {
|
|
@@ -7609,9 +7792,9 @@ import {
|
|
|
7609
7792
|
} from "@sentry/junior-plugin-api";
|
|
7610
7793
|
|
|
7611
7794
|
// src/default-branch.ts
|
|
7612
|
-
import * as
|
|
7795
|
+
import * as z45 from "zod";
|
|
7613
7796
|
var DEFAULT_BRANCH_TTL_MS = 10 * 60 * 1e3;
|
|
7614
|
-
var repositorySchema3 =
|
|
7797
|
+
var repositorySchema3 = z45.object({ default_branch: z45.string().min(1) });
|
|
7615
7798
|
async function loadDefaultBranch(env, cache, repository2) {
|
|
7616
7799
|
const { owner, name } = repository2;
|
|
7617
7800
|
return await cache.getOrLoad(
|
|
@@ -7795,7 +7978,10 @@ function githubErrorMessage2(bodyText) {
|
|
|
7795
7978
|
async function githubForbiddenPermissionDeniedMessage(ctx) {
|
|
7796
7979
|
const sso = ctx.response.headers.get("x-github-sso");
|
|
7797
7980
|
if (sso?.startsWith("required")) {
|
|
7798
|
-
const url = sso.
|
|
7981
|
+
const url = sso.split(";").map((part) => part.trim()).find((part) => part.startsWith("url="))?.slice("url=".length);
|
|
7982
|
+
if (url && URL.parse(url)?.origin !== "https://github.com") {
|
|
7983
|
+
return "GitHub requires SAML SSO authorization for this credential.";
|
|
7984
|
+
}
|
|
7799
7985
|
return `GitHub requires SAML SSO authorization for this credential.${url ? ` Authorize it at ${url}` : ""}`;
|
|
7800
7986
|
}
|
|
7801
7987
|
const message = githubErrorMessage2(
|
|
@@ -8192,6 +8378,8 @@ function githubPlugin(options = {}) {
|
|
|
8192
8378
|
const userScope = userScopes.length ? userScopes.join(" ") : void 0;
|
|
8193
8379
|
return defineJuniorPlugin({
|
|
8194
8380
|
packageName: "@sentry/junior-github",
|
|
8381
|
+
images: githubImageSource,
|
|
8382
|
+
objectLinks: [githubAccountLinks],
|
|
8195
8383
|
events: {
|
|
8196
8384
|
resourceTypes: [
|
|
8197
8385
|
{
|
|
@@ -8331,8 +8519,21 @@ function githubPlugin(options = {}) {
|
|
|
8331
8519
|
)
|
|
8332
8520
|
};
|
|
8333
8521
|
},
|
|
8334
|
-
formatMarkdown({ text: text2 }) {
|
|
8335
|
-
return linkifyGitHubReferences(text2
|
|
8522
|
+
formatMarkdown({ config, mention, platform, provider, text: text2 }) {
|
|
8523
|
+
return linkifyGitHubReferences(text2, {
|
|
8524
|
+
// The dashboard shows a bare GitHub link as a card.
|
|
8525
|
+
bareUrls: platform === "web",
|
|
8526
|
+
config,
|
|
8527
|
+
githubText: provider === "github",
|
|
8528
|
+
mention: (login2) => mention({ provider: "github", handle: login2 })
|
|
8529
|
+
});
|
|
8530
|
+
},
|
|
8531
|
+
systemPrompt() {
|
|
8532
|
+
return [
|
|
8533
|
+
{
|
|
8534
|
+
text: "Write each GitHub issue, pull request, or commit reference with its repository, such as owner/repo#123 or owner/repo@abc1234, and not in code formatting. A bare #123, GH-123, or SHA is ambiguous when a conversation spans several repositories."
|
|
8535
|
+
}
|
|
8536
|
+
];
|
|
8336
8537
|
},
|
|
8337
8538
|
async heartbeat(ctx) {
|
|
8338
8539
|
const db = ctx.db;
|