Skip to content
This repository was archived by the owner on Jan 22, 2019. It is now read-only.

feat: Gitlab#197

Merged
ijsnow merged 14 commits intomasterfrom
gitlab
Sep 27, 2018
Merged

feat: Gitlab#197
ijsnow merged 14 commits intomasterfrom
gitlab

Conversation

@ijsnow
Copy link

@ijsnow ijsnow commented Sep 26, 2018

This PR brings support for GitLab.

Testing plan:

Run the browser extension and visit the following and check to ensure it works

Code intelligence

Search

Action: Enable search feature flag and open this page.

Expected result: A new tab should open on the sourcegraph search results page with the repo:filter and search query in the search bar

I have tested on:

  • Chrome
  • Firefox

return {
url: `search?q=${encodeURIComponent(query)}&sq=repo:%5E${encodeURIComponent(
repoPath.replace(/\./g, '\\.')
)}%24@${encodeURIComponent(rev)}&utm_source=${getPlatformName()}`,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use the URL API to avoid manual encodeURIComponent calls

if (checkIsSearchPage()) {
storage.getSync(({ executeSearchEnabled }) => {
// GitHub search page pathname is <org>/<repo>/search
if (false && !executeSearchEnabled) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lol good catch. Was too lazy to switch the feature flag while working

const buildURL = (owner: string, repoName: string, path: string) =>
`${window.location.origin}/api/v4/projects/${owner}%2f${repoName}${path}`

const get = <T>(url: string): Observable<T> => ajax.get(url).pipe(map(({ response }) => response as T))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid type parameters that are only used in the return type - it's only a cast in disguise. It's better to cast explicitly.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Casting is actually what I intended with that. I think it's easier to read at the call sights.

const repoName = parts[1]

let pageKind: GitLabPageKind
if (window.location.pathname.match(new RegExp(`${owner}/${repoName}/commit`))) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't pathname.includes() do the same? Do you have to escape characters in the regex?

}
}

const createErrorBuilder = (message: string) => (kind: string) => new Error(`${message} (${kind})`)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of kind? It looks more like an error code than meant for human consumption, but it is put into the message.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's added for making it easier to find the site of the error. Maybe kind is just a bad name.

Copy link

@chrismwendt chrismwendt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mostly looked at the code_intelligence files and skimmed over the GitLab-specific code, LGTM

}
}
}
console.log(baseCommitID, headCommitID)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

console.log

* Response from the GitLab API for fetching a merge request. Note that there
* is more information returned but we are not using it.
*/
interface MRResponse {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd spell this out MergeRequestResponse

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's how I originally had it and thought ResuestResponse sounded weird. This comment was enough to convince me to ignore that and spell it out

@ijsnow ijsnow merged commit 4a76e34 into master Sep 27, 2018
@ijsnow ijsnow deleted the gitlab branch September 27, 2018 20:37
@sourcegraph-bot
Copy link

🎉 This PR is included in version 1.16.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants