|
1 | | -import { readFileRequired, parseYamlFile } from "../utils/file"; |
| 1 | +import { parseYamlFile, readFile } from "../utils/file"; |
2 | 2 | import { codigaApiFetch } from "./api"; |
3 | 3 | import { ACTION_TOKEN_ADD, CODIGA_CONFIG_FILE } from "./constants"; |
4 | 4 | import { getGitDirectoryRequired } from "./git"; |
5 | 5 | import { GET_RULESETS_FOR_CLIENT } from "../graphql/queries"; |
6 | | -import { printCommandSuggestion, printFailure, printSuggestion } from "./print"; |
| 6 | +import { |
| 7 | + printCommandSuggestion, |
| 8 | + printEmptyLine, |
| 9 | + printFailure, |
| 10 | + printSuggestion, |
| 11 | +} from "./print"; |
7 | 12 | import { getToken } from "./store"; |
8 | 13 |
|
9 | 14 | /** |
@@ -38,8 +43,22 @@ export function getRulesetsFromCodigaFile() { |
38 | 43 | const rootDir = getGitDirectoryRequired(); |
39 | 44 |
|
40 | 45 | const codigaFileLocation = `${rootDir}/${CODIGA_CONFIG_FILE}`; |
41 | | - const file = readFileRequired(codigaFileLocation); |
42 | | - const parsedFile = parseYamlFile(file, codigaFileLocation); |
| 46 | + const codigaFileContent = readFile(codigaFileLocation); |
| 47 | + if (!codigaFileContent) { |
| 48 | + printEmptyLine(); |
| 49 | + printFailure(`Unable to read a codiga.yml file`); |
| 50 | + printSuggestion( |
| 51 | + " ↳ Please ensure you have a codiga.yml here:", |
| 52 | + codigaFileLocation |
| 53 | + ); |
| 54 | + printSuggestion( |
| 55 | + " ↳ Search for rulesets to add to it here:", |
| 56 | + "https://app.codiga.io/hub/rulesets" |
| 57 | + ); |
| 58 | + printEmptyLine(); |
| 59 | + process.exit(1); |
| 60 | + } |
| 61 | + const parsedFile = parseYamlFile(codigaFileContent, codigaFileLocation); |
43 | 62 |
|
44 | 63 | // if there isn't a rulesets value in the codiga.yml file, throw an error |
45 | 64 | if (!parsedFile) { |
|
0 commit comments