Compare commits

..

9 Commits

Author SHA1 Message Date
akashnimare
9e3cfbd887 echo commit range on travis. 2018-01-30 22:46:52 +05:30
cPhost
720f42ca80 ci: Add commit linter and clean up code. 2018-01-30 11:07:41 -05:00
cPhost
e18ba5dab6 gitlint: Setup commit linter.
This will setup a commit hook that will check the commit msg run
`npm run lint-commits` to check all the commits. Additionaly setup
git hooks by running `npm run setup-gitlint-hooks`.
2018-01-30 08:58:19 -05:00
Balaji
239631a2b6 tools: Add scripts for review Pull Requests. (#399)
* tools: Add script to fetch-pull-request.

Improves #397.

* tools: Add script to fetch-rebase-pull-request.

Improves #397.
2018-01-30 17:11:10 +05:30
Abhigyan Khaund
89d1344e2f preference page: Add a Loading indication for new server button. (#401)
Change the text of "Add" button to "Adding..." when a user clicks on Add button for adding new server.

Fixes: #396.
2018-01-29 23:53:10 +05:30
akashnimare
1948ba2cc3 menu: Fix Zoom In shortcut.
This is a temporary fix. Ideally, 'CmdOrCtrl+Plus' works on all
the platforms but because of https://github.com/electron/electron/issues/6731
it converts accelerator to 'Ctrl+Shift+Plus'.
2018-01-27 19:56:27 +05:30
Abhigyan Khaund
b8da7dd6ee gulp-dev: Add nodeman to dev script and fix renderer reload on changes.
Fixes: #368.
2018-01-23 00:29:15 +05:30
akashnimare
4a0efb7301 Code refactoring. 2018-01-23 00:05:15 +05:30
Priyank P
aedd95259d preference: Only toggle the state if element is present.
Fixes #393.
2018-01-22 22:38:01 +05:30
16 changed files with 346 additions and 14 deletions

View File

@@ -28,7 +28,13 @@ cache:
- app/node_modules - app/node_modules
script: script:
- echo $TRAVIS_COMMIT_RANGE
- echo ${TRAVIS_COMMIT_RANGE/.../..}
- echo "test"
- git log -4
- node ./tools/gitlint --ci-mode
- npm run travis - npm run travis
notifications: notifications:
webhooks: webhooks:
urls: urls:

View File

@@ -54,7 +54,7 @@ class AppMenu {
role: 'togglefullscreen' role: 'togglefullscreen'
}, { }, {
label: 'Zoom In', label: 'Zoom In',
accelerator: 'CommandOrControl+Plus', accelerator: process.platform === 'darwin' ? 'Command+Plus' : 'Control+=',
click(item, focusedWindow) { click(item, focusedWindow) {
if (focusedWindow) { if (focusedWindow) {
AppMenu.sendAction('zoomIn'); AppMenu.sendAction('zoomIn');

View File

@@ -43,11 +43,13 @@ class NewServerForm extends BaseComponent {
} }
submitFormHandler() { submitFormHandler() {
this.$saveServerButton.children[1].innerHTML = 'Adding...';
DomainUtil.checkDomain(this.$newServerUrl.value).then(serverConf => { DomainUtil.checkDomain(this.$newServerUrl.value).then(serverConf => {
DomainUtil.addDomain(serverConf).then(() => { DomainUtil.addDomain(serverConf).then(() => {
this.props.onChange(this.props.index); this.props.onChange(this.props.index);
}); });
}, errorMessage => { }, errorMessage => {
this.$saveServerButton.children[1].innerHTML = 'Add';
alert(errorMessage); alert(errorMessage);
}); });
} }

View File

@@ -69,21 +69,26 @@ class PreferenceView extends BaseComponent {
window.location.hash = `#${navItem}`; window.location.hash = `#${navItem}`;
} }
// Handle toggling and reflect changes in preference page
handleToggle(elementName, state) {
const inputSelector = `#${elementName} .action .switch input`;
const input = document.querySelector(inputSelector);
if (input) {
input.checked = state;
}
}
registerIpcs() { registerIpcs() {
ipcRenderer.on('switch-settings-nav', (event, navItem) => { ipcRenderer.on('switch-settings-nav', (event, navItem) => {
this.handleNavigation(navItem); this.handleNavigation(navItem);
}); });
ipcRenderer.on('toggle-sidebar', (event, state) => { ipcRenderer.on('toggle-sidebar', (event, state) => {
const inputSelector = '#sidebar-option .action .switch input'; this.handleToggle('sidebar-option', state);
const input = document.querySelector(inputSelector);
input.checked = state;
}); });
ipcRenderer.on('toggletray', (event, state) => { ipcRenderer.on('toggletray', (event, state) => {
const inputSelector = '#tray-option .action .switch input'; this.handleToggle('tray-option', state);
const input = document.querySelector(inputSelector);
input.checked = state;
}); });
} }
} }

View File

@@ -99,8 +99,7 @@ class DomainUtil {
checkDomain(domain, silent = false) { checkDomain(domain, silent = false) {
if (!silent && this.duplicateDomain(domain)) { if (!silent && this.duplicateDomain(domain)) {
// Do not check duplicate in silent mode // Do not check duplicate in silent mode
alert('This server has been added.'); return Promise.reject('This server has been added.');
return;
} }
domain = this.formatUrl(domain); domain = this.formatUrl(domain);

View File

@@ -41,4 +41,13 @@
</body> </body>
<script src="js/main.js"></script> <script src="js/main.js"></script>
<!-- To trigger electron.reload on changes in renderer from gulp -->
<script>
window.addEventListener('load', () => {
const isDev = require('electron-is-dev');
if (isDev) {
require('electron-connect').client.create();
}
});
</script>
</html> </html>

View File

@@ -20,5 +20,6 @@ install:
build: off build: off
test_script: test_script:
- node ./tools/gitlint --ci-mode
- npm run test - npm run test
- npm run test-e2e - npm run test-e2e

View File

@@ -14,7 +14,7 @@ gulp.task('dev', () => {
// Reload renderer process // Reload renderer process
gulp.watch('app/renderer/css/*.css', ['reload:renderer']); gulp.watch('app/renderer/css/*.css', ['reload:renderer']);
gulp.watch('app/renderer/*.html', ['reload:renderer']); gulp.watch('app/renderer/*.html', ['reload:renderer']);
gulp.watch('app/renderer/js/*.js', ['reload:renderer']); gulp.watch('app/renderer/js/**/*.js', ['reload:renderer']);
}); });
gulp.task('restart:browser', done => { gulp.task('restart:browser', done => {

28
package-lock.json generated
View File

@@ -4762,6 +4762,34 @@
"inherits": "2.0.1" "inherits": "2.0.1"
} }
}, },
"nodemon": {
"version": "1.14.11",
"resolved": "https://registry.npmjs.org/nodemon/-/nodemon-1.14.11.tgz",
"integrity": "sha512-323uPopdzYcyDR2Ze1UOLF9zocwoQEyGPiKaLm/Y8Mbfjylt/YueAJUVHqox+vgG8TqZqZApcHv5lmUvrn/KQw==",
"dev": true,
"requires": {
"chokidar": "2.0.0",
"debug": "3.1.0",
"ignore-by-default": "1.0.1",
"minimatch": "3.0.4",
"pstree.remy": "1.1.0",
"semver": "5.4.1",
"touch": "3.1.0",
"undefsafe": "2.0.1",
"update-notifier": "2.3.0"
},
"dependencies": {
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"dev": true,
"requires": {
"ms": "2.0.0"
}
}
}
},
"node-abi": { "node-abi": {
"version": "2.1.2", "version": "2.1.2",
"resolved": "https://registry.npmjs.org/node-abi/-/node-abi-2.1.2.tgz", "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-2.1.2.tgz",

View File

@@ -23,10 +23,12 @@
"postinstall": "electron-builder install-app-deps", "postinstall": "electron-builder install-app-deps",
"test": "xo", "test": "xo",
"test-e2e": "gulp test-e2e", "test-e2e": "gulp test-e2e",
"dev": "gulp dev", "dev": "gulp dev & nodemon --watch app/main --watch app/renderer --exec 'npm test' -e html,css,js",
"pack": "electron-builder --dir", "pack": "electron-builder --dir",
"dist": "electron-builder", "dist": "electron-builder",
"mas": "electron-builder --mac mas", "mas": "electron-builder --mac mas",
"setup-gitlint-hooks": "node ./tools/gitlint/setup-gitlint-hook",
"lint-commits": "node ./tools/gitlint --all-commits",
"travis": "cd ./scripts && ./travis-build-test.sh" "travis": "cd ./scripts && ./travis-build-test.sh"
}, },
"pre-commit": [ "pre-commit": [
@@ -107,15 +109,17 @@
], ],
"devDependencies": { "devDependencies": {
"assert": "1.4.1", "assert": "1.4.1",
"chalk": "^2.3.0",
"cp-file": "^5.0.0", "cp-file": "^5.0.0",
"devtron": "1.4.0", "devtron": "1.4.0",
"electron-builder": "19.53.6",
"electron": "1.7.10", "electron": "1.7.10",
"electron-builder": "19.53.6",
"electron-connect": "0.6.2", "electron-connect": "0.6.2",
"electron-debug": "1.4.0", "electron-debug": "1.4.0",
"gulp": "3.9.1", "gulp": "3.9.1",
"gulp-tape": "0.0.9", "gulp-tape": "0.0.9",
"is-ci": "^1.0.10", "is-ci": "^1.0.10",
"nodemon": "^1.14.11",
"pre-commit": "1.2.2", "pre-commit": "1.2.2",
"spectron": "3.7.2", "spectron": "3.7.2",
"tap-colorize": "^1.2.0", "tap-colorize": "^1.2.0",
@@ -150,6 +154,12 @@
"import/no-extraneous-dependencies": 0, "import/no-extraneous-dependencies": 0,
"no-prototype-builtins": 0 "no-prototype-builtins": 0
} }
},
{
"files": "scripts/gitlint/*.js",
"rules": {
"unicorn/no-process-exit": 1
}
} }
], ],
"ignore": [ "ignore": [

16
tools/fetch-pull-request Executable file
View File

@@ -0,0 +1,16 @@
#!/bin/bash
set -e
set -x
if ! git diff-index --quiet HEAD; then
set +x
echo "There are uncommitted changes:"
git status --short
echo "Doing nothing to avoid losing your work."
exit 1
fi
request_id="$1"
remote=${2:-"upstream"}
git fetch "$remote" "pull/$request_id/head"
git checkout -B "review-original-${request_id}"
git reset --hard FETCH_HEAD

17
tools/fetch-rebase-pull-request Executable file
View File

@@ -0,0 +1,17 @@
#!/bin/bash
set -e
set -x
if ! git diff-index --quiet HEAD; then
set +x
echo "There are uncommitted changes:"
git status --short
echo "Doing nothing to avoid losing your work."
exit 1
fi
request_id="$1"
remote=${2:-"upstream"}
git fetch "$remote" "pull/$request_id/head"
git checkout -B "review-${request_id}" $remote/master
git reset --hard FETCH_HEAD
git pull --rebase

31
tools/gitlint/ci.js Normal file
View File

@@ -0,0 +1,31 @@
const {run} = require('./helpers');
module.exports = () => {
if (process.argv.TRAVIS !== undefined) {
return travis();
}
return appveyor();
};
function travis() {
if (!process.env.TRAVIS_PULL_REQUEST) {
// Building against master last commit
return run('git log -1 HEAD');
}
const cmd = `git log ${process.env.TRAVIS_COMMIT_RANGE}`;
const commitRange = run(`git diff --name-only ${process.env.TRAVIS_COMMIT_RANGE}`);
process.stdout.write(`COMMIT_RANGE: ${commitRange}`, 'utf8');
return run(cmd);
}
function appveyor() {
if (!process.env.APPVEYOR_PULL_REQUEST_NUMBER) {
return run('git log -1 HEAD');
}
const cmd =
`git log origin/master...${process.env.APPVEYOR_PULL_REQUEST_HEAD_COMMIT}`;
return run(cmd);
}

91
tools/gitlint/helpers.js Normal file
View File

@@ -0,0 +1,91 @@
const {spawnSync} = require('child_process');
const chalk = require('chalk');
const commitMsgRegex = /[A-Z]+.*\.$/;
const isFullCommitRegex = /(\w|\W){1,}:\s{1}/;
const fullCommitRegex = /(\w|\W){1,}:\s{1}[A-Z]+.*\.$/;
function run(script) {
script = script.split(' ');
const cmd = script.splice(0, 1)[0];
const args = script;
const output = spawnSync(cmd, args, {
cwd: process.cwd(),
encoding: 'utf8',
windowsHide: true
}).stdout;
return output;
}
function garbageCollect(a) {
a.forEach((content, index) => {
if (content === '' || content === undefined) {
a.splice(index, 1);
}
});
return a;
}
function getAllCommits(output) {
output = output.split('\ncommits');
if (!output.length > 1) {
exports.error('There are no commits to lint.');
process.exit(1);
}
output = garbageCollect(output);
output.forEach((commit, index) => {
output[index] = 'commit' + commit;
});
return output;
}
function parseCommit(output) {
output = output.split('\n\n');
let commit = output[0].replace('commit ', '');
commit = commit.replace(/\n.*/g, '');
let commitHash = commit.split('');
commitHash = commitHash.slice(commitHash.length - 7);
commitHash = commitHash.join('');
const fullCommit = output[1].split('\n');
const commitMsg = fullCommit[0];
let lintingStatus = commitMsgRegex.test(commitMsg);
lintingStatus = (commitMsg.length <= 72);
if (lintingStatus && isFullCommitRegex(commitMsg)) {
lintingStatus = fullCommitRegex.test(commitMsg);
}
const result = {
failed: !lintingStatus,
commitHash
};
return result;
}
function logSuccess() {
console.log(chalk`{green commit linter:} commit linter passed.`);
process.exit(0);
}
function error(...args) {
args.unshift(chalk.red('ERROR! '));
console.error.apply(this, args);
}
function warn() {
// console.error(chalk`{yellow ${msg}}`);
}
module.exports = {
run,
getAllCommits,
parseCommit,
logSuccess,
error,
warn
};

44
tools/gitlint/index.js Normal file
View File

@@ -0,0 +1,44 @@
const helpers = require('./helpers');
const getCICmd = require('./ci');
let checkAllCommits = false;
let ciMode = false;
if (process.argv[2]) {
checkAllCommits = process.argv[2].includes('-a');
ciMode = process.argv[2] === '--ci-mode';
}
let cmd;
if (ciMode) {
cmd = getCICmd();
} else {
cmd =
checkAllCommits ? 'git log upstream/master...HEAD' : 'git log -1 HEAD';
}
const commits = helpers.run(cmd);
const commitsArray = helpers.getAllCommits(commits);
let lintFailed = false;
commitsArray.forEach(commit => {
const res = helpers.parseCommit(commit);
if (res.failed) {
const {commitHash} = res;
helpers.error(`commit ${commitHash} does not pass our commit style.`);
lintFailed = true;
} else {
helpers.logSuccess('Commit[s] follow the zulip-electron commit rules.');
}
});
if (lintFailed) {
helpers.warn(`
commit msg linting failed
-------------------------------
Reasons it does not have:
a) capitial latter at start of message
b) period at the end of commit or
c) Commit msg length is more than 72 charaters
`);
helpers.warn('Run with --no-verify flag to skip the commit-linter');
process.exit(1);
}

View File

@@ -0,0 +1,73 @@
// This script sets up the pre-push
// git hook which will be used to lint
// commits
const fs = require('fs');
const path = require('path');
const gitHooks = '../../.git/hooks';
const postCommitPath = path.resolve(__dirname, `${gitHooks}/post-commit`);
const prePushPath = path.resolve(__dirname, `${gitHooks}/pre-push`);
function scriptTemplate(cmds) {
cmds = cmds.join('');
const script = [
'#!/bin/sh',
'set -e',
'echo running gitlint...',
cmds,
'exit $?'
];
return script.join('\n');
}
const postCommitFile = scriptTemplate`node scripts/gitlint`;
const prePushFile = scriptTemplate`node scripts/gitlint --all-commits`;
function writeAndChmod(file, data) {
fs.writeFile(file, data, err => {
if (err) {
throw err;
}
fs.chmod(file, '777', err => {
if (err) {
const msg =
'chmod post-commit, pre-push hooks, at .git/hooks 0777 so they work!';
console.error(msg);
}
});
});
}
[postCommitPath, prePushPath].forEach((file, index) => {
fs.open(file, 'w+', err => {
if (err && err.code !== 'EEXIST') {
throw err;
}
const data = index === 0 ? postCommitFile : prePushFile;
writeAndChmod(file, data);
});
});
// Remove .sample files since
// sometimes the hooks do not work
const postCommitSampleFile = `${postCommitPath}.sample`;
const prePushSampleFile = `${prePushPath}.sample`;
function removeSampleFile(file) {
fs.unlink(file, err => {
if (err) {
throw err;
}
});
}
[postCommitSampleFile, prePushSampleFile].forEach(file => {
fs.exists(file, exists => {
if (exists) {
removeSampleFile(file);
}
});
});