Skip to content

Commit 5d29780

Browse files
committed
fix: reduce code size trough internal refactoring
1 parent 1f52e9b commit 5d29780

File tree

2 files changed

+28
-30
lines changed

2 files changed

+28
-30
lines changed

scripts/update-endpoints/code.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,18 @@ ENDPOINTS.forEach(endpoint => {
2828
/\{([^}]+)}/g,
2929
":$1"
3030
)}`;
31-
const endpointDefaults = {
32-
headers: endpoint.headers.reduce((result, header) => {
31+
const endpointDefaults = {};
32+
const endpointDecorations = {};
33+
34+
if (endpoint.headers.length) {
35+
endpointDefaults.headers = endpoint.headers.reduce((result, header) => {
3336
if (!result) {
3437
result = {};
3538
}
3639
result[header.name] = header.value;
3740
return result;
38-
}, undefined)
39-
};
40-
const endpointDecorations = {};
41+
}, undefined);
42+
}
4143

4244
if (endpoint.previews.length) {
4345
endpointDefaults.mediaType = {
@@ -56,11 +58,16 @@ ENDPOINTS.forEach(endpoint => {
5658
endpointDecorations.deprecated = `octokit.scim.${idName}() is deprecated, see ${endpoint.documentationUrl}`;
5759
}
5860

59-
newRoutes[endpoint.scope][idName] = [
60-
route,
61-
endpointDefaults,
62-
endpointDecorations
63-
].filter(obj => Object.keys(obj).length);
61+
newRoutes[endpoint.scope][idName] = [route];
62+
63+
if (Object.keys(endpointDecorations).length) {
64+
newRoutes[endpoint.scope][idName].push(
65+
endpointDefaults,
66+
endpointDecorations
67+
);
68+
} else if (Object.keys(endpointDefaults).length) {
69+
newRoutes[endpoint.scope][idName].push(endpointDefaults);
70+
}
6471
});
6572

6673
writeFileSync(

src/generated/endpoints.ts

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,43 @@
11
import { EndpointsDefaultsAndDecorations } from "../types";
22
const Endpoints: EndpointsDefaultsAndDecorations = {
33
orgs: {
4-
listCredentialAuthorizations: [
5-
"GET /orgs/:org/credential-authorizations",
6-
{}
7-
],
4+
listCredentialAuthorizations: ["GET /orgs/:org/credential-authorizations"],
85
removeCredentialAuthorization: [
9-
"DELETE /orgs/:org/credential-authorizations/:credential_id",
10-
{}
6+
"DELETE /orgs/:org/credential-authorizations/:credential_id"
117
]
128
},
139
scim: {
1410
getProvisioningDetailsForUser: [
15-
"GET /scim/v2/organizations/:org/Users/:scim_user_id",
16-
{}
11+
"GET /scim/v2/organizations/:org/Users/:scim_user_id"
1712
],
18-
listProvisionedIdentities: ["GET /scim/v2/organizations/:org/Users", {}],
19-
provisionAndInviteUsers: ["POST /scim/v2/organizations/:org/Users", {}],
13+
listProvisionedIdentities: ["GET /scim/v2/organizations/:org/Users"],
14+
provisionAndInviteUsers: ["POST /scim/v2/organizations/:org/Users"],
2015
provisionInviteUsers: [
2116
"POST /scim/v2/organizations/:org/Users",
2217
{},
2318
{ renamed: ["scim", "provisionAndInviteUsers"] }
2419
],
2520
removeUserFromOrg: [
26-
"DELETE /scim/v2/organizations/:org/Users/:scim_user_id",
27-
{}
21+
"DELETE /scim/v2/organizations/:org/Users/:scim_user_id"
2822
],
2923
replaceProvisionedUserInformation: [
30-
"PUT /scim/v2/organizations/:org/Users/:scim_user_id",
31-
{}
24+
"PUT /scim/v2/organizations/:org/Users/:scim_user_id"
3225
],
3326
updateProvisionedOrgMembership: [
3427
"PUT /scim/v2/organizations/:org/Users/:scim_user_id",
3528
{},
3629
{ renamed: ["scim", "replaceProvisionedUserInformation"] }
3730
],
3831
updateUserAttribute: [
39-
"PATCH /scim/v2/organizations/:org/Users/:scim_user_id",
40-
{}
32+
"PATCH /scim/v2/organizations/:org/Users/:scim_user_id"
4133
]
4234
},
4335
teams: {
4436
createOrUpdateIdPGroupConnections: [
45-
"PATCH /teams/:team_id/team-sync/group-mappings",
46-
{}
37+
"PATCH /teams/:team_id/team-sync/group-mappings"
4738
],
48-
listIdPGroups: ["GET /teams/:team_id/team-sync/group-mappings", {}],
49-
listIdPGroupsForOrg: ["GET /orgs/:org/team-sync/groups", {}]
39+
listIdPGroups: ["GET /teams/:team_id/team-sync/group-mappings"],
40+
listIdPGroupsForOrg: ["GET /orgs/:org/team-sync/groups"]
5041
}
5142
};
5243

0 commit comments

Comments
 (0)