Merge pull request #25 from jlengrand/warn-override

Warn override
This commit is contained in:
julien Lengrand-Lambert
2018-04-24 16:24:39 +02:00
committed by GitHub
9 changed files with 71 additions and 7140 deletions

4
.gitignore vendored
View File

@@ -2,4 +2,6 @@ node_modules
.config
yarn-error.log
coverage
package-lock.json
.config*
package-lock.json

View File

@@ -1,9 +1,16 @@
const inquirer = require('inquirer');
const { verify } = require('../verify');
const { writeConfig } = require('../../utils/writeConfig');
const { checkConfigExists } = require('../../utils/checkConfigExists');
const { inputOptions } = require('./inputOptions');
const { logger } = require('../../utils/logger');
const chalk = require('chalk');
const configure = async() => {
if(await checkConfigExists()){
logger.log(chalk.red.bold('⚠️ Mergify is already configured. Configuring again will override the existing file.'));
}
try {
const answers = await inquirer.prompt(inputOptions);
await writeConfig(answers);

View File

@@ -0,0 +1,18 @@
const { access, constants } = require('fs');
const { promisify } = require('util');
const accessAsync = promisify(access);
const { getConfigPath } = require('../getConfigPath');
async function checkConfigExists() {
try {
await accessAsync(getConfigPath(), constants.F_OK);
return true;
}
catch(_){
return false;
}
}
module.exports = {
checkConfigExists
};

View File

@@ -0,0 +1,27 @@
const { checkConfigExists } = require('./index.js');
const mock = require('mock-fs');
describe('utils/checkConfigExists', () => {
it('should return true when checking an existing config', async() => {
const configPath = `${__dirname}/../../../.config`;
mock({
[configPath]: ''
});
const fileExists = await checkConfigExists();
return expect(fileExists).toEqual(true);
});
it('should return false when not configured', async() => {
mock({
});
const fileExists = await checkConfigExists();
return expect(fileExists).toEqual(false);
});
afterEach(mock.restore);
});

View File

@@ -0,0 +1,7 @@
function getConfigPath() {
return `${__dirname}/../../../.config`;;
}
module.exports = {
getConfigPath
};

View File

@@ -2,11 +2,11 @@ const { readFile } = require('fs');
const { promisify } = require('util');
const readFileAsync = promisify(readFile);
const { logger } = require('../logger');
const { getConfigPath } = require('../getConfigPath');
async function readConfig() {
const configFileName = `${__dirname}/../../../.config`;
try {
const config = await readFileAsync(configFileName, 'utf8');
const config = await readFileAsync(getConfigPath(), 'utf8');
return JSON.parse(config);
} catch (_) {
logger.log(`

View File

@@ -1,13 +1,13 @@
const { writeFile } = require('fs');
const { promisify } = require('util');
const writeFileAsync = promisify(writeFile);
const { getConfigPath } = require('../getConfigPath');
async function writeConfig(config) {
const configFileName = `${__dirname}/../../../.config`;
config.userId = parseInt(config.userId);
const body = JSON.stringify(config, null, 2);
return writeFileAsync(configFileName, body, 'utf8');
return writeFileAsync(getConfigPath(), body, 'utf8');
}
module.exports = {

7135
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -35,6 +35,11 @@
"test-travis": "yarn test && cat ./coverage/lcov.info | coveralls"
},
"author": "Ramon Gebben <ramon@sensorfact.nl>",
"contributors": [
{
"name": "Julien Lengrand-Lambert <julien@lengrand.fr> - @jlengrand"
}
],
"license": "MIT",
"jest": {
"coverageDirectory": "./coverage/",