@sentry/junior-github 0.294.0 → 0.295.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/{chunk-J4ZSG7SD.js → chunk-D74ZUIJR.js} +14 -5
- package/dist/credential-support.d.ts +2 -1
- package/dist/default-branch.d.ts +15 -0
- package/dist/egress-policy.d.ts +7 -2
- package/dist/index.js +635 -193
- package/dist/receive-pack-policy.d.ts +21 -0
- package/dist/testing.js +1 -1
- package/dist/tools/update-pull-request-feedback.d.ts +15 -5
- package/dist/webhooks/handler.d.ts +2 -0
- package/dist/webhooks/installation-requests.d.ts +3 -2
- package/dist/webhooks/pull-request-ready.d.ts +3 -2
- package/dist/webhooks/pull-request-review-request.d.ts +32 -0
- package/package.json +4 -2
- package/skills/github-code/references/api-surface.md +1 -1
- package/skills/github-code/references/troubleshooting-workarounds.md +1 -0
package/dist/index.js
CHANGED
|
@@ -59,7 +59,7 @@ import {
|
|
|
59
59
|
readGrantPermissions,
|
|
60
60
|
requireEnv,
|
|
61
61
|
resolveUserAccount
|
|
62
|
-
} from "./chunk-
|
|
62
|
+
} from "./chunk-D74ZUIJR.js";
|
|
63
63
|
|
|
64
64
|
// src/tool-support/attribution.ts
|
|
65
65
|
import * as z from "zod";
|
|
@@ -156,8 +156,8 @@ var GITHUB_REQUEST_ATTRIBUTION_END = "<!-- junior-request-attribution:end -->";
|
|
|
156
156
|
var SLACK_USER_ID_DISPLAY_PATTERN = /^[UW][A-Z0-9]{5,}$/;
|
|
157
157
|
var GITHUB_LOGIN_PATTERN = /^[A-Za-z0-9][A-Za-z0-9_-]{0,99}$/;
|
|
158
158
|
function linkedGitHubLogin(user) {
|
|
159
|
-
const
|
|
160
|
-
return
|
|
159
|
+
const login2 = user?.identities.find((identity) => identity.provider === "github")?.handle?.trim().replace(/^@/, "");
|
|
160
|
+
return login2 && GITHUB_LOGIN_PATTERN.test(login2) ? login2 : void 0;
|
|
161
161
|
}
|
|
162
162
|
function cleanDisplayValue(value, userId) {
|
|
163
163
|
const cleaned = value?.replace(/[\r\n<>]/g, " ").trim();
|
|
@@ -192,9 +192,9 @@ function requesterLabel(args) {
|
|
|
192
192
|
if (!actor || actor.platform === "system") {
|
|
193
193
|
return void 0;
|
|
194
194
|
}
|
|
195
|
-
const
|
|
196
|
-
if (
|
|
197
|
-
return `@${
|
|
195
|
+
const login2 = linkedGitHubLogin(user);
|
|
196
|
+
if (login2) {
|
|
197
|
+
return `@${login2}`;
|
|
198
198
|
}
|
|
199
199
|
const userId = actor.userId;
|
|
200
200
|
const display = cleanDisplayValue(user?.displayName, userId) ?? cleanDisplayValue(identity?.displayName, userId) ?? cleanDisplayValue(identity?.handle, userId) ?? cleanDisplayValue(actor.fullName, userId) ?? cleanDisplayValue(actor.userName, userId);
|
|
@@ -854,11 +854,11 @@ function githubLinkedIssues(body, repositoryFullName) {
|
|
|
854
854
|
if (!body) return [];
|
|
855
855
|
const references = /* @__PURE__ */ new Map();
|
|
856
856
|
const add = (linkedRepository, rawNumber) => {
|
|
857
|
-
const
|
|
858
|
-
if (!Number.isInteger(
|
|
857
|
+
const number27 = Number.parseInt(rawNumber, 10);
|
|
858
|
+
if (!Number.isInteger(number27) || number27 <= 0) return;
|
|
859
859
|
const normalizedRepository = linkedRepository.toLowerCase();
|
|
860
|
-
references.set(`${normalizedRepository}#${
|
|
861
|
-
number:
|
|
860
|
+
references.set(`${normalizedRepository}#${number27}`, {
|
|
861
|
+
number: number27,
|
|
862
862
|
repositoryFullName: linkedRepository
|
|
863
863
|
});
|
|
864
864
|
};
|
|
@@ -1354,7 +1354,7 @@ var outputSchema5 = pluginToolOutputSchema6.merge(
|
|
|
1354
1354
|
issueSchema.extend({ target: z8.literal("getIssue") })
|
|
1355
1355
|
);
|
|
1356
1356
|
var providerIssueSchema = z8.object({
|
|
1357
|
-
assignees: z8.array(z8.object({ login: z8.string() })).nullish().transform((assignees) => assignees?.map(({ login }) =>
|
|
1357
|
+
assignees: z8.array(z8.object({ login: z8.string() })).nullish().transform((assignees) => assignees?.map(({ login: login2 }) => login2) ?? []),
|
|
1358
1358
|
body: z8.string().nullable().optional().default(null),
|
|
1359
1359
|
comments: z8.number().optional().default(0),
|
|
1360
1360
|
html_url: z8.string(),
|
|
@@ -1395,8 +1395,8 @@ function createGitHubGetIssueTool(ctx) {
|
|
|
1395
1395
|
}
|
|
1396
1396
|
const issue = providerIssueSchema.parse(response.body);
|
|
1397
1397
|
const repoRef = issueRepoRef(issue.repository_url) ?? repo.ref;
|
|
1398
|
-
const
|
|
1399
|
-
const needsClaim =
|
|
1398
|
+
const login2 = linkedGitHubLogin(requester?.user)?.toLowerCase();
|
|
1399
|
+
const needsClaim = login2 !== void 0 && issue.state === "open" && !issue.assignees.some((assignee) => assignee.toLowerCase() === login2);
|
|
1400
1400
|
const subscribable = gitHubIssueSubscribable({
|
|
1401
1401
|
canSubscribe: ctx.events.canSubscribe,
|
|
1402
1402
|
number: issue.number,
|
|
@@ -2583,7 +2583,7 @@ var outputSchema10 = pluginToolOutputSchema12.merge(
|
|
|
2583
2583
|
})
|
|
2584
2584
|
);
|
|
2585
2585
|
var providerIssueSchema2 = z17.object({
|
|
2586
|
-
assignees: z17.array(z17.object({ login: z17.string() })).nullish().transform((assignees) => assignees?.map(({ login }) =>
|
|
2586
|
+
assignees: z17.array(z17.object({ login: z17.string() })).nullish().transform((assignees) => assignees?.map(({ login: login2 }) => login2) ?? []),
|
|
2587
2587
|
body: z17.string().nullable().optional().default(null),
|
|
2588
2588
|
html_url: z17.string(),
|
|
2589
2589
|
number: z17.number(),
|
|
@@ -2674,7 +2674,7 @@ function createGitHubUpdateIssueTool(ctx) {
|
|
|
2674
2674
|
}
|
|
2675
2675
|
const providerResult = providerIssueSchema2.parse(parsed);
|
|
2676
2676
|
if (assignee && !providerResult.assignees.some(
|
|
2677
|
-
(
|
|
2677
|
+
(login2) => login2.toLowerCase() === assignee.toLowerCase()
|
|
2678
2678
|
)) {
|
|
2679
2679
|
throw new PluginToolInputError12(
|
|
2680
2680
|
`GitHub did not assign @${assignee} to the issue. They may not have access to ${repo.ref}.`
|
|
@@ -2927,14 +2927,26 @@ var STATUS_TO_REACTION_CONTENT = {
|
|
|
2927
2927
|
var FEEDBACK_REACTION_CONTENTS = new Set(
|
|
2928
2928
|
Object.values(STATUS_TO_REACTION_CONTENT)
|
|
2929
2929
|
);
|
|
2930
|
+
var GRAPHQL_REACTION_CONTENT = {
|
|
2931
|
+
eyes: "EYES",
|
|
2932
|
+
"+1": "THUMBS_UP",
|
|
2933
|
+
"-1": "THUMBS_DOWN"
|
|
2934
|
+
};
|
|
2935
|
+
var REST_REACTION_CONTENT = new Map(
|
|
2936
|
+
Object.entries(GRAPHQL_REACTION_CONTENT).map(([rest, graphql]) => [
|
|
2937
|
+
graphql,
|
|
2938
|
+
rest
|
|
2939
|
+
])
|
|
2940
|
+
);
|
|
2930
2941
|
var inputSchema12 = z19.object({
|
|
2931
2942
|
repo: z19.string().describe('Repository in "owner/name" format.'),
|
|
2932
|
-
comment_kind: z19.enum(["conversation", "review"]).describe(
|
|
2933
|
-
'Comment kind: "conversation" for a pull request conversation comment, "review" for an inline review comment.'
|
|
2943
|
+
comment_kind: z19.enum(["conversation", "review", "review_body"]).describe(
|
|
2944
|
+
'Comment kind: "conversation" for a pull request conversation comment, "review" for an inline review comment, "review_body" for the body of a submitted review.'
|
|
2934
2945
|
),
|
|
2935
2946
|
comment_id: z19.number().int().positive().describe(
|
|
2936
|
-
"GitHub comment id (conversation comment id
|
|
2947
|
+
"GitHub comment id (conversation comment id, inline review comment id, or review id)."
|
|
2937
2948
|
),
|
|
2949
|
+
pull_request: z19.number().int().positive().describe("Pull request number that the comment is on."),
|
|
2938
2950
|
status: z19.enum(["addressed", "declined"]).describe(
|
|
2939
2951
|
"Feedback outcome. Maps to a reaction: addressed -> +1, declined -> -1."
|
|
2940
2952
|
)
|
|
@@ -2943,8 +2955,7 @@ var outputSchema12 = pluginToolOutputSchema14.extend({
|
|
|
2943
2955
|
target: z19.literal("updatePullRequestFeedback"),
|
|
2944
2956
|
repo: z19.string(),
|
|
2945
2957
|
comment_id: z19.number(),
|
|
2946
|
-
status: z19.enum(["addressed", "declined"])
|
|
2947
|
-
reaction_id: z19.number()
|
|
2958
|
+
status: z19.enum(["addressed", "declined"])
|
|
2948
2959
|
});
|
|
2949
2960
|
function pullRequestCommentPath(input) {
|
|
2950
2961
|
const segment = input.commentKind === "conversation" ? "issues" : "pulls";
|
|
@@ -2961,7 +2972,7 @@ var reactionSchema = z19.object({
|
|
|
2961
2972
|
content: z19.string(),
|
|
2962
2973
|
user: z19.object({ id: z19.number() }).nullable()
|
|
2963
2974
|
});
|
|
2964
|
-
async function
|
|
2975
|
+
async function commentParentNumber(egress, input) {
|
|
2965
2976
|
const commentResponse = await githubApi(egress, {
|
|
2966
2977
|
operation: "github.pull.comment.get",
|
|
2967
2978
|
path: pullRequestCommentPath(input)
|
|
@@ -2977,13 +2988,17 @@ async function assertBotAuthoredPullRequest(egress, input) {
|
|
|
2977
2988
|
pull_request_url: z19.string().optional()
|
|
2978
2989
|
}).safeParse(commentPayload);
|
|
2979
2990
|
const parentUrl = comment.success ? input.commentKind === "conversation" ? comment.data.issue_url : comment.data.pull_request_url : void 0;
|
|
2980
|
-
const
|
|
2981
|
-
if (!
|
|
2991
|
+
const number27 = /\/(?:issues|pulls)\/(\d+)$/.exec(parentUrl ?? "")?.[1];
|
|
2992
|
+
if (!number27) {
|
|
2982
2993
|
throw new Error("GitHub comment did not name its issue or pull request.");
|
|
2983
2994
|
}
|
|
2995
|
+
return number27;
|
|
2996
|
+
}
|
|
2997
|
+
async function assertBotAuthoredPullRequest(egress, input) {
|
|
2998
|
+
const { number: number27 } = input;
|
|
2984
2999
|
const pullResponse = await githubApi(egress, {
|
|
2985
3000
|
operation: "github.pull.get",
|
|
2986
|
-
path: `${repoPath(input)}/pulls/${
|
|
3001
|
+
path: `${repoPath(input)}/pulls/${number27}`
|
|
2987
3002
|
});
|
|
2988
3003
|
const pullPayload = pullResponse.body;
|
|
2989
3004
|
if (!pullResponse.ok && pullResponse.status !== 404) {
|
|
@@ -2998,6 +3013,119 @@ async function assertBotAuthoredPullRequest(egress, input) {
|
|
|
2998
3013
|
);
|
|
2999
3014
|
}
|
|
3000
3015
|
}
|
|
3016
|
+
function pullRequestReviewPath(input) {
|
|
3017
|
+
return `${repoPath(input)}/pulls/${input.pullRequest}/reviews/${input.reviewId}`;
|
|
3018
|
+
}
|
|
3019
|
+
function graphqlReactionContent(content) {
|
|
3020
|
+
return GRAPHQL_REACTION_CONTENT[content] ?? content;
|
|
3021
|
+
}
|
|
3022
|
+
var ADD_REVIEW_REACTION_MUTATION = `mutation AddReviewReaction($subjectId: ID!, $content: ReactionContent!) {
|
|
3023
|
+
addReaction(input: {subjectId: $subjectId, content: $content}) {
|
|
3024
|
+
reaction { content }
|
|
3025
|
+
}
|
|
3026
|
+
}`;
|
|
3027
|
+
var REMOVE_REVIEW_REACTION_MUTATION = `mutation RemoveReviewReaction($subjectId: ID!, $content: ReactionContent!) {
|
|
3028
|
+
removeReaction(input: {subjectId: $subjectId, content: $content}) {
|
|
3029
|
+
reaction { content }
|
|
3030
|
+
}
|
|
3031
|
+
}`;
|
|
3032
|
+
var REVIEW_REACTIONS_QUERY = `query ReviewReactions($subjectId: ID!) {
|
|
3033
|
+
node(id: $subjectId) {
|
|
3034
|
+
... on PullRequestReview {
|
|
3035
|
+
reactionGroups {
|
|
3036
|
+
content
|
|
3037
|
+
reactors(first: 100) { nodes { ... on Bot { databaseId } } }
|
|
3038
|
+
}
|
|
3039
|
+
}
|
|
3040
|
+
}
|
|
3041
|
+
}`;
|
|
3042
|
+
var reviewReactionsSchema = z19.object({
|
|
3043
|
+
data: z19.object({
|
|
3044
|
+
node: z19.object({
|
|
3045
|
+
reactionGroups: z19.array(
|
|
3046
|
+
z19.object({
|
|
3047
|
+
content: z19.string(),
|
|
3048
|
+
reactors: z19.object({
|
|
3049
|
+
nodes: z19.array(z19.object({ databaseId: z19.number().optional() }))
|
|
3050
|
+
})
|
|
3051
|
+
})
|
|
3052
|
+
)
|
|
3053
|
+
})
|
|
3054
|
+
})
|
|
3055
|
+
});
|
|
3056
|
+
async function commentReactions(egress, input) {
|
|
3057
|
+
const parentNumber = await commentParentNumber(egress, input);
|
|
3058
|
+
if (parentNumber !== String(input.pullRequest)) {
|
|
3059
|
+
throw new PluginToolInputError14(
|
|
3060
|
+
`GitHub comment ${input.commentId} is not on pull request ${input.pullRequest}.`
|
|
3061
|
+
);
|
|
3062
|
+
}
|
|
3063
|
+
const path = pullRequestCommentReactionsPath(input);
|
|
3064
|
+
return {
|
|
3065
|
+
list: () => githubApi(egress, {
|
|
3066
|
+
operation: "github.pull.comment-reaction.list",
|
|
3067
|
+
path: `${path}?per_page=100`
|
|
3068
|
+
}),
|
|
3069
|
+
botReactions: (body) => z19.array(reactionSchema).parse(body).filter((reaction) => reaction.user?.id === input.botUserId),
|
|
3070
|
+
remove: (reaction) => githubApi(egress, {
|
|
3071
|
+
operation: "github.pull.comment-reaction.delete",
|
|
3072
|
+
method: "DELETE",
|
|
3073
|
+
path: `${path}/${reaction.id}`
|
|
3074
|
+
}),
|
|
3075
|
+
add: (content) => githubApi(egress, {
|
|
3076
|
+
operation: "github.pull.comment-reaction.create",
|
|
3077
|
+
method: "POST",
|
|
3078
|
+
path,
|
|
3079
|
+
body: { content }
|
|
3080
|
+
})
|
|
3081
|
+
};
|
|
3082
|
+
}
|
|
3083
|
+
async function reviewBodyReactions(egress, input) {
|
|
3084
|
+
const reviewResponse = await githubApi(egress, {
|
|
3085
|
+
operation: "github.pull.review.get",
|
|
3086
|
+
path: pullRequestReviewPath(input)
|
|
3087
|
+
});
|
|
3088
|
+
if (!reviewResponse.ok) {
|
|
3089
|
+
const message = `GitHub review lookup failed with HTTP ${reviewResponse.status}: ${githubErrorMessage(reviewResponse.body)}`;
|
|
3090
|
+
if (reviewResponse.status === 404) throw new PluginToolInputError14(message);
|
|
3091
|
+
throw new Error(message);
|
|
3092
|
+
}
|
|
3093
|
+
const subjectId = z19.object({ node_id: z19.string().min(1) }).parse(reviewResponse.body).node_id;
|
|
3094
|
+
const graphql = (operation, operationName, query, variables) => githubApi(egress, {
|
|
3095
|
+
operation,
|
|
3096
|
+
method: "POST",
|
|
3097
|
+
path: "/graphql",
|
|
3098
|
+
body: { operationName, query, variables }
|
|
3099
|
+
});
|
|
3100
|
+
const update = `github.pull.review-reaction.update:${input.owner}/${input.name}`.toLowerCase();
|
|
3101
|
+
return {
|
|
3102
|
+
list: () => graphql(
|
|
3103
|
+
"github.pull.review-reaction.list",
|
|
3104
|
+
"ReviewReactions",
|
|
3105
|
+
REVIEW_REACTIONS_QUERY,
|
|
3106
|
+
{ subjectId }
|
|
3107
|
+
),
|
|
3108
|
+
botReactions: (body) => reviewReactionsSchema.parse(body).data.node.reactionGroups.filter(
|
|
3109
|
+
(group) => group.reactors.nodes.some(
|
|
3110
|
+
(reactor) => reactor.databaseId === input.botUserId
|
|
3111
|
+
)
|
|
3112
|
+
).map((group) => ({
|
|
3113
|
+
content: REST_REACTION_CONTENT.get(group.content) ?? group.content
|
|
3114
|
+
})),
|
|
3115
|
+
remove: (reaction) => graphql(update, "RemoveReviewReaction", REMOVE_REVIEW_REACTION_MUTATION, {
|
|
3116
|
+
subjectId,
|
|
3117
|
+
content: graphqlReactionContent(reaction.content)
|
|
3118
|
+
}),
|
|
3119
|
+
add: (content) => graphql(update, "AddReviewReaction", ADD_REVIEW_REACTION_MUTATION, {
|
|
3120
|
+
subjectId,
|
|
3121
|
+
content: graphqlReactionContent(content)
|
|
3122
|
+
})
|
|
3123
|
+
};
|
|
3124
|
+
}
|
|
3125
|
+
function failed(response) {
|
|
3126
|
+
const errors = response.body?.errors;
|
|
3127
|
+
return !response.ok || Array.isArray(errors) && errors.length > 0;
|
|
3128
|
+
}
|
|
3001
3129
|
function createGitHubUpdatePullRequestFeedbackTool(ctx, botEmail) {
|
|
3002
3130
|
return definePluginTool14({
|
|
3003
3131
|
// No action review: the tool checks in code that the bot authored the pull
|
|
@@ -3009,7 +3137,7 @@ function createGitHubUpdatePullRequestFeedbackTool(ctx, botEmail) {
|
|
|
3009
3137
|
openWorldHint: true,
|
|
3010
3138
|
readOnlyHint: false
|
|
3011
3139
|
},
|
|
3012
|
-
description: "Set your outcome reaction on GitHub pull request feedback: addressed (+1) or declined (-1). Use the comment_id and comment_kind from the event after acting on the feedback. Replaces only your prior status reaction on that comment. Only works on pull requests the bot authored.",
|
|
3140
|
+
description: "Set your outcome reaction on GitHub pull request feedback: addressed (+1) or declined (-1). Use the pull_request, comment_id, and comment_kind from the event after acting on the feedback. Replaces only your prior status reaction on that comment. Only works on pull requests the bot authored.",
|
|
3013
3141
|
exposure: "direct",
|
|
3014
3142
|
inputSchema: inputSchema12,
|
|
3015
3143
|
outputSchema: outputSchema12,
|
|
@@ -3024,6 +3152,7 @@ function createGitHubUpdatePullRequestFeedbackTool(ctx, botEmail) {
|
|
|
3024
3152
|
const {
|
|
3025
3153
|
comment_id: commentId,
|
|
3026
3154
|
comment_kind: commentKind,
|
|
3155
|
+
pull_request: pullRequest,
|
|
3027
3156
|
status
|
|
3028
3157
|
} = parsedInput.data;
|
|
3029
3158
|
const repo = parseRepo(parsedInput.data.repo);
|
|
@@ -3034,74 +3163,55 @@ function createGitHubUpdatePullRequestFeedbackTool(ctx, botEmail) {
|
|
|
3034
3163
|
await assertBotAuthoredPullRequest(ctx.egress, {
|
|
3035
3164
|
owner: repo.owner,
|
|
3036
3165
|
name: repo.name,
|
|
3037
|
-
|
|
3038
|
-
commentId,
|
|
3166
|
+
number: pullRequest,
|
|
3039
3167
|
botUserId
|
|
3040
3168
|
});
|
|
3041
|
-
const
|
|
3042
|
-
|
|
3169
|
+
const reactions = commentKind === "review_body" ? await reviewBodyReactions(ctx.egress, {
|
|
3170
|
+
owner: repo.owner,
|
|
3171
|
+
name: repo.name,
|
|
3172
|
+
pullRequest,
|
|
3173
|
+
reviewId: commentId,
|
|
3174
|
+
botUserId
|
|
3175
|
+
}) : await commentReactions(ctx.egress, {
|
|
3043
3176
|
owner: repo.owner,
|
|
3044
3177
|
name: repo.name,
|
|
3045
3178
|
commentKind,
|
|
3046
|
-
commentId
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
operation: "github.pull.comment-reaction.list",
|
|
3050
|
-
path: `${reactionsPath}?per_page=100`
|
|
3179
|
+
commentId,
|
|
3180
|
+
pullRequest,
|
|
3181
|
+
botUserId
|
|
3051
3182
|
});
|
|
3183
|
+
const targetContent = pullRequestFeedbackReactionContent(status);
|
|
3184
|
+
const listResponse = await reactions.list();
|
|
3052
3185
|
const listPayload = listResponse.body;
|
|
3053
|
-
if (
|
|
3186
|
+
if (failed(listResponse)) {
|
|
3054
3187
|
throw new Error(
|
|
3055
3188
|
`GitHub reaction lookup failed with HTTP ${listResponse.status}: ${githubErrorMessage(listPayload)}`
|
|
3056
3189
|
);
|
|
3057
3190
|
}
|
|
3058
|
-
const botReactions =
|
|
3059
|
-
(reaction) => reaction.user?.id === botUserId && FEEDBACK_REACTION_CONTENTS.has(reaction.content)
|
|
3060
|
-
);
|
|
3061
|
-
const existing = botReactions.find(
|
|
3062
|
-
(reaction) => reaction.content === targetContent
|
|
3063
|
-
);
|
|
3191
|
+
const botReactions = reactions.botReactions(listPayload).filter((reaction) => FEEDBACK_REACTION_CONTENTS.has(reaction.content));
|
|
3064
3192
|
for (const stale of botReactions) {
|
|
3065
3193
|
if (stale.content === targetContent) continue;
|
|
3066
|
-
const deleteResponse = await
|
|
3067
|
-
|
|
3068
|
-
method: "DELETE",
|
|
3069
|
-
path: `${reactionsPath}/${stale.id}`
|
|
3070
|
-
});
|
|
3071
|
-
if (!deleteResponse.ok && deleteResponse.status !== 404) {
|
|
3194
|
+
const deleteResponse = await reactions.remove(stale);
|
|
3195
|
+
if (failed(deleteResponse) && deleteResponse.status !== 404) {
|
|
3072
3196
|
throw new Error(
|
|
3073
3197
|
`GitHub reaction removal failed with HTTP ${deleteResponse.status}: ${githubErrorMessage(deleteResponse.body)}`
|
|
3074
3198
|
);
|
|
3075
3199
|
}
|
|
3076
3200
|
}
|
|
3077
|
-
if (
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
}
|
|
3085
|
-
}
|
|
3086
|
-
const createResponse = await githubApi(ctx.egress, {
|
|
3087
|
-
operation: "github.pull.comment-reaction.create",
|
|
3088
|
-
method: "POST",
|
|
3089
|
-
path: reactionsPath,
|
|
3090
|
-
body: { content: targetContent }
|
|
3091
|
-
});
|
|
3092
|
-
const createPayload = createResponse.body;
|
|
3093
|
-
if (!createResponse.ok) {
|
|
3094
|
-
throw new Error(
|
|
3095
|
-
`GitHub reaction creation failed with HTTP ${createResponse.status}: ${githubErrorMessage(createPayload)}`
|
|
3096
|
-
);
|
|
3201
|
+
if (!botReactions.some((reaction) => reaction.content === targetContent)) {
|
|
3202
|
+
const createResponse = await reactions.add(targetContent);
|
|
3203
|
+
const createPayload = createResponse.body;
|
|
3204
|
+
if (failed(createResponse)) {
|
|
3205
|
+
throw new Error(
|
|
3206
|
+
`GitHub reaction creation failed with HTTP ${createResponse.status}: ${githubErrorMessage(createPayload)}`
|
|
3207
|
+
);
|
|
3208
|
+
}
|
|
3097
3209
|
}
|
|
3098
|
-
const created = reactionSchema.parse(createPayload);
|
|
3099
3210
|
return {
|
|
3100
3211
|
target: "updatePullRequestFeedback",
|
|
3101
3212
|
repo: repo.ref,
|
|
3102
3213
|
comment_id: commentId,
|
|
3103
|
-
status
|
|
3104
|
-
reaction_id: created.id
|
|
3214
|
+
status
|
|
3105
3215
|
};
|
|
3106
3216
|
}
|
|
3107
3217
|
});
|
|
@@ -3394,7 +3504,7 @@ function createGitHubTools(ctx, botEmail, pullRequestSubscription) {
|
|
|
3394
3504
|
|
|
3395
3505
|
// src/webhooks/handler.ts
|
|
3396
3506
|
import { createHmac, timingSafeEqual } from "crypto";
|
|
3397
|
-
import * as
|
|
3507
|
+
import * as z34 from "zod";
|
|
3398
3508
|
|
|
3399
3509
|
// src/issue-outcomes/store.ts
|
|
3400
3510
|
import { and as and2, eq as eq2, lte, sql as sql2 } from "drizzle-orm";
|
|
@@ -4264,6 +4374,41 @@ async function markPullRequestFeedbackReviewing(env, target) {
|
|
|
4264
4374
|
...env,
|
|
4265
4375
|
repositories: [name]
|
|
4266
4376
|
});
|
|
4377
|
+
const content = pullRequestFeedbackReactionContent("reviewing");
|
|
4378
|
+
if (target.commentKind === "review_body") {
|
|
4379
|
+
const review = z29.object({ node_id: z29.string().min(1) }).parse(
|
|
4380
|
+
await githubRequest(
|
|
4381
|
+
"https://api.github.com",
|
|
4382
|
+
pullRequestReviewPath({
|
|
4383
|
+
owner,
|
|
4384
|
+
name,
|
|
4385
|
+
pullRequest: target.pullRequest,
|
|
4386
|
+
reviewId: target.commentId
|
|
4387
|
+
}),
|
|
4388
|
+
{ token: token.token }
|
|
4389
|
+
)
|
|
4390
|
+
);
|
|
4391
|
+
const result = z29.object({ errors: z29.array(z29.unknown()).optional() }).parse(
|
|
4392
|
+
await githubRequest("https://api.github.com", "/graphql", {
|
|
4393
|
+
body: {
|
|
4394
|
+
operationName: "AddReviewReaction",
|
|
4395
|
+
query: ADD_REVIEW_REACTION_MUTATION,
|
|
4396
|
+
variables: {
|
|
4397
|
+
content: graphqlReactionContent(content),
|
|
4398
|
+
subjectId: review.node_id
|
|
4399
|
+
}
|
|
4400
|
+
},
|
|
4401
|
+
method: "POST",
|
|
4402
|
+
token: token.token
|
|
4403
|
+
})
|
|
4404
|
+
);
|
|
4405
|
+
if (result.errors?.length) {
|
|
4406
|
+
throw new Error(
|
|
4407
|
+
`GitHub review reaction failed: ${githubErrorMessage(result)}`
|
|
4408
|
+
);
|
|
4409
|
+
}
|
|
4410
|
+
return;
|
|
4411
|
+
}
|
|
4267
4412
|
await githubRequest(
|
|
4268
4413
|
"https://api.github.com",
|
|
4269
4414
|
pullRequestCommentReactionsPath({
|
|
@@ -4273,7 +4418,7 @@ async function markPullRequestFeedbackReviewing(env, target) {
|
|
|
4273
4418
|
commentId: target.commentId
|
|
4274
4419
|
}),
|
|
4275
4420
|
{
|
|
4276
|
-
body: { content
|
|
4421
|
+
body: { content },
|
|
4277
4422
|
method: "POST",
|
|
4278
4423
|
token: token.token
|
|
4279
4424
|
}
|
|
@@ -4458,7 +4603,8 @@ async function syncOne(args, target) {
|
|
|
4458
4603
|
body: `**${state.title}** is approved, and GitHub says that it can merge: ${state.url}`,
|
|
4459
4604
|
dedupeKey,
|
|
4460
4605
|
subject: { id: state.url, title: name, url: state.url },
|
|
4461
|
-
title: `Ready to merge
|
|
4606
|
+
title: `Ready to merge \xB7 #${target.number}`,
|
|
4607
|
+
waitsOnAssignees: true
|
|
4462
4608
|
});
|
|
4463
4609
|
} else {
|
|
4464
4610
|
await items.close({ dedupeKey, ...closeReason(state) });
|
|
@@ -4491,8 +4637,158 @@ async function syncGitHubPullRequestReadyNotices(args) {
|
|
|
4491
4637
|
}
|
|
4492
4638
|
}
|
|
4493
4639
|
|
|
4494
|
-
// src/webhooks/pull-request-
|
|
4640
|
+
// src/webhooks/pull-request-review-request.ts
|
|
4495
4641
|
import * as z31 from "zod";
|
|
4642
|
+
var login = z31.object({ login: z31.string().min(1) });
|
|
4643
|
+
var pullRequestEventSchema = z31.object({
|
|
4644
|
+
action: z31.enum([
|
|
4645
|
+
"closed",
|
|
4646
|
+
"reopened",
|
|
4647
|
+
"review_request_removed",
|
|
4648
|
+
"review_requested"
|
|
4649
|
+
]),
|
|
4650
|
+
pull_request: z31.object({
|
|
4651
|
+
html_url: z31.string().url(),
|
|
4652
|
+
merged: z31.boolean().optional(),
|
|
4653
|
+
number: z31.number().int().positive(),
|
|
4654
|
+
// The people whose review is still requested. Teams are listed apart.
|
|
4655
|
+
requested_reviewers: z31.array(login).optional(),
|
|
4656
|
+
title: z31.string()
|
|
4657
|
+
}),
|
|
4658
|
+
repository: z31.object({ full_name: z31.string().min(1) }),
|
|
4659
|
+
// A team request has `requested_team` instead.
|
|
4660
|
+
requested_reviewer: login.optional()
|
|
4661
|
+
});
|
|
4662
|
+
var reviewEventSchema = z31.object({
|
|
4663
|
+
action: z31.literal("submitted"),
|
|
4664
|
+
pull_request: z31.object({ number: z31.number().int().positive() }),
|
|
4665
|
+
repository: z31.object({ full_name: z31.string().min(1) }),
|
|
4666
|
+
review: z31.object({ user: login })
|
|
4667
|
+
});
|
|
4668
|
+
function reviewRequestChange(eventName, body) {
|
|
4669
|
+
if (eventName === "pull_request_review") {
|
|
4670
|
+
const parsed2 = reviewEventSchema.safeParse(body);
|
|
4671
|
+
if (!parsed2.success) return void 0;
|
|
4672
|
+
return {
|
|
4673
|
+
change: {
|
|
4674
|
+
kind: "ended",
|
|
4675
|
+
reason: "The requester reviewed the pull request.",
|
|
4676
|
+
reviewer: parsed2.data.review.user.login,
|
|
4677
|
+
status: "done"
|
|
4678
|
+
},
|
|
4679
|
+
number: parsed2.data.pull_request.number,
|
|
4680
|
+
repository: parsed2.data.repository.full_name
|
|
4681
|
+
};
|
|
4682
|
+
}
|
|
4683
|
+
if (eventName !== "pull_request") return void 0;
|
|
4684
|
+
const parsed = pullRequestEventSchema.safeParse(body);
|
|
4685
|
+
if (!parsed.success) return void 0;
|
|
4686
|
+
const { action, pull_request: pull } = parsed.data;
|
|
4687
|
+
const reviewer = parsed.data.requested_reviewer?.login;
|
|
4688
|
+
const target = {
|
|
4689
|
+
number: pull.number,
|
|
4690
|
+
repository: parsed.data.repository.full_name
|
|
4691
|
+
};
|
|
4692
|
+
if (action === "reopened") {
|
|
4693
|
+
const reviewers = (pull.requested_reviewers ?? []).map(
|
|
4694
|
+
(person2) => person2.login
|
|
4695
|
+
);
|
|
4696
|
+
if (reviewers.length === 0) return void 0;
|
|
4697
|
+
return {
|
|
4698
|
+
...target,
|
|
4699
|
+
change: {
|
|
4700
|
+
kind: "requested",
|
|
4701
|
+
reviewers,
|
|
4702
|
+
title: pull.title,
|
|
4703
|
+
url: pull.html_url
|
|
4704
|
+
}
|
|
4705
|
+
};
|
|
4706
|
+
}
|
|
4707
|
+
if (action !== "closed" && !reviewer) {
|
|
4708
|
+
return void 0;
|
|
4709
|
+
}
|
|
4710
|
+
if (action === "review_requested" && reviewer) {
|
|
4711
|
+
return {
|
|
4712
|
+
...target,
|
|
4713
|
+
change: {
|
|
4714
|
+
kind: "requested",
|
|
4715
|
+
reviewers: [reviewer],
|
|
4716
|
+
title: pull.title,
|
|
4717
|
+
url: pull.html_url
|
|
4718
|
+
}
|
|
4719
|
+
};
|
|
4720
|
+
}
|
|
4721
|
+
if (action === "review_request_removed") {
|
|
4722
|
+
return {
|
|
4723
|
+
...target,
|
|
4724
|
+
change: {
|
|
4725
|
+
kind: "ended",
|
|
4726
|
+
reason: "The review request was removed.",
|
|
4727
|
+
reviewer,
|
|
4728
|
+
status: "dismissed"
|
|
4729
|
+
}
|
|
4730
|
+
};
|
|
4731
|
+
}
|
|
4732
|
+
return {
|
|
4733
|
+
...target,
|
|
4734
|
+
change: pull.merged ? { kind: "ended", reason: "The pull request merged.", status: "done" } : {
|
|
4735
|
+
kind: "ended",
|
|
4736
|
+
reason: "The pull request closed without merging.",
|
|
4737
|
+
status: "dismissed"
|
|
4738
|
+
}
|
|
4739
|
+
};
|
|
4740
|
+
}
|
|
4741
|
+
function sameLogin(left, right) {
|
|
4742
|
+
return left.toLowerCase() === right.toLowerCase();
|
|
4743
|
+
}
|
|
4744
|
+
async function syncGitHubPullRequestReviewRequest(args) {
|
|
4745
|
+
const parsed = reviewRequestChange(args.eventName, args.body);
|
|
4746
|
+
if (!parsed) return;
|
|
4747
|
+
const { change, number: number27, repository: repository2 } = parsed;
|
|
4748
|
+
try {
|
|
4749
|
+
const opener = (await listGitHubPullRequestOpeners(args.db, {
|
|
4750
|
+
numbers: [number27],
|
|
4751
|
+
repositoryFullName: repository2
|
|
4752
|
+
})).get(number27);
|
|
4753
|
+
if (!opener?.conversationId) return;
|
|
4754
|
+
const name = `${repository2}#${number27}`;
|
|
4755
|
+
const dedupeKey = `pull-request-review-requested:${name.toLowerCase()}`;
|
|
4756
|
+
const items = args.reviewItems.forConversation(opener.conversationId);
|
|
4757
|
+
const reviewers = change.kind === "requested" ? change.reviewers : change.reviewer === void 0 ? void 0 : [change.reviewer];
|
|
4758
|
+
if (reviewers !== void 0) {
|
|
4759
|
+
const requesterLogin = await args.loadGitHubLogin?.(opener.identityId);
|
|
4760
|
+
if (!requesterLogin || !reviewers.some((reviewer) => sameLogin(reviewer, requesterLogin))) {
|
|
4761
|
+
return;
|
|
4762
|
+
}
|
|
4763
|
+
}
|
|
4764
|
+
if (change.kind === "ended") {
|
|
4765
|
+
await items.close({
|
|
4766
|
+
dedupeKey,
|
|
4767
|
+
reason: change.reason,
|
|
4768
|
+
status: change.status
|
|
4769
|
+
});
|
|
4770
|
+
return;
|
|
4771
|
+
}
|
|
4772
|
+
await items.upsert({
|
|
4773
|
+
assigneeIdentityIds: [opener.identityId],
|
|
4774
|
+
body: `GitHub asks you to review **${change.title}**: ${change.url}`,
|
|
4775
|
+
dedupeKey,
|
|
4776
|
+
subject: { id: change.url, title: name, url: change.url },
|
|
4777
|
+
title: `Review requested \xB7 #${number27}`,
|
|
4778
|
+
waitsOnAssignees: true
|
|
4779
|
+
});
|
|
4780
|
+
} catch (error) {
|
|
4781
|
+
args.log?.error("GitHub pull request review request failed", {
|
|
4782
|
+
deliveryId: args.deliveryId,
|
|
4783
|
+
errorType: error instanceof Error ? error.name : "UnknownError",
|
|
4784
|
+
number: number27,
|
|
4785
|
+
repository: repository2
|
|
4786
|
+
});
|
|
4787
|
+
}
|
|
4788
|
+
}
|
|
4789
|
+
|
|
4790
|
+
// src/webhooks/pull-request-match-data.ts
|
|
4791
|
+
import * as z32 from "zod";
|
|
4496
4792
|
var LOOKUPS_BY_MATCH_KEY = {
|
|
4497
4793
|
authors: ["authors"],
|
|
4498
4794
|
openerEmail: ["opener"],
|
|
@@ -4500,22 +4796,22 @@ var LOOKUPS_BY_MATCH_KEY = {
|
|
|
4500
4796
|
openerUsername: ["opener"]
|
|
4501
4797
|
};
|
|
4502
4798
|
var ALL_LOOKUPS = ["authors", "opener", "openerRole"];
|
|
4503
|
-
var lookupDataSchema =
|
|
4504
|
-
authors:
|
|
4505
|
-
openerRole:
|
|
4506
|
-
openerUsername:
|
|
4799
|
+
var lookupDataSchema = z32.object({
|
|
4800
|
+
authors: z32.array(z32.string().min(1)).min(1).optional(),
|
|
4801
|
+
openerRole: z32.string().min(1).optional(),
|
|
4802
|
+
openerUsername: z32.string().min(1).optional()
|
|
4507
4803
|
}).strict();
|
|
4508
4804
|
function lookupData(input) {
|
|
4509
4805
|
return lookupDataSchema.parse(definedValues(input));
|
|
4510
4806
|
}
|
|
4511
|
-
var webhookSchema =
|
|
4512
|
-
repository:
|
|
4807
|
+
var webhookSchema = z32.object({
|
|
4808
|
+
repository: z32.object({ full_name: z32.string().min(1) })
|
|
4513
4809
|
});
|
|
4514
4810
|
function pullRequestNumbers(events) {
|
|
4515
4811
|
const numbers = /* @__PURE__ */ new Map();
|
|
4516
4812
|
for (const event of events) {
|
|
4517
|
-
const
|
|
4518
|
-
if (typeof
|
|
4813
|
+
const number27 = event.data?.pullRequest;
|
|
4814
|
+
if (typeof number27 === "number") numbers.set(event.eventKey, number27);
|
|
4519
4815
|
}
|
|
4520
4816
|
return numbers;
|
|
4521
4817
|
}
|
|
@@ -4529,8 +4825,8 @@ function logFailure(context, lookup, error) {
|
|
|
4529
4825
|
}
|
|
4530
4826
|
async function withJuniorOpeners(context, events) {
|
|
4531
4827
|
const botNumber = (event) => {
|
|
4532
|
-
const
|
|
4533
|
-
return
|
|
4828
|
+
const number27 = context.numbers.get(event.eventKey);
|
|
4829
|
+
return number27 !== void 0 && isBotLogin(event.data?.openerUsername, context.botEmail) ? number27 : void 0;
|
|
4534
4830
|
};
|
|
4535
4831
|
const numbers = events.flatMap((event) => botNumber(event) ?? []);
|
|
4536
4832
|
if (numbers.length === 0) return events;
|
|
@@ -4549,10 +4845,10 @@ async function withJuniorOpeners(context, events) {
|
|
|
4549
4845
|
}
|
|
4550
4846
|
}
|
|
4551
4847
|
return events.map((event) => {
|
|
4552
|
-
const
|
|
4553
|
-
if (
|
|
4554
|
-
const identityId = openers.get(
|
|
4555
|
-
const
|
|
4848
|
+
const number27 = botNumber(event);
|
|
4849
|
+
if (number27 === void 0) return event;
|
|
4850
|
+
const identityId = openers.get(number27)?.identityId;
|
|
4851
|
+
const login2 = identityId ? logins.get(identityId) : void 0;
|
|
4556
4852
|
const {
|
|
4557
4853
|
openerEmail: _email,
|
|
4558
4854
|
openerUsername: _login,
|
|
@@ -4560,7 +4856,7 @@ async function withJuniorOpeners(context, events) {
|
|
|
4560
4856
|
} = event.data ?? {};
|
|
4561
4857
|
return {
|
|
4562
4858
|
...event,
|
|
4563
|
-
data: { ...data, ...lookupData({ openerUsername:
|
|
4859
|
+
data: { ...data, ...lookupData({ openerUsername: login2 || void 0 }) }
|
|
4564
4860
|
};
|
|
4565
4861
|
});
|
|
4566
4862
|
}
|
|
@@ -4573,27 +4869,27 @@ async function withRolesAndAuthors(context, events, lookups) {
|
|
|
4573
4869
|
if (!loadRole && !loadAuthors) return events;
|
|
4574
4870
|
return await Promise.all(
|
|
4575
4871
|
events.map(async (event) => {
|
|
4576
|
-
const
|
|
4577
|
-
if (
|
|
4578
|
-
const
|
|
4579
|
-
if (loadRole && typeof
|
|
4872
|
+
const number27 = context.numbers.get(event.eventKey);
|
|
4873
|
+
if (number27 === void 0) return event;
|
|
4874
|
+
const login2 = event.data?.openerUsername;
|
|
4875
|
+
if (loadRole && typeof login2 === "string" && !roles.has(login2)) {
|
|
4580
4876
|
roles.set(
|
|
4581
|
-
|
|
4582
|
-
loadRole({ login, repositoryFullName }).catch(
|
|
4877
|
+
login2,
|
|
4878
|
+
loadRole({ login: login2, repositoryFullName }).catch(
|
|
4583
4879
|
(error) => logFailure(context, "role", error)
|
|
4584
4880
|
)
|
|
4585
4881
|
);
|
|
4586
4882
|
}
|
|
4587
|
-
if (loadAuthors && !authors.has(
|
|
4883
|
+
if (loadAuthors && !authors.has(number27)) {
|
|
4588
4884
|
authors.set(
|
|
4589
|
-
|
|
4590
|
-
loadAuthors({ number:
|
|
4885
|
+
number27,
|
|
4886
|
+
loadAuthors({ number: number27, repositoryFullName }).catch(
|
|
4591
4887
|
(error) => logFailure(context, "authors", error)
|
|
4592
4888
|
)
|
|
4593
4889
|
);
|
|
4594
4890
|
}
|
|
4595
|
-
const role = loadRole && typeof
|
|
4596
|
-
const logins = loadAuthors ? await authors.get(
|
|
4891
|
+
const role = loadRole && typeof login2 === "string" ? await roles.get(login2) : void 0;
|
|
4892
|
+
const logins = loadAuthors ? await authors.get(number27) : void 0;
|
|
4597
4893
|
if (!role && !logins?.length) return event;
|
|
4598
4894
|
return {
|
|
4599
4895
|
...event,
|
|
@@ -4650,7 +4946,7 @@ async function withGitHubPullRequestMatchData(args) {
|
|
|
4650
4946
|
}
|
|
4651
4947
|
|
|
4652
4948
|
// src/webhooks/pull-request-people.ts
|
|
4653
|
-
import * as
|
|
4949
|
+
import * as z33 from "zod";
|
|
4654
4950
|
var PEOPLE_EVENTS = /* @__PURE__ */ new Set([
|
|
4655
4951
|
"pull_request.review.approved",
|
|
4656
4952
|
"pull_request.merged"
|
|
@@ -4660,18 +4956,18 @@ var PAGE_SIZE = 100;
|
|
|
4660
4956
|
var MAX_PAGES = 3;
|
|
4661
4957
|
var CO_AUTHOR_TRAILER = /^co-authored-by:[^<\n]*<([^>\s]+@[^>\s]+)>\s*$/gim;
|
|
4662
4958
|
var GITHUB_NOREPLY_EMAIL = /^(?:\d+\+)?(?<login>[^@+]+)@users\.noreply\.github\.com$/i;
|
|
4663
|
-
var webhookSchema2 =
|
|
4664
|
-
pull_request:
|
|
4665
|
-
assignees:
|
|
4666
|
-
number:
|
|
4667
|
-
user:
|
|
4959
|
+
var webhookSchema2 = z33.object({
|
|
4960
|
+
pull_request: z33.object({
|
|
4961
|
+
assignees: z33.array(z33.object({ login: z33.string().min(1) })).nullish(),
|
|
4962
|
+
number: z33.number(),
|
|
4963
|
+
user: z33.object({ login: z33.string().min(1) }).nullish()
|
|
4668
4964
|
}),
|
|
4669
|
-
repository:
|
|
4965
|
+
repository: z33.object({ full_name: z33.string().min(1) })
|
|
4670
4966
|
});
|
|
4671
|
-
var commitPageSchema =
|
|
4672
|
-
|
|
4673
|
-
author:
|
|
4674
|
-
commit:
|
|
4967
|
+
var commitPageSchema = z33.array(
|
|
4968
|
+
z33.object({
|
|
4969
|
+
author: z33.object({ login: z33.string().min(1) }).nullish(),
|
|
4970
|
+
commit: z33.object({ message: z33.string() })
|
|
4675
4971
|
})
|
|
4676
4972
|
);
|
|
4677
4973
|
function shareCommitPages(load) {
|
|
@@ -4712,15 +5008,15 @@ function noreplyLogin(email) {
|
|
|
4712
5008
|
}
|
|
4713
5009
|
async function loadGitHubPullRequestPeople(args) {
|
|
4714
5010
|
const people = /* @__PURE__ */ new Map();
|
|
4715
|
-
const addLogin = (
|
|
4716
|
-
if (/\[bot\]$/i.test(
|
|
4717
|
-
const key = `github:${
|
|
5011
|
+
const addLogin = (login2) => {
|
|
5012
|
+
if (/\[bot\]$/i.test(login2)) return;
|
|
5013
|
+
const key = `github:${login2.toLowerCase()}`;
|
|
4718
5014
|
if (!people.has(key))
|
|
4719
|
-
people.set(key, { provider: "github", handle:
|
|
5015
|
+
people.set(key, { provider: "github", handle: login2 });
|
|
4720
5016
|
};
|
|
4721
5017
|
const addEmail = (value) => {
|
|
4722
|
-
const
|
|
4723
|
-
if (
|
|
5018
|
+
const login2 = noreplyLogin(value);
|
|
5019
|
+
if (login2) return addLogin(login2);
|
|
4724
5020
|
const email = value.toLowerCase();
|
|
4725
5021
|
if (!people.has(`email:${email}`)) {
|
|
4726
5022
|
people.set(`email:${email}`, { email });
|
|
@@ -4735,9 +5031,9 @@ async function loadGitHubPullRequestPeople(args) {
|
|
|
4735
5031
|
}
|
|
4736
5032
|
async function loadGitHubPullRequestAuthors(args) {
|
|
4737
5033
|
const authors = /* @__PURE__ */ new Map();
|
|
4738
|
-
const add = (
|
|
4739
|
-
if (
|
|
4740
|
-
authors.set(
|
|
5034
|
+
const add = (login2) => {
|
|
5035
|
+
if (login2 && !authors.has(login2.toLowerCase())) {
|
|
5036
|
+
authors.set(login2.toLowerCase(), login2);
|
|
4741
5037
|
}
|
|
4742
5038
|
};
|
|
4743
5039
|
await forEachCommit(args.loadPage, (commit) => {
|
|
@@ -4813,17 +5109,19 @@ function webhookInstallationId(body) {
|
|
|
4813
5109
|
}
|
|
4814
5110
|
return parseInstallationId(installation.id);
|
|
4815
5111
|
}
|
|
4816
|
-
var feedbackTargetSchema =
|
|
4817
|
-
commentId:
|
|
4818
|
-
commentKind:
|
|
4819
|
-
|
|
5112
|
+
var feedbackTargetSchema = z34.object({
|
|
5113
|
+
commentId: z34.number(),
|
|
5114
|
+
commentKind: z34.enum(["conversation", "review", "review_body"]),
|
|
5115
|
+
pullRequest: z34.number(),
|
|
5116
|
+
repo: z34.string().min(1)
|
|
4820
5117
|
});
|
|
4821
5118
|
function pullRequestFeedbackTarget(events) {
|
|
4822
|
-
const event
|
|
4823
|
-
(
|
|
4824
|
-
|
|
4825
|
-
|
|
4826
|
-
|
|
5119
|
+
for (const event of events) {
|
|
5120
|
+
if (!event.eventType.startsWith("pull_request.")) continue;
|
|
5121
|
+
const parsed = feedbackTargetSchema.safeParse(event.data);
|
|
5122
|
+
if (parsed.success) return parsed.data;
|
|
5123
|
+
}
|
|
5124
|
+
return void 0;
|
|
4827
5125
|
}
|
|
4828
5126
|
function githubCodeChange(outcome, conversationIds) {
|
|
4829
5127
|
return {
|
|
@@ -5064,6 +5362,15 @@ function createGitHubWebhookRoute(args) {
|
|
|
5064
5362
|
reviewItems: args.reviewItems,
|
|
5065
5363
|
targets: pullRequestReadyTargets(eventName, body)
|
|
5066
5364
|
});
|
|
5365
|
+
await syncGitHubPullRequestReviewRequest({
|
|
5366
|
+
body,
|
|
5367
|
+
db: args.db,
|
|
5368
|
+
deliveryId,
|
|
5369
|
+
eventName,
|
|
5370
|
+
loadGitHubLogin: args.loadGitHubLogin,
|
|
5371
|
+
log: args.log,
|
|
5372
|
+
reviewItems: args.reviewItems
|
|
5373
|
+
});
|
|
5067
5374
|
if (!pullRequestOutcome && !issueOutcome && !recordedIssueConversations && !recordedPullRequestConversations && !recordedPullRequestLinkedIssues && events.length === 0) {
|
|
5068
5375
|
return new Response("Ignored", { status: 202 });
|
|
5069
5376
|
}
|
|
@@ -5073,36 +5380,36 @@ function createGitHubWebhookRoute(args) {
|
|
|
5073
5380
|
}
|
|
5074
5381
|
|
|
5075
5382
|
// src/merge-conflict-checks/heartbeat.ts
|
|
5076
|
-
import * as
|
|
5383
|
+
import * as z35 from "zod";
|
|
5077
5384
|
var CHECK_LIMIT = 10;
|
|
5078
5385
|
var MAX_PAGES2 = 5;
|
|
5079
5386
|
var CLAIM_MS = 5 * 6e4;
|
|
5080
5387
|
var UNKNOWN_RETRY_MS = 6e4;
|
|
5081
5388
|
var MAX_ATTEMPTS = 5;
|
|
5082
|
-
var searchNodeSchema =
|
|
5083
|
-
|
|
5084
|
-
baseRefName:
|
|
5085
|
-
headRefOid:
|
|
5086
|
-
mergeable:
|
|
5087
|
-
number:
|
|
5088
|
-
state:
|
|
5089
|
-
url:
|
|
5389
|
+
var searchNodeSchema = z35.union([
|
|
5390
|
+
z35.object({
|
|
5391
|
+
baseRefName: z35.string().min(1),
|
|
5392
|
+
headRefOid: z35.string().min(1),
|
|
5393
|
+
mergeable: z35.enum(["CONFLICTING", "MERGEABLE", "UNKNOWN"]),
|
|
5394
|
+
number: z35.number().int().positive(),
|
|
5395
|
+
state: z35.string(),
|
|
5396
|
+
url: z35.string().min(1)
|
|
5090
5397
|
}),
|
|
5091
|
-
|
|
5398
|
+
z35.object({}).strict()
|
|
5092
5399
|
]);
|
|
5093
|
-
var searchResponseSchema =
|
|
5094
|
-
data:
|
|
5095
|
-
search:
|
|
5096
|
-
nodes:
|
|
5097
|
-
pageInfo:
|
|
5098
|
-
endCursor:
|
|
5099
|
-
hasNextPage:
|
|
5400
|
+
var searchResponseSchema = z35.object({
|
|
5401
|
+
data: z35.object({
|
|
5402
|
+
search: z35.object({
|
|
5403
|
+
nodes: z35.array(searchNodeSchema.nullable()),
|
|
5404
|
+
pageInfo: z35.object({
|
|
5405
|
+
endCursor: z35.string().nullable(),
|
|
5406
|
+
hasNextPage: z35.boolean()
|
|
5100
5407
|
})
|
|
5101
5408
|
})
|
|
5102
5409
|
})
|
|
5103
5410
|
});
|
|
5104
5411
|
async function checkRepository(args, repositoryFullName) {
|
|
5105
|
-
let
|
|
5412
|
+
let unknown3 = false;
|
|
5106
5413
|
let after;
|
|
5107
5414
|
for (let page = 0; page < MAX_PAGES2; page += 1) {
|
|
5108
5415
|
const { search } = searchResponseSchema.parse(
|
|
@@ -5110,7 +5417,7 @@ async function checkRepository(args, repositoryFullName) {
|
|
|
5110
5417
|
).data;
|
|
5111
5418
|
for (const node of search.nodes) {
|
|
5112
5419
|
if (!node || !("number" in node) || node.state !== "OPEN") continue;
|
|
5113
|
-
if (node.mergeable === "UNKNOWN")
|
|
5420
|
+
if (node.mergeable === "UNKNOWN") unknown3 = true;
|
|
5114
5421
|
if (node.mergeable !== "CONFLICTING") continue;
|
|
5115
5422
|
const events = gitHubMergeConflictEvents({
|
|
5116
5423
|
conflict: {
|
|
@@ -5127,12 +5434,12 @@ async function checkRepository(args, repositoryFullName) {
|
|
|
5127
5434
|
if (!search.pageInfo.hasNextPage || !search.pageInfo.endCursor) break;
|
|
5128
5435
|
after = search.pageInfo.endCursor;
|
|
5129
5436
|
}
|
|
5130
|
-
return
|
|
5437
|
+
return unknown3;
|
|
5131
5438
|
}
|
|
5132
5439
|
async function runCheck(args, check) {
|
|
5133
|
-
let
|
|
5440
|
+
let unknown3;
|
|
5134
5441
|
try {
|
|
5135
|
-
|
|
5442
|
+
unknown3 = await checkRepository(args, check.repositoryFullName);
|
|
5136
5443
|
} catch (error) {
|
|
5137
5444
|
args.log.error("GitHub merge conflict check failed", {
|
|
5138
5445
|
attempts: check.attempts,
|
|
@@ -5147,7 +5454,7 @@ async function runCheck(args, check) {
|
|
|
5147
5454
|
await settleGitHubConflictCheck(
|
|
5148
5455
|
args.state,
|
|
5149
5456
|
check,
|
|
5150
|
-
|
|
5457
|
+
unknown3 && check.attempts < MAX_ATTEMPTS ? args.now.getTime() + UNKNOWN_RETRY_MS : void 0
|
|
5151
5458
|
);
|
|
5152
5459
|
}
|
|
5153
5460
|
async function runGitHubConflictChecks(args) {
|
|
@@ -5193,30 +5500,30 @@ function gitHubResourceUrl(input) {
|
|
|
5193
5500
|
if (input.resourceType === "repository") {
|
|
5194
5501
|
return `https://github.com/${input.identifier}`;
|
|
5195
5502
|
}
|
|
5196
|
-
const [repo,
|
|
5197
|
-
if (!repo || !
|
|
5503
|
+
const [repo, number27] = input.identifier.split("#");
|
|
5504
|
+
if (!repo || !number27) return void 0;
|
|
5198
5505
|
if (input.resourceType === "pull_request") {
|
|
5199
|
-
return `https://github.com/${repo}/pull/${
|
|
5506
|
+
return `https://github.com/${repo}/pull/${number27}`;
|
|
5200
5507
|
}
|
|
5201
5508
|
if (input.resourceType === "issue") {
|
|
5202
|
-
return `https://github.com/${repo}/issues/${
|
|
5509
|
+
return `https://github.com/${repo}/issues/${number27}`;
|
|
5203
5510
|
}
|
|
5204
5511
|
return void 0;
|
|
5205
5512
|
}
|
|
5206
5513
|
|
|
5207
5514
|
// src/pull-request-outcomes/commit-composition.ts
|
|
5208
|
-
import * as
|
|
5209
|
-
var canonicalCommitSchema =
|
|
5210
|
-
authorEmail:
|
|
5211
|
-
authorLogin:
|
|
5515
|
+
import * as z36 from "zod";
|
|
5516
|
+
var canonicalCommitSchema = z36.object({
|
|
5517
|
+
authorEmail: z36.string().nullable(),
|
|
5518
|
+
authorLogin: z36.string().nullable()
|
|
5212
5519
|
}).strict();
|
|
5213
|
-
var providerCommitSchema =
|
|
5214
|
-
author:
|
|
5215
|
-
commit:
|
|
5216
|
-
author:
|
|
5520
|
+
var providerCommitSchema = z36.object({
|
|
5521
|
+
author: z36.object({ login: z36.string() }).passthrough().nullable(),
|
|
5522
|
+
commit: z36.object({
|
|
5523
|
+
author: z36.object({ email: z36.string() }).passthrough().nullable()
|
|
5217
5524
|
}).passthrough()
|
|
5218
5525
|
}).passthrough();
|
|
5219
|
-
var commitPageSchema2 =
|
|
5526
|
+
var commitPageSchema2 = z36.array(providerCommitSchema).transform(
|
|
5220
5527
|
(commits) => commits.map(
|
|
5221
5528
|
(commit) => canonicalCommitSchema.parse({
|
|
5222
5529
|
authorEmail: commit.commit.author?.email ?? null,
|
|
@@ -5290,15 +5597,15 @@ function githubNoreplyEmail(user) {
|
|
|
5290
5597
|
if (identity.provider !== "github") {
|
|
5291
5598
|
continue;
|
|
5292
5599
|
}
|
|
5293
|
-
const
|
|
5600
|
+
const login2 = cleanIdentityPart(identity.handle);
|
|
5294
5601
|
const userId = cleanIdentityPart(identity.providerSubjectId);
|
|
5295
|
-
if (!
|
|
5602
|
+
if (!login2 || login2.toLowerCase().endsWith("[bot]")) {
|
|
5296
5603
|
continue;
|
|
5297
5604
|
}
|
|
5298
5605
|
if (/^[1-9]\d*$/.test(userId)) {
|
|
5299
|
-
return `${userId}+${
|
|
5606
|
+
return `${userId}+${login2}@users.noreply.github.com`;
|
|
5300
5607
|
}
|
|
5301
|
-
return `${
|
|
5608
|
+
return `${login2}@users.noreply.github.com`;
|
|
5302
5609
|
}
|
|
5303
5610
|
return void 0;
|
|
5304
5611
|
}
|
|
@@ -5723,8 +6030,8 @@ function linkifyLine(line) {
|
|
|
5723
6030
|
if (isReferenceBoundary(index2 === 0 ? void 0 : line[index2 - 1])) {
|
|
5724
6031
|
const match = GITHUB_ISSUE_REFERENCE_PATTERN.exec(line.slice(index2));
|
|
5725
6032
|
if (match) {
|
|
5726
|
-
const [reference, owner, repository2,
|
|
5727
|
-
output += `[${reference}](https://github.com/${owner}/${repository2}/issues/${
|
|
6033
|
+
const [reference, owner, repository2, number27] = match;
|
|
6034
|
+
output += `[${reference}](https://github.com/${owner}/${repository2}/issues/${number27})`;
|
|
5728
6035
|
index2 += reference.length;
|
|
5729
6036
|
continue;
|
|
5730
6037
|
}
|
|
@@ -5866,9 +6173,9 @@ function parseGitHubReferences(text2, config) {
|
|
|
5866
6173
|
}
|
|
5867
6174
|
return [...references.values()];
|
|
5868
6175
|
}
|
|
5869
|
-
function objectTitle(kind,
|
|
5870
|
-
if (!isRecord(
|
|
5871
|
-
const raw = kind === "commit" ? isRecord(
|
|
6176
|
+
function objectTitle(kind, object37) {
|
|
6177
|
+
if (!isRecord(object37)) return void 0;
|
|
6178
|
+
const raw = kind === "commit" ? isRecord(object37.commit) && typeof object37.commit.message === "string" ? object37.commit.message.split("\n")[0] : void 0 : typeof object37.title === "string" ? object37.title : void 0;
|
|
5872
6179
|
return raw?.replace(/\s+/g, " ").trim() || void 0;
|
|
5873
6180
|
}
|
|
5874
6181
|
async function loadGitHubConversationTitleContext(args) {
|
|
@@ -6083,7 +6390,7 @@ function isGitHubRemote(arg) {
|
|
|
6083
6390
|
|
|
6084
6391
|
// src/egress-policy.ts
|
|
6085
6392
|
import {
|
|
6086
|
-
EgressPolicyDenied as
|
|
6393
|
+
EgressPolicyDenied as EgressPolicyDenied3,
|
|
6087
6394
|
enforceEgressPolicy
|
|
6088
6395
|
} from "@sentry/junior-plugin-api";
|
|
6089
6396
|
|
|
@@ -6141,6 +6448,98 @@ function assertGitHubPullRequestApprovalDenied(input) {
|
|
|
6141
6448
|
}
|
|
6142
6449
|
}
|
|
6143
6450
|
|
|
6451
|
+
// src/receive-pack-policy.ts
|
|
6452
|
+
import {
|
|
6453
|
+
EgressPolicyDenied as EgressPolicyDenied2
|
|
6454
|
+
} from "@sentry/junior-plugin-api";
|
|
6455
|
+
|
|
6456
|
+
// src/default-branch.ts
|
|
6457
|
+
import * as z37 from "zod";
|
|
6458
|
+
var DEFAULT_BRANCH_TTL_MS = 10 * 60 * 1e3;
|
|
6459
|
+
var repositorySchema2 = z37.object({ default_branch: z37.string().min(1) });
|
|
6460
|
+
async function loadDefaultBranch(env, cache, repository2) {
|
|
6461
|
+
const { owner, name } = repository2;
|
|
6462
|
+
return await cache.getOrLoad(
|
|
6463
|
+
`default-branch:${owner}/${name}`.toLowerCase(),
|
|
6464
|
+
async () => {
|
|
6465
|
+
const token = await issueInstallationToken({
|
|
6466
|
+
...env,
|
|
6467
|
+
permissions: { metadata: "read" },
|
|
6468
|
+
repositories: [name]
|
|
6469
|
+
});
|
|
6470
|
+
const response = repositorySchema2.parse(
|
|
6471
|
+
await githubRequest(
|
|
6472
|
+
"https://api.github.com",
|
|
6473
|
+
`/repos/${encodeURIComponent(owner)}/${encodeURIComponent(name)}`,
|
|
6474
|
+
{ token: token.token }
|
|
6475
|
+
)
|
|
6476
|
+
);
|
|
6477
|
+
return { value: response.default_branch, ttlMs: DEFAULT_BRANCH_TTL_MS };
|
|
6478
|
+
}
|
|
6479
|
+
);
|
|
6480
|
+
}
|
|
6481
|
+
|
|
6482
|
+
// src/receive-pack-policy.ts
|
|
6483
|
+
var DENIAL_SUFFIX = "This is a runtime policy denial, not a GitHub permission failure. Push to a new branch and open a pull request with github_createPullRequest.";
|
|
6484
|
+
var UNREADABLE_MESSAGES = {
|
|
6485
|
+
gzip: "The runtime cannot read a gzip-compressed Git push.",
|
|
6486
|
+
malformed: "The runtime could not read the Git push command list.",
|
|
6487
|
+
signed: "The runtime does not accept signed Git pushes.",
|
|
6488
|
+
unterminated: "The runtime could not find the end of the Git push command list."
|
|
6489
|
+
};
|
|
6490
|
+
function deny(message, options) {
|
|
6491
|
+
throw new EgressPolicyDenied2(`${message} ${DENIAL_SUFFIX}`, options);
|
|
6492
|
+
}
|
|
6493
|
+
async function assertGitHubPushAllowed(input) {
|
|
6494
|
+
if (!input.gitPush) {
|
|
6495
|
+
deny(UNREADABLE_MESSAGES.malformed);
|
|
6496
|
+
}
|
|
6497
|
+
if (input.gitPush.kind === "unreadable") {
|
|
6498
|
+
deny(UNREADABLE_MESSAGES[input.gitPush.reason]);
|
|
6499
|
+
}
|
|
6500
|
+
const { updates } = input.gitPush;
|
|
6501
|
+
const refs = updates.map((update) => update.ref);
|
|
6502
|
+
const outsideBranches = refs.filter((ref) => !ref.startsWith("refs/heads/"));
|
|
6503
|
+
if (outsideBranches.length > 0) {
|
|
6504
|
+
deny(
|
|
6505
|
+
`The runtime pushes only branches. It refused ${outsideBranches.join(", ")}.`,
|
|
6506
|
+
{ auditAttributes: { "app.github.refs": refs } }
|
|
6507
|
+
);
|
|
6508
|
+
}
|
|
6509
|
+
if (updates.length === 0) {
|
|
6510
|
+
return { "app.github.refs": refs };
|
|
6511
|
+
}
|
|
6512
|
+
let defaultBranch;
|
|
6513
|
+
try {
|
|
6514
|
+
defaultBranch = await loadDefaultBranch(
|
|
6515
|
+
input.env,
|
|
6516
|
+
input.cache,
|
|
6517
|
+
input.repository
|
|
6518
|
+
);
|
|
6519
|
+
} catch (error) {
|
|
6520
|
+
deny(
|
|
6521
|
+
`The runtime could not read the default branch of ${input.repository.owner}/${input.repository.name}, so it refused the push.`,
|
|
6522
|
+
{ auditAttributes: { "app.github.refs": refs }, cause: error }
|
|
6523
|
+
);
|
|
6524
|
+
}
|
|
6525
|
+
const defaultRef = `refs/heads/${defaultBranch}`.toLowerCase();
|
|
6526
|
+
const defaultUpdate = updates.find(
|
|
6527
|
+
(update) => update.ref.toLowerCase() === defaultRef
|
|
6528
|
+
);
|
|
6529
|
+
const attributes = {
|
|
6530
|
+
"app.github.default_branch": defaultBranch,
|
|
6531
|
+
"app.github.default_branch_targeted": defaultUpdate !== void 0,
|
|
6532
|
+
"app.github.refs": refs
|
|
6533
|
+
};
|
|
6534
|
+
if (defaultUpdate) {
|
|
6535
|
+
deny(
|
|
6536
|
+
`The runtime never ${defaultUpdate.deletes ? "deletes" : "pushes to"} the default branch (${defaultBranch}) of ${input.repository.owner}/${input.repository.name}.`,
|
|
6537
|
+
{ auditAttributes: attributes }
|
|
6538
|
+
);
|
|
6539
|
+
}
|
|
6540
|
+
return attributes;
|
|
6541
|
+
}
|
|
6542
|
+
|
|
6144
6543
|
// src/egress-policy.ts
|
|
6145
6544
|
function githubSmartHttpAccess(upstreamUrl) {
|
|
6146
6545
|
const pathname = upstreamUrl.pathname.toLowerCase();
|
|
@@ -6458,6 +6857,17 @@ var HOST_GRAPHQL_MUTATIONS = [
|
|
|
6458
6857
|
field: "convertPullRequestToDraft",
|
|
6459
6858
|
operationName: "ConvertPullRequestToDraft",
|
|
6460
6859
|
operationPrefix: "github.pull.draft.update:"
|
|
6860
|
+
},
|
|
6861
|
+
// Feedback-status reactions on review bodies, which have no REST endpoint.
|
|
6862
|
+
{
|
|
6863
|
+
field: "addReaction",
|
|
6864
|
+
operationName: "AddReviewReaction",
|
|
6865
|
+
operationPrefix: "github.pull.review-reaction.update:"
|
|
6866
|
+
},
|
|
6867
|
+
{
|
|
6868
|
+
field: "removeReaction",
|
|
6869
|
+
operationName: "RemoveReviewReaction",
|
|
6870
|
+
operationPrefix: "github.pull.review-reaction.update:"
|
|
6461
6871
|
}
|
|
6462
6872
|
];
|
|
6463
6873
|
function hostGraphqlMutationRepository(operation, method, upstreamUrl, bodyText) {
|
|
@@ -6531,16 +6941,28 @@ function grantForAccess(access, reason, name) {
|
|
|
6531
6941
|
};
|
|
6532
6942
|
}
|
|
6533
6943
|
function requireRepositoryTarget(upstreamUrl) {
|
|
6534
|
-
|
|
6535
|
-
|
|
6944
|
+
const repository2 = githubRepositoryFromUrl(upstreamUrl);
|
|
6945
|
+
if (repository2) {
|
|
6946
|
+
return repository2;
|
|
6536
6947
|
}
|
|
6537
|
-
throw new
|
|
6948
|
+
throw new EgressPolicyDenied3(
|
|
6538
6949
|
"GitHub write request has no repository in its URL. Use a /repos/{owner}/{repo}/... URL or a GitHub tool for the operation."
|
|
6539
6950
|
);
|
|
6540
6951
|
}
|
|
6541
|
-
async function githubGrantForEgress(ctx) {
|
|
6542
|
-
const method = ctx.request.method.toUpperCase();
|
|
6952
|
+
async function githubGrantForEgress(ctx, env) {
|
|
6543
6953
|
const upstreamUrl = new URL(ctx.request.url);
|
|
6954
|
+
const grant = await selectGitHubGrant(ctx, env, upstreamUrl);
|
|
6955
|
+
const repository2 = githubRepositoryFromUrl(upstreamUrl);
|
|
6956
|
+
return repository2 ? {
|
|
6957
|
+
...grant,
|
|
6958
|
+
auditAttributes: {
|
|
6959
|
+
...grant.auditAttributes,
|
|
6960
|
+
"app.github.repository": `${repository2.owner}/${repository2.name}`
|
|
6961
|
+
}
|
|
6962
|
+
} : grant;
|
|
6963
|
+
}
|
|
6964
|
+
async function selectGitHubGrant(ctx, env, upstreamUrl) {
|
|
6965
|
+
const method = ctx.request.method.toUpperCase();
|
|
6544
6966
|
applyGitHubEgressPolicy({
|
|
6545
6967
|
...ctx.request.bodyText !== void 0 ? { bodyText: ctx.request.bodyText } : void 0,
|
|
6546
6968
|
method,
|
|
@@ -6553,12 +6975,24 @@ async function githubGrantForEgress(ctx) {
|
|
|
6553
6975
|
const smartHttpAccess = githubSmartHttpAccess(upstreamUrl);
|
|
6554
6976
|
if (smartHttpAccess) {
|
|
6555
6977
|
if (smartHttpAccess === "write") {
|
|
6556
|
-
requireRepositoryTarget(upstreamUrl);
|
|
6557
|
-
|
|
6978
|
+
const repository2 = requireRepositoryTarget(upstreamUrl);
|
|
6979
|
+
const grant = grantForAccess(
|
|
6558
6980
|
"write",
|
|
6559
6981
|
"github.installation-write",
|
|
6560
6982
|
"installation-write"
|
|
6561
6983
|
);
|
|
6984
|
+
if (method !== "POST" || !upstreamUrl.pathname.toLowerCase().endsWith("/git-receive-pack")) {
|
|
6985
|
+
return grant;
|
|
6986
|
+
}
|
|
6987
|
+
return {
|
|
6988
|
+
...grant,
|
|
6989
|
+
auditAttributes: await assertGitHubPushAllowed({
|
|
6990
|
+
cache: ctx.cache,
|
|
6991
|
+
env,
|
|
6992
|
+
gitPush: ctx.request.gitPush,
|
|
6993
|
+
repository: repository2
|
|
6994
|
+
})
|
|
6995
|
+
};
|
|
6562
6996
|
}
|
|
6563
6997
|
return grantForAccess(
|
|
6564
6998
|
smartHttpAccess,
|
|
@@ -6588,11 +7022,15 @@ async function githubGrantForEgress(ctx) {
|
|
|
6588
7022
|
ctx.request.bodyText
|
|
6589
7023
|
);
|
|
6590
7024
|
if (hostMutationRepository) {
|
|
6591
|
-
return
|
|
6592
|
-
|
|
6593
|
-
|
|
6594
|
-
|
|
6595
|
-
|
|
7025
|
+
return {
|
|
7026
|
+
...grantForAccess(
|
|
7027
|
+
"write",
|
|
7028
|
+
"github.installation-write",
|
|
7029
|
+
"installation-write"
|
|
7030
|
+
),
|
|
7031
|
+
// GraphQL URLs name no repository; the host operation does.
|
|
7032
|
+
auditAttributes: { "app.github.repository": hostMutationRepository }
|
|
7033
|
+
};
|
|
6596
7034
|
}
|
|
6597
7035
|
const graphqlAccess = githubGraphqlAccess(
|
|
6598
7036
|
method,
|
|
@@ -6601,7 +7039,7 @@ async function githubGrantForEgress(ctx) {
|
|
|
6601
7039
|
);
|
|
6602
7040
|
if (graphqlAccess) {
|
|
6603
7041
|
if (graphqlAccess === "write") {
|
|
6604
|
-
throw new
|
|
7042
|
+
throw new EgressPolicyDenied3(
|
|
6605
7043
|
"GitHub GraphQL mutations are not enabled for runtime credentials. Use the matching GitHub tool or a supported REST endpoint. For pull request reviews, use github_submitPullRequestReview. It posts to /repos/{owner}/{repo}/pulls/{number}/reviews."
|
|
6606
7044
|
);
|
|
6607
7045
|
}
|
|
@@ -6613,7 +7051,7 @@ async function githubGrantForEgress(ctx) {
|
|
|
6613
7051
|
}
|
|
6614
7052
|
const access = HTTP_READ_METHODS.has(method) ? "read" : "write";
|
|
6615
7053
|
if (access === "write") {
|
|
6616
|
-
throw new
|
|
7054
|
+
throw new EgressPolicyDenied3(
|
|
6617
7055
|
"This GitHub write request is not supported. Use the matching GitHub tool or a supported REST endpoint."
|
|
6618
7056
|
);
|
|
6619
7057
|
}
|
|
@@ -6786,13 +7224,13 @@ function githubPlugin(options = {}) {
|
|
|
6786
7224
|
log: ctx.log,
|
|
6787
7225
|
now: new Date(ctx.nowMs),
|
|
6788
7226
|
search: async (input) => {
|
|
6789
|
-
const
|
|
6790
|
-
if (!
|
|
7227
|
+
const login2 = botLoginFromEmail(requireEnv(botEmailEnv));
|
|
7228
|
+
if (!login2) {
|
|
6791
7229
|
throw new Error(`${botEmailEnv} is not a GitHub bot address`);
|
|
6792
7230
|
}
|
|
6793
7231
|
return await searchOpenPullRequestMergeability(
|
|
6794
7232
|
{ appIdEnv, installationIdEnv, privateKeyEnv },
|
|
6795
|
-
{ ...input, author: `app/${
|
|
7233
|
+
{ ...input, author: `app/${login2.replace(/\[bot\]$/, "")}` }
|
|
6796
7234
|
);
|
|
6797
7235
|
},
|
|
6798
7236
|
state: ctx.state
|
|
@@ -6903,7 +7341,11 @@ function githubPlugin(options = {}) {
|
|
|
6903
7341
|
);
|
|
6904
7342
|
},
|
|
6905
7343
|
grantForEgress(ctx) {
|
|
6906
|
-
return githubGrantForEgress(ctx
|
|
7344
|
+
return githubGrantForEgress(ctx, {
|
|
7345
|
+
appIdEnv,
|
|
7346
|
+
installationIdEnv,
|
|
7347
|
+
privateKeyEnv
|
|
7348
|
+
});
|
|
6907
7349
|
},
|
|
6908
7350
|
async onEgressResponse(ctx) {
|
|
6909
7351
|
if (ctx.response.status === 403) {
|