mirror of
https://github.com/RamonGebben/mergify.git
synced 2026-03-10 08:51:18 +00:00
4
.gitignore
vendored
4
.gitignore
vendored
@@ -2,4 +2,6 @@ node_modules
|
||||
.config
|
||||
yarn-error.log
|
||||
coverage
|
||||
package-lock.json
|
||||
|
||||
.config*
|
||||
package-lock.json
|
||||
|
||||
@@ -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);
|
||||
|
||||
18
lib/utils/checkConfigExists/index.js
Normal file
18
lib/utils/checkConfigExists/index.js
Normal 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
|
||||
};
|
||||
27
lib/utils/checkConfigExists/index.spec.js
Normal file
27
lib/utils/checkConfigExists/index.spec.js
Normal 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);
|
||||
});
|
||||
|
||||
7
lib/utils/getConfigPath/index.js
Normal file
7
lib/utils/getConfigPath/index.js
Normal file
@@ -0,0 +1,7 @@
|
||||
function getConfigPath() {
|
||||
return `${__dirname}/../../../.config`;;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getConfigPath
|
||||
};
|
||||
@@ -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(`
|
||||
|
||||
@@ -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
7135
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -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/",
|
||||
|
||||
Reference in New Issue
Block a user