Fix eslint warnings

This commit is contained in:
Marcel van Remmerden 2022-02-13 00:32:37 +00:00
parent a975986e48
commit a19014720b
23 changed files with 1020 additions and 1791 deletions

View File

@ -9,6 +9,7 @@
"parserOptions": {
"ecmaVersion": 13
},
"ignorePatterns": ["test/"],
"rules": {
"prettier/prettier": "error",
"object-curly-newline": [
@ -24,7 +25,8 @@
"minProperties": 3
}
}
]
],
"operator-linebreak": ["error", "after"]
},
"plugins": ["prettier"]
}

View File

@ -141,6 +141,9 @@ eslint:
script:
- npm run lint:check
allow_failure: true
artifacts:
reports:
codequality: gl-codequality.json
build-windows:
stage: build

View File

@ -1,6 +1,7 @@
const fetch = require('node-fetch');
const { store } = require('./store');
const { JSDOM } = require('jsdom');
const { store } = require('./store');
const { DOMParser } = new JSDOM().window;
const serializeAndEscapeOptions = (options) => {
@ -23,7 +24,10 @@ module.exports = {
*/
async get(what, options = {}, host = store.host) {
if (!options || !options.access_token) {
options = { ...options, access_token: store.access_token };
options = {
...options,
access_token: store.access_token,
};
}
return fetch(`${host}/api/v4/${what}?${serializeAndEscapeOptions(options)}`).then((res) =>
res.json(),
@ -31,7 +35,7 @@ module.exports = {
},
async parseUrl(link) {
if (!/^(?:f|ht)tps?\:\/\//.test(link)) {
link = 'https://' + link;
link = `https://${link}`;
}
const urlInfo = await this.fetchUrlInfo(link);
@ -70,27 +74,26 @@ module.exports = {
}
return object;
} else {
const result = await fetch(gitlabUrl).then((res) => res.text());
const resultDocument = new DOMParser().parseFromString(result, 'text/html');
let type = 'unknown';
if (resultDocument.querySelector('.group-home-panel')) {
type = 'groups';
} else if (resultDocument.querySelector('.project-home-panel')) {
type = 'projects';
} else if (resultDocument.querySelector('.user-profile')) {
type = 'users';
}
return {
namespaceWithProject: path,
type,
id: null,
doc: type === 'unknown' ? resultDocument : null,
};
}
const result = await fetch(gitlabUrl).then((res) => res.text());
const resultDocument = new DOMParser().parseFromString(result, 'text/html');
let type = 'unknown';
if (resultDocument.querySelector('.group-home-panel')) {
type = 'groups';
} else if (resultDocument.querySelector('.project-home-panel')) {
type = 'projects';
} else if (resultDocument.querySelector('.user-profile')) {
type = 'users';
}
return {
namespaceWithProject: path,
type,
id: null,
doc: type === 'unknown' ? resultDocument : null,
};
},
urlHasValidHost(url) {
const allowedHosts = [String(store.host), 'gitlab.com', 'https://gitlab.com'];
@ -98,7 +101,7 @@ module.exports = {
return allowedHosts.some((host) => url.startsWith(host));
},
commentToNoteableUrl(comment) {
let basePath = `projects/${comment.project_id}`;
const basePath = `projects/${comment.project_id}`;
switch (comment.note.noteable_type) {
case 'MergeRequest':
return `${basePath}/merge_requests/${comment.note.noteable_iid}`;

View File

@ -16,11 +16,10 @@ const store = new ElectronStore();
const proxy = new Proxy(store, {
get(target, key) {
if (target.get(key) == undefined) {
if (target.get(key) === undefined) {
return defaults[key];
} else {
return target.get(key);
}
return target.get(key);
},
set(target, key, value) {
target.set(key, value);

View File

@ -5,7 +5,7 @@ module.exports = class BaseParser {
this.urlInfo = urlInfo;
}
static check(type) {
static check() {
throw Error(`static ${this.constructor.name}#check(type) is not implemented`);
}

View File

@ -22,9 +22,9 @@ module.exports = class GroupParser extends BaseParser {
avatar_url: group.avatar_url,
};
if (group.full_name.indexOf(' / ' + group.name) != -1) {
groupObject.parent_name = group.full_name.replace(' / ' + group.name, '');
groupObject.parent_url = group.web_url.replace('/' + group.path, '');
if (group.full_name.indexOf(` / ${group.name}`) !== -1) {
groupObject.parent_name = group.full_name.replace(` / ${group.name}`, '');
groupObject.parent_url = group.web_url.replace(`/${group.path}`, '');
}
return groupObject;

View File

@ -9,16 +9,16 @@ module.exports = class UnknownParser extends BaseParser {
async parse() {
const { doc } = this.urlInfo;
let titleArray = doc.querySelector('title').text.split(' · ');
let unknownObject = {
const titleArray = doc.querySelector('title').text.split(' · ');
const unknownObject = {
title: titleArray[0],
};
if (doc.querySelector('.context-header a')) {
unknownObject.parent_url =
store.host + doc.querySelector('.context-header a').getAttribute('href');
if (titleArray.length == 3) {
if (titleArray.length === 3) {
unknownObject.parent_name = titleArray[1];
} else if (titleArray.length == 4) {
} else if (titleArray.length === 4) {
unknownObject.parent_name = titleArray[2];
}
}

2064
myApp.js

File diff suppressed because it is too large Load Diff

221
package-lock.json generated
View File

@ -8,7 +8,6 @@
"name": "gitdock",
"version": "0.1.20",
"dependencies": {
"electron": "^13.5.2",
"electron-squirrel-startup": "^1.0.0",
"electron-store": "^8.0.0",
"jsdom": "^17.0.0",
@ -28,9 +27,10 @@
"@electron-forge/maker-zip": "^6.0.0-beta.59",
"@electron-forge/publisher-github": "^6.0.0-beta.59",
"electron": "^16.0.4",
"eslint": "^8.4.1",
"eslint": "^8.9.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^8.3.0",
"eslint-formatter-gitlab": "^3.0.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-prettier": "^4.0.0",
"mocha": "^9.1.2",
@ -1010,14 +1010,14 @@
}
},
"node_modules/@eslint/eslintrc": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.0.5.tgz",
"integrity": "sha512-BLxsnmK3KyPunz5wmCCpqy0YelEoxxGmH73Is+Z74oOTMtExcjkr3dDR6quwrjh1YspA8DH9gnX1o069KiS9AQ==",
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.1.0.tgz",
"integrity": "sha512-C1DfL7XX4nPqGd6jcP01W9pVM1HYCuUkFk1432D7F0v3JSlUIeOYn9oCoi3eoLZ+iwBSb29BMFxxny0YrrEZqg==",
"dev": true,
"dependencies": {
"ajv": "^6.12.4",
"debug": "^4.3.2",
"espree": "^9.2.0",
"espree": "^9.3.1",
"globals": "^13.9.0",
"ignore": "^4.0.6",
"import-fresh": "^3.2.1",
@ -1029,6 +1029,15 @@
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
}
},
"node_modules/@eslint/eslintrc/node_modules/ignore": {
"version": "4.0.6",
"resolved": "https://registry.npmjs.org/ignore/-/ignore-4.0.6.tgz",
"integrity": "sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==",
"dev": true,
"engines": {
"node": ">= 4"
}
},
"node_modules/@eslint/eslintrc/node_modules/strip-json-comments": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz",
@ -1378,9 +1387,9 @@
"integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q=="
},
"node_modules/acorn": {
"version": "8.6.0",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.6.0.tgz",
"integrity": "sha512-U1riIR+lBSNi3IbxtaHOIKdH8sLFv3NYfNv8sg7ZsNhcfl4HF2++BfqqrNAxoCLQW1iiylOj76ecnaUxz+z9yw==",
"version": "8.7.0",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.7.0.tgz",
"integrity": "sha512-V/LGr1APy+PXIwKebEWrkZPwoeoF+w1jiOBUmuxuiUIaOHtob8Qc9BTrYo7VuI5fR8tqsy+buA2WFooR5olqvQ==",
"bin": {
"acorn": "bin/acorn"
},
@ -3894,18 +3903,6 @@
"once": "^1.4.0"
}
},
"node_modules/enquirer": {
"version": "2.3.6",
"resolved": "https://registry.npmjs.org/enquirer/-/enquirer-2.3.6.tgz",
"integrity": "sha512-yjNnPr315/FjS4zIsUxYguYUPP2e1NK4d7E7ZOLiyYCcbFBiTMyID+2wvm2w6+pZ/odMA7cRkjhsPbltwBOrLg==",
"dev": true,
"dependencies": {
"ansi-colors": "^4.1.1"
},
"engines": {
"node": ">=8.6"
}
},
"node_modules/env-paths": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/env-paths/-/env-paths-2.2.1.tgz",
@ -4023,24 +4020,23 @@
}
},
"node_modules/eslint": {
"version": "8.4.1",
"resolved": "https://registry.npmjs.org/eslint/-/eslint-8.4.1.tgz",
"integrity": "sha512-TxU/p7LB1KxQ6+7aztTnO7K0i+h0tDi81YRY9VzB6Id71kNz+fFYnf5HD5UOQmxkzcoa0TlVZf9dpMtUv0GpWg==",
"version": "8.9.0",
"resolved": "https://registry.npmjs.org/eslint/-/eslint-8.9.0.tgz",
"integrity": "sha512-PB09IGwv4F4b0/atrbcMFboF/giawbBLVC7fyDamk5Wtey4Jh2K+rYaBhCAbUyEI4QzB1ly09Uglc9iCtFaG2Q==",
"dev": true,
"dependencies": {
"@eslint/eslintrc": "^1.0.5",
"@eslint/eslintrc": "^1.1.0",
"@humanwhocodes/config-array": "^0.9.2",
"ajv": "^6.10.0",
"chalk": "^4.0.0",
"cross-spawn": "^7.0.2",
"debug": "^4.3.2",
"doctrine": "^3.0.0",
"enquirer": "^2.3.5",
"escape-string-regexp": "^4.0.0",
"eslint-scope": "^7.1.0",
"eslint-scope": "^7.1.1",
"eslint-utils": "^3.0.0",
"eslint-visitor-keys": "^3.1.0",
"espree": "^9.2.0",
"eslint-visitor-keys": "^3.3.0",
"espree": "^9.3.1",
"esquery": "^1.4.0",
"esutils": "^2.0.2",
"fast-deep-equal": "^3.1.3",
@ -4048,7 +4044,7 @@
"functional-red-black-tree": "^1.0.1",
"glob-parent": "^6.0.1",
"globals": "^13.6.0",
"ignore": "^4.0.6",
"ignore": "^5.2.0",
"import-fresh": "^3.0.0",
"imurmurhash": "^0.1.4",
"is-glob": "^4.0.0",
@ -4059,9 +4055,7 @@
"minimatch": "^3.0.4",
"natural-compare": "^1.4.0",
"optionator": "^0.9.1",
"progress": "^2.0.0",
"regexpp": "^3.2.0",
"semver": "^7.2.1",
"strip-ansi": "^6.0.1",
"strip-json-comments": "^3.1.0",
"text-table": "^0.2.0",
@ -4108,6 +4102,19 @@
"eslint": ">=7.0.0"
}
},
"node_modules/eslint-formatter-gitlab": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/eslint-formatter-gitlab/-/eslint-formatter-gitlab-3.0.0.tgz",
"integrity": "sha512-fqZ2G45rgbrHcFunqmwuG5Qo6QAOlxEsR+KdOP08T1Xegw5tJhHh9KFWMSct8q6x8xCMUyYGHypZd342bLUttA==",
"dev": true,
"dependencies": {
"chalk": "^4.0.0",
"js-yaml": "^4.0.0"
},
"peerDependencies": {
"eslint": "^5 || ^6 || ^7 || ^8"
}
},
"node_modules/eslint-import-resolver-node": {
"version": "0.3.6",
"resolved": "https://registry.npmjs.org/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.6.tgz",
@ -4250,9 +4257,9 @@
}
},
"node_modules/eslint-scope": {
"version": "7.1.0",
"resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.1.0.tgz",
"integrity": "sha512-aWwkhnS0qAXqNOgKOK0dJ2nvzEbhEvpy8OlJ9kZ0FeZnA6zpjv1/Vei+puGFFX7zkPCkHHXb7IDX3A+7yPrRWg==",
"version": "7.1.1",
"resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.1.1.tgz",
"integrity": "sha512-QKQM/UXpIiHcLqJ5AOyIW7XZmzjkzQXYE54n1++wb0u9V/abW3l9uQnxX8Z5Xd18xyKIMTUAyQ0k1e8pz6LUrw==",
"dev": true,
"dependencies": {
"esrecurse": "^4.3.0",
@ -4290,9 +4297,9 @@
}
},
"node_modules/eslint-visitor-keys": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.1.0.tgz",
"integrity": "sha512-yWJFpu4DtjsWKkt5GeNBBuZMlNcYVs6vRCLoCVEJrTjaSB6LC98gFipNK/erM2Heg/E8mIK+hXG/pJMLK+eRZA==",
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.3.0.tgz",
"integrity": "sha512-mQ+suqKJVyeuwGYHAdjMFqjCyfl8+Ldnxuyp3ldiMBFKkvytrXUZWaiPCEav8qDHKty44bD+qV1IP4T+w+xXRA==",
"dev": true,
"engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
@ -4349,21 +4356,6 @@
"node": ">= 0.8.0"
}
},
"node_modules/eslint/node_modules/semver": {
"version": "7.3.5",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz",
"integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==",
"dev": true,
"dependencies": {
"lru-cache": "^6.0.0"
},
"bin": {
"semver": "bin/semver.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/eslint/node_modules/strip-json-comments": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz",
@ -4389,14 +4381,14 @@
}
},
"node_modules/espree": {
"version": "9.2.0",
"resolved": "https://registry.npmjs.org/espree/-/espree-9.2.0.tgz",
"integrity": "sha512-oP3utRkynpZWF/F2x/HZJ+AGtnIclaR7z1pYPxy7NYM2fSO6LgK/Rkny8anRSPK/VwEA1eqm2squui0T7ZMOBg==",
"version": "9.3.1",
"resolved": "https://registry.npmjs.org/espree/-/espree-9.3.1.tgz",
"integrity": "sha512-bvdyLmJMfwkV3NCRl5ZhJf22zBFo1y8bYh3VYb+bfzqNB4Je68P2sSuXyuFquzWLebHpNd2/d5uv7yoP9ISnGQ==",
"dev": true,
"dependencies": {
"acorn": "^8.6.0",
"acorn": "^8.7.0",
"acorn-jsx": "^5.3.1",
"eslint-visitor-keys": "^3.1.0"
"eslint-visitor-keys": "^3.3.0"
},
"engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
@ -5328,9 +5320,9 @@
}
},
"node_modules/globals": {
"version": "13.12.0",
"resolved": "https://registry.npmjs.org/globals/-/globals-13.12.0.tgz",
"integrity": "sha512-uS8X6lSKN2JumVoXrbUz+uG4BYG+eiawqm3qFcT7ammfbUHeCBoJMlHcec/S3krSk73/AE/f0szYFmgAA3kYZg==",
"version": "13.12.1",
"resolved": "https://registry.npmjs.org/globals/-/globals-13.12.1.tgz",
"integrity": "sha512-317dFlgY2pdJZ9rspXDks7073GpDmXdfbM3vYYp0HAMKGDh1FfWPleI2ljVNLQX5M5lXcAslTcPTrOrMEFOjyw==",
"dev": true,
"dependencies": {
"type-fest": "^0.20.2"
@ -5614,9 +5606,9 @@
]
},
"node_modules/ignore": {
"version": "4.0.6",
"resolved": "https://registry.npmjs.org/ignore/-/ignore-4.0.6.tgz",
"integrity": "sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==",
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.0.tgz",
"integrity": "sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ==",
"dev": true,
"engines": {
"node": ">= 4"
@ -10976,14 +10968,14 @@
}
},
"@eslint/eslintrc": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.0.5.tgz",
"integrity": "sha512-BLxsnmK3KyPunz5wmCCpqy0YelEoxxGmH73Is+Z74oOTMtExcjkr3dDR6quwrjh1YspA8DH9gnX1o069KiS9AQ==",
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.1.0.tgz",
"integrity": "sha512-C1DfL7XX4nPqGd6jcP01W9pVM1HYCuUkFk1432D7F0v3JSlUIeOYn9oCoi3eoLZ+iwBSb29BMFxxny0YrrEZqg==",
"dev": true,
"requires": {
"ajv": "^6.12.4",
"debug": "^4.3.2",
"espree": "^9.2.0",
"espree": "^9.3.1",
"globals": "^13.9.0",
"ignore": "^4.0.6",
"import-fresh": "^3.2.1",
@ -10992,6 +10984,12 @@
"strip-json-comments": "^3.1.1"
},
"dependencies": {
"ignore": {
"version": "4.0.6",
"resolved": "https://registry.npmjs.org/ignore/-/ignore-4.0.6.tgz",
"integrity": "sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==",
"dev": true
},
"strip-json-comments": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz",
@ -11295,9 +11293,9 @@
"integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q=="
},
"acorn": {
"version": "8.6.0",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.6.0.tgz",
"integrity": "sha512-U1riIR+lBSNi3IbxtaHOIKdH8sLFv3NYfNv8sg7ZsNhcfl4HF2++BfqqrNAxoCLQW1iiylOj76ecnaUxz+z9yw=="
"version": "8.7.0",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.7.0.tgz",
"integrity": "sha512-V/LGr1APy+PXIwKebEWrkZPwoeoF+w1jiOBUmuxuiUIaOHtob8Qc9BTrYo7VuI5fR8tqsy+buA2WFooR5olqvQ=="
},
"acorn-globals": {
"version": "6.0.0",
@ -13165,15 +13163,6 @@
"once": "^1.4.0"
}
},
"enquirer": {
"version": "2.3.6",
"resolved": "https://registry.npmjs.org/enquirer/-/enquirer-2.3.6.tgz",
"integrity": "sha512-yjNnPr315/FjS4zIsUxYguYUPP2e1NK4d7E7ZOLiyYCcbFBiTMyID+2wvm2w6+pZ/odMA7cRkjhsPbltwBOrLg==",
"dev": true,
"requires": {
"ansi-colors": "^4.1.1"
}
},
"env-paths": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/env-paths/-/env-paths-2.2.1.tgz",
@ -13258,24 +13247,23 @@
}
},
"eslint": {
"version": "8.4.1",
"resolved": "https://registry.npmjs.org/eslint/-/eslint-8.4.1.tgz",
"integrity": "sha512-TxU/p7LB1KxQ6+7aztTnO7K0i+h0tDi81YRY9VzB6Id71kNz+fFYnf5HD5UOQmxkzcoa0TlVZf9dpMtUv0GpWg==",
"version": "8.9.0",
"resolved": "https://registry.npmjs.org/eslint/-/eslint-8.9.0.tgz",
"integrity": "sha512-PB09IGwv4F4b0/atrbcMFboF/giawbBLVC7fyDamk5Wtey4Jh2K+rYaBhCAbUyEI4QzB1ly09Uglc9iCtFaG2Q==",
"dev": true,
"requires": {
"@eslint/eslintrc": "^1.0.5",
"@eslint/eslintrc": "^1.1.0",
"@humanwhocodes/config-array": "^0.9.2",
"ajv": "^6.10.0",
"chalk": "^4.0.0",
"cross-spawn": "^7.0.2",
"debug": "^4.3.2",
"doctrine": "^3.0.0",
"enquirer": "^2.3.5",
"escape-string-regexp": "^4.0.0",
"eslint-scope": "^7.1.0",
"eslint-scope": "^7.1.1",
"eslint-utils": "^3.0.0",
"eslint-visitor-keys": "^3.1.0",
"espree": "^9.2.0",
"eslint-visitor-keys": "^3.3.0",
"espree": "^9.3.1",
"esquery": "^1.4.0",
"esutils": "^2.0.2",
"fast-deep-equal": "^3.1.3",
@ -13283,7 +13271,7 @@
"functional-red-black-tree": "^1.0.1",
"glob-parent": "^6.0.1",
"globals": "^13.6.0",
"ignore": "^4.0.6",
"ignore": "^5.2.0",
"import-fresh": "^3.0.0",
"imurmurhash": "^0.1.4",
"is-glob": "^4.0.0",
@ -13294,9 +13282,7 @@
"minimatch": "^3.0.4",
"natural-compare": "^1.4.0",
"optionator": "^0.9.1",
"progress": "^2.0.0",
"regexpp": "^3.2.0",
"semver": "^7.2.1",
"strip-ansi": "^6.0.1",
"strip-json-comments": "^3.1.0",
"text-table": "^0.2.0",
@ -13342,15 +13328,6 @@
"integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==",
"dev": true
},
"semver": {
"version": "7.3.5",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz",
"integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==",
"dev": true,
"requires": {
"lru-cache": "^6.0.0"
}
},
"strip-json-comments": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz",
@ -13387,6 +13364,16 @@
"dev": true,
"requires": {}
},
"eslint-formatter-gitlab": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/eslint-formatter-gitlab/-/eslint-formatter-gitlab-3.0.0.tgz",
"integrity": "sha512-fqZ2G45rgbrHcFunqmwuG5Qo6QAOlxEsR+KdOP08T1Xegw5tJhHh9KFWMSct8q6x8xCMUyYGHypZd342bLUttA==",
"dev": true,
"requires": {
"chalk": "^4.0.0",
"js-yaml": "^4.0.0"
}
},
"eslint-import-resolver-node": {
"version": "0.3.6",
"resolved": "https://registry.npmjs.org/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.6.tgz",
@ -13505,9 +13492,9 @@
}
},
"eslint-scope": {
"version": "7.1.0",
"resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.1.0.tgz",
"integrity": "sha512-aWwkhnS0qAXqNOgKOK0dJ2nvzEbhEvpy8OlJ9kZ0FeZnA6zpjv1/Vei+puGFFX7zkPCkHHXb7IDX3A+7yPrRWg==",
"version": "7.1.1",
"resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.1.1.tgz",
"integrity": "sha512-QKQM/UXpIiHcLqJ5AOyIW7XZmzjkzQXYE54n1++wb0u9V/abW3l9uQnxX8Z5Xd18xyKIMTUAyQ0k1e8pz6LUrw==",
"dev": true,
"requires": {
"esrecurse": "^4.3.0",
@ -13532,20 +13519,20 @@
}
},
"eslint-visitor-keys": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.1.0.tgz",
"integrity": "sha512-yWJFpu4DtjsWKkt5GeNBBuZMlNcYVs6vRCLoCVEJrTjaSB6LC98gFipNK/erM2Heg/E8mIK+hXG/pJMLK+eRZA==",
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.3.0.tgz",
"integrity": "sha512-mQ+suqKJVyeuwGYHAdjMFqjCyfl8+Ldnxuyp3ldiMBFKkvytrXUZWaiPCEav8qDHKty44bD+qV1IP4T+w+xXRA==",
"dev": true
},
"espree": {
"version": "9.2.0",
"resolved": "https://registry.npmjs.org/espree/-/espree-9.2.0.tgz",
"integrity": "sha512-oP3utRkynpZWF/F2x/HZJ+AGtnIclaR7z1pYPxy7NYM2fSO6LgK/Rkny8anRSPK/VwEA1eqm2squui0T7ZMOBg==",
"version": "9.3.1",
"resolved": "https://registry.npmjs.org/espree/-/espree-9.3.1.tgz",
"integrity": "sha512-bvdyLmJMfwkV3NCRl5ZhJf22zBFo1y8bYh3VYb+bfzqNB4Je68P2sSuXyuFquzWLebHpNd2/d5uv7yoP9ISnGQ==",
"dev": true,
"requires": {
"acorn": "^8.6.0",
"acorn": "^8.7.0",
"acorn-jsx": "^5.3.1",
"eslint-visitor-keys": "^3.1.0"
"eslint-visitor-keys": "^3.3.0"
}
},
"esprima": {
@ -14286,9 +14273,9 @@
}
},
"globals": {
"version": "13.12.0",
"resolved": "https://registry.npmjs.org/globals/-/globals-13.12.0.tgz",
"integrity": "sha512-uS8X6lSKN2JumVoXrbUz+uG4BYG+eiawqm3qFcT7ammfbUHeCBoJMlHcec/S3krSk73/AE/f0szYFmgAA3kYZg==",
"version": "13.12.1",
"resolved": "https://registry.npmjs.org/globals/-/globals-13.12.1.tgz",
"integrity": "sha512-317dFlgY2pdJZ9rspXDks7073GpDmXdfbM3vYYp0HAMKGDh1FfWPleI2ljVNLQX5M5lXcAslTcPTrOrMEFOjyw==",
"dev": true,
"requires": {
"type-fest": "^0.20.2"
@ -14483,9 +14470,9 @@
"dev": true
},
"ignore": {
"version": "4.0.6",
"resolved": "https://registry.npmjs.org/ignore/-/ignore-4.0.6.tgz",
"integrity": "sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==",
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.0.tgz",
"integrity": "sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ==",
"dev": true
},
"ignore-walk": {

View File

@ -12,7 +12,7 @@
"publish": "electron-forge publish",
"prettier:check": "prettier --check .",
"prettier:fix": "prettier --write .",
"lint:check": "eslint --ignore-path .prettierignore .",
"lint:check": "eslint --ignore-path .prettierignore --format gitlab .",
"lint:fix": "eslint --ignore-path .prettierignore --fix ."
},
"repository": "https://github.com/mvremmerden/gitdock",
@ -33,9 +33,10 @@
"@electron-forge/maker-zip": "^6.0.0-beta.59",
"@electron-forge/publisher-github": "^6.0.0-beta.59",
"electron": "^16.0.4",
"eslint": "^8.4.1",
"eslint": "^8.9.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^8.3.0",
"eslint-formatter-gitlab": "^3.0.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-prettier": "^4.0.0",
"mocha": "^9.1.2",
@ -51,7 +52,6 @@
"node-browser-history": "^2.4.6",
"node-fetch": "^2.6.1",
"playwright": "^1.17.1",
"electron": "^13.5.2",
"universal-analytics": "^0.4.23",
"uuid": "^8.3.2"
},

