diff --git a/src/driver/core/SideBar.js b/src/driver/core/SideBar.js index 12d7b82..489698c 100644 --- a/src/driver/core/SideBar.js +++ b/src/driver/core/SideBar.js @@ -6,6 +6,7 @@ import keyHelper from '../../utils/keyHelper' const init = dispatch => async () => { try { + if (!URLHelper.isInRepoPage()) return let nothingWentWrong = true const metaData = URLHelper.parse() dispatch(setMetaData, metaData) diff --git a/src/utils/URLHelper.js b/src/utils/URLHelper.js index 07bdfde..4fc890a 100644 --- a/src/utils/URLHelper.js +++ b/src/utils/URLHelper.js @@ -33,12 +33,21 @@ const TYPES = { // known but not related types: issues, pulls, wiki, insight, // TODO: record more types } -function isInCodePage(metaData = {}) { - const { userName, repoName, type, branchName } = { ...parseRaw(), ...metaData } + +function isInRepoPage(metaData) { + const { userName, repoName } = metaData || parseRaw() return Boolean( userName && !RESERVED_NAME.find(_ => _ === userName) && - repoName && + repoName + ) +} + +function isInCodePage(metaData = {}) { + const mergedRepo = { ...parseRaw(), ...metaData } + const { type, branchName } = mergedRepo + return Boolean( + isInRepoPage(mergedRepo) && (!type || type === TYPES.TREE || type === TYPES.BLOB) && type !== TYPES.COMMIT && (branchName || (!type && !branchName)) @@ -52,6 +61,7 @@ function getCurrentPath(decode = false) { export default { getCurrentPath, + isInRepoPage, isInCodePage, parse, }