Skip to content

Commit c7faba0

Browse files
committed
code cleanup
1 parent dd748a5 commit c7faba0

File tree

4 files changed

+27
-36
lines changed

4 files changed

+27
-36
lines changed

.github/testing/src/affected.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,28 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import {Map, List, Set} from 'immutable';
15+
import { Map, List, Set } from 'immutable';
1616

1717
export type PackageName = string;
1818
export type TestPath = string;
1919
export type TestName = string;
2020

21+
export type AffectedTests = Map<TestPath, Set<TestName>>
22+
2123
export const TestAll = (path: string): Affected => ({
2224
path: path,
2325
TestAll: null,
2426
});
2527
export const TestSome = (
2628
path: string,
27-
tests: Map<TestPath, Set<TestName>>
29+
tests: AffectedTests
2830
): Affected => ({
2931
path: path,
3032
TestSome: tests,
3133
});
3234
export type Affected =
33-
| {path: string; TestAll: null}
34-
| {path: string; TestSome: Map<TestPath, Set<TestName>>};
35+
| { path: string; TestAll: null }
36+
| { path: string; TestSome: AffectedTests };
3537

3638
export function mergeAffected(
3739
path: string,

.github/testing/src/config.ts

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,24 @@
1515
import * as fs from 'node:fs';
1616
import * as git from './git';
1717
import * as path from 'path';
18-
import {List, Map, Set} from 'immutable';
19-
import {minimatch} from 'minimatch'; /* eslint-disable @typescript-eslint/no-explicit-any */
20-
import {Affected, TestAll, TestName, TestPath, mergeAffected} from './affected';
18+
import { List, Map, Set } from 'immutable';
19+
import { minimatch } from 'minimatch'; /* eslint-disable @typescript-eslint/no-explicit-any */
20+
import { Affected, AffectedTests, TestAll, TestName, TestPath, mergeAffected } from './affected';
2121

2222
type Args = {
2323
root: string;
2424
path: string;
2525
};
2626

27-
type ArgsTestSome = {
28-
root: string;
29-
path: string;
30-
tests: Map<TestPath, Set<TestName>>;
31-
};
32-
3327
const IGNORE_GLOBAL = ['README.md'];
3428

3529
export class Config {
3630
match: List<string>;
3731
ignore: List<string>;
3832
packageFile: List<string>;
39-
_lint: (_: Args) => void;
40-
_testAll: (_: Args) => void;
41-
_testSome: (_: ArgsTestSome) => void;
33+
_lint: (args: Args) => void;
34+
_testAll: (args: Args) => void;
35+
_testSome: (args: Args, tests: AffectedTests) => void;
4236

4337
constructor({
4438
match,
@@ -51,16 +45,16 @@ export class Config {
5145
match?: string[];
5246
ignore?: string[];
5347
packageFile?: string[];
54-
lint?: (_: Args) => void;
55-
testAll?: (_: Args) => void;
56-
testSome?: (_: ArgsTestSome) => void;
48+
lint?: (args: Args) => void;
49+
testAll?: (args: Args) => void;
50+
testSome?: (args: Args, tests: AffectedTests) => void;
5751
}) {
5852
this.match = List(match || ['**']);
5953
this.ignore = List(ignore);
6054
this.packageFile = List(packageFile);
61-
this._lint = lint || (_ => {});
62-
this._testAll = testAll || (_ => {});
63-
this._testSome = testSome || (_ => {});
55+
this._lint = lint || (_ => { });
56+
this._testAll = testAll || (_ => { });
57+
this._testSome = testSome || (_ => { });
6458
}
6559

6660
affected = (head: string, main: string): List<Affected> =>
@@ -76,30 +70,26 @@ export class Config {
7670
);
7771

7872
lint = (affected: Affected) => {
73+
const args = { root: git.root(), path: affected.path };
7974
const cwd = process.cwd();
80-
const root = git.root();
81-
const dir = path.join(root, affected.path);
75+
const dir = path.join(args.root, affected.path);
8276
console.log(`> cd ${dir}`);
8377
process.chdir(dir);
84-
this._lint({root: root, path: affected.path});
78+
this._lint(args);
8579
process.chdir(cwd);
8680
};
8781

8882
test = (affected: Affected) => {
83+
const args = { root: git.root(), path: affected.path };
8984
const cwd = process.cwd();
90-
const root = git.root();
91-
const dir = path.join(root, affected.path);
85+
const dir = path.join(args.root, affected.path);
9286
console.log(`> cd ${dir}`);
9387
process.chdir(dir);
9488
if ('TestAll' in affected) {
95-
this._testAll({root: root, path: affected.path});
89+
this._testAll(args);
9690
}
9791
if ('TestSome' in affected) {
98-
this._testSome({
99-
root: root,
100-
path: affected.path,
101-
tests: affected.TestSome,
102-
});
92+
this._testSome(args, affected.TestSome);
10393
}
10494
process.chdir(cwd);
10595
};

.github/testing/src/config/python.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const python = (version = '3.11') =>
3838
subprocess.run('cp', [noxfile, 'noxfile.py']);
3939
subprocess.run('nox', ['-s', `py-${version}`]);
4040
},
41-
testSome: args => {
41+
testSome: (args, tests) => {
4242
const noxfile = path.join(args.root, 'noxfile-template.py');
4343
subprocess.run('cp', [noxfile, 'noxfile.py']);
4444
throw `TODO: config/python.ts testSome ${JSON.stringify(args)}`;

.github/testing/tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
},
77
"include": [
88
"src/**/*.ts",
9-
"test/**/*.ts",
10-
"src/diffs.ts"
9+
"test/**/*.ts"
1110
]
1211
}

0 commit comments

Comments
 (0)