View File

@ -30,24 +30,25 @@ const api = {
logout: () => ipcRenderer.send('logout'),
};
function deepFreeze(o) {
Object.freeze(o);
Object.getOwnPropertyNames(o).forEach((prop) => {
if (
Object.prototype.hasOwnProperty.call(o, prop) &&
o[prop] !== null &&
(typeof o[prop] === 'object' || typeof o[prop] === 'function') &&
!Object.isFrozen(o[prop])
) {
deepFreeze(o[prop]);
}
});
return o;
}
if (process.contextIsolated) {
contextBridge.exposeInMainWorld('electron', api);
} else {
function deepFreeze(o) {
Object.freeze(o);
Object.getOwnPropertyNames(o).forEach((prop) => {
if (
o.hasOwnProperty(prop) &&
o[prop] !== null &&
(typeof o[prop] === 'object' || typeof o[prop] === 'function') &&
!Object.isFrozen(o[prop])
) {
deepFreeze(o[prop]);
}
});
return o;
}
deepFreeze(api);
// @ts-expect-error https://github.com/electron-userland/spectron#node-integration
window.electronRequire = require;
@ -61,7 +62,7 @@ window.addEventListener('DOMContentLoaded', () => {
if (element) element.innerText = text;
};
for (const type of ['chrome', 'node', 'electron']) {
['chrome', 'node', 'electron'].forEach((type) => {
replaceText(`${type}-version`, process.versions[type]);
}
});
});

