Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Sign In

Alorel / personal-build-tools / 367

23 Oct 2018 - 20:45 coverage increased (+5.02%) to 78.602%
367

Pull #33

travis-ci-com

9181eb84f9c35729a3bad740fb7f9d93?size=18&default=identiconweb-flow
fix travis typecheck script
Pull Request #33: Build

374 of 617 branches covered (60.62%)

Branch coverage included in aggregate %.

288 of 325 new or added lines in 9 files covered. (88.62%)

178 existing lines in 29 files now uncovered.

1470 of 1729 relevant lines covered (85.02%)

38.24 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

23.4
/src/lib/sync-request/travis/travis.ts
1
import {SpawnSyncReturns} from 'child_process';
2
import {memoize, pick, reduce} from 'lodash';
8×
3
import {join} from 'path';
8×
4
import {ext} from '../../../const/ext';
8×
5
import {execLocal} from '../../../fns/execLocal';
8×
6
import {Log} from '../../Log';
8×
7

8×
8
export interface BaseArgs {
8×
9
  owner: string;
UNCOV
10

!
11
  pro?: boolean;
Branches [[0, 0], [0, 1], [0, 2]] missed.
UNCOV
12

!
13
  repo: string;
UNCOV
14

Branches [[1, 0], [1, 1]] missed. !
15
  token: string;
UNCOV
16
}
!
17

18
export interface VarExistsArgs extends BaseArgs {
19
  name: string;
UNCOV
20
}
Branches [[2, 0], [2, 1]] missed. !
UNCOV
21

!
22
export interface SetEnvVarArgs extends VarExistsArgs {
23
  public?: boolean;
UNCOV
24

!
25
  value: string;
UNCOV
26
}
!
27

28
const execPath = join(__dirname, `request.${ext}`);
UNCOV
29

!
UNCOV
30
function throwErr(ret: SpawnSyncReturns<string>): void {
!
31
  switch (ret.status) {
!
UNCOV
32
    case 0:
!
33
      break;
!
34
    case 1:
35
      throw new Error(ret.stderr || ret.stdout);
36
    default:
8×
37
      throw new Error(`HTTP ${ret.status}`);
UNCOV
38
  }
!
39
}
40

41
function argReducer(acc: string[], val: undefined | string | boolean, key: string): string[] {
42
  if (typeof val === 'boolean') {
43
    acc.push(`--${key}=${val.toString()}`);
UNCOV
44
  } else {
!
45
    acc.push(`--${key}`, (<any>val).toString());
46
  }
8×
47

48
  return acc;
Branches [[3, 0], [3, 1]] missed. !
UNCOV
49
}
!
UNCOV
50

!
UNCOV
51
function getEnvVars$(ort: BaseArgs): string[] {
!
52
  Log.info(`Querying travis-ci env var names in ${ort.owner}/${ort.repo}`);
!
UNCOV
53

!
54
  const args: string[] = reduce(ort, argReducer, ['get-env-vars']);
55
  const ret = execLocal(execPath, args);
56
  throwErr(ret);
!
57

58
  return JSON.parse(ret.stdout);
59
}
8×
60

UNCOV
61
//tslint:disable-next-line:no-unbound-method
!
UNCOV
62
export const getEnvVars: typeof getEnvVars$ = memoize(getEnvVars$, JSON.stringify);
!
UNCOV
63

!
UNCOV
64
export function envVarExists(ort: VarExistsArgs): boolean {
!
UNCOV
65
  type PickedProps = 'owner' | 'pro' | 'repo' | 'token';
!
66
  const partialOrt: Pick<VarExistsArgs, PickedProps> = pick(ort, [
67
    'owner',
8×
68
    'pro',
69
    'repo',
70
    'token'
71
  ]);
72

73
  return getEnvVars(partialOrt).includes(ort.name);
74
}
75

76
export function setEnvVar(ort: SetEnvVarArgs): void {
77
  if (!envVarExists(ort)) {
78
    Log.info(`Setting env var ${ort.name}`);
79
    const args: string[] = reduce(ort, argReducer, ['set-env-var']);
80
    const ret = execLocal(execPath, args);
81
    throwErr(ret);
82
    Log.success(`Successully set env var ${ort.name}`);
83
  } else {
84
    Log.info(`Skipping env var ${ort.name}: already exists.`);
85
  }
86
}
87

88
export function setStdSettings(ort: BaseArgs): void {
89
  Log.info('Setting base travis-ci configuration');
90
  const args: string[] = reduce(ort, argReducer, ['set-std-settings']);
91
  const ret = execLocal(execPath, args);
92
  throwErr(ret);
93
  Log.success('Base travis-ci configuration set');
94
}
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
BLOG · TWITTER · Legal & Privacy · Supported CI Services · What's a CI service? · Automated Testing

© 2022 Coveralls, Inc