declastruct-github 1.0.6 → 1.1.1
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/access/daos/DeclaredGithubAppDao.d.ts +8 -0
- package/dist/access/daos/DeclaredGithubAppDao.js +32 -0
- package/dist/access/daos/DeclaredGithubAppDao.js.map +1 -0
- package/dist/access/daos/DeclaredGithubAppInstallationDao.d.ts +9 -0
- package/dist/access/daos/DeclaredGithubAppInstallationDao.js +33 -0
- package/dist/access/daos/DeclaredGithubAppInstallationDao.js.map +1 -0
- package/dist/access/daos/DeclaredGithubBranchDao.js +4 -4
- package/dist/access/daos/DeclaredGithubBranchDao.js.map +1 -1
- package/dist/access/daos/DeclaredGithubBranchProtectionDao.js +4 -4
- package/dist/access/daos/DeclaredGithubBranchProtectionDao.js.map +1 -1
- package/dist/access/daos/DeclaredGithubRepoConfigDao.js +4 -4
- package/dist/access/daos/DeclaredGithubRepoConfigDao.js.map +1 -1
- package/dist/access/daos/DeclaredGithubRepoDao.js +4 -4
- package/dist/access/daos/DeclaredGithubRepoDao.js.map +1 -1
- package/dist/contract/sdks/index.d.ts +4 -0
- package/dist/contract/sdks/index.js +9 -3
- package/dist/contract/sdks/index.js.map +1 -1
- package/dist/domain.objects/DeclaredGithubApp.d.ts +75 -0
- package/dist/domain.objects/DeclaredGithubApp.js +16 -0
- package/dist/domain.objects/DeclaredGithubApp.js.map +1 -0
- package/dist/domain.objects/DeclaredGithubAppInstallation.d.ts +61 -0
- package/dist/domain.objects/DeclaredGithubAppInstallation.js +16 -0
- package/dist/domain.objects/DeclaredGithubAppInstallation.js.map +1 -0
- package/dist/domain.objects/DeclaredGithubAppPermissions.d.ts +126 -0
- package/dist/domain.objects/DeclaredGithubAppPermissions.js +12 -0
- package/dist/domain.objects/DeclaredGithubAppPermissions.js.map +1 -0
- package/dist/domain.objects/DeclaredGithubOwner.d.ts +17 -0
- package/dist/domain.objects/DeclaredGithubOwner.js +8 -0
- package/dist/domain.objects/DeclaredGithubOwner.js.map +1 -0
- package/dist/domain.objects/DeclaredGithubRepoConfig.d.ts +0 -4
- package/dist/domain.objects/DeclaredGithubRepoConfig.js.map +1 -1
- package/dist/domain.objects/DeclastructGithubProvider.d.ts +4 -0
- package/dist/domain.operations/app/castToDeclaredGithubApp.d.ts +12 -0
- package/dist/domain.operations/app/castToDeclaredGithubApp.js +133 -0
- package/dist/domain.operations/app/castToDeclaredGithubApp.js.map +1 -0
- package/dist/domain.operations/app/getOneApp.d.ts +15 -0
- package/dist/domain.operations/app/getOneApp.js +67 -0
- package/dist/domain.operations/app/getOneApp.js.map +1 -0
- package/dist/domain.operations/app/setApp.d.ts +13 -0
- package/dist/domain.operations/app/setApp.js +77 -0
- package/dist/domain.operations/app/setApp.js.map +1 -0
- package/dist/domain.operations/appInstallation/castToDeclaredGithubAppInstallation.d.ts +19 -0
- package/dist/domain.operations/appInstallation/castToDeclaredGithubAppInstallation.js +61 -0
- package/dist/domain.operations/appInstallation/castToDeclaredGithubAppInstallation.js.map +1 -0
- package/dist/domain.operations/appInstallation/deleteAppInstallation.d.ts +11 -0
- package/dist/domain.operations/appInstallation/deleteAppInstallation.js +30 -0
- package/dist/domain.operations/appInstallation/deleteAppInstallation.js.map +1 -0
- package/dist/domain.operations/appInstallation/getOneAppInstallation.d.ts +15 -0
- package/dist/domain.operations/appInstallation/getOneAppInstallation.js +92 -0
- package/dist/domain.operations/appInstallation/getOneAppInstallation.js.map +1 -0
- package/dist/domain.operations/appInstallation/setAppInstallation.d.ts +13 -0
- package/dist/domain.operations/appInstallation/setAppInstallation.js +131 -0
- package/dist/domain.operations/appInstallation/setAppInstallation.js.map +1 -0
- package/dist/domain.operations/branch/setBranch.js +23 -19
- package/dist/domain.operations/branch/setBranch.js.map +1 -1
- package/dist/domain.operations/context/hasContextWithAppToken.d.ts +6 -0
- package/dist/domain.operations/context/hasContextWithAppToken.js +15 -0
- package/dist/domain.operations/context/hasContextWithAppToken.js.map +1 -0
- package/dist/domain.operations/context/hasContextWithPatToken.d.ts +6 -0
- package/dist/domain.operations/context/hasContextWithPatToken.js +17 -0
- package/dist/domain.operations/context/hasContextWithPatToken.js.map +1 -0
- package/dist/domain.operations/provider/getDeclastructGithubProvider.js +4 -0
- package/dist/domain.operations/provider/getDeclastructGithubProvider.js.map +1 -1
- package/dist/domain.operations/repo/getRepos.js +22 -5
- package/dist/domain.operations/repo/getRepos.js.map +1 -1
- package/dist/domain.operations/repoConfig/castToDeclaredGithubRepoConfig.js +0 -1
- package/dist/domain.operations/repoConfig/castToDeclaredGithubRepoConfig.js.map +1 -1
- package/dist/domain.operations/repoConfig/setRepoConfig.js +0 -1
- package/dist/domain.operations/repoConfig/setRepoConfig.js.map +1 -1
- package/package.json +9 -8
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getOneAppInstallation.js","sourceRoot":"","sources":["../../../src/domain.operations/appInstallation/getOneAppInstallation.ts"],"names":[],"mappings":";;;AAAA,+CAA2C;AAE3C,mDAAuE;AAIvE,uEAAoE;AAGpE,8EAA2E;AAC3E,8EAA2E;AAC3E,+FAA4F;AAE5F;;;;GAIG;AACU,QAAA,qBAAqB,GAAG,IAAA,0BAAW,EAC9C,KAAK,EACH,KAEC,EACD,OAA6C,EACe,EAAE;IAC9D,2BAA2B;IAC3B,MAAM,MAAM,GAAG,IAAA,iCAAe,EAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IAE5C,2BAA2B;IAC3B,IAAI,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC;QACpB,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC;QAExC,wDAAwD;QACxD,6EAA6E;QAC7E,IAAI,CAAC;YACH,IAAI,MAAM,CAAC,IAAI,KAAK,cAAc,EAAE,CAAC;gBACnC,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC;oBACtD,GAAG,EAAE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|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { HasMetadata, PickOne } from 'type-fns';
|
|
2
|
+
import type { VisualogicContext } from 'visualogic';
|
|
3
|
+
import type { ContextGithubApi } from '../../domain.objects/ContextGithubApi';
|
|
4
|
+
import type { DeclaredGithubAppInstallation } from '../../domain.objects/DeclaredGithubAppInstallation';
|
|
5
|
+
/**
|
|
6
|
+
* .what = sets a GitHub App installation: finsert or upsert
|
|
7
|
+
* .why = provides declarative interface for managing installations with partial automation
|
|
8
|
+
* .note = installations cannot be created via API; repository selection can be synced for existing installations
|
|
9
|
+
*/
|
|
10
|
+
export declare const setAppInstallation: (input: PickOne<{
|
|
11
|
+
finsert: DeclaredGithubAppInstallation;
|
|
12
|
+
upsert: DeclaredGithubAppInstallation;
|
|
13
|
+
}>, context: ContextGithubApi & VisualogicContext) => Promise<HasMetadata<DeclaredGithubAppInstallation>>;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setAppInstallation = void 0;
|
|
4
|
+
const as_procedure_1 = require("as-procedure");
|
|
5
|
+
const helpful_errors_1 = require("helpful-errors");
|
|
6
|
+
const getGithubClient_1 = require("../../access/sdks/getGithubClient");
|
|
7
|
+
const getOneAppInstallation_1 = require("./getOneAppInstallation");
|
|
8
|
+
/**
|
|
9
|
+
* .what = sets a GitHub App installation: finsert or upsert
|
|
10
|
+
* .why = provides declarative interface for managing installations with partial automation
|
|
11
|
+
* .note = installations cannot be created via API; repository selection can be synced for existing installations
|
|
12
|
+
*/
|
|
13
|
+
exports.setAppInstallation = (0, as_procedure_1.asProcedure)(async (input, context) => {
|
|
14
|
+
const desired = input.finsert ??
|
|
15
|
+
input.upsert ??
|
|
16
|
+
helpful_errors_1.UnexpectedCodePathError.throw('no installation provided to setAppInstallation', { input });
|
|
17
|
+
// check whether it already exists
|
|
18
|
+
const foundBefore = await (0, getOneAppInstallation_1.getOneAppInstallation)({
|
|
19
|
+
by: {
|
|
20
|
+
unique: {
|
|
21
|
+
app: desired.app,
|
|
22
|
+
target: desired.target,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
}, context);
|
|
26
|
+
// if installation doesn't exist, throw HelpfulError with installation instructions
|
|
27
|
+
if (!foundBefore) {
|
|
28
|
+
const installUrl = `https://github.com/apps/${desired.app.slug}/installations/new`;
|
|
29
|
+
throw new helpful_errors_1.HelpfulError('GitHub App installations cannot be created via API. Please install the app manually.', {
|
|
30
|
+
installUrl,
|
|
31
|
+
instructions: [
|
|
32
|
+
`1. Navigate to: ${installUrl}`,
|
|
33
|
+
`2. Select the ${desired.target.type.toLowerCase()}: ${desired.target.slug}`,
|
|
34
|
+
desired.repositorySelection === 'selected'
|
|
35
|
+
? `3. Choose "Only select repositories" and select: ${desired.repositories?.join(', ') ?? '(none specified)'}`
|
|
36
|
+
: '3. Choose "All repositories" for full access',
|
|
37
|
+
'4. Click "Install" to complete the installation',
|
|
38
|
+
],
|
|
39
|
+
desired,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
// if it's a finsert and exists, return the found installation
|
|
43
|
+
if (input.finsert)
|
|
44
|
+
return foundBefore;
|
|
45
|
+
// if it's an upsert and exists, sync repository selection if needed
|
|
46
|
+
if (input.upsert) {
|
|
47
|
+
// check if we need to sync repository selection
|
|
48
|
+
if (desired.repositorySelection === 'selected') {
|
|
49
|
+
const result = await syncInstallationRepositories({
|
|
50
|
+
installationId: foundBefore.id,
|
|
51
|
+
desiredRepositories: desired.repositories ?? [],
|
|
52
|
+
currentRepositories: foundBefore.repositories ?? [],
|
|
53
|
+
app: desired.app,
|
|
54
|
+
}, context);
|
|
55
|
+
// get updated installation after sync
|
|
56
|
+
const foundAfter = await (0, getOneAppInstallation_1.getOneAppInstallation)({ by: { unique: { app: desired.app, target: desired.target } } }, context);
|
|
57
|
+
if (!foundAfter)
|
|
58
|
+
helpful_errors_1.UnexpectedCodePathError.throw('installation not found after sync. should not be possible', { desired, result });
|
|
59
|
+
return foundAfter;
|
|
60
|
+
}
|
|
61
|
+
// no sync needed, return as-is
|
|
62
|
+
return foundBefore;
|
|
63
|
+
}
|
|
64
|
+
// unreachable
|
|
65
|
+
helpful_errors_1.UnexpectedCodePathError.throw('unexpected code path in setAppInstallation', {
|
|
66
|
+
input,
|
|
67
|
+
foundBefore,
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
/**
|
|
71
|
+
* .what = syncs repositories for an installation by adding/removing as needed
|
|
72
|
+
* .why = enables declarative management of which repos an installation has access to
|
|
73
|
+
*/
|
|
74
|
+
const syncInstallationRepositories = async (input, context) => {
|
|
75
|
+
const github = (0, getGithubClient_1.getGithubClient)({}, context);
|
|
76
|
+
// determine repos to add and remove
|
|
77
|
+
const reposToAdd = input.desiredRepositories.filter((repo) => !input.currentRepositories.includes(repo));
|
|
78
|
+
const reposToRemove = input.currentRepositories.filter((repo) => !input.desiredRepositories.includes(repo));
|
|
79
|
+
// add repos that are missing
|
|
80
|
+
for (const repoName of reposToAdd) {
|
|
81
|
+
try {
|
|
82
|
+
// first get the repo id
|
|
83
|
+
const repoResponse = await github.repos.get({
|
|
84
|
+
owner: input.app.owner.slug,
|
|
85
|
+
repo: repoName,
|
|
86
|
+
});
|
|
87
|
+
const repoId = repoResponse.data.id;
|
|
88
|
+
// then add it to the installation
|
|
89
|
+
await github.apps.addRepoToInstallationForAuthenticatedUser({
|
|
90
|
+
installation_id: input.installationId,
|
|
91
|
+
repository_id: repoId,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
if (!(error instanceof Error))
|
|
96
|
+
throw error;
|
|
97
|
+
throw new helpful_errors_1.HelpfulError(`failed to add repository "${repoName}" to installation`, {
|
|
98
|
+
cause: error,
|
|
99
|
+
repoName,
|
|
100
|
+
installationId: input.installationId,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// remove repos that shouldn't be there
|
|
105
|
+
for (const repoName of reposToRemove) {
|
|
106
|
+
try {
|
|
107
|
+
// first get the repo id
|
|
108
|
+
const repoResponse = await github.repos.get({
|
|
109
|
+
owner: input.app.owner.slug,
|
|
110
|
+
repo: repoName,
|
|
111
|
+
});
|
|
112
|
+
const repoId = repoResponse.data.id;
|
|
113
|
+
// then remove it from the installation
|
|
114
|
+
await github.apps.removeRepoFromInstallationForAuthenticatedUser({
|
|
115
|
+
installation_id: input.installationId,
|
|
116
|
+
repository_id: repoId,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
if (!(error instanceof Error))
|
|
121
|
+
throw error;
|
|
122
|
+
throw new helpful_errors_1.HelpfulError(`failed to remove repository "${repoName}" from installation`, {
|
|
123
|
+
cause: error,
|
|
124
|
+
repoName,
|
|
125
|
+
installationId: input.installationId,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return { repositories: input.desiredRepositories };
|
|
130
|
+
};
|
|
131
|
+
//# sourceMappingURL=setAppInstallation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setAppInstallation.js","sourceRoot":"","sources":["../../../src/domain.operations/appInstallation/setAppInstallation.ts"],"names":[],"mappings":";;;AAAA,+CAA2C;AAC3C,mDAAuE;AAIvE,uEAAoE;AAGpE,mEAAgE;AAEhE;;;;GAIG;AACU,QAAA,kBAAkB,GAAG,IAAA,0BAAW,EAC3C,KAAK,EACH,KAGE,EACF,OAA6C,EACQ,EAAE;IACvD,MAAM,OAAO,GACX,KAAK,CAAC,OAAO;QACb,KAAK,CAAC,MAAM;QACZ,wCAAuB,CAAC,KAAK,CAC3B,gDAAgD,EAChD,EAAE,KAAK,EAAE,CACV,CAAC;IAEJ,kCAAkC;IAClC,MAAM,WAAW,GAAG,MAAM,IAAA,6CAAqB,EAC7C;QACE,EAAE,EAAE;YACF,MAAM,EAAE;gBACN,GAAG,EAAE,OAAO,CAA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AC,mBAAmB,EAAE,CAAC;AACrD,CAAC,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setBranch = void 0;
|
|
4
|
+
const uni_time_1 = require("@ehmpathy/uni-time");
|
|
4
5
|
const as_procedure_1 = require("as-procedure");
|
|
5
6
|
const helpful_errors_1 = require("helpful-errors");
|
|
6
7
|
const getGithubClient_1 = require("../../access/sdks/getGithubClient");
|
|
@@ -41,18 +42,15 @@ exports.setBranch = (0, as_procedure_1.asProcedure)(async (input, context) => {
|
|
|
41
42
|
sha: desired.commit.sha,
|
|
42
43
|
force: false, // don't force update - fail if not fast-forward
|
|
43
44
|
});
|
|
44
|
-
// fetch the updated branch to return full metadata
|
|
45
|
-
return ((await (0, getBranch_1.getBranch)({
|
|
45
|
+
// fetch the updated branch to return full metadata (with retry for eventual consistency)
|
|
46
|
+
return await (0, uni_time_1.waitFor)(async () => (await (0, getBranch_1.getBranch)({
|
|
46
47
|
by: {
|
|
47
48
|
unique: {
|
|
48
49
|
repo: desired.repo,
|
|
49
50
|
name: desired.name,
|
|
50
51
|
},
|
|
51
52
|
},
|
|
52
|
-
}, context)) ??
|
|
53
|
-
helpful_errors_1.UnexpectedCodePathError.throw('updated branch not found', {
|
|
54
|
-
name: desired.name,
|
|
55
|
-
}));
|
|
53
|
+
}, context)) ?? undefined, { timeout: { seconds: 10 } });
|
|
56
54
|
}
|
|
57
55
|
catch (error) {
|
|
58
56
|
if (!(error instanceof Error))
|
|
@@ -63,36 +61,42 @@ exports.setBranch = (0, as_procedure_1.asProcedure)(async (input, context) => {
|
|
|
63
61
|
}
|
|
64
62
|
}
|
|
65
63
|
// otherwise, create it
|
|
64
|
+
// determine commit SHA to create branch from
|
|
65
|
+
const commitSha = desired.commit?.sha ??
|
|
66
|
+
(await (0, getBranchCommitShaByRepoDefault_1.getBranchCommitShaByRepoDefault)({
|
|
67
|
+
repo: desired.repo,
|
|
68
|
+
}, context));
|
|
69
|
+
// create the branch using git refs API
|
|
66
70
|
try {
|
|
67
|
-
// determine commit SHA to create branch from
|
|
68
|
-
const commitSha = desired.commit?.sha ??
|
|
69
|
-
(await (0, getBranchCommitShaByRepoDefault_1.getBranchCommitShaByRepoDefault)({
|
|
70
|
-
repo: desired.repo,
|
|
71
|
-
}, context));
|
|
72
|
-
// create the branch using git refs API
|
|
73
71
|
await github.git.createRef({
|
|
74
72
|
owner: desired.repo.owner,
|
|
75
73
|
repo: desired.repo.name,
|
|
76
74
|
ref: `refs/heads/${desired.name}`,
|
|
77
75
|
sha: commitSha,
|
|
78
76
|
});
|
|
79
|
-
|
|
80
|
-
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
if (!(error instanceof Error))
|
|
80
|
+
throw error;
|
|
81
|
+
throw new helpful_errors_1.HelpfulError('github.setBranch.createRef error', {
|
|
82
|
+
cause: error,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
// fetch the created branch to return full metadata (with retry for eventual consistency)
|
|
86
|
+
try {
|
|
87
|
+
return await (0, uni_time_1.waitFor)(async () => (await (0, getBranch_1.getBranch)({
|
|
81
88
|
by: {
|
|
82
89
|
unique: {
|
|
83
90
|
repo: desired.repo,
|
|
84
91
|
name: desired.name,
|
|
85
92
|
},
|
|
86
93
|
},
|
|
87
|
-
}, context)) ??
|
|
88
|
-
helpful_errors_1.UnexpectedCodePathError.throw('created branch not found', {
|
|
89
|
-
name: desired.name,
|
|
90
|
-
}));
|
|
94
|
+
}, context)) ?? undefined, { timeout: { seconds: 10 } });
|
|
91
95
|
}
|
|
92
96
|
catch (error) {
|
|
93
97
|
if (!(error instanceof Error))
|
|
94
98
|
throw error;
|
|
95
|
-
throw new helpful_errors_1.HelpfulError('github.setBranch.
|
|
99
|
+
throw new helpful_errors_1.HelpfulError('github.setBranch.waitForBranch error', {
|
|
96
100
|
cause: error,
|
|
97
101
|
});
|
|
98
102
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setBranch.js","sourceRoot":"","sources":["../../../src/domain.operations/branch/setBranch.ts"],"names":[],"mappings":";;;AAAA,+CAA2C;AAC3C,
|
|
1
|
+
{"version":3,"file":"setBranch.js","sourceRoot":"","sources":["../../../src/domain.operations/branch/setBranch.ts"],"names":[],"mappings":";;;AAAA,iDAA6C;AAC7C,+CAA2C;AAC3C,mDAA8C;AAI9C,uEAAoE;AAGpE,2CAAwC;AACxC,uFAAoF;AAEpF;;;GAGG;AACU,QAAA,SAAS,GAAG,IAAA,0BAAW,EAClC,KAAK,EACH,KAGE,EACF,OAA6C,EACD,EAAE;IAC9C,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC;IAE9C,2BAA2B;IAC3B,MAAM,MAAM,GAAG,IAAA,iCAAe,EAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IAE5C,sCAAsC;IACtC,MAAM,MAAM,GAAG,MAAM,IAAA,qBAAS,EAC5B;QACE,EAAE,EAAE;YACF,MAAM,EAAE;gBACN,IAAI,EAAE,OAAO,CAAC,IAAI;gBAClB,IAAI,EAAE,OAAO,CAAC,IAAI;aACnB;SACF;KACF,EACD,OAAO,CACR,CAAC;IAEF,uDAAuD;IACvD,IAAI,MAAM,IAAI,KAAK,CAAC,OAAO;QAAE,OAAO,MAAM,CAAC;IAE3C,8EAA8E;IAC9E,IAAI,MAAM,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG;QAAE,OAAO,MAAM,CAAC;IAClE,IAAI,MAAM,IAAI,KAAK,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,EAAE,GAAG,KAAK,MAAM,CAAC,MAAM,EAAE,GAAG;QACtE,OAAO,MAAM,CAAC;IAEhB,+DAA+D;IAC/D,IAAI,MAAM,IAAI,KAAK,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,EAAE,GAAG,EAAE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O,CAAC,IAAI,CAAC,IAAI;YACvB,GAAG,EAAE,cAAc,OAAO,CAAC,IAAI,EAAE;YACjC,GAAG,EAAE,SAAS;SACf,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC;YAAE,MAAM,KAAK,CAAC;QAC3C,MAAM,IAAI,6BAAY,CAAC,kCAAkC,EAAE;YACzD,KAAK,EAAE,KAAK;SACb,CAAC,CAAC;IACL,CAAC;IAED,yFAAyF;IACzF,IAAI,CAAC;QACH,OAAO,MAAM,IAAA,kBAAO,EAClB,KAAK,IAAI,EAAE,CACT,CAAC,MAAM,IAAA,qBAAS,EACd;YACE,EAAE,EAAE;gBACF,MAAM,EAAE;oBACN,IAAI,EAAE,OAAO,CAAC,IAAI;oBAClB,IAAI,EAAE,OAAO,CAAC,IAAI;iBACnB;aACF;SACF,EACD,OAAO,CACR,CAAC,IAAI,SAAS,EACjB,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,CAC7B,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC;YAAE,MAAM,KAAK,CAAC;QAC3C,MAAM,IAAI,6BAAY,CAAC,sCAAsC,EAAE;YAC7D,KAAK,EAAE,KAAK;SACb,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CACF,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ContextGithubApi } from '../../domain.objects/ContextGithubApi';
|
|
2
|
+
/**
|
|
3
|
+
* .what = checks if context contains a GitHub App installation token
|
|
4
|
+
* .why = different GitHub API endpoints require different token types; app tokens have different scopes than PATs
|
|
5
|
+
*/
|
|
6
|
+
export declare const hasContextWithAppToken: (_input: null, context: ContextGithubApi) => boolean;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hasContextWithAppToken = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* .what = checks if context contains a GitHub App installation token
|
|
6
|
+
* .why = different GitHub API endpoints require different token types; app tokens have different scopes than PATs
|
|
7
|
+
*/
|
|
8
|
+
const hasContextWithAppToken = (_input, context) => {
|
|
9
|
+
const token = context.github.token;
|
|
10
|
+
// GitHub App installation token format (server-to-server token)
|
|
11
|
+
const isAppToken = token.startsWith('ghs_');
|
|
12
|
+
return isAppToken;
|
|
13
|
+
};
|
|
14
|
+
exports.hasContextWithAppToken = hasContextWithAppToken;
|
|
15
|
+
//# sourceMappingURL=hasContextWithAppToken.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hasContextWithAppToken.js","sourceRoot":"","sources":["../../../src/domain.operations/context/hasContextWithAppToken.ts"],"names":[],"mappings":";;;AAEA;;;GAGG;AACI,MAAM,sBAAsB,GAAG,CACpC,MAAY,EACZ,OAAyB,EAChB,EAAE;IACX,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC;IAEnC,gEAAgE;IAChE,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IAE5C,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAVW,QAAA,sBAAsB,0BAUjC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ContextGithubApi } from '../../domain.objects/ContextGithubApi';
|
|
2
|
+
/**
|
|
3
|
+
* .what = checks if context contains a GitHub Personal Access Token (PAT)
|
|
4
|
+
* .why = different GitHub API endpoints require different token types; PATs have different permissions than app tokens
|
|
5
|
+
*/
|
|
6
|
+
export declare const hasContextWithPatToken: (_input: null, context: ContextGithubApi) => boolean;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hasContextWithPatToken = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* .what = checks if context contains a GitHub Personal Access Token (PAT)
|
|
6
|
+
* .why = different GitHub API endpoints require different token types; PATs have different permissions than app tokens
|
|
7
|
+
*/
|
|
8
|
+
const hasContextWithPatToken = (_input, context) => {
|
|
9
|
+
const token = context.github.token;
|
|
10
|
+
// classic PAT format
|
|
11
|
+
const isClassicPat = token.startsWith('ghp_');
|
|
12
|
+
// fine-grained PAT format
|
|
13
|
+
const isFineGrainedPat = token.startsWith('github_pat_');
|
|
14
|
+
return isClassicPat || isFineGrainedPat;
|
|
15
|
+
};
|
|
16
|
+
exports.hasContextWithPatToken = hasContextWithPatToken;
|
|
17
|
+
//# sourceMappingURL=hasContextWithPatToken.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hasContextWithPatToken.js","sourceRoot":"","sources":["../../../src/domain.operations/context/hasContextWithPatToken.ts"],"names":[],"mappings":";;;AAEA;;;GAGG;AACI,MAAM,sBAAsB,GAAG,CACpC,MAAY,EACZ,OAAyB,EAChB,EAAE;IACX,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC;IAEnC,qBAAqB;IACrB,MAAM,YAAY,GAAG,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IAE9C,0BAA0B;IAC1B,MAAM,gBAAgB,GAAG,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;IAEzD,OAAO,YAAY,IAAI,gBAAgB,CAAC;AAC1C,CAAC,CAAC;AAbW,QAAA,sBAAsB,0BAajC"}
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getDeclastructGithubProvider = void 0;
|
|
4
4
|
const declastruct_1 = require("declastruct");
|
|
5
|
+
const DeclaredGithubAppDao_1 = require("../../access/daos/DeclaredGithubAppDao");
|
|
6
|
+
const DeclaredGithubAppInstallationDao_1 = require("../../access/daos/DeclaredGithubAppInstallationDao");
|
|
5
7
|
const DeclaredGithubBranchDao_1 = require("../../access/daos/DeclaredGithubBranchDao");
|
|
6
8
|
const DeclaredGithubBranchProtectionDao_1 = require("../../access/daos/DeclaredGithubBranchProtectionDao");
|
|
7
9
|
const DeclaredGithubRepoConfigDao_1 = require("../../access/daos/DeclaredGithubRepoConfigDao");
|
|
@@ -24,6 +26,8 @@ const getDeclastructGithubProvider = (input, context) => {
|
|
|
24
26
|
DeclaredGithubBranch: DeclaredGithubBranchDao_1.DeclaredGithubBranchDao,
|
|
25
27
|
DeclaredGithubRepoConfig: DeclaredGithubRepoConfigDao_1.DeclaredGithubRepoConfigDao,
|
|
26
28
|
DeclaredGithubBranchProtection: DeclaredGithubBranchProtectionDao_1.DeclaredGithubBranchProtectionDao,
|
|
29
|
+
DeclaredGithubApp: DeclaredGithubAppDao_1.DeclaredGithubAppDao,
|
|
30
|
+
DeclaredGithubAppInstallation: DeclaredGithubAppInstallationDao_1.DeclaredGithubAppInstallationDao,
|
|
27
31
|
};
|
|
28
32
|
// return provider with all required properties
|
|
29
33
|
return new declastruct_1.DeclastructProvider({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDeclastructGithubProvider.js","sourceRoot":"","sources":["../../../src/domain.operations/provider/getDeclastructGithubProvider.ts"],"names":[],"mappings":";;;AAAA,6CAAkD;AAGlD,uFAAoF;AACpF,2GAAwG;AACxG,+FAA4F;AAC5F,mFAAgF;AAIhF;;;GAGG;AACI,MAAM,4BAA4B,GAAG,CAC1C,KAIC,EACD,OAAwB,EACG,EAAE;IAC7B,+CAA+C;IAC/C,MAAM,eAAe,GAAuC;QAC1D,GAAG,OAAO;QACV,MAAM,EAAE;YACN,KAAK,EAAE,KAAK,CAAC,WAAW,CAAC,KAAK;SAC/B;KACF,CAAC;IAEF,8CAA8C;IAC9C,MAAM,IAAI,GAAG;QACX,kBAAkB,EAAE,6CAAqB;QACzC,oBAAoB,EAAE,iDAAuB;QAC7C,wBAAwB,EAAE,yDAA2B;QACrD,8BAA8B,EAAE,qEAAiC;
|
|
1
|
+
{"version":3,"file":"getDeclastructGithubProvider.js","sourceRoot":"","sources":["../../../src/domain.operations/provider/getDeclastructGithubProvider.ts"],"names":[],"mappings":";;;AAAA,6CAAkD;AAGlD,iFAA8E;AAC9E,yGAAsG;AACtG,uFAAoF;AACpF,2GAAwG;AACxG,+FAA4F;AAC5F,mFAAgF;AAIhF;;;GAGG;AACI,MAAM,4BAA4B,GAAG,CAC1C,KAIC,EACD,OAAwB,EACG,EAAE;IAC7B,+CAA+C;IAC/C,MAAM,eAAe,GAAuC;QAC1D,GAAG,OAAO;QACV,MAAM,EAAE;YACN,KAAK,EAAE,KAAK,CAAC,WAAW,CAAC,KAAK;SAC/B;KACF,CAAC;IAEF,8CAA8C;IAC9C,MAAM,IAAI,GAAG;QACX,kBAAkB,EAAE,6CAAqB;QACzC,oBAAoB,EAAE,iDAAuB;QAC7C,wBAAwB,EAAE,yDAA2B;QACrD,8BAA8B,EAAE,qEAAiC;QACjE,iBAAiB,EAAE,2CAAoB;QACvC,6BAA6B,EAAE,mEAAgC;KAChE,CAAC;IAEF,+CAA+C;IAC/C,OAAO,IAAI,iCAAmB,CAAC;QAC7B,IAAI,EAAE,QAAQ;QACd,IAAI;QACJ,OAAO,EAAE,eAAe;QACxB,KAAK,EAAE;YACL,SAAS,EAAE,KAAK,IAAI,EAAE;gBACpB,sCAAsC;YACxC,CAAC;YACD,QAAQ,EAAE,KAAK,IAAI,EAAE;gBACnB,yCAAyC;YAC3C,CAAC;SACF;KACF,CAAC,CAAC;AACL,CAAC,CAAC;AAxCW,QAAA,4BAA4B,gCAwCvC"}
|
|
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getRepos = void 0;
|
|
4
4
|
const helpful_errors_1 = require("helpful-errors");
|
|
5
5
|
const getGithubClient_1 = require("../../access/sdks/getGithubClient");
|
|
6
|
+
const hasContextWithAppToken_1 = require("../context/hasContextWithAppToken");
|
|
7
|
+
const hasContextWithPatToken_1 = require("../context/hasContextWithPatToken");
|
|
6
8
|
const castToDeclaredGithubRepo_1 = require("./castToDeclaredGithubRepo");
|
|
7
9
|
/**
|
|
8
10
|
* .what = lists GitHub repositories
|
|
@@ -11,6 +13,9 @@ const castToDeclaredGithubRepo_1 = require("./castToDeclaredGithubRepo");
|
|
|
11
13
|
const getRepos = async (input, context) => {
|
|
12
14
|
// get cached GitHub client
|
|
13
15
|
const github = (0, getGithubClient_1.getGithubClient)({}, context);
|
|
16
|
+
// detect token type for choosing appropriate endpoint
|
|
17
|
+
const isAppToken = (0, hasContextWithAppToken_1.hasContextWithAppToken)(null, context);
|
|
18
|
+
const isPat = (0, hasContextWithPatToken_1.hasContextWithPatToken)(null, context);
|
|
14
19
|
// execute the GitHub API call
|
|
15
20
|
try {
|
|
16
21
|
const response = await (async () => {
|
|
@@ -22,11 +27,23 @@ const getRepos = async (input, context) => {
|
|
|
22
27
|
per_page: input.page?.limit,
|
|
23
28
|
});
|
|
24
29
|
}
|
|
25
|
-
//
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
// list repos accessible to the authenticated context
|
|
31
|
+
// - app token: use installation endpoint (listForAuthenticatedUser not available)
|
|
32
|
+
// - PAT: use user endpoint
|
|
33
|
+
if (isAppToken) {
|
|
34
|
+
const result = await github.apps.listReposAccessibleToInstallation({
|
|
35
|
+
page: input.page?.range?.until.page,
|
|
36
|
+
per_page: input.page?.limit,
|
|
37
|
+
});
|
|
38
|
+
return { data: result.data.repositories };
|
|
39
|
+
}
|
|
40
|
+
if (isPat) {
|
|
41
|
+
return github.repos.listForAuthenticatedUser({
|
|
42
|
+
page: input.page?.range?.until.page,
|
|
43
|
+
per_page: input.page?.limit,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
throw new helpful_errors_1.UnexpectedCodePathError('unsupported token type for listing repos', { tokenPrefix: context.github.token.slice(0, 10) + '...' });
|
|
30
47
|
})();
|
|
31
48
|
const repos = response.data ?? [];
|
|
32
49
|
return repos.map(castToDeclaredGithubRepo_1.castToDeclaredGithubRepo);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getRepos.js","sourceRoot":"","sources":["../../../src/domain.operations/repo/getRepos.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"getRepos.js","sourceRoot":"","sources":["../../../src/domain.operations/repo/getRepos.ts"],"names":[],"mappings":";;;AAAA,mDAAuE;AAIvE,uEAAoE;AAGpE,8EAA2E;AAC3E,8EAA2E;AAC3E,yEAAsE;AAEtE;;;GAGG;AACI,MAAM,QAAQ,GAAG,KAAK,EAC3B,KAQC,EACD,OAA6C,EACD,EAAE;IAC9C,2BAA2B;IAC3B,MAAM,MAAM,GAAG,IAAA,iCAAe,EAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IAE5C,sDAAsD;IACtD,MAAM,UAAU,GAAG,IAAA,+CAAsB,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACzD,MAAM,KAAK,GAAG,IAAA,+CAAsB,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAEpD,8BAA8B;IAC9B,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,IAAI,EAAE;YACjC,sDAAsD;YACtD,IAAI,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,CAAC;gBACvB,OAAO,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC;oBAC7B,GAAG,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK;oBACtB,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI;oBACnC,QAAQ,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK;iBAC5B,CAAC,CAAC;YACL,CAAC;YAED,qDAAqD;YACrD,kFAAkF;YAClF,2BAA2B;YAC3B,IAAI,UAAU,EAAE,CAAC;gBACf,MAAM,MA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asWiki: input.response.has_wiki,
|
|
19
|
-
hasDownloads: input.response.has_downloads,
|
|
20
19
|
isTemplate: input.response.is_template,
|
|
21
20
|
defaultBranch: input.response.default_branch,
|
|
22
21
|
allowSquashMerge: input.response.allow_squash_merge,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"castToDeclaredGithubRepoConfig.js","sourceRoot":"","sources":["../../../src/domain.operations/repoConfig/castToDeclaredGithubRepoConfig.ts"],"names":[],"mappings":";;;AACA,mDAA+D;AAG/D,gFAA6E;AAC7E,4FAAyF;AAKzF;;;GAGG;AACI,MAAM,8BAA8B,GAAG,CAAC,KAG9C,EAAyC,EAAE;IAC1C,OAAO,mDAAwB,CAAC,EAAE,CAAC;QACjC,IAAI,EACF,KAAK,CAAC,IAAI,YAAY,uCAAkB;YACtC,CAAC,CAAC,IAAA,4BAAW,EAA4B,KAAK,CAAC,IAAI,CAAC;YACpD,CAAC,CAAC,KAAK,CAAC,IAAI;QAChB,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,UAAU;QACpC,WAAW,EAAE,KAAK,CAAC,QAAQ,CAAC,YAAY;QACxC,OAAO,EAAE,KAAK,CAAC,QAAQ,CAAC,QAAQ;QAChC,
|
|
1
|
+
{"version":3,"file":"castToDeclaredGithubRepoConfig.js","sourceRoot":"","sources":["../../../src/domain.operations/repoConfig/castToDeclaredGithubRepoConfig.ts"],"names":[],"mappings":";;;AACA,mDAA+D;AAG/D,gFAA6E;AAC7E,4FAAyF;AAKzF;;;GAGG;AACI,MAAM,8BAA8B,GAAG,CAAC,KAG9C,EAAyC,EAAE;IAC1C,OAAO,mDAAwB,CAAC,EAAE,CAAC;QACjC,IAAI,EACF,KAAK,CAAC,IAAI,YAAY,uCAAkB;YACtC,CAAC,CAAC,IAAA,4BAAW,EAA4B,KAAK,CAAC,IAAI,CAAC;YACpD,CAAC,CAAC,KAAK,CAAC,IAAI;QAChB,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,UAAU;QACpC,WAAW,EAAE,KAAK,CAAC,QAAQ,CAAC,YAAY;QACxC,OAAO,EAAE,KAAK,CAAC,QAAQ,CAAC,QAAQ;QAChC,UAAU,EAAE,KAAK,CAAC,QAAQ,CAAC,WAAW;QACtC,aAAa,EAAE,KAAK,CAAC,QAAQ,CAAC,cAAc;QAC5C,gBAAgB,EAAE,KAAK,CAAC,QAAQ,CAAC,kBAAkB;QACnD,gBAAgB,EAAE,KAAK,CAAC,QAAQ,CAAC,kBAAkB;QACnD,gBAAgB,EAAE,KAAK,CAAC,QAAQ,CAAC,kBAAkB;QACnD,cAAc,EAAE,KAAK,CAAC,QAAQ,CAAC,gBAAgB;QAC/C,mBAAmB,EAAE,KAAK,CAAC,QAAQ,CAAC,sBAAsB;QAC1D,iBAAiB,EAAE,KAAK,CAAC,QAAQ,CAAC,mBAAmB;QACrD,sBAAsB,EAAE,KAAK,CAAC,QAAQ,CAAC,yBAG1B;QACb,wBAAwB,EAAE,KAAK,CAAC,QAAQ,CAAC,2BAI5B;QACb,gBAAgB,EAAE,KAAK,CAAC,QAAQ,CAAC,kBAGpB;QACb,kBAAkB,EAAE,KAAK,CAAC,QAAQ,CAAC,oBAItB;QACb,wBAAwB,EAAE,KAAK,CAAC,QAAQ,CAAC,2BAA2B;KACrE,CAA0C,CAAC;AAC9C,CAAC,CAAC;AAxCW,QAAA,8BAA8B,kCAwCzC"}
|
|
@@ -34,7 +34,6 @@ exports.setRepoConfig = (0, as_procedure_1.asProcedure)(async (input, context) =
|
|
|
34
34
|
has_issues: desired.hasIssues,
|
|
35
35
|
has_projects: desired.hasProjects,
|
|
36
36
|
has_wiki: desired.hasWiki,
|
|
37
|
-
has_downloads: desired.hasDownloads,
|
|
38
37
|
is_template: desired.isTemplate,
|
|
39
38
|
default_branch: desired.defaultBranch,
|
|
40
39
|
allow_squash_merge: desired.allowSquashMerge,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setRepoConfig.js","sourceRoot":"","sources":["../../../src/domain.operations/repoConfig/setRepoConfig.ts"],"names":[],"mappings":";;;AAAA,+CAA2C;AAC3C,mDAA8C;AAI9C,uEAAoE;AAGpE,qFAAkF;AAClF,mDAAgD;AAEhD;;;GAGG;AACU,QAAA,aAAa,GAAG,IAAA,0BAAW,EACtC,KAAK,EACH,KAGE,EACF,OAA6C,EACG,EAAE;IAClD,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC;IAE9C,2BAA2B;IAC3B,MAAM,MAAM,GAAG,IAAA,iCAAe,EAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IAE5C,kCAAkC;IAClC,MAAM,MAAM,GAAG,MAAM,IAAA,6BAAa,EAChC;QACE,EAAE,EAAE;YACF,MAAM,EAAE;gBACN,IAAI,EAAE,OAAO,CAAC,IAAI;aACnB;SACF;KACF,EACD,OAAO,CACR,CAAC;IAEF,uDAAuD;IACvD,IAAI,MAAM,IAAI,KAAK,CAAC,OAAO;QAAE,OAAO,MAAM,CAAC;IAE3C,mGAAmG;IACnG,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,OAAO,CAAC,IAAuC,CAAC;QAChE,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC;YACxC,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,UAAU,EAAE,OAAO,CAAC,SAAS;YAC7B,YAAY,EAAE,OAAO,CAAC,WAAW;YACjC,QAAQ,EAAE,OAAO,CAAC,OAAO;YACzB,
|
|
1
|
+
{"version":3,"file":"setRepoConfig.js","sourceRoot":"","sources":["../../../src/domain.operations/repoConfig/setRepoConfig.ts"],"names":[],"mappings":";;;AAAA,+CAA2C;AAC3C,mDAA8C;AAI9C,uEAAoE;AAGpE,qFAAkF;AAClF,mDAAgD;AAEhD;;;GAGG;AACU,QAAA,aAAa,GAAG,IAAA,0BAAW,EACtC,KAAK,EACH,KAGE,EACF,OAA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,CAAC,kBAAkB;YAChD,2BAA2B,EAAE,OAAO,CAAC,wBAAwB;SAC9D,CAAC,CAAC;QAEH,OAAO,IAAA,+DAA8B,EAAC;YACpC,QAAQ,EAAE,OAAO,CAAC,IAAI;YACtB,IAAI,EAAE,OAAO,CAAC,IAAI;SACnB,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC;YAAE,MAAM,KAAK,CAAC;QAC3C,MAAM,IAAI,6BAAY,CAAC,mCAAmC,EAAE;YAC1D,KAAK,EAAE,KAAK;SACb,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "declastruct-github",
|
|
3
3
|
"author": "ehmpathy",
|
|
4
4
|
"description": "declarative control of GitHub constructs via declastruct - manage repos, branches, and protection rules",
|
|
5
|
-
"version": "1.
|
|
5
|
+
"version": "1.1.1",
|
|
6
6
|
"repository": "ehmpathy/declastruct-github",
|
|
7
7
|
"homepage": "https://github.com/ehmpathy/declastruct-github",
|
|
8
8
|
"keywords": [
|
|
@@ -29,11 +29,12 @@
|
|
|
29
29
|
"fix:format:biome": "biome check --write src",
|
|
30
30
|
"fix:format": "npm run fix:format:biome",
|
|
31
31
|
"fix:lint": "biome check --write src",
|
|
32
|
+
"fix": "npm run fix:format && npm run fix:lint",
|
|
32
33
|
"build:clean": "rm dist/ -rf",
|
|
33
34
|
"build:compile": "tsc -p ./tsconfig.build.json",
|
|
34
35
|
"build": "npm run build:clean && npm run build:compile",
|
|
35
36
|
"test:commits": "LAST_TAG=$(git describe --tags --abbrev=0 @^ 2> /dev/null || git rev-list --max-parents=0 HEAD) && npx commitlint --from $LAST_TAG --to HEAD --verbose",
|
|
36
|
-
"test:types": "tsc -p ./tsconfig.json --noEmit",
|
|
37
|
+
"test:types": "rm -f dist/tsconfig.tsbuildinfo && tsc -p ./tsconfig.json --noEmit",
|
|
37
38
|
"test:format": "npm run test:format:biome",
|
|
38
39
|
"test:lint:deps": "npx depcheck -c ./.depcheckrc.yml",
|
|
39
40
|
"test:format:biome": "biome format src",
|
|
@@ -50,7 +51,7 @@
|
|
|
50
51
|
"preversion": "npm run prepush",
|
|
51
52
|
"postversion": "git push origin HEAD --tags --no-verify",
|
|
52
53
|
"prepare:husky": "npx husky install && chmod ug+x .husky/*",
|
|
53
|
-
"prepare": "[ -
|
|
54
|
+
"prepare": "[ -e .git ] && npm run prepare:husky || exit 0"
|
|
54
55
|
},
|
|
55
56
|
"dependencies": {
|
|
56
57
|
"@ehmpathy/uni-time": "1.7.4",
|
|
@@ -76,15 +77,15 @@
|
|
|
76
77
|
"@types/node": "22.15.21",
|
|
77
78
|
"cz-conventional-changelog": "3.3.0",
|
|
78
79
|
"declapract": "0.13.0",
|
|
79
|
-
"declapract-typescript-ehmpathy": "0.43.
|
|
80
|
-
"declastruct": "
|
|
81
|
-
"declastruct-github": "
|
|
80
|
+
"declapract-typescript-ehmpathy": "0.43.11",
|
|
81
|
+
"declastruct": "1.7.0",
|
|
82
|
+
"declastruct-github": "1.0.6",
|
|
82
83
|
"depcheck": "1.4.3",
|
|
83
84
|
"esbuild-register": "3.6.0",
|
|
84
85
|
"husky": "8.0.3",
|
|
85
86
|
"jest": "30.2.0",
|
|
86
|
-
"rhachet": "1.
|
|
87
|
-
"rhachet-roles-ehmpathy": "1.
|
|
87
|
+
"rhachet": "1.13.1",
|
|
88
|
+
"rhachet-roles-ehmpathy": "1.13.3",
|
|
88
89
|
"simple-log-methods": "0.6.2",
|
|
89
90
|
"test-fns": "1.5.0",
|
|
90
91
|
"tsx": "4.20.6",
|