From d4d068dd152ef730127b01f82111e1b8593d0371 Mon Sep 17 00:00:00 2001 From: Jordie Biemold Date: Wed, 25 Oct 2023 18:06:19 +0200 Subject: [PATCH 1/3] Compatibility with current "New Repository Overview" experiment on GH --- .eslintrc.json | 1 + github.js | 64 +++++++++++++++++++++++++++++++++----------------- package.json | 1 + 3 files changed, 45 insertions(+), 21 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 31c5902..fa624ad 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -14,6 +14,7 @@ ], "rules": { "max-len": ["error", { "code": 120, "tabWidth": 2 }], + "complexity": ["error", 8], "no-magic-numbers": ["error", { "ignore": [0, 1] }], "indent": ["error", 2, { "ignoredNodes": ["TemplateLiteral", "SwitchCase"] diff --git a/github.js b/github.js index 24435db..20bdab8 100644 --- a/github.js +++ b/github.js @@ -240,30 +240,52 @@ const renderCloneButtons = (tools, githubMetadata) => { }); getRepoController.insertAdjacentElement('beforebegin', toolboxCloneButtonGroup); + + return; + } + + // new UI as of 24.06.20 + getRepoController = document.querySelector('get-repo'); + + if (!getRepoController) { + return; + } + + // https://github.com/orgs/community/discussions/61982 + const isNewRepositoryOverview = getRepoController. + parentElement?.parentElement?.classList?.contains('pagehead-actions') ?? false; + + if (isNewRepositoryOverview) { + const toolboxCloneButtonGroup = document.createElement('li'); + toolboxCloneButtonGroup.setAttribute('class', + `BtnGroup ${CLONE_BUTTON_GROUP_JS_CSS_CLASS}`); + + tools.forEach(tool => { + const btn = createCloneButton(tool, githubMetadata, true); + toolboxCloneButtonGroup.appendChild(btn); + }); + + getRepoController.parentElement.insertAdjacentElement('beforebegin', toolboxCloneButtonGroup); } else { - // new UI as of 24.06.20 - getRepoController = document.querySelector('get-repo'); - if (getRepoController) { - const summary = getRepoController.querySelector('summary'); - // the Code tab contains the green Code button (primary), - // the Pull requests tab contains the ordinary Code button (outlined) - const isOnCodeTab = summary && summary.classList.contains('Button--primary'); - - const toolboxCloneButtonGroup = document.createElement('div'); - toolboxCloneButtonGroup.setAttribute( - 'class', - `BtnGroup ${isOnCodeTab - ? 'd-block ml-2' - : 'flex-md-order-2'} ${CLONE_BUTTON_GROUP_JS_CSS_CLASS}` - ); + const summary = getRepoController.querySelector('summary'); + // the Code tab contains the green Code button (primary), + // the Pull requests tab contains the ordinary Code button (outlined) + const isOnCodeTab = summary && summary.classList.contains('Button--primary'); - tools.forEach(tool => { - const btn = createCloneButton(tool, githubMetadata, !isOnCodeTab); - toolboxCloneButtonGroup.appendChild(btn); - }); + const toolboxCloneButtonGroup = document.createElement('div'); + toolboxCloneButtonGroup.setAttribute( + 'class', + `BtnGroup ${isOnCodeTab + ? 'd-block ml-2' + : 'flex-md-order-2'} ${CLONE_BUTTON_GROUP_JS_CSS_CLASS}` + ); - getRepoController.parentElement.insertAdjacentElement('beforebegin', toolboxCloneButtonGroup); - } + tools.forEach(tool => { + const btn = createCloneButton(tool, githubMetadata, !isOnCodeTab); + toolboxCloneButtonGroup.appendChild(btn); + }); + + getRepoController.parentElement.insertAdjacentElement('beforebegin', toolboxCloneButtonGroup); } }; diff --git a/package.json b/package.json index 68bbe81..2282340 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "license": "Apache-2.0", "scripts": { "prebuild": "eslint .", + "prebuild2": "eslint . --fix", "build": "webpack --bail --mode production", "postbuild": "node .scripts/generate-readme.js | node .scripts/generate-license-list.js", "build:dev": "webpack --bail --mode development --devtool inline-source-map --infrastructure-logging-debug", From 4ab18b0194f21df8a8a932c379ccd23aaaec2b6f Mon Sep 17 00:00:00 2001 From: Jordie Biemold Date: Wed, 25 Oct 2023 18:27:35 +0200 Subject: [PATCH 2/3] Resolve issue on PR details tab --- .eslintrc.json | 2 +- github.js | 34 ++++++++++------------------------ 2 files changed, 11 insertions(+), 25 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index fa624ad..b189d6e 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -14,7 +14,7 @@ ], "rules": { "max-len": ["error", { "code": 120, "tabWidth": 2 }], - "complexity": ["error", 8], + "complexity": ["off"], "no-magic-numbers": ["error", { "ignore": [0, 1] }], "indent": ["error", 2, { "ignoredNodes": ["TemplateLiteral", "SwitchCase"] diff --git a/github.js b/github.js index 20bdab8..2680991 100644 --- a/github.js +++ b/github.js @@ -247,41 +247,27 @@ const renderCloneButtons = (tools, githubMetadata) => { // new UI as of 24.06.20 getRepoController = document.querySelector('get-repo'); - if (!getRepoController) { - return; - } - - // https://github.com/orgs/community/discussions/61982 - const isNewRepositoryOverview = getRepoController. - parentElement?.parentElement?.classList?.contains('pagehead-actions') ?? false; - - if (isNewRepositoryOverview) { - const toolboxCloneButtonGroup = document.createElement('li'); - toolboxCloneButtonGroup.setAttribute('class', - `BtnGroup ${CLONE_BUTTON_GROUP_JS_CSS_CLASS}`); - - tools.forEach(tool => { - const btn = createCloneButton(tool, githubMetadata, true); - toolboxCloneButtonGroup.appendChild(btn); - }); + if (getRepoController) { + // https://github.com/orgs/community/discussions/61982 + const isNewRepositoryOverview = getRepoController. + parentElement?.parentElement?.classList?.contains('pagehead-actions') ?? false; - getRepoController.parentElement.insertAdjacentElement('beforebegin', toolboxCloneButtonGroup); - } else { const summary = getRepoController.querySelector('summary'); // the Code tab contains the green Code button (primary), // the Pull requests tab contains the ordinary Code button (outlined) const isOnCodeTab = summary && summary.classList.contains('Button--primary'); - const toolboxCloneButtonGroup = document.createElement('div'); + const toolboxCloneButtonGroup = document.createElement(isNewRepositoryOverview ? 'li' : 'div'); + const classes = isOnCodeTab + ? (!isNewRepositoryOverview && 'd-block ml-2') + : 'flex-md-order-2'; toolboxCloneButtonGroup.setAttribute( 'class', - `BtnGroup ${isOnCodeTab - ? 'd-block ml-2' - : 'flex-md-order-2'} ${CLONE_BUTTON_GROUP_JS_CSS_CLASS}` + `BtnGroup ${classes} ${CLONE_BUTTON_GROUP_JS_CSS_CLASS}` ); tools.forEach(tool => { - const btn = createCloneButton(tool, githubMetadata, !isOnCodeTab); + const btn = createCloneButton(tool, githubMetadata, !isOnCodeTab || isNewRepositoryOverview); toolboxCloneButtonGroup.appendChild(btn); }); From b807922b2af04286a41b38dab92cc0d81bf48cbd Mon Sep 17 00:00:00 2001 From: Jordie Biemold Date: Wed, 25 Oct 2023 18:29:06 +0200 Subject: [PATCH 3/3] Cleanup --- github.js | 58 +++++++++++++++++++++++++--------------------------- package.json | 1 - 2 files changed, 28 insertions(+), 31 deletions(-) diff --git a/github.js b/github.js index 2680991..7e4f5cf 100644 --- a/github.js +++ b/github.js @@ -240,38 +240,36 @@ const renderCloneButtons = (tools, githubMetadata) => { }); getRepoController.insertAdjacentElement('beforebegin', toolboxCloneButtonGroup); + } else { + // new UI as of 24.06.20 + getRepoController = document.querySelector('get-repo'); + + if (getRepoController) { + // https://github.com/orgs/community/discussions/61982 + const isNewRepositoryOverview = getRepoController. + parentElement?.parentElement?.classList?.contains('pagehead-actions') ?? false; + + const summary = getRepoController.querySelector('summary'); + // the Code tab contains the green Code button (primary), + // the Pull requests tab contains the ordinary Code button (outlined) + const isOnCodeTab = summary && summary.classList.contains('Button--primary'); + + const toolboxCloneButtonGroup = document.createElement(isNewRepositoryOverview ? 'li' : 'div'); + const classes = isOnCodeTab + ? (!isNewRepositoryOverview && 'd-block ml-2') + : 'flex-md-order-2'; + toolboxCloneButtonGroup.setAttribute( + 'class', + `BtnGroup ${classes} ${CLONE_BUTTON_GROUP_JS_CSS_CLASS}` + ); - return; - } - - // new UI as of 24.06.20 - getRepoController = document.querySelector('get-repo'); - - if (getRepoController) { - // https://github.com/orgs/community/discussions/61982 - const isNewRepositoryOverview = getRepoController. - parentElement?.parentElement?.classList?.contains('pagehead-actions') ?? false; - - const summary = getRepoController.querySelector('summary'); - // the Code tab contains the green Code button (primary), - // the Pull requests tab contains the ordinary Code button (outlined) - const isOnCodeTab = summary && summary.classList.contains('Button--primary'); - - const toolboxCloneButtonGroup = document.createElement(isNewRepositoryOverview ? 'li' : 'div'); - const classes = isOnCodeTab - ? (!isNewRepositoryOverview && 'd-block ml-2') - : 'flex-md-order-2'; - toolboxCloneButtonGroup.setAttribute( - 'class', - `BtnGroup ${classes} ${CLONE_BUTTON_GROUP_JS_CSS_CLASS}` - ); - - tools.forEach(tool => { - const btn = createCloneButton(tool, githubMetadata, !isOnCodeTab || isNewRepositoryOverview); - toolboxCloneButtonGroup.appendChild(btn); - }); + tools.forEach(tool => { + const btn = createCloneButton(tool, githubMetadata, !isOnCodeTab || isNewRepositoryOverview); + toolboxCloneButtonGroup.appendChild(btn); + }); - getRepoController.parentElement.insertAdjacentElement('beforebegin', toolboxCloneButtonGroup); + getRepoController.parentElement.insertAdjacentElement('beforebegin', toolboxCloneButtonGroup); + } } }; diff --git a/package.json b/package.json index 2282340..68bbe81 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,6 @@ "license": "Apache-2.0", "scripts": { "prebuild": "eslint .", - "prebuild2": "eslint . --fix", "build": "webpack --bail --mode production", "postbuild": "node .scripts/generate-readme.js | node .scripts/generate-license-list.js", "build:dev": "webpack --bail --mode development --devtool inline-source-map --infrastructure-logging-debug",