Skip to content

Commit d64a21b

Browse files
Copilotmheap
andauthored
Convert project to TypeScript (#128)
* Initial plan * Convert project to TypeScript Co-authored-by: mheap <59130+mheap@users.noreply.github.com> * Remove old JavaScript files Co-authored-by: mheap <59130+mheap@users.noreply.github.com> * Replace 'any' types with proper Octokit types Co-authored-by: mheap <59130+mheap@users.noreply.github.com> * Bump Node versions in CI --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: mheap <59130+mheap@users.noreply.github.com> Co-authored-by: Michael Heap <m@michaelheap.com>
1 parent bb76d01 commit d64a21b

File tree

11 files changed

+1692
-550
lines changed

11 files changed

+1692
-550
lines changed

.eslintrc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"parser": "@typescript-eslint/parser",
23
"parserOptions": {
34
"ecmaVersion": 2020,
45
"impliedStrict": true,
@@ -9,7 +10,8 @@
910
}
1011
},
1112
"plugins": [
12-
"prettier"
13+
"prettier",
14+
"@typescript-eslint"
1315
],
1416
"rules": {
1517
"prettier/prettier": "error"

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88

99
strategy:
1010
matrix:
11-
node-version: [14.x, 16.x, 18.x]
11+
node-version: [18.x, 20.x, 22.x]
1212

1313
env:
1414
CI: true

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
11
node_modules
2+
dist
3+
*.js
4+
*.d.ts
5+
*.d.ts.map
6+
*.js.map
7+
!jest.config.js
8+
!.eslintrc.js

create-or-update-files.test.js renamed to create-or-update-files.test.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const nock = require("nock");
55
nock.disableNetConnect();
66
const octokit = new Octokit();
77

8-
function run(body) {
8+
function run(body: any) {
99
return plugin(octokit, body);
1010
}
1111

@@ -345,7 +345,7 @@ test(`success (createBranch, use default base branch)`, async () => {
345345
});
346346

347347
test(`success (createBranch, use default base branch, multiple commits)`, async () => {
348-
const body = {
348+
const body: any = {
349349
...validRequest,
350350
createBranch: true,
351351
};
@@ -510,7 +510,7 @@ test("Does not overwrite other methods", () => {
510510
expect(testOctokit).toHaveProperty("rest.repos.acceptInvitation");
511511
});
512512

513-
function mockGetRef(branch, sha, success) {
513+
function mockGetRef(branch: string, sha: string, success: boolean) {
514514
const m = nock("https://api.github.com").get(
515515
`/repos/${owner}/${repo}/git/ref/heads%2F${branch}`,
516516
);
@@ -528,7 +528,7 @@ function mockGetRef(branch, sha, success) {
528528
}
529529
}
530530

531-
function mockCreateBlob(content, sha) {
531+
function mockCreateBlob(content: string, sha: string) {
532532
const expectedBody = { content: content, encoding: "base64" };
533533
const m = nock("https://api.github.com").post(
534534
`/repos/${owner}/${repo}/git/blobs`,
@@ -575,7 +575,7 @@ function mockCreateBlobBase64PreEncoded() {
575575
);
576576
}
577577

578-
function mockCreateTreeSubmodule(baseTree) {
578+
function mockCreateTreeSubmodule(baseTree: string) {
579579
const expectedBody = {
580580
tree: [
581581
{
@@ -600,7 +600,7 @@ function mockCreateTreeSubmodule(baseTree) {
600600
m.reply(200, body);
601601
}
602602

603-
function mockCreateTree(baseTree) {
603+
function mockCreateTree(baseTree: string) {
604604
const expectedBody = {
605605
tree: [
606606
{
@@ -631,7 +631,7 @@ function mockCreateTree(baseTree) {
631631
m.reply(200, body);
632632
}
633633

634-
function mockCreateTreeSecond(baseTree) {
634+
function mockCreateTreeSecond(baseTree: string) {
635635
const expectedBody = {
636636
tree: [
637637
{
@@ -656,7 +656,7 @@ function mockCreateTreeSecond(baseTree) {
656656
m.reply(200, body);
657657
}
658658

659-
function mockCreateTreeWithIgnoredDelete(baseTree) {
659+
function mockCreateTreeWithIgnoredDelete(baseTree: string) {
660660
const expectedBody = {
661661
tree: [
662662
{
@@ -681,7 +681,7 @@ function mockCreateTreeWithIgnoredDelete(baseTree) {
681681
m.reply(200, body);
682682
}
683683

684-
function mockCreateTreeWithDeleteOnly(baseTree) {
684+
function mockCreateTreeWithDeleteOnly(baseTree: string) {
685685
// The order here is important. Removals must be applied before creations
686686
const expectedBody = {
687687
tree: [
@@ -707,7 +707,7 @@ function mockCreateTreeWithDeleteOnly(baseTree) {
707707
m.reply(200, body);
708708
}
709709

710-
function mockCreateTreeWithDelete(baseTree) {
710+
function mockCreateTreeWithDelete(baseTree: string) {
711711
// The order here is important. Removals must be applied before creations
712712
const expectedBody = {
713713
tree: [
@@ -739,7 +739,7 @@ function mockCreateTreeWithDelete(baseTree) {
739739
m.reply(200, body);
740740
}
741741

742-
function mockCommitSubmodule(baseTree) {
742+
function mockCommitSubmodule(baseTree: string) {
743743
const expectedBody = {
744744
message: "Your submodule commit message",
745745
tree: "4112258c05f8ce2b0570f1bbb1a330c0f9595ff9",
@@ -758,7 +758,7 @@ function mockCommitSubmodule(baseTree) {
758758
m.reply(200, body);
759759
}
760760

761-
function mockCommit(baseTree, additional) {
761+
function mockCommit(baseTree: string, additional?: any) {
762762
additional = additional || {};
763763

764764
const expectedBody = {
@@ -780,7 +780,7 @@ function mockCommit(baseTree, additional) {
780780
m.reply(200, body);
781781
}
782782

783-
function mockCommitSecond(baseTree) {
783+
function mockCommitSecond(baseTree: string) {
784784
const expectedBody = {
785785
message: "This is the second commit",
786786
tree: "fffff6bbf5ab983d31b1cca28e204b71ab722764",
@@ -799,7 +799,7 @@ function mockCommitSecond(baseTree) {
799799
m.reply(200, body);
800800
}
801801

802-
function mockUpdateRef(branch) {
802+
function mockUpdateRef(branch: string) {
803803
const expectedBody = {
804804
force: true,
805805
sha: "ef105a72c03ce2743d90944c2977b1b5563b43c0",
@@ -813,7 +813,7 @@ function mockUpdateRef(branch) {
813813
m.reply(200);
814814
}
815815

816-
function mockCreateRef(branch, sha) {
816+
function mockCreateRef(branch: string, sha?: string) {
817817
const expectedBody = {
818818
force: true,
819819
ref: `refs/heads/${branch}`,
@@ -828,7 +828,7 @@ function mockCreateRef(branch, sha) {
828828
m.reply(200);
829829
}
830830

831-
function mockCreateRefSecond(branch, sha) {
831+
function mockCreateRefSecond(branch: string, sha?: string) {
832832
const expectedBody = {
833833
force: true,
834834
ref: `refs/heads/${branch}`,
@@ -843,17 +843,17 @@ function mockCreateRefSecond(branch, sha) {
843843
m.reply(200);
844844
}
845845

846-
function mockGetRepo() {
846+
function mockGetRepo(defaultBranch?: string) {
847847
const body = {
848-
default_branch: "master",
848+
default_branch: defaultBranch || "master",
849849
};
850850

851851
nock("https://api.github.com")
852852
.get(`/repos/${owner}/${repo}`)
853853
.reply(200, body);
854854
}
855855

856-
function mockGetContents(fileName, branch, success) {
856+
function mockGetContents(fileName: string, branch: string, success: boolean) {
857857
const m = nock("https://api.github.com").head(
858858
`/repos/${owner}/${repo}/contents/${fileName}?ref=${branch}`,
859859
);

0 commit comments

Comments
 (0)