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.
Files changed (138) hide show
  1. package/LICENSE +21 -0
  2. package/dist/.test/assets/getSampleGithubContext.d.ts +6 -0
  3. package/dist/.test/assets/getSampleGithubContext.js +18 -0
  4. package/dist/.test/assets/getSampleGithubContext.js.map +1 -0
  5. package/dist/.test/assets/getSampleRepo.d.ts +9 -0
  6. package/dist/.test/assets/getSampleRepo.js +19 -0
  7. package/dist/.test/assets/getSampleRepo.js.map +1 -0
  8. package/dist/access/daos/DeclaredGithubBranchDao.d.ts +10 -0
  9. package/dist/access/daos/DeclaredGithubBranchDao.js +35 -0
  10. package/dist/access/daos/DeclaredGithubBranchDao.js.map +1 -0
  11. package/dist/access/daos/DeclaredGithubBranchProtectionDao.d.ts +9 -0
  12. package/dist/access/daos/DeclaredGithubBranchProtectionDao.js +34 -0
  13. package/dist/access/daos/DeclaredGithubBranchProtectionDao.js.map +1 -0
  14. package/dist/access/daos/DeclaredGithubRepoConfigDao.d.ts +9 -0
  15. package/dist/access/daos/DeclaredGithubRepoConfigDao.js +34 -0
  16. package/dist/access/daos/DeclaredGithubRepoConfigDao.js.map +1 -0
  17. package/dist/access/daos/DeclaredGithubRepoDao.d.ts +9 -0
  18. package/dist/access/daos/DeclaredGithubRepoDao.js +34 -0
  19. package/dist/access/daos/DeclaredGithubRepoDao.js.map +1 -0
  20. package/dist/access/sdks/getGithubClient.d.ts +8 -0
  21. package/dist/access/sdks/getGithubClient.js +22 -0
  22. package/dist/access/sdks/getGithubClient.js.map +1 -0
  23. package/dist/contract/sdks/declastruct.acceptance.test.d.ts +1 -0
  24. package/dist/contract/sdks/declastruct.acceptance.test.js +104 -0
  25. package/dist/contract/sdks/declastruct.acceptance.test.js.map +1 -0
  26. package/dist/contract/sdks/index.d.ts +10 -0
  27. package/dist/contract/sdks/index.js +20 -0
  28. package/dist/contract/sdks/index.js.map +1 -0
  29. package/dist/domain.objects/ContextGithubApi.d.ts +9 -0
  30. package/dist/domain.objects/ContextGithubApi.js +3 -0
  31. package/dist/domain.objects/ContextGithubApi.js.map +1 -0
  32. package/dist/domain.objects/DeclaredGithubBranch.d.ts +39 -0
  33. package/dist/domain.objects/DeclaredGithubBranch.js +12 -0
  34. package/dist/domain.objects/DeclaredGithubBranch.js.map +1 -0
  35. package/dist/domain.objects/DeclaredGithubBranchProtection.d.ts +108 -0
  36. package/dist/domain.objects/DeclaredGithubBranchProtection.js +12 -0
  37. package/dist/domain.objects/DeclaredGithubBranchProtection.js.map +1 -0
  38. package/dist/domain.objects/DeclaredGithubRepo.d.ts +57 -0
  39. package/dist/domain.objects/DeclaredGithubRepo.js +9 -0
  40. package/dist/domain.objects/DeclaredGithubRepo.js.map +1 -0
  41. package/dist/domain.objects/DeclaredGithubRepoConfig.d.ts +100 -0
  42. package/dist/domain.objects/DeclaredGithubRepoConfig.js +12 -0
  43. package/dist/domain.objects/DeclaredGithubRepoConfig.js.map +1 -0
  44. package/dist/domain.objects/DeclastructGithubProvider.d.ts +17 -0
  45. package/dist/domain.objects/DeclastructGithubProvider.js +3 -0
  46. package/dist/domain.objects/DeclastructGithubProvider.js.map +1 -0
  47. package/dist/domain.operations/branch/castToDeclaredGithubBranch.d.ts +15 -0
  48. package/dist/domain.operations/branch/castToDeclaredGithubBranch.js +39 -0
  49. package/dist/domain.operations/branch/castToDeclaredGithubBranch.js.map +1 -0
  50. package/dist/domain.operations/branch/getBranch.d.ts +14 -0
  51. package/dist/domain.operations/branch/getBranch.integration.test.d.ts +1 -0
  52. package/dist/domain.operations/branch/getBranch.integration.test.js +59 -0
  53. package/dist/domain.operations/branch/getBranch.integration.test.js.map +1 -0
  54. package/dist/domain.operations/branch/getBranch.js +50 -0
  55. package/dist/domain.operations/branch/getBranch.js.map +1 -0
  56. package/dist/domain.operations/branch/getBranchCommitShaByRepoDefault.d.ts +11 -0
  57. package/dist/domain.operations/branch/getBranchCommitShaByRepoDefault.js +37 -0
  58. package/dist/domain.operations/branch/getBranchCommitShaByRepoDefault.js.map +1 -0
  59. package/dist/domain.operations/branch/getBranches.d.ts +23 -0
  60. package/dist/domain.operations/branch/getBranches.integration.test.d.ts +1 -0
  61. package/dist/domain.operations/branch/getBranches.integration.test.js +40 -0
  62. package/dist/domain.operations/branch/getBranches.integration.test.js.map +1 -0
  63. package/dist/domain.operations/branch/getBranches.js +33 -0
  64. package/dist/domain.operations/branch/getBranches.js.map +1 -0
  65. package/dist/domain.operations/branch/setBranch.d.ts +12 -0
  66. package/dist/domain.operations/branch/setBranch.integration.test.d.ts +1 -0
  67. package/dist/domain.operations/branch/setBranch.integration.test.js +65 -0
  68. package/dist/domain.operations/branch/setBranch.integration.test.js.map +1 -0
  69. package/dist/domain.operations/branch/setBranch.js +100 -0
  70. package/dist/domain.operations/branch/setBranch.js.map +1 -0
  71. package/dist/domain.operations/branch/setBranch.test.d.ts +1 -0
  72. package/dist/domain.operations/branch/setBranch.test.js +151 -0
  73. package/dist/domain.operations/branch/setBranch.test.js.map +1 -0
  74. package/dist/domain.operations/branchProtection/castToDeclaredGithubBranchProtection.d.ts +14 -0
  75. package/dist/domain.operations/branchProtection/castToDeclaredGithubBranchProtection.js +66 -0
  76. package/dist/domain.operations/branchProtection/castToDeclaredGithubBranchProtection.js.map +1 -0
  77. package/dist/domain.operations/branchProtection/getBranchProtection.d.ts +14 -0
  78. package/dist/domain.operations/branchProtection/getBranchProtection.integration.test.d.ts +1 -0
  79. package/dist/domain.operations/branchProtection/getBranchProtection.integration.test.js +63 -0
  80. package/dist/domain.operations/branchProtection/getBranchProtection.integration.test.js.map +1 -0
  81. package/dist/domain.operations/branchProtection/getBranchProtection.js +53 -0
  82. package/dist/domain.operations/branchProtection/getBranchProtection.js.map +1 -0
  83. package/dist/domain.operations/branchProtection/setBranchProtection.d.ts +12 -0
  84. package/dist/domain.operations/branchProtection/setBranchProtection.integration.test.d.ts +1 -0
  85. package/dist/domain.operations/branchProtection/setBranchProtection.integration.test.js +96 -0
  86. package/dist/domain.operations/branchProtection/setBranchProtection.integration.test.js.map +1 -0
  87. package/dist/domain.operations/branchProtection/setBranchProtection.js +90 -0
  88. package/dist/domain.operations/branchProtection/setBranchProtection.js.map +1 -0
  89. package/dist/domain.operations/branchProtection/setBranchProtection.test.d.ts +1 -0
  90. package/dist/domain.operations/branchProtection/setBranchProtection.test.js +173 -0
  91. package/dist/domain.operations/branchProtection/setBranchProtection.test.js.map +1 -0
  92. package/dist/domain.operations/provider/getDeclastructGithubProvider.d.ts +11 -0
  93. package/dist/domain.operations/provider/getDeclastructGithubProvider.integration.test.d.ts +1 -0
  94. package/dist/domain.operations/provider/getDeclastructGithubProvider.integration.test.js +212 -0
  95. package/dist/domain.operations/provider/getDeclastructGithubProvider.integration.test.js.map +1 -0
  96. package/dist/domain.operations/provider/getDeclastructGithubProvider.js +44 -0
  97. package/dist/domain.operations/provider/getDeclastructGithubProvider.js.map +1 -0
  98. package/dist/domain.operations/repo/castToDeclaredGithubRepo.d.ts +10 -0
  99. package/dist/domain.operations/repo/castToDeclaredGithubRepo.js +42 -0
  100. package/dist/domain.operations/repo/castToDeclaredGithubRepo.js.map +1 -0
  101. package/dist/domain.operations/repo/getRepo.d.ts +14 -0
  102. package/dist/domain.operations/repo/getRepo.integration.test.d.ts +1 -0
  103. package/dist/domain.operations/repo/getRepo.integration.test.js +45 -0
  104. package/dist/domain.operations/repo/getRepo.integration.test.js.map +1 -0
  105. package/dist/domain.operations/repo/getRepo.js +38 -0
  106. package/dist/domain.operations/repo/getRepo.js.map +1 -0
  107. package/dist/domain.operations/repo/getRepos.d.ts +21 -0
  108. package/dist/domain.operations/repo/getRepos.integration.test.d.ts +1 -0
  109. package/dist/domain.operations/repo/getRepos.integration.test.js +28 -0
  110. package/dist/domain.operations/repo/getRepos.integration.test.js.map +1 -0
  111. package/dist/domain.operations/repo/getRepos.js +41 -0
  112. package/dist/domain.operations/repo/getRepos.js.map +1 -0
  113. package/dist/domain.operations/repo/setRepo.d.ts +12 -0
  114. package/dist/domain.operations/repo/setRepo.integration.test.d.ts +1 -0
  115. package/dist/domain.operations/repo/setRepo.integration.test.js +29 -0
  116. package/dist/domain.operations/repo/setRepo.integration.test.js.map +1 -0
  117. package/dist/domain.operations/repo/setRepo.js +70 -0
  118. package/dist/domain.operations/repo/setRepo.js.map +1 -0
  119. package/dist/domain.operations/repo/setRepo.test.d.ts +1 -0
  120. package/dist/domain.operations/repo/setRepo.test.js +150 -0
  121. package/dist/domain.operations/repo/setRepo.test.js.map +1 -0
  122. package/dist/domain.operations/repoConfig/castToDeclaredGithubRepoConfig.d.ts +15 -0
  123. package/dist/domain.operations/repoConfig/castToDeclaredGithubRepoConfig.js +36 -0
  124. package/dist/domain.operations/repoConfig/castToDeclaredGithubRepoConfig.js.map +1 -0
  125. package/dist/domain.operations/repoConfig/getRepoConfig.d.ts +14 -0
  126. package/dist/domain.operations/repoConfig/getRepoConfig.integration.test.d.ts +1 -0
  127. package/dist/domain.operations/repoConfig/getRepoConfig.integration.test.js +55 -0
  128. package/dist/domain.operations/repoConfig/getRepoConfig.integration.test.js.map +1 -0
  129. package/dist/domain.operations/repoConfig/getRepoConfig.js +47 -0
  130. package/dist/domain.operations/repoConfig/getRepoConfig.js.map +1 -0
  131. package/dist/domain.operations/repoConfig/setRepoConfig.d.ts +12 -0
  132. package/dist/domain.operations/repoConfig/setRepoConfig.integration.test.d.ts +1 -0
  133. package/dist/domain.operations/repoConfig/setRepoConfig.integration.test.js +87 -0
  134. package/dist/domain.operations/repoConfig/setRepoConfig.integration.test.js.map +1 -0
  135. package/dist/domain.operations/repoConfig/setRepoConfig.js +65 -0
  136. package/dist/domain.operations/repoConfig/setRepoConfig.js.map +1 -0
  137. package/package.json +104 -0
  138. package/readme.md +181 -0
package/package.json ADDED
@@ -0,0 +1,104 @@
1
+ {
2
+ "name": "declastruct-github",
3
+ "author": "ehmpathy",
4
+ "description": "declarative control of GitHub constructs via declastruct - manage repos, branches, and protection rules",
5
+ "version": "1.0.0",
6
+ "repository": "ehmpathy/declastruct-github",
7
+ "homepage": "https://github.com/ehmpathy/declastruct-github",
8
+ "keywords": [
9
+ "github",
10
+ "declarative",
11
+ "declastruct",
12
+ "infrastructure-as-code",
13
+ "repository-management",
14
+ "branch-protection",
15
+ "github-api"
16
+ ],
17
+ "bugs": "https://github.com/ehmpathy/declastruct-github/issues",
18
+ "license": "MIT",
19
+ "main": "dist/contract/sdks/index.js",
20
+ "engines": {
21
+ "node": ">=8.0.0"
22
+ },
23
+ "files": [
24
+ "/dist"
25
+ ],
26
+ "scripts": {
27
+ "build:ts": "tsc -p ./tsconfig.build.json",
28
+ "commit:with-cli": "npx cz",
29
+ "fix:format:prettier": "prettier --write '**/*.ts' --config ./prettier.config.js",
30
+ "fix:format": "npm run fix:format:prettier",
31
+ "fix:lint": "eslint -c ./.eslintrc.js src/**/*.ts --fix",
32
+ "build:clean": "rm dist/ -rf",
33
+ "build:compile": "tsc -p ./tsconfig.build.json",
34
+ "build": "npm run build:clean && npm run build:compile",
35
+ "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.build.json --noEmit",
37
+ "test:format:prettier": "prettier --parser typescript --check 'src/**/*.ts' --config ./prettier.config.js",
38
+ "test:format": "npm run test:format:prettier",
39
+ "test:lint:deps": "npx depcheck -c ./depcheckrc.yml",
40
+ "test:lint:eslint": "eslint -c ./.eslintrc.js src/**/*.ts",
41
+ "test:lint": "npm run test:lint:eslint && npm run test:lint:deps",
42
+ "test:unit": "jest -c ./jest.unit.config.ts --forceExit --verbose --passWithNoTests $([ -z $THOROUGH ] && echo '--changedSince=main')",
43
+ "test:integration": "LOCALLY=true jest -c ./jest.integration.config.ts --forceExit --verbose --runInBand --passWithNoTests",
44
+ "test:acceptance:locally": "npm run build && LOCALLY=true jest -c ./jest.acceptance.config.ts --forceExit --verbose --runInBand --passWithNoTests",
45
+ "test": "npm run test:commits && npm run test:types && npm run test:format && npm run test:lint && npm run test:unit && npm run test:integration && npm run test:acceptance:locally",
46
+ "test:acceptance": "npm run build && jest -c ./jest.acceptance.config.ts --forceExit --verbose --runInBand --passWithNoTests",
47
+ "prepush": "npm run test && npm run build",
48
+ "prepublish": "npm run build",
49
+ "preversion": "npm run prepush",
50
+ "postversion": "git push origin HEAD --tags --no-verify",
51
+ "postinstall": "[ -d .git ] && npm run prepare:husky || exit 0",
52
+ "prepare:husky": "npx husky install && chmod ug+x .husky/*"
53
+ },
54
+ "dependencies": {
55
+ "@ehmpathy/uni-time": "1.7.4",
56
+ "@octokit/rest": "^21.0.0",
57
+ "as-procedure": "1.1.1",
58
+ "declastruct": "1.1.5",
59
+ "domain-objects": "0.29.1",
60
+ "helpful-errors": "1.5.3",
61
+ "simple-in-memory-cache": "0.4.0",
62
+ "type-fns": "1.19.0",
63
+ "visualogic": "1.3.2",
64
+ "with-simple-cache": "0.15.1"
65
+ },
66
+ "devDependencies": {
67
+ "@babel/core": "7.28.5",
68
+ "@babel/preset-env": "7.28.5",
69
+ "@commitlint/cli": "19.3.0",
70
+ "@commitlint/config-conventional": "13.1.0",
71
+ "@octokit/types": "13.10.0",
72
+ "@trivago/prettier-plugin-sort-imports": "4.3.0",
73
+ "@tsconfig/node-lts-strictest": "18.12.1",
74
+ "@types/jest": "29.2.4",
75
+ "@typescript-eslint/eslint-plugin": "7.8.0",
76
+ "@typescript-eslint/parser": "7.8.0",
77
+ "babel-jest": "30.2.0",
78
+ "core-js": "3.26.1",
79
+ "cz-conventional-changelog": "3.3.0",
80
+ "declapract": "0.12.0",
81
+ "declapract-typescript-ehmpathy": "0.39.5",
82
+ "depcheck": "1.4.3",
83
+ "eslint": "8.56.0",
84
+ "eslint-config-airbnb-typescript": "18.0.0",
85
+ "eslint-config-prettier": "8.5.0",
86
+ "eslint-plugin-import": "2.26.0",
87
+ "eslint-plugin-prettier": "4.2.1",
88
+ "husky": "8.0.3",
89
+ "jest": "29.3.1",
90
+ "prettier": "2.8.1",
91
+ "rhachet": "1.12.1",
92
+ "rhachet-roles-ehmpathy": "1.8.0",
93
+ "simple-log-methods": "0.6.2",
94
+ "test-fns": "1.5.0",
95
+ "ts-jest": "29.4.5",
96
+ "ts-node": "10.9.2",
97
+ "typescript": "5.4.5"
98
+ },
99
+ "config": {
100
+ "commitizen": {
101
+ "path": "./node_modules/cz-conventional-changelog"
102
+ }
103
+ }
104
+ }
package/readme.md ADDED
@@ -0,0 +1,181 @@
1
+ # declastruct-github
2
+
3
+ ![test](https://github.com/ehmpathy/declastruct-github/workflows/test/badge.svg)
4
+ ![publish](https://github.com/ehmpathy/declastruct-github/workflows/publish/badge.svg)
5
+
6
+ Declarative control of Github resource constructs, via [declastruct](https://github.com/ehmpathy/declastruct).
7
+
8
+ Declare the structures you want. Plan to see the changes required. Apply to make it so 🪄
9
+
10
+
11
+ # install
12
+
13
+ ```sh
14
+ npm install -s declastruct-github
15
+ ```
16
+
17
+ # use via cli
18
+
19
+ ## example.1
20
+
21
+ ### wish ✨
22
+
23
+ declare the resources you wish to have - and what state you wish them to be in
24
+
25
+ ```ts
26
+ import { getDeclastructGithubProvider, DeclaredGithubRepo, DeclaredGithubRepoConfig } from 'declastruct-github';
27
+
28
+ export const getProviders = async () => [
29
+ getDeclastructGithubProvider({
30
+ credentials: {
31
+ token: process.env.GITHUB_TOKEN,
32
+ }
33
+ })
34
+ ]
35
+
36
+ export const getResources = async () => {
37
+ const repo = DeclaredGithubRepo.as({
38
+ name: 'super repo',
39
+ });
40
+ const repoConfig = DeclaredGithubRepoConfig.as({
41
+ repo: refByUnique(repo),
42
+
43
+ // for example, only allow squash merges
44
+ allowSquashMerge: true,
45
+ allowMergeCommit: false,
46
+ allowRebaseMerge: false,
47
+
48
+ // ... see the docs or types for other options
49
+ });
50
+
51
+ // ... add whatever resources you wish
52
+
53
+ return [
54
+ repo,
55
+ repoConfig,
56
+ // ... all the resources you wish for will go here
57
+ ],
58
+ }
59
+ ```
60
+
61
+ ### plan 🔮
62
+
63
+ plan how to achieve the wish of resources you've declared
64
+
65
+ this will emit a plan that declares the changes required in order to fulfill the wish
66
+
67
+ ```sh
68
+ npx declastruct plan --wish provision/github/resources.ts --output provision/github/.temp/plan.json
69
+ ```
70
+
71
+ ### apply 🪄
72
+
73
+ apply the plan to fulfill the wish
74
+
75
+ this will apply only the changes declared in the plan - and only if this plan is still applicable
76
+
77
+ ```sh
78
+ npx declastruct apply --plan provision/github/.temp/plan.json
79
+ ```
80
+
81
+
82
+ ## example.2
83
+
84
+ ```ts
85
+ export const getResources = async () => {
86
+ // declare the repo
87
+ const repo = DeclaredGithubRepo.as({
88
+ name: "your repo",
89
+ });
90
+
91
+ // declare the main branch
92
+ const branchMain = DeclaredGithubBranch.as({
93
+ repo: refByUnique(repo),
94
+ name: 'main',
95
+ })
96
+
97
+ // declare config for the repo
98
+ const repoConfig = DeclaredGithubRepoConfig.as({
99
+ // explicitly set the main branch
100
+ defaultBranch: refByUnique(branchMain),
101
+
102
+ // we only use issues; the rest is noise today
103
+ hasIssues: true,
104
+ hasProjects: false,
105
+ hasWiki: false,
106
+ hasDownloads: false,
107
+ isTemplate: false,
108
+
109
+ // only squash merges are allowed
110
+ allowSquashMerge: true,
111
+ allowMergeCommit: false, // but especially not merge merges. never merge merges
112
+ allowRebaseMerge: false,
113
+
114
+ // always cleanup after yourself
115
+ deleteBranchOnMerge: true,
116
+ });
117
+
118
+ // declare protection for that branch, too
119
+ const branchMainProtection = DeclaredGithubBranchProtection.as({
120
+ branch: refByUnique(branchMain),
121
+
122
+ enforceAdmins: true, // yes, even admins need to follow this (note: they can still take the time to go and change the settings temporarily for the exceptions)
123
+ allowsDeletions: false, // dont allow the `main` branch to be deleted
124
+ allowsForcePushes: false, // dont allow `main` branch to be force pushed to
125
+ requireLinearHistory: false, // # no ugly merge commits, woo! 🎉
126
+
127
+ requiedStatusChecks: {
128
+ strict: true, // branch must be up to date. otherwise, we dont know if it will really pass once it is merged
129
+ contexts = [
130
+ "suite / install / npm",
131
+ "suite / test-commits",
132
+ "suite / test-types",
133
+ "suite / test-format",
134
+ "suite / test-lint",
135
+ "suite / test-unit",
136
+ "suite / test-integration",
137
+ "suite / test-acceptance-locally",
138
+ "pullreq-title" // "review / pullreq-title",
139
+ ]
140
+ }
141
+ })
142
+
143
+
144
+ return [
145
+ repo,
146
+ branchMain,
147
+ repoConfig,
148
+ branchMainProtection,
149
+ ]
150
+ }
151
+ ```
152
+
153
+ # use imperatively
154
+
155
+ ## resource=DeclaredGithubRepo
156
+
157
+ ### getRepos
158
+
159
+ ### getRepo
160
+
161
+ ### setRepo
162
+
163
+ ## resource=DeclaredGithubBranch
164
+
165
+ ### getBranches
166
+
167
+ ### getBranch
168
+
169
+ ### setBranch
170
+
171
+ ## resource=DeclaredGithubRepoConfig
172
+
173
+ ### getRepoConfig
174
+
175
+ ### setRepoConfig
176
+
177
+ ## resource=DeclaredGithubBranchProtection
178
+
179
+ ### getBranchProtection
180
+
181
+ ### setBranchProtection