Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility with current "New Repository Overview" experiment on GitHub #55

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
],
"rules": {
"max-len": ["error", { "code": 120, "tabWidth": 2 }],
"complexity": ["off"],
"no-magic-numbers": ["error", { "ignore": [0, 1] }],
"indent": ["error", 2, {
"ignoredNodes": ["TemplateLiteral", "SwitchCase"]
Expand Down
16 changes: 11 additions & 5 deletions github.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,22 +243,28 @@ const renderCloneButtons = (tools, githubMetadata) => {
} 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('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);
});

Expand Down