mirror of
https://github.com/zulip/zulip-desktop.git
synced 2025-11-04 22:13:13 +00:00
Compare commits
9 Commits
v1.8.1
...
git-linter
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9e3cfbd887 | ||
|
|
720f42ca80 | ||
|
|
e18ba5dab6 | ||
|
|
239631a2b6 | ||
|
|
89d1344e2f | ||
|
|
1948ba2cc3 | ||
|
|
b8da7dd6ee | ||
|
|
4a0efb7301 | ||
|
|
aedd95259d |
@@ -28,7 +28,13 @@ cache:
|
||||
- app/node_modules
|
||||
|
||||
script:
|
||||
- npm run travis
|
||||
- echo $TRAVIS_COMMIT_RANGE
|
||||
- echo ${TRAVIS_COMMIT_RANGE/.../..}
|
||||
- echo "test"
|
||||
- git log -4
|
||||
- node ./tools/gitlint --ci-mode
|
||||
- npm run travis
|
||||
|
||||
notifications:
|
||||
webhooks:
|
||||
urls:
|
||||
|
||||
@@ -54,7 +54,7 @@ class AppMenu {
|
||||
role: 'togglefullscreen'
|
||||
}, {
|
||||
label: 'Zoom In',
|
||||
accelerator: 'CommandOrControl+Plus',
|
||||
accelerator: process.platform === 'darwin' ? 'Command+Plus' : 'Control+=',
|
||||
click(item, focusedWindow) {
|
||||
if (focusedWindow) {
|
||||
AppMenu.sendAction('zoomIn');
|
||||
|
||||
@@ -43,11 +43,13 @@ class NewServerForm extends BaseComponent {
|
||||
}
|
||||
|
||||
submitFormHandler() {
|
||||
this.$saveServerButton.children[1].innerHTML = 'Adding...';
|
||||
DomainUtil.checkDomain(this.$newServerUrl.value).then(serverConf => {
|
||||
DomainUtil.addDomain(serverConf).then(() => {
|
||||
this.props.onChange(this.props.index);
|
||||
});
|
||||
}, errorMessage => {
|
||||
this.$saveServerButton.children[1].innerHTML = 'Add';
|
||||
alert(errorMessage);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -69,21 +69,26 @@ class PreferenceView extends BaseComponent {
|
||||
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() {
|
||||
ipcRenderer.on('switch-settings-nav', (event, navItem) => {
|
||||
this.handleNavigation(navItem);
|
||||
});
|
||||
|
||||
ipcRenderer.on('toggle-sidebar', (event, state) => {
|
||||
const inputSelector = '#sidebar-option .action .switch input';
|
||||
const input = document.querySelector(inputSelector);
|
||||
input.checked = state;
|
||||
this.handleToggle('sidebar-option', state);
|
||||
});
|
||||
|
||||
ipcRenderer.on('toggletray', (event, state) => {
|
||||
const inputSelector = '#tray-option .action .switch input';
|
||||
const input = document.querySelector(inputSelector);
|
||||
input.checked = state;
|
||||
this.handleToggle('tray-option', state);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,8 +99,7 @@ class DomainUtil {
|
||||
checkDomain(domain, silent = false) {
|
||||
if (!silent && this.duplicateDomain(domain)) {
|
||||
// Do not check duplicate in silent mode
|
||||
alert('This server has been added.');
|
||||
return;
|
||||
return Promise.reject('This server has been added.');
|
||||
}
|
||||
|
||||
domain = this.formatUrl(domain);
|
||||
|
||||
@@ -41,4 +41,13 @@
|
||||
</body>
|
||||
<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>
|
||||
@@ -20,5 +20,6 @@ install:
|
||||
build: off
|
||||
|
||||
test_script:
|
||||
- node ./tools/gitlint --ci-mode
|
||||
- npm run test
|
||||
- npm run test-e2e
|
||||
|
||||
@@ -14,7 +14,7 @@ gulp.task('dev', () => {
|
||||
// Reload renderer process
|
||||
gulp.watch('app/renderer/css/*.css', ['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 => {
|
||||
|
||||
28
package-lock.json
generated
28
package-lock.json
generated
@@ -4762,6 +4762,34 @@
|
||||
"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": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/node-abi/-/node-abi-2.1.2.tgz",
|
||||
|
||||
14
package.json
14
package.json
@@ -23,10 +23,12 @@
|
||||
"postinstall": "electron-builder install-app-deps",
|
||||
"test": "xo",
|
||||
"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",
|
||||
"dist": "electron-builder",
|
||||
"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"
|
||||
},
|
||||
"pre-commit": [
|
||||
@@ -107,15 +109,17 @@
|
||||
],
|
||||
"devDependencies": {
|
||||
"assert": "1.4.1",
|
||||
"chalk": "^2.3.0",
|
||||
"cp-file": "^5.0.0",
|
||||
"devtron": "1.4.0",
|
||||
"electron-builder": "19.53.6",
|
||||
"electron": "1.7.10",
|
||||
"electron-builder": "19.53.6",
|
||||
"electron-connect": "0.6.2",
|
||||
"electron-debug": "1.4.0",
|
||||
"gulp": "3.9.1",
|
||||
"gulp-tape": "0.0.9",
|
||||
"is-ci": "^1.0.10",
|
||||
"nodemon": "^1.14.11",
|
||||
"pre-commit": "1.2.2",
|
||||
"spectron": "3.7.2",
|
||||
"tap-colorize": "^1.2.0",
|
||||
@@ -150,6 +154,12 @@
|
||||
"import/no-extraneous-dependencies": 0,
|
||||
"no-prototype-builtins": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
"files": "scripts/gitlint/*.js",
|
||||
"rules": {
|
||||
"unicorn/no-process-exit": 1
|
||||
}
|
||||
}
|
||||
],
|
||||
"ignore": [
|
||||
|
||||
16
tools/fetch-pull-request
Executable file
16
tools/fetch-pull-request
Executable 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
17
tools/fetch-rebase-pull-request
Executable 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
31
tools/gitlint/ci.js
Normal 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
91
tools/gitlint/helpers.js
Normal 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
44
tools/gitlint/index.js
Normal 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);
|
||||
}
|
||||
73
tools/gitlint/setup-gitlint-hook.js
Normal file
73
tools/gitlint/setup-gitlint-hook.js
Normal 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);
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user