Thanks to visit codestin.com
Credit goes to github.com

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 into
masterfrom
gitlab
Sep 27, 2018
Merged

ijsnow merged 14 commits into
masterfrom
gitlab

Conversation

@ijsnow

@ijsnow ijsnow commented Sep 26, 2018

Copy link
Copy Markdown

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()}`,

Copy link
Copy Markdown

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

Comment thread src/libs/code_intelligence/search.ts Outdated
if (checkIsSearchPage()) {
storage.getSync(({ executeSearchEnabled }) => {
// GitHub search page pathname is <org>/<repo>/search
if (false && !executeSearchEnabled) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

?

Copy link
Copy Markdown
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

Comment thread src/libs/gitlab/api.ts
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))

Copy link
Copy Markdown

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
Copy Markdown
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.

Comment thread src/libs/gitlab/scrape.ts Outdated
const repoName = parts[1]

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

Copy link
Copy Markdown

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?

Comment thread src/libs/gitlab/scrape.ts
}
}

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

Copy link
Copy Markdown

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
Copy Markdown
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.

@chrismwendt chrismwendt left a comment

Copy link
Copy Markdown

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

Comment thread src/libs/github/util.tsx Outdated
}
}
}
console.log(baseCommitID, headCommitID)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

console.log

Comment thread src/libs/gitlab/api.ts Outdated
* 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 {

Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown

🎉 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