-
Notifications
You must be signed in to change notification settings - Fork 196
/
Copy pathvalidateBranch.ts
67 lines (64 loc) · 2.24 KB
/
validateBranch.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { LookerNodeSDK } from '@looker/sdk-node';
import { IProjectError } from '@looker/sdk';
const sdk = LookerNodeSDK.init40();
// this will validate lookml in development mode
const validateBranch = async (
projectName: string,
branch: string
): Promise<IProjectError[]> => {
// check current workspace, if prod switch to dev (needed to be able to checkout a different git branch)
const workspace = await sdk.ok(sdk.session());
console.log(JSON.stringify(workspace));
if (workspace.workspace_id == 'production') {
const updatedWorkspace = await sdk.ok(
sdk.update_session({ workspace_id: 'dev' })
);
console.log(JSON.stringify(updatedWorkspace));
}
const currentBranch = await sdk.ok(sdk.git_branch(projectName));
// compare the current branch of the user to that inputted, if different update git branch of user to that which is specified
if (currentBranch.name == branch) {
try {
const validateResults = await sdk.ok(sdk.validate_project(projectName));
if (validateResults.errors.length > 0) {
console.log(
`There are errors with this lookml project. Errors: ${JSON.stringify(
validateResults.errors
)}`
);
return validateResults.errors;
} else {
console.log('There are no errors with this lookml project.');
}
} catch (e) {
throw new Error(
`There was an error validating this project. Here is the full message: ${e}.`
);
}
} else {
try {
await sdk.ok(
sdk.update_git_branch(projectName, {
name: branch,
})
);
} catch (e) {
throw new Error(
`There was an error checking out ${branch}. Check to make sure the branch inputted is a valid branch in the repo. Error: ${e}.`
);
}
const validateResults = await sdk.ok(sdk.validate_project(projectName));
if (validateResults.errors.length > 0) {
console.log(
`There are errors with this lookml project. Errors: ${JSON.stringify(
validateResults.errors
)}`
);
return validateResults.errors;
} else {
console.log('There are no errors with this lookml project.');
}
}
};
// Example
//validateBranch('luka_thesis', 'dev-lukas-fontanilla-2z5k')