View File

@ -1,7 +1,8 @@
/* eslint-disable no-unused-vars */
function goToDetail(page, object) {
let value = {
page: page,
object: object,
const value = {
page,
object,
};
document.getElementById('detail-view').style.left = 0;
document.body.style.overflow = 'hidden';
@ -14,10 +15,10 @@ function goBackToDetail() {
}
function goToSubDetail(page, project, all = false) {
let value = {
page: page,
project: project,
all: all,
const value = {
page,
project,
all,
};
document.getElementById('sub-detail-view').style.left = 0;
window.electron.goToSubDetail(value);
@ -36,27 +37,27 @@ function goToSettings() {
}
function switchIssues(value, type, text) {
let object = {
const object = {
label: value,
type: type,
text: text,
type,
text,
};
window.electron.switchIssues(object);
}
function switchMRs(value, type, text) {
let object = {
const object = {
label: value,
type: type,
text: text,
type,
text,
};
window.electron.switchMRs(object);
}
function switchPage(url, type) {
let value = {
url: url,
type: type,
const value = {
url,
type,
};
window.electron.switchPage(value);
}
@ -78,9 +79,9 @@ function addBookmark(value) {
}
function addProject(input, target) {
let value = {
input: input,
target: target,
const value = {
input,
target,
};
window.electron.addProject(value);
}
@ -133,10 +134,10 @@ function startLogin() {
window.electron.startLogin();
}
function startManualLogin(access_token, host) {
let value = {
access_token: access_token,
host: host,
function startManualLogin(accessToken, host) {
const value = {
access_token: accessToken,
host,
};
window.electron.startManualLogin(value);
}

View File

@ -2,9 +2,16 @@ const $search = document.querySelector('input');
const $results = document.querySelector('#results');
let html = [];
let $selected = 0;
const mrIcon = `<svg xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M10.34 1.22a.75.75 0 0 0-1.06 0L7.53 2.97 7 3.5l.53.53 1.75 1.75a.75.75 0 1 0 1.06-1.06l-.47-.47h.63c.69 0 1.25.56 1.25 1.25v4.614a2.501 2.501 0 1 0 1.5 0V5.5a2.75 2.75 0 0 0-2.75-2.75h-.63l.47-.47a.75.75 0 0 0 0-1.06ZM13.5 12.5a1 1 0 1 1-2 0 1 1 0 0 1 2 0Zm-9 0a1 1 0 1 1-2 0 1 1 0 0 1 2 0Zm1.5 0a2.5 2.5 0 1 1-3.25-2.386V5.886a2.501 2.501 0 1 1 1.5 0v4.228A2.501 2.501 0 0 1 6 12.5Zm-1.5-9a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"/></svg>`;
const issueIcon = `<svg xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M3 2.5h6a.5.5 0 0 1 .5.5v10a.5.5 0 0 1-.5.5H3a.5.5 0 0 1-.5-.5V3a.5.5 0 0 1 .5-.5ZM1 3a2 2 0 0 1 2-2h6a2 2 0 0 1 1.97 1.658l2.913 1.516a1.75 1.75 0 0 1 .744 2.36l-3.878 7.45a.753.753 0 0 1-.098.145c-.36.526-.965.871-1.651.871H3a2 2 0 0 1-2-2V3Zm10 7.254 2.297-4.413a.25.25 0 0 0-.106-.337L11 4.364v5.89Z"/></svg>`;
const projectIcon = `<svg xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="m9.5 14.5-6-2.5V4l6-2.5v13Zm-6.885-1.244A1 1 0 0 1 2 12.333V3.667a1 1 0 0 1 .615-.923L8.923.115A1.5 1.5 0 0 1 11 1.5V2h1.25c.966 0 1.75.783 1.75 1.75v8.5A1.75 1.75 0 0 1 12.25 14H11v.5a1.5 1.5 0 0 1-2.077 1.385l-6.308-2.629ZM11 12.5h1.25a.25.25 0 0 0 .25-.25v-8.5a.25.25 0 0 0-.25-.25H11v9Z"/></svg>`;
const mrIcon =
'<svg xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M10.34 1.22a.75.75 0 0 0-1.06 0L7.53 2.97 7 3.5l.53.53 1.75 1.75a.75.75 0 1 0 1.06-1.06l-.47-.47h.63c.69 0 1.25.56 1.25 1.25v4.614a2.501 2.501 0 1 0 1.5 0V5.5a2.75 2.75 0 0 0-2.75-2.75h-.63l.47-.47a.75.75 0 0 0 0-1.06ZM13.5 12.5a1 1 0 1 1-2 0 1 1 0 0 1 2 0Zm-9 0a1 1 0 1 1-2 0 1 1 0 0 1 2 0Zm1.5 0a2.5 2.5 0 1 1-3.25-2.386V5.886a2.501 2.501 0 1 1 1.5 0v4.228A2.501 2.501 0 0 1 6 12.5Zm-1.5-9a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"/></svg>';
const issueIcon =
'<svg xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M3 2.5h6a.5.5 0 0 1 .5.5v10a.5.5 0 0 1-.5.5H3a.5.5 0 0 1-.5-.5V3a.5.5 0 0 1 .5-.5ZM1 3a2 2 0 0 1 2-2h6a2 2 0 0 1 1.97 1.658l2.913 1.516a1.75 1.75 0 0 1 .744 2.36l-3.878 7.45a.753.753 0 0 1-.098.145c-.36.526-.965.871-1.651.871H3a2 2 0 0 1-2-2V3Zm10 7.254 2.297-4.413a.25.25 0 0 0-.106-.337L11 4.364v5.89Z"/></svg>';
const projectIcon =
'<svg xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="m9.5 14.5-6-2.5V4l6-2.5v13Zm-6.885-1.244A1 1 0 0 1 2 12.333V3.667a1 1 0 0 1 .615-.923L8.923.115A1.5 1.5 0 0 1 11 1.5V2h1.25c.966 0 1.75.783 1.75 1.75v8.5A1.75 1.75 0 0 1 12.25 14H11v.5a1.5 1.5 0 0 1-2.077 1.385l-6.308-2.629ZM11 12.5h1.25a.25.25 0 0 0 .25-.25v-8.5a.25.25 0 0 0-.25-.25H11v9Z"/></svg>';
let ALL_FAVORITES = gitdock.getFavorites() || [];
let ALL_BOOKMARKS = gitdock.getBookmarks() || [];
let ALL_RECENTS = gitdock.getRecents() || [];
const ALL_ACTIONS = {
newProject: {
@ -16,14 +23,14 @@ const ALL_ACTIONS = {
},
newGroup: {
title: 'New group',
icon: `<svg width="16" height="16" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M6 4a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0Zm1.5 0a3 3 0 1 1-6 0 3 3 0 0 1 6 0Zm4 5.5a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3Zm0 1.5a3 3 0 1 0 0-6 3 3 0 0 0 0 6Zm-7 2.5a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3Zm0 1.5a3 3 0 1 0 0-6 3 3 0 0 0 0 6Z"/></svg>`,
icon: '<svg width="16" height="16" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M6 4a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0Zm1.5 0a3 3 0 1 1-6 0 3 3 0 0 1 6 0Zm4 5.5a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3Zm0 1.5a3 3 0 1 0 0-6 3 3 0 0 0 0 6Zm-7 2.5a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3Zm0 1.5a3 3 0 1 0 0-6 3 3 0 0 0 0 6Z"/></svg>',
execute() {
gitdock.openGitLab('/groups/new');
},
},
newSnippet: {
title: 'New snippet',
icon: `<svg width="16" height="16" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M3.625.1A.75.75 0 0 1 4.65.375L8 6.177 11.35.375a.75.75 0 1 1 1.3.75L8.864 7.677l1.97 3.412A2.503 2.503 0 0 1 14 13.5a2.5 2.5 0 1 1-4.425-1.595L7.999 9.176l-.26.45a.75.75 0 0 1-1.298-.751l.692-1.199L3.35 1.125A.75.75 0 0 1 3.625.1ZM5.5 13.5a1 1 0 1 1-2 0 1 1 0 0 1 2 0Zm1.5 0a2.5 2.5 0 1 1-5 0 2.5 2.5 0 0 1 5 0Zm5.5 0a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"/></svg>`,
icon: '<svg width="16" height="16" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M3.625.1A.75.75 0 0 1 4.65.375L8 6.177 11.35.375a.75.75 0 1 1 1.3.75L8.864 7.677l1.97 3.412A2.503 2.503 0 0 1 14 13.5a2.5 2.5 0 1 1-4.425-1.595L7.999 9.176l-.26.45a.75.75 0 0 1-1.298-.751l.692-1.199L3.35 1.125A.75.75 0 0 1 3.625.1ZM5.5 13.5a1 1 0 1 1-2 0 1 1 0 0 1 2 0Zm1.5 0a2.5 2.5 0 1 1-5 0 2.5 2.5 0 0 1 5 0Zm5.5 0a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"/></svg>',
execute() {
gitdock.openGitLab('/-/snippets/new');
},
@ -33,9 +40,9 @@ const ALL_ACTIONS = {
const ALL_OVERVIEWS = {
overviewTodos: {
title: 'To-Do list',
icon: `<svg width="16" height="16" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M3 13.5a.5.5 0 0 1-.5-.5V3a.5.5 0 0 1 .5-.5h9.25a.75.75 0 0 0 0-1.5H3a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V9.75a.75.75 0 0 0-1.5 0V13a.5.5 0 0 1-.5.5H3Zm12.78-8.82a.75.75 0 0 0-1.06-1.06L9.162 9.177 7.289 7.241a.75.75 0 1 0-1.078 1.043l2.403 2.484a.75.75 0 0 0 1.07.01L15.78 4.68Z"/></svg>`,
icon: '<svg width="16" height="16" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M3 13.5a.5.5 0 0 1-.5-.5V3a.5.5 0 0 1 .5-.5h9.25a.75.75 0 0 0 0-1.5H3a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V9.75a.75.75 0 0 0-1.5 0V13a.5.5 0 0 1-.5.5H3Zm12.78-8.82a.75.75 0 0 0-1.06-1.06L9.162 9.177 7.289 7.241a.75.75 0 1 0-1.078 1.043l2.403 2.484a.75.75 0 0 0 1.07.01L15.78 4.68Z"/></svg>',
execute() {
gitdock.openGitLab(`/dashboard/todos`);
gitdock.openGitLab('/dashboard/todos');
},
},
overviewAssignedIssues: {
@ -58,7 +65,7 @@ const ALL_OVERVIEWS = {
},
overviewMRsToReview: {
title: 'Review requests',
icon: `<svg width="16" height="16" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M8 3.5a1 1 0 1 0 0-2 1 1 0 0 0 0 2ZM8 0a2.5 2.5 0 0 1 2.45 2H13a1 1 0 0 1 1 1v12a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3a1 1 0 0 1 1-1h2.55A2.5 2.5 0 0 1 8 0ZM7 5h3.5V3.5h2v11h-9v-11h2V5H7Zm3.53 3.28a.75.75 0 1 0-1.06-1.06L7.5 9.19l-.47-.47a.75.75 0 0 0-1.06 1.06l1 1a.75.75 0 0 0 1.06 0l2.5-2.5Z"/></svg>`,
icon: '<svg width="16" height="16" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M8 3.5a1 1 0 1 0 0-2 1 1 0 0 0 0 2ZM8 0a2.5 2.5 0 0 1 2.45 2H13a1 1 0 0 1 1 1v12a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3a1 1 0 0 1 1-1h2.55A2.5 2.5 0 0 1 8 0ZM7 5h3.5V3.5h2v11h-9v-11h2V5H7Zm3.53 3.28a.75.75 0 1 0-1.06-1.06L7.5 9.19l-.47-.47a.75.75 0 0 0-1.06 1.06l1 1a.75.75 0 0 0 1.06 0l2.5-2.5Z"/></svg>',
execute() {
const username = encodeURIComponent(gitdock.getUsername());
gitdock.openGitLab(`/dashboard/merge_requests?reviewer_username=${username}`);
@ -66,6 +73,25 @@ const ALL_OVERVIEWS = {
},
};
function matcher({ title }) {
let lowerCaseTitle = title.toLowerCase();
const searchTerm = $search.value;
const terms = searchTerm.toLowerCase().split(' ').filter(Boolean);
let matchCount = 1;
for (const term of terms) {
matchCount += lowerCaseTitle.split(' ').filter((x) => x.includes(term)).length;
const newTitle = lowerCaseTitle.replace(term, '');
if (newTitle === lowerCaseTitle) {
return false;
}
lowerCaseTitle = newTitle;
}
return matchCount;
}
function loadActions() {
const actions = Object.entries(ALL_ACTIONS);
@ -99,7 +125,10 @@ function loadFavorites() {
function loadBookmarks() {
const bookmarks = ALL_BOOKMARKS.map((bookmark) => [
`open-bookmark::${bookmark.added}`,
{ title: `${bookmark.title}`, type: `${bookmark.type}` },
{
title: `${bookmark.title}`,
type: `${bookmark.type}`,
},
]);
return [...bookmarks]
@ -110,7 +139,10 @@ function loadBookmarks() {
function loadRecents() {
const recents = ALL_RECENTS.map((recent) => [
`open-recent::${new Date(recent.utc_time).getTime()}`,
{ title: `${recent.title}`, type: `${recent.type}` },
{
title: `${recent.title}`,
type: `${recent.type}`,
},
]);
return [...recents]
@ -118,9 +150,19 @@ function loadRecents() {
.sort(([, recentA], [, recentB]) => matcher(recentB) - matcher(recentA));
}
let ALL_FAVORITES = gitdock.getFavorites() || [];
let ALL_BOOKMARKS = gitdock.getBookmarks() || [];
let ALL_RECENTS = gitdock.getRecents() || [];
function changeTheme() {
if (gitdock.getTheme() === 'light') {
document.documentElement.setAttribute('data-theme', 'light');
} else if (gitdock.getTheme() === 'dark') {
document.documentElement.setAttribute('data-theme', 'dark');
}
}
function changeHighlight(i) {
document.getElementById(`item-${$selected}`)?.classList.remove('selected');
document.getElementById(`item-${i}`).classList.add('selected');
$selected = i;
}
function search() {
html = [];
@ -137,7 +179,7 @@ function search() {
const availableRecents = loadRecents();
if (availableOverviews.length > 0) {
html.push(`<h5>Overview</h5>`);
html.push('<h5>Overview</h5>');
for (const [key, action] of availableOverviews) {
const icon = action.icon ? `${action.icon}` : '';
@ -148,12 +190,12 @@ function search() {
<div class="action-title">${action.title}</div>
</li>`,
);
i++;
i += 1;
}
}
if (availableFavorites.length > 0) {
html.push(`<h5>Favorite projects</h5>`);
html.push('<h5>Favorite projects</h5>');
for (const [key, action] of availableFavorites) {
const avatar = action.avatar_url ? `<img src="${action.avatar_url}" />` : projectIcon;
@ -164,21 +206,22 @@ function search() {
<div class="action-title">${action.title}</div>
</li>`,
);
i++;
i += 1;
}
}
if (availableBookmarks.length > 0) {
html.push(`<h5>Bookmarks</h5>`);
html.push('<h5>Bookmarks</h5>');
for (const [key, action] of availableBookmarks) {
let icon;
if (action.type == 'issues') {
if (action.type === 'issues') {
icon = issueIcon;
} else if (action.type == 'merge_requests') {
} else if (action.type === 'merge_requests') {
icon = mrIcon;
} else {
icon = `<svg width="16" height="16" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M15.747 9.441a.611.611 0 0 0 .224-.682l-.896-2.755-1.277-3.931-.14-.434-.06-.186-.226-.695-.003-.007-.068-.211a.307.307 0 0 0-.582 0l-.068.21-.003.008-.226.696-.06.185-.14.433-1.277 3.929H5.052L3.777 2.074l-.142-.435-.062-.19L3.35.755 3.347.75 3.278.54a.306.306 0 0 0-.58 0l-.07.21-.001.006-.224.691-.062.192-.141.435L.926 6.001.03 8.759a.61.61 0 0 0 .22.682L8 15.071l7.747-5.63Zm-7.748 3.776 6.345-4.61-.696-2.139L13.01 4.5l-.638 1.963A1.5 1.5 0 0 1 10.945 7.5H5.052a1.5 1.5 0 0 1-1.427-1.037l-.636-1.96-.636 1.96-.697 2.144L8 13.218Z"/></svg>`;
icon =
'<svg width="16" height="16" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M15.747 9.441a.611.611 0 0 0 .224-.682l-.896-2.755-1.277-3.931-.14-.434-.06-.186-.226-.695-.003-.007-.068-.211a.307.307 0 0 0-.582 0l-.068.21-.003.008-.226.696-.06.185-.14.433-1.277 3.929H5.052L3.777 2.074l-.142-.435-.062-.19L3.35.755 3.347.75 3.278.54a.306.306 0 0 0-.58 0l-.07.21-.001.006-.224.691-.062.192-.141.435L.926 6.001.03 8.759a.61.61 0 0 0 .22.682L8 15.071l7.747-5.63Zm-7.748 3.776 6.345-4.61-.696-2.139L13.01 4.5l-.638 1.963A1.5 1.5 0 0 1 10.945 7.5H5.052a1.5 1.5 0 0 1-1.427-1.037l-.636-1.96-.636 1.96-.697 2.144L8 13.218Z"/></svg>';
}
html.push(
`<li id="item-${i}" class="${
@ -187,21 +230,22 @@ function search() {
<div class="action-title">${action.title}</div>
</li>`,
);
i++;
i += 1;
}
}
if (availableRecents.length > 0) {
html.push(`<h5>Recently viewed</h5>`);
html.push('<h5>Recently viewed</h5>');
for (const [key, action] of availableRecents) {
let icon;
if (action.type == 'issues') {
if (action.type === 'issues') {
icon = issueIcon;
} else if (action.type == 'merge_requests') {
} else if (action.type === 'merge_requests') {
icon = mrIcon;
} else {
icon = `<svg width="16" height="16" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M15.747 9.441a.611.611 0 0 0 .224-.682l-.896-2.755-1.277-3.931-.14-.434-.06-.186-.226-.695-.003-.007-.068-.211a.307.307 0 0 0-.582 0l-.068.21-.003.008-.226.696-.06.185-.14.433-1.277 3.929H5.052L3.777 2.074l-.142-.435-.062-.19L3.35.755 3.347.75 3.278.54a.306.306 0 0 0-.58 0l-.07.21-.001.006-.224.691-.062.192-.141.435L.926 6.001.03 8.759a.61.61 0 0 0 .22.682L8 15.071l7.747-5.63Zm-7.748 3.776 6.345-4.61-.696-2.139L13.01 4.5l-.638 1.963A1.5 1.5 0 0 1 10.945 7.5H5.052a1.5 1.5 0 0 1-1.427-1.037l-.636-1.96-.636 1.96-.697 2.144L8 13.218Z"/></svg>`;
icon =
'<svg width="16" height="16" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M15.747 9.441a.611.611 0 0 0 .224-.682l-.896-2.755-1.277-3.931-.14-.434-.06-.186-.226-.695-.003-.007-.068-.211a.307.307 0 0 0-.582 0l-.068.21-.003.008-.226.696-.06.185-.14.433-1.277 3.929H5.052L3.777 2.074l-.142-.435-.062-.19L3.35.755 3.347.75 3.278.54a.306.306 0 0 0-.58 0l-.07.21-.001.006-.224.691-.062.192-.141.435L.926 6.001.03 8.759a.61.61 0 0 0 .22.682L8 15.071l7.747-5.63Zm-7.748 3.776 6.345-4.61-.696-2.139L13.01 4.5l-.638 1.963A1.5 1.5 0 0 1 10.945 7.5H5.052a1.5 1.5 0 0 1-1.427-1.037l-.636-1.96-.636 1.96-.697 2.144L8 13.218Z"/></svg>';
}
html.push(
`<li id="item-${i}" class="${
@ -210,12 +254,12 @@ function search() {
<div class="action-title">${action.title}</div>
</li>`,
);
i++;
i += 1;
}
}
if (availableActions.length > 0) {
html.push(`<h5>Actions</h5>`);
html.push('<h5>Actions</h5>');
for (const [key, action] of availableActions) {
const icon = action.icon ? `${action.icon}` : '';
@ -226,7 +270,7 @@ function search() {
<div class="action-title">${action.title}</div>
</li>`,
);
i++;
i += 1;
}
}
@ -235,27 +279,20 @@ function search() {
changeTheme();
}
function matcher({ title }) {
let lowerCaseTitle = title.toLowerCase();
const term = $search.value;
const terms = term.toLowerCase().split(' ').filter(Boolean);
const hide = () => {
gitdock.hideCommandPalette();
$search.value = '';
search();
};
let matchCount = 1;
for (const term of terms) {
matchCount += lowerCaseTitle.split(' ').filter((x) => x.includes(term)).length;
const newTitle = lowerCaseTitle.replace(term, '');
if (newTitle === lowerCaseTitle) {
return false;
}
lowerCaseTitle = newTitle;
}
return matchCount;
function hideCursor() {
document.querySelector('body').style.cursor = 'none';
document.getElementById('mouseoverDisabler').style.display = 'block';
}
let lastClick = Date.now();
// eslint-disable-next-line no-unused-vars
function handleClick(target) {
if (Date.now() - lastClick < 500) {
return;
@ -265,12 +302,12 @@ function handleClick(target) {
if (key.startsWith('open-favorite::')) {
const favoriteId = parseInt(key.split('::')[1], 10);
const { web_url } = ALL_FAVORITES.find((favorite) => favorite.id === favoriteId);
gitdock.openGitLab(web_url);
const webUrl = ALL_FAVORITES.find((favorite) => favorite.id === favoriteId).web_url;
gitdock.openGitLab(webUrl);
} else if (key.startsWith('open-bookmark::')) {
const bookmarkAdded = parseInt(key.split('::')[1], 10);
const { web_url } = ALL_BOOKMARKS.find((bookmark) => bookmark.added === bookmarkAdded);
gitdock.openGitLab(web_url);
const webUrl = ALL_BOOKMARKS.find((bookmark) => bookmark.added === bookmarkAdded).web_url;
gitdock.openGitLab(webUrl);
} else if (key.startsWith('open-recent::')) {
const recentVisited = parseInt(key.split('::')[1], 10);
const { url } = ALL_RECENTS.find(
@ -288,61 +325,16 @@ function handleClick(target) {
}, 10);
}
function changeHighlight(i) {
document.getElementById('item-' + $selected)?.classList.remove('selected');
document.getElementById('item-' + i).classList.add('selected');
$selected = i;
}
$search.addEventListener('input', search);
search();
document.getElementById('search').addEventListener('keydown', function (e) {
document.getElementById('search').addEventListener('keydown', (e) => {
if (e.which === 38 || e.which === 40) {
e.preventDefault();
}
});
document.addEventListener('keydown', (x) => {
if (x.key === 'Escape') {
hide();
} else {
switch (x.keyCode) {
case 13:
document.getElementById('item-' + $selected).click();
case 38:
if ($selected > 0) {
changeHighlight($selected - 1);
scroll(document.querySelector('ul').querySelectorAll('li')[$selected], true);
} else {
changeHighlight(html.filter((item) => item.indexOf('<li') !== -1).length - 1);
scroll(document.querySelector('ul').querySelectorAll('li')[$selected], false);
}
break;
case 40:
if (document.getElementById('item-' + ($selected + 1))) {
changeHighlight($selected + 1);
scroll(document.querySelector('ul').querySelectorAll('li')[$selected], false);
} else {
changeHighlight(0);
scroll(document.querySelector('ul').querySelectorAll('li')[$selected], true);
}
break;
}
}
});
document.addEventListener('mousemove', (x) => {
document.querySelector('body').style.cursor = 'auto';
document.getElementById('mouseoverDisabler').style.display = 'none';
});
function hideCursor() {
document.querySelector('body').style.cursor = 'none';
document.getElementById('mouseoverDisabler').style.display = 'block';
}
function scroll(element, up) {
hideCursor();
let top;
@ -352,20 +344,55 @@ function scroll(element, up) {
top = element.offsetTop - (window.innerHeight - 89);
}
if (element.getBoundingClientRect().top < 89) {
window.scrollTo({ top: top, behavior: 'smooth' });
window.scrollTo({
top,
behavior: 'smooth',
});
}
if (element.getBoundingClientRect().bottom > window.innerHeight - 40) {
window.scrollTo({ top: top, behavior: 'smooth' });
window.scrollTo({
top,
behavior: 'smooth',
});
}
}
function changeTheme() {
if (gitdock.getTheme() == 'light') {
document.documentElement.setAttribute('data-theme', 'light');
} else if (gitdock.getTheme() == 'dark') {
document.documentElement.setAttribute('data-theme', 'dark');
document.addEventListener('keydown', (x) => {
if (x.key === 'Escape') {
hide();
} else {
switch (x.keyCode) {
case 13:
document.getElementById(`item-${$selected}`).click();
break;
case 38:
if ($selected > 0) {
changeHighlight($selected - 1);
scroll(document.querySelector('ul').querySelectorAll('li')[$selected], true);
} else {
changeHighlight(html.filter((item) => item.indexOf('<li') !== -1).length - 1);
scroll(document.querySelector('ul').querySelectorAll('li')[$selected], false);
}
break;
case 40:
if (document.getElementById(`item-${$selected + 1}`)) {
changeHighlight($selected + 1);
scroll(document.querySelector('ul').querySelectorAll('li')[$selected], false);
} else {
changeHighlight(0);
scroll(document.querySelector('ul').querySelectorAll('li')[$selected], true);
}
break;
default:
break;
}
}
}
});
document.addEventListener('mousemove', () => {
document.querySelector('body').style.cursor = 'auto';
document.getElementById('mouseoverDisabler').style.display = 'none';
});
window.addEventListener('blur', () => {
search();
@ -374,9 +401,3 @@ window.addEventListener('blur', () => {
window.addEventListener('focus', () => {
search();
});
const hide = () => {
gitdock.hideCommandPalette();
$search.value = '';
search();
};

View File

@ -1,6 +1,6 @@
const { globalShortcut, BrowserWindow, ipcMain, shell } = require('electron');
const { store } = require('../../lib/store');
const path = require('path');
const { store } = require('../../lib/store');
const BrowserHistory = require('../../lib/browser-history');
const gitdock = require('../../lib/gitlab');
@ -11,8 +11,8 @@ let cpWindow;
async function getRecentlyVisited() {
recentlyVisitedArray = [];
await BrowserHistory.getAllHistory().then(async (history) => {
let item = Array.prototype.concat.apply([], history);
item.sort(function (a, b) {
const item = Array.prototype.concat.apply([], history);
item.sort((a, b) => {
if (a.utc_time > b.utc_time) {
return -1;
}
@ -21,16 +21,16 @@ async function getRecentlyVisited() {
}
});
let i = 0;
for (let j = 0; j < item.length; j++) {
for (let j = 0; j < item.length; j += 1) {
const { title } = item[j];
let { url } = item[j];
const isHostUrl = url.startsWith(`${store.host}/`);
const isIssuable =
url.includes('/-/issues/') ||
url.includes('/-/merge_requests/') ||
url.includes('/-/epics/');
const isIssuable = url.includes('/-/issues/');
url.includes('/-/merge_requests/') || url.includes('/-/epics/');
const displayedTitle = (title || '').split(' · ')[0].split(' (')[0];
const wasNotProcessed = !recentlyVisitedArray.some((item) => item.title == displayedTitle);
const wasNotProcessed = !recentlyVisitedArray.some(
(arrayItem) => arrayItem.title === displayedTitle,
);
const ignoredTitlePrefixes = [
'Not Found ',
'New Issue ',
@ -51,23 +51,15 @@ async function getRecentlyVisited() {
wasNotProcessed &&
!ignoredTitlePrefixes.includes(titlePrefix)
) {
let nameWithNamespace = item[j].url.replace(store.host + '/', '').split('/-/')[0];
if (nameWithNamespace.split('/')[0] != 'groups') {
url =
store.host +
'/api/v4/projects/' +
nameWithNamespace.split('/')[0] +
'%2F' +
nameWithNamespace.split('/')[1] +
'?access_token=' +
store.access_token;
const nameWithNamespace = item[j].url.replace(`${store.host}/`, '').split('/-/')[0];
if (nameWithNamespace.split('/')[0] !== 'groups') {
url = store.host;
`/api/v4/projects/${nameWithNamespace.split('/')[0]}%2F${
nameWithNamespace.split('/')[1]
}?access_token=${store.access_token}`;
} else {
url =
store.host +
'/api/v4/groups/' +
nameWithNamespace.split('/')[0] +
'?access_token=' +
store.access_token;
url = `${store.host}/api/v4/groups/`;
`${nameWithNamespace.split('/')[0]}?access_token=${store.access_token}`;
}
await gitdock.fetchUrlInfo(item[j].url).then((result) => {
item[j].type = result.type;
@ -75,8 +67,8 @@ async function getRecentlyVisited() {
item[j].title = item[j].title.split(' · ')[0];
item[j].title = item[j].title.split(' (')[0];
recentlyVisitedArray.push(item[j]);
i++;
if (i == 5) {
i += 1;
if (i === 5) {
break;
}
}
@ -123,7 +115,7 @@ module.exports = class CommandPalette {
async open() {
cpWindow.show();
//cpWindow.openDevTools();
// cpWindow.openDevTools();
}
newWindow(show = false) {

View File

@ -6,7 +6,7 @@ const api = {
hideCommandPalette: () => ipcRenderer.send('hide-command-palette'),
getUsername: () => store.username,
getFavorites: () => store['favorite-projects'],
getBookmarks: () => store['bookmarks'],
getBookmarks: () => store.bookmarks,
getRecents: () => store['recently-visited'],
getTheme: () => store.theme,
};

View File

@ -9,9 +9,11 @@ describe('"Bookmarks" section', function () {
await window.click('#bookmark-add-button');
};
describe('without bookmarks', function () {
describe('without bookmarks', () => {
beforeEach(async function () {
await newApp(this, { loggedIn: true });
await newApp(this, {
loggedIn: true,
});
});
stopAppAfterEach();
@ -30,7 +32,7 @@ describe('"Bookmarks" section', function () {
});
});
describe('with bookmarks', function () {
describe('with bookmarks', () => {
const FIRST_BOOKMARK_URL = 'https://gitlab.com/user/project/-/merge_requests/1';
beforeEach(async function () {

View File

@ -12,7 +12,9 @@ describe('Favorite projects', function () {
visibility: 'public',
name: 'GitDock ⚓️',
title: 'GitDock ⚓️',
namespace: { name: 'Marcel van Remmerden' },
namespace: {
name: 'Marcel van Remmerden',
},
parent_name: 'Marcel van Remmerden / GitDock ⚓️',
parent_url: 'https://gitlab.com/mvanremmerden',
name_with_namespace: 'Marcel van Remmerden / GitDock ⚓️',
@ -39,7 +41,9 @@ describe('Favorite projects', function () {
};
beforeEach(async function () {
await newApp(this, { loggedIn: true });
await newApp(this, {
loggedIn: true,
});
});
stopAppAfterEach();

View File

@ -5,7 +5,9 @@ describe('Feature tests', function () {
this.timeout(25000);
beforeEach(async function () {
await newApp(this, { loggedIn: true });
await newApp(this, {
loggedIn: true,
});
});
stopAppAfterEach();

View File

@ -19,21 +19,22 @@ describe('"Recently viewed" section', function () {
},
];
const supportedBrowsersText = async (page) => {
return page.innerText('.supported-browsers');
};
const supportedBrowsersText = async (page) => page.innerText('.supported-browsers');
const historyTexts = async (page) => {
const elements = await page.locator('.history-entry');
return elements.allInnerTexts();
};
SUPPORTED_PLATFORMS.forEach(function ({ platform, emptyMessage }) {
describe(`${platform} platform`, function () {
SUPPORTED_PLATFORMS.forEach(({ platform, emptyMessage }) => {
describe(`${platform} platform`, () => {
describe('without history', function () {
stopAppAfterEach();
this.beforeEach(async function () {
await newApp(this, { platform, loggedIn: true });
await newApp(this, {
platform,
loggedIn: true,
});
});
it('renders the correct message', async function () {
@ -72,14 +73,17 @@ describe('"Recently viewed" section', function () {
});
});
describe('unsupported platform', function () {
describe('unsupported platform', () => {
const platform = 'android';
const emptyMessage = 'No browsers are supported on your operating system yet.';
describe('without history', function () {
stopAppAfterEach();
this.beforeEach(async function () {
await newApp(this, { platform, loggedIn: true });
await newApp(this, {
platform,
loggedIn: true,
});
});
it('renders the correct message', async function () {
@ -95,7 +99,10 @@ describe('"Recently viewed" section', function () {
platform,
loggedIn: true,
browserHistory: [
{ title: 'Test Issue #1', url: 'https://gitlab.com/user/project/-/issues/1' },
{
title: 'Test Issue #1',
url: 'https://gitlab.com/user/project/-/issues/1',
},
],
});
});

View File

@ -9,7 +9,7 @@ describe('Themes', function () {
return await body.evaluate((button) => getComputedStyle(button).backgroundColor);
};
describe('default theme', function () {
describe('default theme', () => {
stopAppAfterEach();
beforeEach(async function () {
@ -23,11 +23,13 @@ describe('Themes', function () {
});
});
describe('dark theme', function () {
describe('dark theme', () => {
stopAppAfterEach();
beforeEach(async function () {
await newApp(this, { theme: 'dark' });
await newApp(this, {
theme: 'dark',
});
});
it('has the correct background color', async function () {
@ -37,11 +39,13 @@ describe('Themes', function () {
});
});
describe('light theme', function () {
describe('light theme', () => {
stopAppAfterEach();
beforeEach(async function () {
await newApp(this, { theme: 'light' });
await newApp(this, {
theme: 'light',
});
});
it('has the correct background color', async function () {

View File

@ -15,11 +15,10 @@ const store = JSON.parse(process.env.MOCK_STORE || '{}');
const proxy = new Proxy(store, {
get(target, key) {
if (target[key] == undefined) {
if (target[key] === undefined) {
return defaults[key];
} else {
return target[key];
}
return target[key];
},
set(target, key, value) {
target[key] = value;

View File

@ -71,7 +71,10 @@ module.exports = {
thisValue.window = window;
}
return { app, window };
return {
app,
window,
};
},
stopAppAfterEach() {
afterEach(async function () {

View File

@ -18,6 +18,7 @@ const mockRegistry = {
// Below is the dependency replace logic
const path = require('path');
const nodeRequire = require.extensions['.js'];
const PROJECT_ROOT = path.join(__dirname, '..', '..');