Skip to content

Commit 23e4f88

Browse files
committed
cleanup and refactor reusable code
1 parent c7faba0 commit 23e4f88

File tree

5 files changed

+34
-39
lines changed

5 files changed

+34
-39
lines changed

.github/testing/src/affected.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,25 @@
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>>
21+
export type AffectedTests = Map<TestPath, Set<TestName>>;
2222

2323
export const TestAll = (path: string): Affected => ({
2424
path: path,
2525
TestAll: null,
2626
});
27-
export const TestSome = (
28-
path: string,
29-
tests: AffectedTests
30-
): Affected => ({
27+
export const TestSome = (path: string, tests: AffectedTests): Affected => ({
3128
path: path,
3229
TestSome: tests,
3330
});
3431
export type Affected =
35-
| { path: string; TestAll: null }
36-
| { path: string; TestSome: AffectedTests };
32+
| {path: string; TestAll: null}
33+
| {path: string; TestSome: AffectedTests};
3734

3835
export function mergeAffected(
3936
path: string,

.github/testing/src/config.ts

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
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, AffectedTests, TestAll, TestName, TestPath, mergeAffected } from './affected';
18+
import {List} from 'immutable';
19+
import {minimatch} from 'minimatch'; /* eslint-disable @typescript-eslint/no-explicit-any */
20+
import {Affected, AffectedTests, TestAll, mergeAffected} from './affected';
2121

2222
type Args = {
2323
root: string;
@@ -52,9 +52,9 @@ export class Config {
5252
this.match = List(match || ['**']);
5353
this.ignore = List(ignore);
5454
this.packageFile = List(packageFile);
55-
this._lint = lint || (_ => { });
56-
this._testAll = testAll || (_ => { });
57-
this._testSome = testSome || (_ => { });
55+
this._lint = lint || (_ => {});
56+
this._testAll = testAll || (_ => {});
57+
this._testSome = testSome || (_ => {});
5858
}
5959

6060
affected = (head: string, main: string): List<Affected> =>
@@ -69,28 +69,26 @@ export class Config {
6969
.values()
7070
);
7171

72-
lint = (affected: Affected) => {
73-
const args = { root: git.root(), path: affected.path };
74-
const cwd = process.cwd();
75-
const dir = path.join(args.root, affected.path);
76-
console.log(`> cd ${dir}`);
77-
process.chdir(dir);
78-
this._lint(args);
79-
process.chdir(cwd);
80-
};
72+
lint = (affected: Affected) =>
73+
this.withDir(affected.path, args => this._lint(args));
8174

82-
test = (affected: Affected) => {
83-
const args = { root: git.root(), path: affected.path };
75+
test = (affected: Affected) =>
76+
this.withDir(affected.path, args => {
77+
if ('TestAll' in affected) {
78+
this._testAll(args);
79+
}
80+
if ('TestSome' in affected) {
81+
this._testSome(args, affected.TestSome);
82+
}
83+
});
84+
85+
withDir = (dir: string, f: (args: Args) => void) => {
86+
const args = {root: git.root(), path: dir};
8487
const cwd = process.cwd();
85-
const dir = path.join(args.root, affected.path);
86-
console.log(`> cd ${dir}`);
87-
process.chdir(dir);
88-
if ('TestAll' in affected) {
89-
this._testAll(args);
90-
}
91-
if ('TestSome' in affected) {
92-
this._testSome(args, affected.TestSome);
93-
}
88+
const absDir = path.join(args.root, dir);
89+
console.log(`> cd ${absDir}`);
90+
process.chdir(absDir);
91+
f(args);
9492
process.chdir(cwd);
9593
};
9694

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import * as path from 'path';
1616
import * as subprocess from '../subprocess';
17-
import { Config } from '../config';
17+
import {Config} from '../config';
1818

1919
export const python = (version = '3.11') =>
2020
new Config({

.github/testing/src/main.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
// limitations under the License.
1414

1515
import * as git from './git';
16-
import { Config } from './config';
17-
import { python } from './config/python';
18-
import { Affected } from './affected';
16+
import {Config} from './config';
17+
import {python} from './config/python';
18+
import {Affected} from './affected';
1919

2020
function getConfig(lang: string): Config {
2121
switch (lang) {

.github/workflows/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
- uses: actions/setup-python@v5
6262
with:
6363
python-version: '3.12'
64-
- run: pip install nox black
64+
- run: pip install nox
6565
- run: bun install
6666
- run: bun run ci-lint python AFFECTED
6767
env:

0 commit comments

Comments
 (0)