declastruct-github 1.0.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/LICENSE +21 -0
- package/dist/.test/assets/getSampleGithubContext.d.ts +6 -0
- package/dist/.test/assets/getSampleGithubContext.js +18 -0
- package/dist/.test/assets/getSampleGithubContext.js.map +1 -0
- package/dist/.test/assets/getSampleRepo.d.ts +9 -0
- package/dist/.test/assets/getSampleRepo.js +19 -0
- package/dist/.test/assets/getSampleRepo.js.map +1 -0
- package/dist/access/daos/DeclaredGithubBranchDao.d.ts +10 -0
- package/dist/access/daos/DeclaredGithubBranchDao.js +35 -0
- package/dist/access/daos/DeclaredGithubBranchDao.js.map +1 -0
- package/dist/access/daos/DeclaredGithubBranchProtectionDao.d.ts +9 -0
- package/dist/access/daos/DeclaredGithubBranchProtectionDao.js +34 -0
- package/dist/access/daos/DeclaredGithubBranchProtectionDao.js.map +1 -0
- package/dist/access/daos/DeclaredGithubRepoConfigDao.d.ts +9 -0
- package/dist/access/daos/DeclaredGithubRepoConfigDao.js +34 -0
- package/dist/access/daos/DeclaredGithubRepoConfigDao.js.map +1 -0
- package/dist/access/daos/DeclaredGithubRepoDao.d.ts +9 -0
- package/dist/access/daos/DeclaredGithubRepoDao.js +34 -0
- package/dist/access/daos/DeclaredGithubRepoDao.js.map +1 -0
- package/dist/access/sdks/getGithubClient.d.ts +8 -0
- package/dist/access/sdks/getGithubClient.js +22 -0
- package/dist/access/sdks/getGithubClient.js.map +1 -0
- package/dist/contract/sdks/declastruct.acceptance.test.d.ts +1 -0
- package/dist/contract/sdks/declastruct.acceptance.test.js +104 -0
- package/dist/contract/sdks/declastruct.acceptance.test.js.map +1 -0
- package/dist/contract/sdks/index.d.ts +10 -0
- package/dist/contract/sdks/index.js +20 -0
- package/dist/contract/sdks/index.js.map +1 -0
- package/dist/domain.objects/ContextGithubApi.d.ts +9 -0
- package/dist/domain.objects/ContextGithubApi.js +3 -0
- package/dist/domain.objects/ContextGithubApi.js.map +1 -0
- package/dist/domain.objects/DeclaredGithubBranch.d.ts +39 -0
- package/dist/domain.objects/DeclaredGithubBranch.js +12 -0
- package/dist/domain.objects/DeclaredGithubBranch.js.map +1 -0
- package/dist/domain.objects/DeclaredGithubBranchProtection.d.ts +108 -0
- package/dist/domain.objects/DeclaredGithubBranchProtection.js +12 -0
- package/dist/domain.objects/DeclaredGithubBranchProtection.js.map +1 -0
- package/dist/domain.objects/DeclaredGithubRepo.d.ts +57 -0
- package/dist/domain.objects/DeclaredGithubRepo.js +9 -0
- package/dist/domain.objects/DeclaredGithubRepo.js.map +1 -0
- package/dist/domain.objects/DeclaredGithubRepoConfig.d.ts +100 -0
- package/dist/domain.objects/DeclaredGithubRepoConfig.js +12 -0
- package/dist/domain.objects/DeclaredGithubRepoConfig.js.map +1 -0
- package/dist/domain.objects/DeclastructGithubProvider.d.ts +17 -0
- package/dist/domain.objects/DeclastructGithubProvider.js +3 -0
- package/dist/domain.objects/DeclastructGithubProvider.js.map +1 -0
- package/dist/domain.operations/branch/castToDeclaredGithubBranch.d.ts +15 -0
- package/dist/domain.operations/branch/castToDeclaredGithubBranch.js +39 -0
- package/dist/domain.operations/branch/castToDeclaredGithubBranch.js.map +1 -0
- package/dist/domain.operations/branch/getBranch.d.ts +14 -0
- package/dist/domain.operations/branch/getBranch.integration.test.d.ts +1 -0
- package/dist/domain.operations/branch/getBranch.integration.test.js +59 -0
- package/dist/domain.operations/branch/getBranch.integration.test.js.map +1 -0
- package/dist/domain.operations/branch/getBranch.js +50 -0
- package/dist/domain.operations/branch/getBranch.js.map +1 -0
- package/dist/domain.operations/branch/getBranchCommitShaByRepoDefault.d.ts +11 -0
- package/dist/domain.operations/branch/getBranchCommitShaByRepoDefault.js +37 -0
- package/dist/domain.operations/branch/getBranchCommitShaByRepoDefault.js.map +1 -0
- package/dist/domain.operations/branch/getBranches.d.ts +23 -0
- package/dist/domain.operations/branch/getBranches.integration.test.d.ts +1 -0
- package/dist/domain.operations/branch/getBranches.integration.test.js +40 -0
- package/dist/domain.operations/branch/getBranches.integration.test.js.map +1 -0
- package/dist/domain.operations/branch/getBranches.js +33 -0
- package/dist/domain.operations/branch/getBranches.js.map +1 -0
- package/dist/domain.operations/branch/setBranch.d.ts +12 -0
- package/dist/domain.operations/branch/setBranch.integration.test.d.ts +1 -0
- package/dist/domain.operations/branch/setBranch.integration.test.js +65 -0
- package/dist/domain.operations/branch/setBranch.integration.test.js.map +1 -0
- package/dist/domain.operations/branch/setBranch.js +100 -0
- package/dist/domain.operations/branch/setBranch.js.map +1 -0
- package/dist/domain.operations/branch/setBranch.test.d.ts +1 -0
- package/dist/domain.operations/branch/setBranch.test.js +151 -0
- package/dist/domain.operations/branch/setBranch.test.js.map +1 -0
- package/dist/domain.operations/branchProtection/castToDeclaredGithubBranchProtection.d.ts +14 -0
- package/dist/domain.operations/branchProtection/castToDeclaredGithubBranchProtection.js +66 -0
- package/dist/domain.operations/branchProtection/castToDeclaredGithubBranchProtection.js.map +1 -0
- package/dist/domain.operations/branchProtection/getBranchProtection.d.ts +14 -0
- package/dist/domain.operations/branchProtection/getBranchProtection.integration.test.d.ts +1 -0
- package/dist/domain.operations/branchProtection/getBranchProtection.integration.test.js +63 -0
- package/dist/domain.operations/branchProtection/getBranchProtection.integration.test.js.map +1 -0
- package/dist/domain.operations/branchProtection/getBranchProtection.js +53 -0
- package/dist/domain.operations/branchProtection/getBranchProtection.js.map +1 -0
- package/dist/domain.operations/branchProtection/setBranchProtection.d.ts +12 -0
- package/dist/domain.operations/branchProtection/setBranchProtection.integration.test.d.ts +1 -0
- package/dist/domain.operations/branchProtection/setBranchProtection.integration.test.js +96 -0
- package/dist/domain.operations/branchProtection/setBranchProtection.integration.test.js.map +1 -0
- package/dist/domain.operations/branchProtection/setBranchProtection.js +90 -0
- package/dist/domain.operations/branchProtection/setBranchProtection.js.map +1 -0
- package/dist/domain.operations/branchProtection/setBranchProtection.test.d.ts +1 -0
- package/dist/domain.operations/branchProtection/setBranchProtection.test.js +173 -0
- package/dist/domain.operations/branchProtection/setBranchProtection.test.js.map +1 -0
- package/dist/domain.operations/provider/getDeclastructGithubProvider.d.ts +11 -0
- package/dist/domain.operations/provider/getDeclastructGithubProvider.integration.test.d.ts +1 -0
- package/dist/domain.operations/provider/getDeclastructGithubProvider.integration.test.js +212 -0
- package/dist/domain.operations/provider/getDeclastructGithubProvider.integration.test.js.map +1 -0
- package/dist/domain.operations/provider/getDeclastructGithubProvider.js +44 -0
- package/dist/domain.operations/provider/getDeclastructGithubProvider.js.map +1 -0
- package/dist/domain.operations/repo/castToDeclaredGithubRepo.d.ts +10 -0
- package/dist/domain.operations/repo/castToDeclaredGithubRepo.js +42 -0
- package/dist/domain.operations/repo/castToDeclaredGithubRepo.js.map +1 -0
- package/dist/domain.operations/repo/getRepo.d.ts +14 -0
- package/dist/domain.operations/repo/getRepo.integration.test.d.ts +1 -0
- package/dist/domain.operations/repo/getRepo.integration.test.js +45 -0
- package/dist/domain.operations/repo/getRepo.integration.test.js.map +1 -0
- package/dist/domain.operations/repo/getRepo.js +38 -0
- package/dist/domain.operations/repo/getRepo.js.map +1 -0
- package/dist/domain.operations/repo/getRepos.d.ts +21 -0
- package/dist/domain.operations/repo/getRepos.integration.test.d.ts +1 -0
- package/dist/domain.operations/repo/getRepos.integration.test.js +28 -0
- package/dist/domain.operations/repo/getRepos.integration.test.js.map +1 -0
- package/dist/domain.operations/repo/getRepos.js +41 -0
- package/dist/domain.operations/repo/getRepos.js.map +1 -0
- package/dist/domain.operations/repo/setRepo.d.ts +12 -0
- package/dist/domain.operations/repo/setRepo.integration.test.d.ts +1 -0
- package/dist/domain.operations/repo/setRepo.integration.test.js +29 -0
- package/dist/domain.operations/repo/setRepo.integration.test.js.map +1 -0
- package/dist/domain.operations/repo/setRepo.js +70 -0
- package/dist/domain.operations/repo/setRepo.js.map +1 -0
- package/dist/domain.operations/repo/setRepo.test.d.ts +1 -0
- package/dist/domain.operations/repo/setRepo.test.js +150 -0
- package/dist/domain.operations/repo/setRepo.test.js.map +1 -0
- package/dist/domain.operations/repoConfig/castToDeclaredGithubRepoConfig.d.ts +15 -0
- package/dist/domain.operations/repoConfig/castToDeclaredGithubRepoConfig.js +36 -0
- package/dist/domain.operations/repoConfig/castToDeclaredGithubRepoConfig.js.map +1 -0
- package/dist/domain.operations/repoConfig/getRepoConfig.d.ts +14 -0
- package/dist/domain.operations/repoConfig/getRepoConfig.integration.test.d.ts +1 -0
- package/dist/domain.operations/repoConfig/getRepoConfig.integration.test.js +55 -0
- package/dist/domain.operations/repoConfig/getRepoConfig.integration.test.js.map +1 -0
- package/dist/domain.operations/repoConfig/getRepoConfig.js +47 -0
- package/dist/domain.operations/repoConfig/getRepoConfig.js.map +1 -0
- package/dist/domain.operations/repoConfig/setRepoConfig.d.ts +12 -0
- package/dist/domain.operations/repoConfig/setRepoConfig.integration.test.d.ts +1 -0
- package/dist/domain.operations/repoConfig/setRepoConfig.integration.test.js +87 -0
- package/dist/domain.operations/repoConfig/setRepoConfig.integration.test.js.map +1 -0
- package/dist/domain.operations/repoConfig/setRepoConfig.js +65 -0
- package/dist/domain.operations/repoConfig/setRepoConfig.js.map +1 -0
- package/package.json +104 -0
- package/readme.md +181 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const test_fns_1 = require("test-fns");
|
|
4
|
+
const getSampleGithubContext_1 = require("../../.test/assets/getSampleGithubContext");
|
|
5
|
+
const getSampleRepo_1 = require("../../.test/assets/getSampleRepo");
|
|
6
|
+
const getBranches_1 = require("./getBranches");
|
|
7
|
+
const log = console;
|
|
8
|
+
describe('getBranches', () => {
|
|
9
|
+
const context = { log, ...(0, getSampleGithubContext_1.getSampleGithubContext)() };
|
|
10
|
+
(0, test_fns_1.given)('a live example repo with branches', () => {
|
|
11
|
+
(0, test_fns_1.then)('we should be able to list its branches', async () => {
|
|
12
|
+
const sampleRepo = (0, getSampleRepo_1.getSampleRepo)({
|
|
13
|
+
owner: 'ehmpathy',
|
|
14
|
+
name: 'declastruct-github-demo',
|
|
15
|
+
});
|
|
16
|
+
const branches = await (0, getBranches_1.getBranches)({
|
|
17
|
+
where: {
|
|
18
|
+
repo: {
|
|
19
|
+
owner: sampleRepo.owner,
|
|
20
|
+
name: sampleRepo.name,
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
}, context);
|
|
24
|
+
console.log(branches);
|
|
25
|
+
expect(branches).toBeDefined();
|
|
26
|
+
expect(Array.isArray(branches)).toBe(true);
|
|
27
|
+
expect(branches.length).toBeGreaterThan(0);
|
|
28
|
+
// verify first branch has expected shape
|
|
29
|
+
const firstBranch = branches[0];
|
|
30
|
+
expect(firstBranch?.name).toBeDefined();
|
|
31
|
+
expect(firstBranch?.commit?.sha).toBeDefined();
|
|
32
|
+
expect(firstBranch?.repo).toEqual({
|
|
33
|
+
owner: sampleRepo.owner,
|
|
34
|
+
name: sampleRepo.name,
|
|
35
|
+
});
|
|
36
|
+
expect(typeof firstBranch?.protected).toBe('boolean');
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
//# sourceMappingURL=getBranches.integration.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getBranches.integration.test.js","sourceRoot":"","sources":["../../../src/domain.operations/branch/getBranches.integration.test.ts"],"names":[],"mappings":";;AAAA,uCAAuC;AAEvC,sFAAmF;AACnF,oEAAiE;AACjE,+CAA4C;AAE5C,MAAM,GAAG,GAAG,OAAO,CAAC;AAEpB,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,MAAM,OAAO,GAAG,EAAE,GAAG,EAAE,GAAG,IAAA,+CAAsB,GAAE,EAAE,CAAC;IAErD,IAAA,gBAAK,EAAC,mCAAmC,EAAE,GAAG,EAAE;QAC9C,IAAA,eAAI,EAAC,wCAAwC,EAAE,KAAK,IAAI,EAAE;YACxD,MAAM,U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
|
+
const helpful_errors_1 = require("helpful-errors");
|
|
5
|
+
const getGithubClient_1 = require("../../access/sdks/getGithubClient");
|
|
6
|
+
const castToDeclaredGithubBranch_1 = require("./castToDeclaredGithubBranch");
|
|
7
|
+
/**
|
|
8
|
+
* .what = lists GitHub branches for a repository
|
|
9
|
+
* .why = retrieves multiple branches from GitHub API for declarative management
|
|
10
|
+
*/
|
|
11
|
+
const getBranches = async (input, context) => {
|
|
12
|
+
// get cached GitHub client
|
|
13
|
+
const github = (0, getGithubClient_1.getGithubClient)({}, context);
|
|
14
|
+
// execute the GitHub API call
|
|
15
|
+
try {
|
|
16
|
+
const response = await github.repos.listBranches({
|
|
17
|
+
owner: input.where.repo.owner,
|
|
18
|
+
repo: input.where.repo.name,
|
|
19
|
+
page: input.page?.range?.until.page,
|
|
20
|
+
per_page: input.page?.limit,
|
|
21
|
+
});
|
|
22
|
+
const branches = response.data ?? [];
|
|
23
|
+
return branches.map((branch) => (0, castToDeclaredGithubBranch_1.castToDeclaredGithubBranch)({ branch, repo: input.where.repo }));
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
if (!(error instanceof Error))
|
|
27
|
+
throw error;
|
|
28
|
+
// throw helpful error for all failures
|
|
29
|
+
throw new helpful_errors_1.HelpfulError('github.getBranches error', { cause: error });
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
exports.getBranches = getBranches;
|
|
33
|
+
//# sourceMappingURL=getBranches.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getBranches.js","sourceRoot":"","sources":["../../../src/domain.operations/branch/getBranches.ts"],"names":[],"mappings":";;;AACA,mDAA8C;AAI9C,uEAAoE;AAIpE,6EAA0E;AAE1E;;;GAGG;AACI,MAAM,WAAW,GAAG,KAAK,EAC9B,KAQC,EACD,OAA6C,EACC,EAAE;IAChD,2BAA2B;IAC3B,MAAM,MAAM,GAAG,IAAA,iCAAe,EAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IAE5C,8BAA8B;IAC9B,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC;YAC/C,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK;YAC7B,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI;YAC3B,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI;YACnC,QAAQ,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK;SAC5B,CAAC,CAAC;QAEH,MAAM,QAAQ,GAAG,QAAQ,CAAC,IAAI,IAAI,EAAE,CAAC;QACrC,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAC7B,IAAA,uDAA0B,EAAC,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAC/D,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC;YAAE,MAAM,KAAK,CAAC;QAE3C,uCAAuC;QACvC,MAAM,IAAI,6BAAY,CAAC,0BAA0B,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IACvE,CAAC;AACH,CAAC,CAAC;AAlCW,QAAA,WAAW,eAkCtB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { HasMetadata, PickOne } from 'type-fns';
|
|
2
|
+
import { VisualogicContext } from 'visualogic';
|
|
3
|
+
import { ContextGithubApi } from '../../domain.objects/ContextGithubApi';
|
|
4
|
+
import { DeclaredGithubBranch } from '../../domain.objects/DeclaredGithubBranch';
|
|
5
|
+
/**
|
|
6
|
+
* .what = sets a GitHub branch: upsert or finsert
|
|
7
|
+
* .why = enables declarative creation and updates of branches following declastruct patterns
|
|
8
|
+
*/
|
|
9
|
+
export declare const setBranch: (input: PickOne<{
|
|
10
|
+
finsert: DeclaredGithubBranch;
|
|
11
|
+
upsert: DeclaredGithubBranch;
|
|
12
|
+
}>, context: ContextGithubApi & VisualogicContext) => Promise<HasMetadata<DeclaredGithubBranch>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const helpful_errors_1 = require("helpful-errors");
|
|
4
|
+
const getSampleGithubContext_1 = require("../../.test/assets/getSampleGithubContext");
|
|
5
|
+
const getSampleRepo_1 = require("../../.test/assets/getSampleRepo");
|
|
6
|
+
const getBranch_1 = require("./getBranch");
|
|
7
|
+
const setBranch_1 = require("./setBranch");
|
|
8
|
+
const log = console;
|
|
9
|
+
describe('setBranch', () => {
|
|
10
|
+
const context = { log, ...(0, getSampleGithubContext_1.getSampleGithubContext)() };
|
|
11
|
+
describe('live tests', () => {
|
|
12
|
+
it('should create a new branch with explicit commit.sha', async () => {
|
|
13
|
+
const sampleRepo = (0, getSampleRepo_1.getSampleRepo)({
|
|
14
|
+
owner: 'ehmpathy',
|
|
15
|
+
name: 'declastruct-github-demo',
|
|
16
|
+
});
|
|
17
|
+
// Get a commit SHA from the demo repo's main branch
|
|
18
|
+
const demoRepoBranch = (await (0, getBranch_1.getBranch)({
|
|
19
|
+
by: {
|
|
20
|
+
unique: {
|
|
21
|
+
repo: { owner: 'ehmpathy', name: 'declastruct-github-demo' },
|
|
22
|
+
name: 'main',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
}, context)) ??
|
|
26
|
+
helpful_errors_1.UnexpectedCodePathError.throw('demo repo branch not found', {
|
|
27
|
+
sampleRepo,
|
|
28
|
+
});
|
|
29
|
+
const branchName = `test-branch-${Date.now()}`;
|
|
30
|
+
const result = await (0, setBranch_1.setBranch)({
|
|
31
|
+
finsert: {
|
|
32
|
+
repo: {
|
|
33
|
+
owner: sampleRepo.owner,
|
|
34
|
+
name: sampleRepo.name,
|
|
35
|
+
},
|
|
36
|
+
name: branchName,
|
|
37
|
+
commit: { sha: demoRepoBranch.commit.sha },
|
|
38
|
+
},
|
|
39
|
+
}, context);
|
|
40
|
+
expect(result).toBeDefined();
|
|
41
|
+
expect(result.name).toBe(branchName);
|
|
42
|
+
expect(result.commit?.sha).toBe(demoRepoBranch.commit.sha);
|
|
43
|
+
});
|
|
44
|
+
it('should return existing branch for finsert', async () => {
|
|
45
|
+
// Use the main declastruct-github repo which we know exists
|
|
46
|
+
const sampleRepo = (0, getSampleRepo_1.getSampleRepo)({
|
|
47
|
+
owner: 'ehmpathy',
|
|
48
|
+
name: 'declastruct-github',
|
|
49
|
+
});
|
|
50
|
+
const result = await (0, setBranch_1.setBranch)({
|
|
51
|
+
finsert: {
|
|
52
|
+
repo: {
|
|
53
|
+
owner: sampleRepo.owner,
|
|
54
|
+
name: sampleRepo.name,
|
|
55
|
+
},
|
|
56
|
+
name: 'main',
|
|
57
|
+
},
|
|
58
|
+
}, context);
|
|
59
|
+
expect(result).toBeDefined();
|
|
60
|
+
expect(result.name).toBe('main');
|
|
61
|
+
expect(result.commit?.sha).toBeDefined();
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
//# sourceMappingURL=setBranch.integration.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setBranch.integration.test.js","sourceRoot":"","sources":["../../../src/domain.operations/branch/setBranch.integration.test.ts"],"names":[],"mappings":";;AAAA,mDAAyD;AAEzD,sFAAmF;AACnF,oEAAiE;AACjE,2CAAwC;AACxC,2CAAwC;AAExC,MAAM,GAAG,GAAG,OAAO,CAAC;AAEpB,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,MAAM,OAAO,GAAG,EAAE,GAAG,EAAE,GAAG,IAAA,+CAAsB,GAAE,EAAE,CAAC;IAErD,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;QAC1B,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C;gBAC/B,KAAK,EAAE,UAAU;gBACjB,IAAI,EAAE,oBAAoB;aAC3B,CAAC,CAAC;YAEH,MAAM,MAAM,GAAG,MAAM,IAAA,qBAAS,EAC5B;gBACE,OAAO,EAAE;oBACP,IAAI,EAAE;wBACJ,KAAK,EAAE,UAAU,CAAC,KAAK;wBACvB,IAAI,EAAE,UAAU,CAAC,IAAI;qBACtB;oBACD,IAAI,EAAE,MAAM;iBACb;aACF,EACD,OAAO,CACR,CAAC;YAEF,MAAM,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC;YAC7B,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACjC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC;QAC3C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setBranch = 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 getBranch_1 = require("./getBranch");
|
|
8
|
+
const getBranchCommitShaByRepoDefault_1 = require("./getBranchCommitShaByRepoDefault");
|
|
9
|
+
/**
|
|
10
|
+
* .what = sets a GitHub branch: upsert or finsert
|
|
11
|
+
* .why = enables declarative creation and updates of branches following declastruct patterns
|
|
12
|
+
*/
|
|
13
|
+
exports.setBranch = (0, as_procedure_1.asProcedure)(async (input, context) => {
|
|
14
|
+
const desired = input.finsert ?? input.upsert;
|
|
15
|
+
// get cached GitHub client
|
|
16
|
+
const github = (0, getGithubClient_1.getGithubClient)({}, context);
|
|
17
|
+
// check whether branch already exists
|
|
18
|
+
const before = await (0, getBranch_1.getBranch)({
|
|
19
|
+
by: {
|
|
20
|
+
unique: {
|
|
21
|
+
repo: desired.repo,
|
|
22
|
+
name: desired.name,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
}, context);
|
|
26
|
+
// if it's a finsert and had a before, then return that
|
|
27
|
+
if (before && input.finsert)
|
|
28
|
+
return before;
|
|
29
|
+
// if its an upsert and had a before but no commit.sha change, return existing
|
|
30
|
+
if (before && input.upsert && !desired.commit?.sha)
|
|
31
|
+
return before;
|
|
32
|
+
if (before && input.upsert && desired.commit?.sha === before.commit?.sha)
|
|
33
|
+
return before;
|
|
34
|
+
// if its an upsert with a commit.sha change, update the branch
|
|
35
|
+
if (before && input.upsert && desired.commit?.sha) {
|
|
36
|
+
try {
|
|
37
|
+
await github.git.updateRef({
|
|
38
|
+
owner: desired.repo.owner,
|
|
39
|
+
repo: desired.repo.name,
|
|
40
|
+
ref: `heads/${desired.name}`,
|
|
41
|
+
sha: desired.commit.sha,
|
|
42
|
+
force: false, // don't force update - fail if not fast-forward
|
|
43
|
+
});
|
|
44
|
+
// fetch the updated branch to return full metadata
|
|
45
|
+
return ((await (0, getBranch_1.getBranch)({
|
|
46
|
+
by: {
|
|
47
|
+
unique: {
|
|
48
|
+
repo: desired.repo,
|
|
49
|
+
name: desired.name,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
}, context)) ??
|
|
53
|
+
helpful_errors_1.UnexpectedCodePathError.throw('updated branch not found', {
|
|
54
|
+
name: desired.name,
|
|
55
|
+
}));
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
if (!(error instanceof Error))
|
|
59
|
+
throw error;
|
|
60
|
+
throw new helpful_errors_1.HelpfulError('github.setBranch.update error', {
|
|
61
|
+
cause: error,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// otherwise, create it
|
|
66
|
+
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
|
+
await github.git.createRef({
|
|
74
|
+
owner: desired.repo.owner,
|
|
75
|
+
repo: desired.repo.name,
|
|
76
|
+
ref: `refs/heads/${desired.name}`,
|
|
77
|
+
sha: commitSha,
|
|
78
|
+
});
|
|
79
|
+
// fetch the created branch to return full metadata
|
|
80
|
+
return ((await (0, getBranch_1.getBranch)({
|
|
81
|
+
by: {
|
|
82
|
+
unique: {
|
|
83
|
+
repo: desired.repo,
|
|
84
|
+
name: desired.name,
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
}, context)) ??
|
|
88
|
+
helpful_errors_1.UnexpectedCodePathError.throw('created branch not found', {
|
|
89
|
+
name: desired.name,
|
|
90
|
+
}));
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
if (!(error instanceof Error))
|
|
94
|
+
throw error;
|
|
95
|
+
throw new helpful_errors_1.HelpfulError('github.setBranch.create error', {
|
|
96
|
+
cause: error,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
//# sourceMappingURL=setBranch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setBranch.js","sourceRoot":"","sources":["../../../src/domain.operations/branch/setBranch.ts"],"names":[],"mappings":";;;AAAA,+CAA2C;AAC3C,mDAAuE;AAIvE,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,EA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CAAC,+BAA+B,EAAE;YACtD,KAAK,EAAE,KAAK;SACb,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const getBranchModule = __importStar(require("./getBranch"));
|
|
27
|
+
const setBranch_1 = require("./setBranch");
|
|
28
|
+
jest.mock('@octokit/rest', () => ({
|
|
29
|
+
Octokit: jest.fn(),
|
|
30
|
+
}));
|
|
31
|
+
jest.mock('./getBranch');
|
|
32
|
+
const mockCreateRef = jest.fn();
|
|
33
|
+
const mockGet = jest.fn();
|
|
34
|
+
const { Octokit } = jest.requireMock('@octokit/rest');
|
|
35
|
+
Octokit.mockImplementation(() => ({
|
|
36
|
+
git: {
|
|
37
|
+
createRef: mockCreateRef,
|
|
38
|
+
},
|
|
39
|
+
repos: {
|
|
40
|
+
get: mockGet,
|
|
41
|
+
},
|
|
42
|
+
}));
|
|
43
|
+
const context = {
|
|
44
|
+
github: { token: 'test-token' },
|
|
45
|
+
log: console,
|
|
46
|
+
};
|
|
47
|
+
const branchSample = {
|
|
48
|
+
repo: {
|
|
49
|
+
owner: 'test-owner',
|
|
50
|
+
name: 'test-repo',
|
|
51
|
+
},
|
|
52
|
+
name: 'test-branch',
|
|
53
|
+
commit: { sha: 'abc123' },
|
|
54
|
+
};
|
|
55
|
+
describe('setBranch', () => {
|
|
56
|
+
beforeEach(() => {
|
|
57
|
+
jest.clearAllMocks();
|
|
58
|
+
});
|
|
59
|
+
it('returns early for finsert if branch already exists (before)', async () => {
|
|
60
|
+
const before = {
|
|
61
|
+
...branchSample,
|
|
62
|
+
commit: { sha: 'abc123' },
|
|
63
|
+
protected: false,
|
|
64
|
+
};
|
|
65
|
+
getBranchModule.getBranch.mockResolvedValue(before);
|
|
66
|
+
const result = await (0, setBranch_1.setBranch)({ finsert: branchSample }, context);
|
|
67
|
+
expect(result).toBe(before);
|
|
68
|
+
expect(getBranchModule.getBranch).toHaveBeenCalled();
|
|
69
|
+
expect(mockCreateRef).not.toHaveBeenCalled();
|
|
70
|
+
});
|
|
71
|
+
it('returns existing for upsert if branch exists and no commit.sha change', async () => {
|
|
72
|
+
const before = {
|
|
73
|
+
...branchSample,
|
|
74
|
+
commit: { sha: 'abc123' },
|
|
75
|
+
protected: false,
|
|
76
|
+
};
|
|
77
|
+
getBranchModule.getBranch.mockResolvedValue(before);
|
|
78
|
+
const result = await (0, setBranch_1.setBranch)({ upsert: branchSample }, context);
|
|
79
|
+
expect(result).toBe(before);
|
|
80
|
+
expect(getBranchModule.getBranch).toHaveBeenCalled();
|
|
81
|
+
expect(mockCreateRef).not.toHaveBeenCalled();
|
|
82
|
+
});
|
|
83
|
+
it('creates branch with specified commit.sha', async () => {
|
|
84
|
+
const branchWithCommit = {
|
|
85
|
+
...branchSample,
|
|
86
|
+
commit: { sha: 'specifiedSha123' },
|
|
87
|
+
};
|
|
88
|
+
// first getBranch call returns null (branch doesn't exist)
|
|
89
|
+
// second getBranch call returns created branch
|
|
90
|
+
getBranchModule.getBranch
|
|
91
|
+
.mockResolvedValueOnce(null)
|
|
92
|
+
.mockResolvedValueOnce({
|
|
93
|
+
...branchSample,
|
|
94
|
+
commit: { sha: 'specifiedSha123' },
|
|
95
|
+
protected: false,
|
|
96
|
+
});
|
|
97
|
+
mockCreateRef.mockResolvedValue({ data: {} });
|
|
98
|
+
const result = await (0, setBranch_1.setBranch)({ finsert: branchWithCommit }, context);
|
|
99
|
+
expect(mockCreateRef).toHaveBeenCalledWith({
|
|
100
|
+
owner: 'test-owner',
|
|
101
|
+
repo: 'test-repo',
|
|
102
|
+
ref: 'refs/heads/test-branch',
|
|
103
|
+
sha: 'specifiedSha123',
|
|
104
|
+
});
|
|
105
|
+
expect(result.commit?.sha).toBe('specifiedSha123');
|
|
106
|
+
});
|
|
107
|
+
it('creates branch from default branch if commit.sha not specified', async () => {
|
|
108
|
+
const branchWithoutCommit = {
|
|
109
|
+
repo: {
|
|
110
|
+
owner: 'test-owner',
|
|
111
|
+
name: 'test-repo',
|
|
112
|
+
},
|
|
113
|
+
name: 'test-branch',
|
|
114
|
+
};
|
|
115
|
+
// first getBranch call returns null (branch doesn't exist)
|
|
116
|
+
// second getBranch call returns default branch
|
|
117
|
+
// third getBranch call returns created branch
|
|
118
|
+
getBranchModule.getBranch
|
|
119
|
+
.mockResolvedValueOnce(null)
|
|
120
|
+
.mockResolvedValueOnce({
|
|
121
|
+
...branchSample,
|
|
122
|
+
name: 'main',
|
|
123
|
+
commit: { sha: 'defaultSha456' },
|
|
124
|
+
protected: false,
|
|
125
|
+
})
|
|
126
|
+
.mockResolvedValueOnce({
|
|
127
|
+
...branchSample,
|
|
128
|
+
commit: { sha: 'defaultSha456' },
|
|
129
|
+
protected: false,
|
|
130
|
+
});
|
|
131
|
+
mockGet.mockResolvedValue({
|
|
132
|
+
data: {
|
|
133
|
+
default_branch: 'main',
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
mockCreateRef.mockResolvedValue({ data: {} });
|
|
137
|
+
const result = await (0, setBranch_1.setBranch)({ finsert: branchWithoutCommit }, context);
|
|
138
|
+
expect(mockGet).toHaveBeenCalledWith({
|
|
139
|
+
owner: 'test-owner',
|
|
140
|
+
repo: 'test-repo',
|
|
141
|
+
});
|
|
142
|
+
expect(mockCreateRef).toHaveBeenCalledWith({
|
|
143
|
+
owner: 'test-owner',
|
|
144
|
+
repo: 'test-repo',
|
|
145
|
+
ref: 'refs/heads/test-branch',
|
|
146
|
+
sha: 'defaultSha456',
|
|
147
|
+
});
|
|
148
|
+
expect(result.commit?.sha).toBe('defaultSha456');
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
//# sourceMappingURL=setBranch.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setBranch.test.js","sourceRoot":"","sources":["../../../src/domain.operations/branch/setBranch.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAIA,6DAA+C;AAC/C,2CAAwC;AAExC,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,GAAG,EAAE,CAAC,CAAC;IAChC,OAAO,EAAE,IAAI,CAAC,EAAE,EAAE;CACnB,CAAC,CAAC,CAAC;AACJ,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;AAEzB,MAAM,aAAa,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAChC,MAAM,OAAO,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAE1B,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,W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AE,wBAAwB;YAC7B,GAAG,EAAE,eAAe;SACrB,CAAC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Endpoints } from '@octokit/types';
|
|
2
|
+
import { RefByUnique } from 'domain-objects';
|
|
3
|
+
import { HasMetadata } from 'type-fns';
|
|
4
|
+
import { DeclaredGithubBranch } from '../../domain.objects/DeclaredGithubBranch';
|
|
5
|
+
import { DeclaredGithubBranchProtection } from '../../domain.objects/DeclaredGithubBranchProtection';
|
|
6
|
+
export type GithubBranchProtectionResponse = Endpoints['GET /repos/{owner}/{repo}/branches/{branch}/protection']['response']['data'];
|
|
7
|
+
/**
|
|
8
|
+
* .what = casts GitHub API branch protection response to DeclaredGithubBranchProtection
|
|
9
|
+
* .why = transforms external API shape to our branch protection domain model with type safety and validation
|
|
10
|
+
*/
|
|
11
|
+
export declare const castToDeclaredGithubBranchProtection: (input: {
|
|
12
|
+
response: GithubBranchProtectionResponse;
|
|
13
|
+
branch: RefByUnique<typeof DeclaredGithubBranch>;
|
|
14
|
+
}) => HasMetadata<DeclaredGithubBranchProtection>;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.castToDeclaredGithubBranchProtection = void 0;
|
|
4
|
+
const domain_objects_1 = require("domain-objects");
|
|
5
|
+
const DeclaredGithubBranch_1 = require("../../domain.objects/DeclaredGithubBranch");
|
|
6
|
+
const DeclaredGithubBranchProtection_1 = require("../../domain.objects/DeclaredGithubBranchProtection");
|
|
7
|
+
/**
|
|
8
|
+
* .what = casts GitHub API branch protection response to DeclaredGithubBranchProtection
|
|
9
|
+
* .why = transforms external API shape to our branch protection domain model with type safety and validation
|
|
10
|
+
*/
|
|
11
|
+
const castToDeclaredGithubBranchProtection = (input) => {
|
|
12
|
+
return DeclaredGithubBranchProtection_1.DeclaredGithubBranchProtection.as({
|
|
13
|
+
branch: input.branch instanceof DeclaredGithubBranch_1.DeclaredGithubBranch
|
|
14
|
+
? (0, domain_objects_1.refByUnique)(input.branch)
|
|
15
|
+
: input.branch,
|
|
16
|
+
enforceAdmins: input.response.enforce_admins?.enabled,
|
|
17
|
+
allowsDeletions: input.response.allow_deletions?.enabled,
|
|
18
|
+
allowsForcePushes: input.response.allow_force_pushes?.enabled,
|
|
19
|
+
requireLinearHistory: input.response.required_linear_history?.enabled,
|
|
20
|
+
blockCreations: input.response.block_creations?.enabled,
|
|
21
|
+
lockBranch: input.response.lock_branch?.enabled,
|
|
22
|
+
allowForkSyncing: input.response.allow_fork_syncing?.enabled,
|
|
23
|
+
requiredStatusChecks: input.response.required_status_checks
|
|
24
|
+
? {
|
|
25
|
+
strict: input.response.required_status_checks.strict ?? false,
|
|
26
|
+
contexts: input.response.required_status_checks.contexts ?? [],
|
|
27
|
+
}
|
|
28
|
+
: null,
|
|
29
|
+
requiredPullRequestReviews: input.response.required_pull_request_reviews
|
|
30
|
+
? {
|
|
31
|
+
dismissStaleReviews: input.response.required_pull_request_reviews.dismiss_stale_reviews,
|
|
32
|
+
requireCodeOwnerReviews: input.response.required_pull_request_reviews
|
|
33
|
+
.require_code_owner_reviews,
|
|
34
|
+
requiredApprovingReviewCount: input.response.required_pull_request_reviews
|
|
35
|
+
.required_approving_review_count,
|
|
36
|
+
dismissalRestrictions: input.response.required_pull_request_reviews
|
|
37
|
+
.dismissal_restrictions
|
|
38
|
+
? {
|
|
39
|
+
users: input.response.required_pull_request_reviews.dismissal_restrictions.users?.map((u) => u.login) ?? [],
|
|
40
|
+
teams: input.response.required_pull_request_reviews.dismissal_restrictions.teams?.map((t) => t.slug) ?? [],
|
|
41
|
+
apps: input.response.required_pull_request_reviews.dismissal_restrictions.apps
|
|
42
|
+
?.map((a) => a?.slug)
|
|
43
|
+
.filter((s) => !!s) ?? [],
|
|
44
|
+
}
|
|
45
|
+
: undefined,
|
|
46
|
+
}
|
|
47
|
+
: null,
|
|
48
|
+
restrictions: input.response.restrictions
|
|
49
|
+
? {
|
|
50
|
+
users: input.response.restrictions.users
|
|
51
|
+
?.map((u) => u.login)
|
|
52
|
+
.filter((l) => !!l) ?? [],
|
|
53
|
+
teams: input.response.restrictions.teams
|
|
54
|
+
?.map((t) => t.slug)
|
|
55
|
+
.filter((s) => !!s) ?? [],
|
|
56
|
+
apps: input.response.restrictions.apps
|
|
57
|
+
?.map((a) => a?.slug)
|
|
58
|
+
.filter((s) => !!s) ?? [],
|
|
59
|
+
}
|
|
60
|
+
: null,
|
|
61
|
+
requiredSignatures: input.response.required_signatures?.enabled,
|
|
62
|
+
requiredConversationResolution: input.response.required_conversation_resolution?.enabled,
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
exports.castToDeclaredGithubBranchProtection = castToDeclaredGithubBranchProtection;
|
|
66
|
+
//# sourceMappingURL=castToDeclaredGithubBranchProtection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"castToDeclaredGithubBranchProtection.js","sourceRoot":"","sources":["../../../src/domain.operations/branchProtection/castToDeclaredGithubBranchProtection.ts"],"names":[],"mappings":";;;AACA,mDAA0D;AAG1D,oFAAiF;AACjF,wGAAqG;AAKrG;;;GAGG;AACI,MAAM,oCAAoC,GAAG,CAAC,KAGpD,EAA+C,EAAE;IAChD,OAAO,+DAA8B,CAAC,EAAE,CAAC;QACvC,MAAM,EACJ,KAAK,CAAC,MAAM,YAAY,2CAAoB;YAC1C,CAAC,CAAC,IAAA,4BAAW,EAA8B,KAAK,CAAC,MAAM,CAAC;YACxD,CAAC,CAAC,KAAK,CAAC,MAAM;QAClB,aAAa,EAAE,KAAK,CAAC,QAAQ,CAAC,cAAc,EAAE,OAAO;QACrD,eAAe,EAAE,KAAK,CAAC,QAAQ,CAAC,eAAe,EAA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CAAC,QAAQ,CAAC,gCAAgC,EAAE,OAAO;KAC3D,CAAgD,CAAC;AACpD,CAAC,CAAC;AAvEW,QAAA,oCAAoC,wCAuE/C"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { RefByUnique } from 'domain-objects';
|
|
2
|
+
import { HasMetadata, PickOne } from 'type-fns';
|
|
3
|
+
import { VisualogicContext } from 'visualogic';
|
|
4
|
+
import { ContextGithubApi } from '../../domain.objects/ContextGithubApi';
|
|
5
|
+
import { DeclaredGithubBranchProtection } from '../../domain.objects/DeclaredGithubBranchProtection';
|
|
6
|
+
/**
|
|
7
|
+
* .what = gets a GitHub branch's protection rules
|
|
8
|
+
* .why = retrieves current protection state from GitHub API for declarative management
|
|
9
|
+
*/
|
|
10
|
+
export declare const getBranchProtection: (input: {
|
|
11
|
+
by: PickOne<{
|
|
12
|
+
unique: RefByUnique<typeof DeclaredGithubBranchProtection>;
|
|
13
|
+
}>;
|
|
14
|
+
}, context: ContextGithubApi & VisualogicContext) => Promise<HasMetadata<DeclaredGithubBranchProtection> | null>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const test_fns_1 = require("test-fns");
|
|
4
|
+
const getSampleGithubContext_1 = require("../../.test/assets/getSampleGithubContext");
|
|
5
|
+
const getSampleRepo_1 = require("../../.test/assets/getSampleRepo");
|
|
6
|
+
const getBranchProtection_1 = require("./getBranchProtection");
|
|
7
|
+
const log = console;
|
|
8
|
+
describe('getBranchProtection', () => {
|
|
9
|
+
const context = { log, ...(0, getSampleGithubContext_1.getSampleGithubContext)() };
|
|
10
|
+
(0, test_fns_1.given)('a protected branch exists', () => {
|
|
11
|
+
(0, test_fns_1.then)('we should be able to get its protection rules', async () => {
|
|
12
|
+
const sampleRepo = (0, getSampleRepo_1.getSampleRepo)({
|
|
13
|
+
owner: 'ehmpathy',
|
|
14
|
+
name: 'declastruct-github-demo',
|
|
15
|
+
});
|
|
16
|
+
const protection = await (0, getBranchProtection_1.getBranchProtection)({
|
|
17
|
+
by: {
|
|
18
|
+
unique: {
|
|
19
|
+
branch: {
|
|
20
|
+
repo: {
|
|
21
|
+
owner: sampleRepo.owner,
|
|
22
|
+
name: sampleRepo.name,
|
|
23
|
+
},
|
|
24
|
+
name: 'main',
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
}, context);
|
|
29
|
+
console.log(protection);
|
|
30
|
+
// May be null if branch has no protection
|
|
31
|
+
if (protection) {
|
|
32
|
+
expect(protection.branch.repo.owner).toBe(sampleRepo.owner);
|
|
33
|
+
expect(protection.branch.repo.name).toBe(sampleRepo.name);
|
|
34
|
+
expect(protection.branch.name).toBe('main');
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
(0, test_fns_1.given)('an unprotected branch', () => {
|
|
39
|
+
(0, test_fns_1.then)('it should return null', async () => {
|
|
40
|
+
const sampleRepo = (0, getSampleRepo_1.getSampleRepo)({
|
|
41
|
+
owner: 'ehmpathy',
|
|
42
|
+
name: 'declastruct-github-demo',
|
|
43
|
+
});
|
|
44
|
+
// Try to get protection for a branch that likely doesn't have protection
|
|
45
|
+
const protection = await (0, getBranchProtection_1.getBranchProtection)({
|
|
46
|
+
by: {
|
|
47
|
+
unique: {
|
|
48
|
+
branch: {
|
|
49
|
+
repo: {
|
|
50
|
+
owner: sampleRepo.owner,
|
|
51
|
+
name: sampleRepo.name,
|
|
52
|
+
},
|
|
53
|
+
name: 'test-branch-unprotected-99999',
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
}, context);
|
|
58
|
+
// Should return null for non-existent branch or unprotected branch
|
|
59
|
+
expect(protection).toBeNull();
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
//# sourceMappingURL=getBranchProtection.integration.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getBranchProtection.integration.test.js","sourceRoot":"","sources":["../../../src/domain.operations/branchProtection/getBranchProtection.integration.test.ts"],"names":[],"mappings":";;AAAA,uCAAuC;AAEvC,sFAAmF;AACnF,oEAAiE;AACjE,+DAA4D;AAE5D,MAAM,GAAG,GAAG,OAAO,CAAC;AAEpB,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,MAAM,OAAO,GAAG,EAAE,GAAG,EAAE,GAAG,IAAA,+CAAsB,GAAE,EAAE,CAAC;IAErD,IAAA,gBAAK,EAAC,2BAA2B,EAAE,GAAG,EAAE;QACtC,IAAA,eAAI,EAAC,+CAA+C,EAAE,KAAK,IAAI,EAAE;YAC/D,MAAM,UAAU,GAAG,IAAA,6BAAa,EAAC;gBAC/B,KAAK,EAAE,UAAU;gBACjB,IAAI,EAAE,yBAAyB;aAChC,CAAC,CAAC;YAEH,MAAM,UAAU,GAAG,MAAM,IAAA,yCAAmB,EAC1C;gBACE,EAAE,EAAE;oBACF,MAAM,EAAE;wBACN,MAAM,EAAE;4BACN,IAAI,EAAE;gCACJ,KAAK,EAAE,UAAU,CAAC,KAAK;gCACvB,IAAI,EAAE,UAAU,CAAC,IAAI;6BACtB;4BACD,IAAI,EAAE,MAAM;yBACb;qBACF;iBACF;aACF,EACD,OAAO,CACR,CAAC;YAEF,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YACxB,0CAA0C;YAC1C,IAAI,UAAU,EAAE,CAAC;gBACf,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;gBAC5D,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;gBAC1D,MAAM,CAAC,UAAU,CAAC,MAAM,CAA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