Skip to content
This repository was archived by the owner on May 4, 2023. It is now read-only.

Commit 994c3b2

Browse files
feat: improve no codiga file messaging
1 parent eeec426 commit 994c3b2

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

utils/rulesets.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
import { readFileRequired, parseYamlFile } from "../utils/file";
1+
import { parseYamlFile, readFile } from "../utils/file";
22
import { codigaApiFetch } from "./api";
33
import { ACTION_TOKEN_ADD, CODIGA_CONFIG_FILE } from "./constants";
44
import { getGitDirectoryRequired } from "./git";
55
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";
712
import { getToken } from "./store";
813

914
/**
@@ -38,8 +43,22 @@ export function getRulesetsFromCodigaFile() {
3843
const rootDir = getGitDirectoryRequired();
3944

4045
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);
4362

4463
// if there isn't a rulesets value in the codiga.yml file, throw an error
4564
if (!parsedFile) {

0 commit comments

Comments
 (0)