@sentry/junior-github 0.258.0 → 0.259.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.
|
@@ -855,6 +855,35 @@ async function issueInstallationCredential(options) {
|
|
|
855
855
|
expiresAtMs: token.expiresAtMs
|
|
856
856
|
});
|
|
857
857
|
}
|
|
858
|
+
async function issueGitHubCredential(ctx, options) {
|
|
859
|
+
const installation = {
|
|
860
|
+
appIdEnv: options.appIdEnv,
|
|
861
|
+
installationIdEnv: options.installationIdEnv,
|
|
862
|
+
privateKeyEnv: options.privateKeyEnv
|
|
863
|
+
};
|
|
864
|
+
try {
|
|
865
|
+
if (ctx.grant.name === "installation-read") {
|
|
866
|
+
return await issueInstallationCredential({
|
|
867
|
+
...installation,
|
|
868
|
+
...options.readPermissions
|
|
869
|
+
});
|
|
870
|
+
}
|
|
871
|
+
if (ctx.grant.name === "installation-write") {
|
|
872
|
+
return await issueInstallationCredential(installation);
|
|
873
|
+
}
|
|
874
|
+
if (USER_TOKEN_GRANTS.has(ctx.grant.name)) {
|
|
875
|
+
return await issueUserCredential(ctx, options);
|
|
876
|
+
}
|
|
877
|
+
} catch (error) {
|
|
878
|
+
if (error instanceof GitHubPluginSetupError) {
|
|
879
|
+
return credentialUnavailable(error.message);
|
|
880
|
+
}
|
|
881
|
+
throw error;
|
|
882
|
+
}
|
|
883
|
+
throw new Error(
|
|
884
|
+
`GitHub plugin cannot issue unknown grant "${ctx.grant.name}".`
|
|
885
|
+
);
|
|
886
|
+
}
|
|
858
887
|
function createPermissionCache() {
|
|
859
888
|
let cached;
|
|
860
889
|
let pending;
|
|
@@ -1966,22 +1995,18 @@ export {
|
|
|
1966
1995
|
GITHUB_AUTH_TOKEN_PLACEHOLDER,
|
|
1967
1996
|
GITHUB_GRAPHQL_RESPONSE_BODY_LIMIT_BYTES,
|
|
1968
1997
|
HTTP_READ_METHODS,
|
|
1969
|
-
USER_TOKEN_GRANTS,
|
|
1970
1998
|
CREATE_TOOL_ROUTING_GUIDANCE,
|
|
1971
1999
|
USER_WRITE_REQUIREMENTS,
|
|
1972
|
-
GitHubPluginSetupError,
|
|
1973
2000
|
isRecord,
|
|
1974
2001
|
readEnv,
|
|
1975
2002
|
requireEnv,
|
|
1976
2003
|
normalizeScopeList,
|
|
1977
2004
|
githubRequest,
|
|
1978
|
-
credentialUnavailable,
|
|
1979
2005
|
githubRepositoryFromUrl,
|
|
1980
2006
|
resolveUserAccount,
|
|
1981
2007
|
listVerifiedUserEmails,
|
|
1982
|
-
issueUserCredential,
|
|
1983
2008
|
issueInstallationToken,
|
|
1984
|
-
|
|
2009
|
+
issueGitHubCredential,
|
|
1985
2010
|
createPermissionCache,
|
|
1986
2011
|
parseCheckSuitePublishTargets,
|
|
1987
2012
|
needsCheckSuitePullRequestFacts,
|
|
@@ -75,15 +75,25 @@ export declare function resolveUserAccount(tokens: PluginStoredTokens): Promise<
|
|
|
75
75
|
* Return an empty list when the App does not have it.
|
|
76
76
|
*/
|
|
77
77
|
export declare function listVerifiedUserEmails(tokens: PluginStoredTokens): Promise<string[]>;
|
|
78
|
-
/** Issue a bounded GitHub user credential for an approved grant. */
|
|
79
|
-
export declare function issueUserCredential(ctx: IssueCredentialHookContext, options: UserCredentialOptions): Promise<PluginCredentialResult>;
|
|
80
78
|
/** Issue a bounded raw token for plugin-owned GitHub API calls. */
|
|
81
79
|
export declare function issueInstallationToken(options: InstallationCredentialOptions): Promise<{
|
|
82
80
|
expiresAtMs: number;
|
|
83
81
|
token: string;
|
|
84
82
|
}>;
|
|
85
|
-
|
|
86
|
-
|
|
83
|
+
interface GitHubCredentialOptions extends InstallationCredentialBaseOptions, UserCredentialOptions {
|
|
84
|
+
/** Declared read permissions, or a loader for the installed ones. */
|
|
85
|
+
readPermissions: {
|
|
86
|
+
permissions: GitHubAppPermissions;
|
|
87
|
+
} | {
|
|
88
|
+
loadPermissions: LoadInstallationReadPermissions;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Issue the credential for one GitHub grant that host egress selected. Only
|
|
93
|
+
* the `issueCredential` hook may call this. Other code reads and writes GitHub
|
|
94
|
+
* through host egress.
|
|
95
|
+
*/
|
|
96
|
+
export declare function issueGitHubCredential(ctx: IssueCredentialHookContext, options: GitHubCredentialOptions): Promise<PluginCredentialResult>;
|
|
87
97
|
/** Cache the installation's read permissions for one lease period. */
|
|
88
98
|
export declare function createPermissionCache(): LoadInstallationReadPermissions;
|
|
89
99
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -20,14 +20,11 @@ import {
|
|
|
20
20
|
GITHUB_RELEASE_SOURCE_IDENTIFIER,
|
|
21
21
|
GITHUB_RELEASE_SUGGESTED_EVENTS,
|
|
22
22
|
GITHUB_REPOSITORY_IDENTIFIER,
|
|
23
|
-
GitHubPluginSetupError,
|
|
24
23
|
HTTP_READ_METHODS,
|
|
25
|
-
USER_TOKEN_GRANTS,
|
|
26
24
|
USER_WRITE_REQUIREMENTS,
|
|
27
25
|
botLoginFromEmail,
|
|
28
26
|
botUserIdFromEmail,
|
|
29
27
|
createPermissionCache,
|
|
30
|
-
credentialUnavailable,
|
|
31
28
|
gitHubDeploymentSourceSubscribable,
|
|
32
29
|
gitHubIssueSubscribable,
|
|
33
30
|
gitHubPullRequestCreateWatch,
|
|
@@ -39,9 +36,8 @@ import {
|
|
|
39
36
|
githubRequest,
|
|
40
37
|
isBotLogin,
|
|
41
38
|
isRecord,
|
|
42
|
-
|
|
39
|
+
issueGitHubCredential,
|
|
43
40
|
issueInstallationToken,
|
|
44
|
-
issueUserCredential,
|
|
45
41
|
listVerifiedUserEmails,
|
|
46
42
|
loadCheckSuiteFacts,
|
|
47
43
|
needsCheckSuitePullRequestFacts,
|
|
@@ -53,7 +49,7 @@ import {
|
|
|
53
49
|
readGrantPermissions,
|
|
54
50
|
requireEnv,
|
|
55
51
|
resolveUserAccount
|
|
56
|
-
} from "./chunk-
|
|
52
|
+
} from "./chunk-6F62DDRZ.js";
|
|
57
53
|
|
|
58
54
|
// src/plugin.ts
|
|
59
55
|
import {
|
|
@@ -3864,6 +3860,52 @@ function createGitHubWebhookRoute(args) {
|
|
|
3864
3860
|
};
|
|
3865
3861
|
}
|
|
3866
3862
|
|
|
3863
|
+
// src/webhooks/installation-requests.ts
|
|
3864
|
+
function splitRepository(fullName, label) {
|
|
3865
|
+
const [owner, name, ...extra] = fullName.split("/");
|
|
3866
|
+
if (!owner || !name || extra.length > 0) {
|
|
3867
|
+
throw new Error(`GitHub ${label} received an invalid repository name`);
|
|
3868
|
+
}
|
|
3869
|
+
return { owner, name };
|
|
3870
|
+
}
|
|
3871
|
+
async function loadPullRequestCommitPages(env, pullRequest) {
|
|
3872
|
+
const { owner, name } = splitRepository(
|
|
3873
|
+
pullRequest.repositoryFullName,
|
|
3874
|
+
"pull request commits"
|
|
3875
|
+
);
|
|
3876
|
+
const token = await issueInstallationToken({
|
|
3877
|
+
...env,
|
|
3878
|
+
permissions: { pull_requests: "read" },
|
|
3879
|
+
repositories: [name]
|
|
3880
|
+
});
|
|
3881
|
+
return async (page, perPage) => await githubRequest(
|
|
3882
|
+
"https://api.github.com",
|
|
3883
|
+
`/repos/${encodeURIComponent(owner)}/${encodeURIComponent(name)}/pulls/${pullRequest.number}/commits?per_page=${perPage}&page=${page}`,
|
|
3884
|
+
{ token: token.token }
|
|
3885
|
+
);
|
|
3886
|
+
}
|
|
3887
|
+
async function markPullRequestFeedbackReviewing(env, target) {
|
|
3888
|
+
const { owner, name } = splitRepository(target.repo, "pull request feedback");
|
|
3889
|
+
const token = await issueInstallationToken({
|
|
3890
|
+
...env,
|
|
3891
|
+
repositories: [name]
|
|
3892
|
+
});
|
|
3893
|
+
await githubRequest(
|
|
3894
|
+
"https://api.github.com",
|
|
3895
|
+
pullRequestCommentReactionsPath({
|
|
3896
|
+
owner,
|
|
3897
|
+
name,
|
|
3898
|
+
commentKind: target.commentKind,
|
|
3899
|
+
commentId: target.commentId
|
|
3900
|
+
}),
|
|
3901
|
+
{
|
|
3902
|
+
body: { content: pullRequestFeedbackReactionContent("reviewing") },
|
|
3903
|
+
method: "POST",
|
|
3904
|
+
token: token.token
|
|
3905
|
+
}
|
|
3906
|
+
);
|
|
3907
|
+
}
|
|
3908
|
+
|
|
3867
3909
|
// src/pull-request-outcomes/commit-composition.ts
|
|
3868
3910
|
import { z as z20 } from "zod";
|
|
3869
3911
|
var canonicalCommitSchema = z20.object({
|
|
@@ -5034,25 +5076,10 @@ function githubPlugin(options = {}) {
|
|
|
5034
5076
|
};
|
|
5035
5077
|
},
|
|
5036
5078
|
routes(ctx) {
|
|
5037
|
-
const
|
|
5038
|
-
|
|
5039
|
-
|
|
5040
|
-
|
|
5041
|
-
"GitHub pull request commits received an invalid repository name"
|
|
5042
|
-
);
|
|
5043
|
-
}
|
|
5044
|
-
const token = await issueInstallationToken({
|
|
5045
|
-
appIdEnv,
|
|
5046
|
-
privateKeyEnv,
|
|
5047
|
-
installationIdEnv,
|
|
5048
|
-
permissions: { pull_requests: "read" },
|
|
5049
|
-
repositories: [name]
|
|
5050
|
-
});
|
|
5051
|
-
return async (page, perPage) => await githubRequest(
|
|
5052
|
-
"https://api.github.com",
|
|
5053
|
-
`/repos/${encodeURIComponent(owner)}/${encodeURIComponent(name)}/pulls/${pullRequest.number}/commits?per_page=${perPage}&page=${page}`,
|
|
5054
|
-
{ token: token.token }
|
|
5055
|
-
);
|
|
5079
|
+
const installationEnv = {
|
|
5080
|
+
appIdEnv,
|
|
5081
|
+
installationIdEnv,
|
|
5082
|
+
privateKeyEnv
|
|
5056
5083
|
};
|
|
5057
5084
|
return [
|
|
5058
5085
|
createGitHubWebhookRoute({
|
|
@@ -5061,7 +5088,10 @@ function githubPlugin(options = {}) {
|
|
|
5061
5088
|
botEmail: () => readEnv(botEmailEnv),
|
|
5062
5089
|
classifyPullRequestCommits: async (pullRequest) => await classifyGitHubPullRequestCommitComposition({
|
|
5063
5090
|
botEmail: requireEnv(botEmailEnv),
|
|
5064
|
-
loadPage: await
|
|
5091
|
+
loadPage: await loadPullRequestCommitPages(
|
|
5092
|
+
installationEnv,
|
|
5093
|
+
pullRequest
|
|
5094
|
+
)
|
|
5065
5095
|
}),
|
|
5066
5096
|
codeChanges: ctx.codeChanges,
|
|
5067
5097
|
db: ctx.db,
|
|
@@ -5069,39 +5099,13 @@ function githubPlugin(options = {}) {
|
|
|
5069
5099
|
installationIdEnv,
|
|
5070
5100
|
loadPullRequestPeople: async (pullRequest) => await loadGitHubPullRequestPeople({
|
|
5071
5101
|
logins: pullRequest.logins,
|
|
5072
|
-
loadPage: await
|
|
5102
|
+
loadPage: await loadPullRequestCommitPages(
|
|
5103
|
+
installationEnv,
|
|
5104
|
+
pullRequest
|
|
5105
|
+
)
|
|
5073
5106
|
}),
|
|
5074
5107
|
log: ctx.log,
|
|
5075
|
-
markFeedbackReviewing: async (
|
|
5076
|
-
const [owner, name, ...extra] = repo.split("/");
|
|
5077
|
-
if (!owner || !name || extra.length > 0) {
|
|
5078
|
-
throw new Error(
|
|
5079
|
-
"GitHub pull request feedback received an invalid repository name"
|
|
5080
|
-
);
|
|
5081
|
-
}
|
|
5082
|
-
const token = await issueInstallationToken({
|
|
5083
|
-
appIdEnv,
|
|
5084
|
-
privateKeyEnv,
|
|
5085
|
-
installationIdEnv,
|
|
5086
|
-
repositories: [name]
|
|
5087
|
-
});
|
|
5088
|
-
await githubRequest(
|
|
5089
|
-
"https://api.github.com",
|
|
5090
|
-
pullRequestCommentReactionsPath({
|
|
5091
|
-
owner,
|
|
5092
|
-
name,
|
|
5093
|
-
commentKind,
|
|
5094
|
-
commentId
|
|
5095
|
-
}),
|
|
5096
|
-
{
|
|
5097
|
-
body: {
|
|
5098
|
-
content: pullRequestFeedbackReactionContent("reviewing")
|
|
5099
|
-
},
|
|
5100
|
-
method: "POST",
|
|
5101
|
-
token: token.token
|
|
5102
|
-
}
|
|
5103
|
-
);
|
|
5104
|
-
},
|
|
5108
|
+
markFeedbackReviewing: async (target) => await markPullRequestFeedbackReviewing(installationEnv, target),
|
|
5105
5109
|
privateKeyEnv,
|
|
5106
5110
|
events: ctx.events,
|
|
5107
5111
|
webhookSecret: () => readEnv("GITHUB_WEBHOOK_SECRET")
|
|
@@ -5191,38 +5195,15 @@ function githubPlugin(options = {}) {
|
|
|
5191
5195
|
return verifiedEmails.length > 0 ? { ...account, verifiedEmails } : account;
|
|
5192
5196
|
},
|
|
5193
5197
|
async issueCredential(ctx) {
|
|
5194
|
-
|
|
5195
|
-
|
|
5196
|
-
|
|
5197
|
-
|
|
5198
|
-
|
|
5199
|
-
|
|
5200
|
-
|
|
5201
|
-
|
|
5202
|
-
|
|
5203
|
-
if (ctx.grant.name === "installation-write") {
|
|
5204
|
-
return await issueInstallationCredential({
|
|
5205
|
-
appIdEnv,
|
|
5206
|
-
privateKeyEnv,
|
|
5207
|
-
installationIdEnv
|
|
5208
|
-
});
|
|
5209
|
-
}
|
|
5210
|
-
if (USER_TOKEN_GRANTS.has(ctx.grant.name)) {
|
|
5211
|
-
return await issueUserCredential(ctx, {
|
|
5212
|
-
clientIdEnv,
|
|
5213
|
-
clientSecretEnv,
|
|
5214
|
-
userScope
|
|
5215
|
-
});
|
|
5216
|
-
}
|
|
5217
|
-
} catch (error) {
|
|
5218
|
-
if (error instanceof GitHubPluginSetupError) {
|
|
5219
|
-
return credentialUnavailable(error.message);
|
|
5220
|
-
}
|
|
5221
|
-
throw error;
|
|
5222
|
-
}
|
|
5223
|
-
throw new Error(
|
|
5224
|
-
`GitHub plugin cannot issue unknown grant "${ctx.grant.name}".`
|
|
5225
|
-
);
|
|
5198
|
+
return await issueGitHubCredential(ctx, {
|
|
5199
|
+
appIdEnv,
|
|
5200
|
+
clientIdEnv,
|
|
5201
|
+
clientSecretEnv,
|
|
5202
|
+
installationIdEnv,
|
|
5203
|
+
privateKeyEnv,
|
|
5204
|
+
readPermissions: declaredReadPermissions ? { permissions: declaredReadPermissions } : { loadPermissions: loadReadPermissions },
|
|
5205
|
+
userScope
|
|
5206
|
+
});
|
|
5226
5207
|
}
|
|
5227
5208
|
}
|
|
5228
5209
|
});
|
package/dist/testing.js
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Environment variable names for the GitHub App installation. */
|
|
2
|
+
export interface GitHubInstallationEnv {
|
|
3
|
+
appIdEnv: string;
|
|
4
|
+
installationIdEnv: string;
|
|
5
|
+
privateKeyEnv: string;
|
|
6
|
+
}
|
|
7
|
+
/** Return a reader for pages of a pull request's commits, with a read-only token. */
|
|
8
|
+
export declare function loadPullRequestCommitPages(env: GitHubInstallationEnv, pullRequest: {
|
|
9
|
+
number: number;
|
|
10
|
+
repositoryFullName: string;
|
|
11
|
+
}): Promise<(page: number, perPage: number) => Promise<unknown>>;
|
|
12
|
+
/** Add the "reviewing" reaction to one pull request feedback comment. */
|
|
13
|
+
export declare function markPullRequestFeedbackReviewing(env: GitHubInstallationEnv, target: {
|
|
14
|
+
commentId: number;
|
|
15
|
+
commentKind: "conversation" | "review";
|
|
16
|
+
repo: string;
|
|
17
|
+
}): Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentry/junior-github",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.259.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"@sinclair/typebox": "^0.34.49",
|
|
32
32
|
"drizzle-orm": "^0.45.2",
|
|
33
33
|
"zod": "^4.5.4",
|
|
34
|
-
"@sentry/junior-plugin-api": "0.
|
|
34
|
+
"@sentry/junior-plugin-api": "0.259.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@oxlint/plugins": "1.79.0",
|