@@ -143,15 +143,31 @@ class GitHub extends PjaxAdapter {
143
143
144
144
// Get branch by inspecting URL or DOM, quite fragile so provide multiple fallbacks.
145
145
// TODO would be great if there's a more robust way to do this
146
- const branchDropdownMenu = $ ( '.branch-select-menu' ) ;
146
+ /**
147
+ * Github renders the branch name in one of below structure depending on the length
148
+ * of branch name
149
+ *
150
+ * Option 1: when the length is short enough
151
+ * <summary title="Switch branches or tags">
152
+ * <span class="css-truncate-target">feature/1/2/3</span>
153
+ * </summary>
154
+ *
155
+ * Option 2: when the length is too long
156
+ * <summary title="feature/1/2/3/4/5/6/7/8">
157
+ * <span class="css-truncate-target">feature/1/2/3...</span>
158
+ * </summary>
159
+ */
160
+ const branchDropdownMenuSummary = $ ( '.branch-select-menu summary' ) ;
161
+ const branchNameInTitle = branchDropdownMenuSummary . attr ( 'title' ) ;
162
+ const branchNameInSpan = branchDropdownMenuSummary . find ( 'span' ) . text ( ) ;
163
+
147
164
const branch =
148
165
// Pick the commit ID as branch name when the code page is listing tree in a particular commit
149
166
( type === 'commit' && typeId ) ||
150
167
// Pick the commit ID or branch name from the DOM
151
168
// Note: we can't use URL as it would not work with branches with slashes, e.g. features/hotfix-1
152
169
( $ ( '.overall-summary .numbers-summary .commits a' ) . attr ( 'href' ) || '' ) . split ( '/' ) . slice ( - 1 ) [ 0 ] ||
153
- $ ( '.select-menu-item[aria-checked="true"] span' , branchDropdownMenu ) . text ( ) ||
154
- $ ( '.select-menu-button span' , branchDropdownMenu ) . text ( ) ||
170
+ ( branchNameInTitle . toLowerCase ( ) . startsWith ( 'switch branches' ) ? branchNameInSpan : branchNameInTitle ) ||
155
171
// Pull requests page
156
172
( $ ( '.commit-ref.base-ref' ) . attr ( 'title' ) || ':' ) . match ( / : ( .* ) / ) [ 1 ] ||
157
173
// Reuse last selected branch if exist
0 commit comments