-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: create generic interface for SCMs
This prepares the project for adding other SCMs. The changes to Babel were due to an issue with shimming Promises and Firefox (mozilla/webextension-polyfill#105 (comment))
- Loading branch information
1 parent
7e622ea
commit d2e8cd0
Showing
17 changed files
with
227 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,23 @@ | ||
import { browser } from "webextension-polyfill-ts"; | ||
import { messages } from "~app/constants"; | ||
import { Message } from "~app/types/messenging"; | ||
|
||
const sendMessageRobust = async (currentTabId: number, message: Message) => | ||
browser.tabs.sendMessage(currentTabId, message).catch((error: unknown) => { | ||
console.warn(`Could not send message: [${error}]. Ignoring...`); | ||
}); | ||
|
||
export const setTabSupportsMulePreview = async (supported: boolean) => { | ||
await browser.runtime.sendMessage({ | ||
type: messages.Supported, | ||
export const setTabSupportsMulePreview = async (supported: boolean) => | ||
browser.runtime.sendMessage({ | ||
type: "Supported", | ||
value: supported | ||
}); | ||
}; | ||
|
||
export const resetTab = async (tabId: number) => | ||
sendMessageRobust(tabId, { | ||
type: messages.Reset | ||
type: "Reset" | ||
}); | ||
|
||
export const toggleDiffOnTab = async (tabId: number) => | ||
sendMessageRobust(tabId, { | ||
type: messages.ToggleDiff | ||
type: "ToggleDiff" | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { | ||
DiffContent, | ||
PreviewContent, | ||
ScmMode, | ||
ScmModule | ||
} from "~app/types/scms"; | ||
import { handleBitbucketData } from "./fetch"; | ||
import { | ||
getBitbucketData, | ||
getBitbucketDiffElement, | ||
getBitbucketFilePreviewElement, | ||
getFileRawUrlFromContentView | ||
} from "./ui"; | ||
|
||
/** | ||
* Supports the self hosted version of Atlassian Bitbucket (Bitbucket Server) | ||
* | ||
* Does not support Bitbucket Cloud, this works very differently under the hood | ||
* and will need to be a separate module. | ||
* | ||
* Tested on Atlassian Bitbucket v6.1.1 | ||
* It will probably work on any version of v6 and maybe even earlier versions | ||
* but has not be tested on those versions. | ||
*/ | ||
export const bitbucketServerScmModule: ScmModule = { | ||
isSupported: async (): Promise<boolean> => { | ||
const metaTag = document.querySelector("meta[name=application-name]"); | ||
return metaTag === null | ||
? false | ||
: metaTag.getAttribute("content") === "Bitbucket"; | ||
}, | ||
isReady: (): boolean => | ||
getBitbucketDiffElement() !== null || | ||
getBitbucketFilePreviewElement() !== null, | ||
determineScmMode: async (): Promise<ScmMode> => { | ||
if (new URL(document.URL).pathname.endsWith("diff")) { | ||
return "Diff"; | ||
} | ||
if (new URL(document.URL).pathname.endsWith(".xml")) { | ||
return "Preview"; | ||
} | ||
return "None"; | ||
}, | ||
getDiffContent: async (): Promise<DiffContent> => | ||
getBitbucketData().then(handleBitbucketData), | ||
getPreviewContent: async (): Promise<PreviewContent> => { | ||
const url = getFileRawUrlFromContentView(); | ||
return fetch(url).then(response => response.text()); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.