Skip to content

Commit 9f205a7

Browse files
authored
chore: turn script into esm and update all dependencies (#171)
* chore: update @actions/core * chore: update yaml * chore: upgrade dependencies and turn the project into esm * chore: update schema * chore: update typescript * chore: restore format shared action * docs: update the changelog
1 parent d8cbec3 commit 9f205a7

49 files changed

Lines changed: 4962 additions & 13009 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2222
- new args for repositories and branch protection rules
2323

2424
### Changed
25-
- Updated the signatures of all the shared actions; now the runAction function will persist the changes to disk while action functions will operate on the in-memory state
25+
- **BREAKING**: turned scripts into an ESM project (please ensure you remove the following files during the upgrade: `scripts/.eslintignore`, `scripts/.eslintrc.json`, `scripts/jest.config.js`, `jest.d.ts`, `jest.setup.ts`; please update your imports in the `scripts/src/actions/fix-yaml-config.ts` file to include the `.js` extension)
26+
- **BREAKING**: Updated the signatures of all the shared actions; now the runAction function will persist the changes to disk while action functions will operate on the in-memory state (please update your imports in the `scripts/src/actions/fix-yaml-config.ts` file accordingly)
2627
- Synchronization script: to use GitHub API directly instead of relying on TF GH Provider's Data Sources
2728
- Configuration: replaced multiple JSONs with a single, unified YAML
2829
- Synchronization script: rewrote the script in JS

github/.schema.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
"additionalProperties": {
2828
"additionalProperties": false,
2929
"properties": {
30+
"advanced_security": {
31+
"type": "boolean"
32+
},
3033
"allow_auto_merge": {
3134
"type": "boolean"
3235
},
@@ -39,6 +42,9 @@
3942
"allow_squash_merge": {
4043
"type": "boolean"
4144
},
45+
"allow_update_branch": {
46+
"type": "boolean"
47+
},
4248
"archive_on_destroy": {
4349
"type": "boolean"
4450
},
@@ -108,6 +114,9 @@
108114
"gitignore_template": {
109115
"type": "string"
110116
},
117+
"has_discussions": {
118+
"type": "boolean"
119+
},
111120
"has_downloads": {
112121
"type": "boolean"
113122
},
@@ -129,9 +138,21 @@
129138
"is_template": {
130139
"type": "boolean"
131140
},
141+
"labels": {
142+
"additionalProperties": {
143+
"$ref": "#/definitions/RepositoryLabel"
144+
},
145+
"type": "object"
146+
},
132147
"license_template": {
133148
"type": "string"
134149
},
150+
"merge_commit_message": {
151+
"type": "string"
152+
},
153+
"merge_commit_title": {
154+
"type": "string"
155+
},
135156
"pages": {
136157
"additionalProperties": false,
137158
"properties": {
@@ -153,6 +174,18 @@
153174
},
154175
"type": "object"
155176
},
177+
"secret_scanning": {
178+
"type": "boolean"
179+
},
180+
"secret_scanning_push_protection": {
181+
"type": "boolean"
182+
},
183+
"squash_merge_commit_message": {
184+
"type": "string"
185+
},
186+
"squash_merge_commit_title": {
187+
"type": "string"
188+
},
156189
"teams": {
157190
"additionalProperties": false,
158191
"properties": {
@@ -276,9 +309,15 @@
276309
"allows_force_pushes": {
277310
"type": "boolean"
278311
},
312+
"blocks_creations": {
313+
"type": "boolean"
314+
},
279315
"enforce_admins": {
280316
"type": "boolean"
281317
},
318+
"lock_branch": {
319+
"type": "boolean"
320+
},
282321
"push_restrictions": {
283322
"items": {
284323
"type": "string"
@@ -354,6 +393,18 @@
354393
},
355394
"type": "object"
356395
},
396+
"RepositoryLabel": {
397+
"additionalProperties": false,
398+
"properties": {
399+
"color": {
400+
"type": "string"
401+
},
402+
"description": {
403+
"type": "string"
404+
}
405+
},
406+
"type": "object"
407+
},
357408
"Visibility": {
358409
"enum": [
359410
"private",

scripts/.eslintignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

scripts/.eslintrc.json

Lines changed: 0 additions & 57 deletions
This file was deleted.

scripts/__tests__/github.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import {mock} from 'node:test'
2+
3+
export function mockGitHub(): void {
4+
mock.module('@octokit/auth-app', {
5+
namedExports: {
6+
createAppAuth: () => () => ({token: undefined})
7+
}
8+
})
9+
10+
mock.module('@octokit/rest', {
11+
namedExports: {
12+
Octokit: {
13+
plugin: () => {
14+
// return Constructor of Octokit-like object
15+
return class {
16+
issues = {
17+
listCommentsForRepo: async () => [],
18+
listForRepo: async () => [],
19+
listLabelsForRepo: async () => []
20+
}
21+
orgs = {
22+
getMembershipForUser: async () => {},
23+
listInvitationTeams: async () => [],
24+
listMembers: async () => [],
25+
listPendingInvitations: async () => []
26+
}
27+
pulls = {
28+
listReviewCommentsForRepo: async () => []
29+
}
30+
repos = {
31+
get: async (opts: {owner: string; repo: string}) => ({
32+
data: {
33+
owner: {
34+
login: opts.owner
35+
},
36+
name: opts.repo,
37+
default_branch: 'main'
38+
}
39+
}),
40+
getContent: async (opts: {
41+
owner: string
42+
repo: string
43+
path: string
44+
ref: string
45+
}) => ({
46+
data: {
47+
path: opts.path,
48+
url: `https://github.com/${opts.owner}/${opts.repo}/blob/${opts.ref}/${opts.path}`,
49+
ref: opts.ref
50+
}
51+
}),
52+
listActivities: async () => [],
53+
listCollaborators: async () => [],
54+
listCommitCommentsForRepo: async () => [],
55+
listForOrg: async () => [],
56+
listInvitations: async () => []
57+
}
58+
teams = {
59+
getMembershipForUserInOrg: async () => {},
60+
list: async () => [],
61+
listMembersInOrg: async () => [],
62+
listPendingInvitationsInOrg: async () => [],
63+
listReposInOrg: async () => []
64+
}
65+
async paginate<T, K>(
66+
f: (opts: K) => Promise<T>,
67+
opts: K
68+
): Promise<T> {
69+
return f(opts)
70+
}
71+
}
72+
}
73+
}
74+
}
75+
})
76+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import {Member} from '../../src/resources/member.js'
2+
import {RepositoryBranchProtectionRule} from '../../src/resources/repository-branch-protection-rule.js'
3+
import {RepositoryCollaborator} from '../../src/resources/repository-collaborator.js'
4+
import {RepositoryFile} from '../../src/resources/repository-file.js'
5+
import {RepositoryLabel} from '../../src/resources/repository-label.js'
6+
import {RepositoryTeam} from '../../src/resources/repository-team.js'
7+
import {Repository} from '../../src/resources/repository.js'
8+
import {TeamMember} from '../../src/resources/team-member.js'
9+
import {Team} from '../../src/resources/team.js'
10+
11+
export const ConfigResourceCounts = {
12+
[Member.name]: 2,
13+
[Repository.name]: 7,
14+
[Team.name]: 2,
15+
[RepositoryCollaborator.name]: 1,
16+
[RepositoryBranchProtectionRule.name]: 1,
17+
[RepositoryTeam.name]: 6,
18+
[TeamMember.name]: 2,
19+
[RepositoryFile.name]: 1,
20+
[RepositoryLabel.name]: 3
21+
}
22+
export const ConfigResourcesCount = Object.values(ConfigResourceCounts).reduce(
23+
(a, b) => a + b,
24+
0
25+
)
26+
export const StateResourceCounts = {
27+
[Member.name]: 2,
28+
[Repository.name]: 7,
29+
[Team.name]: 2,
30+
[RepositoryCollaborator.name]: 1,
31+
[RepositoryBranchProtectionRule.name]: 1,
32+
[RepositoryTeam.name]: 7,
33+
[TeamMember.name]: 2,
34+
[RepositoryFile.name]: 1,
35+
[RepositoryLabel.name]: 3
36+
}
37+
export const StateResourcesCount = Object.values(StateResourceCounts).reduce(
38+
(a, b) => a + b,
39+
0
40+
)
Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import * as fs from 'fs'
2-
import {findFileByContent} from '../../src/resources/repository-file'
2+
import {findFileByContent} from '../../src/resources/repository-file.js'
3+
import {describe, it} from 'node:test'
4+
import assert from 'node:assert'
35

4-
test('finds file by content', async () => {
5-
const filePath = '__tests__/__resources__/files/README.md'
6-
const fileContent = fs.readFileSync(filePath).toString()
7-
const foundFilePath = findFileByContent(
8-
'__tests__/__resources__',
9-
fileContent
10-
)
11-
expect(foundFilePath).toEqual(filePath)
6+
describe('repository file', () => {
7+
it('finds file by content', async () => {
8+
const filePath = '__tests__/__resources__/files/README.md'
9+
const fileContent = fs.readFileSync(filePath).toString()
10+
const foundFilePath = findFileByContent(
11+
'__tests__/__resources__',
12+
fileContent
13+
)
14+
assert.equal(foundFilePath, filePath)
15+
})
1216
})

0 commit comments

Comments
 (0)