Skip to content

Commit

Permalink
Merge pull request #296 from src-d/gitbase-0.18
Browse files Browse the repository at this point in the history
Update to gitbase v0.18.0
  • Loading branch information
carlosms authored Dec 17, 2018
2 parents ea2ecaf + 3b34c13 commit 30953f7
Show file tree
Hide file tree
Showing 63 changed files with 1,769 additions and 3,509 deletions.
14 changes: 2 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,8 @@ language: go
services:
- docker

addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- gcc-6
- g++-6

go:
- "1.10.x"
- "1.11.x"

before_install:
- . $HOME/.nvm/nvm.sh
Expand All @@ -21,8 +13,6 @@ before_install:
- npm install -g yarn

install:
- sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-6 90
- sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 90
- make dependencies

stages:
Expand All @@ -48,7 +38,7 @@ jobs:
- docker exec -it bblfshd bblfshctl driver install --force javascript docker://bblfsh/javascript-driver:latest
- mkdir $HOME/repos
- git clone https://github.com/src-d/gitbase-web.git $HOME/repos/gitbase-web
- docker run -d --name gitbase -p "3367:3306" -e "BBLFSH_ENDPOINT=bblfshd:9432" --volume $HOME/repos:/opt/repos --link bblfshd srcd/gitbase
- docker run -d --name gitbase -p "3367:3306" -e "BBLFSH_ENDPOINT=bblfshd:9432" --volume $HOME/repos:/opt/repos --link bblfshd srcd/gitbase:v0.18.0
- sleep 15
- GITBASEPG_DB_CONNECTION='root@tcp(localhost:3367)/none' GITBASEPG_INTEGRATION_TESTS=true make test
- script:
Expand Down
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ FROM debian:stretch-slim
RUN apt-get update && \
apt-get install -y --no-install-recommends --no-install-suggests \
ca-certificates \
libxml2 \
&& apt-get clean

ADD ./build/bin /bin
Expand Down
25 changes: 13 additions & 12 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
unused-packages = true
non-go = true

[[prune.project]]
name = "gopkg.in/bblfsh/client-go.v2"
non-go = false

[[constraint]]
name = "github.com/go-chi/chi"
version = "3.3.2"
Expand Down Expand Up @@ -39,12 +35,16 @@
version = "1.2.2"

[[constraint]]
name = "gopkg.in/bblfsh/client-go.v3"
version = "3.1.0"

[[override]]
name = "gopkg.in/bblfsh/sdk.v1"
version = "1.16.0"

[[constraint]]
name = "gopkg.in/bblfsh/client-go.v2"
version = "2.8.4"
name = "gopkg.in/bblfsh/sdk.v2"
version = "2.3.0"

[[constraint]]
name = "gopkg.in/DATA-DOG/go-sqlmock.v1"
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:
depends_on:
- gitbase
gitbase:
image: "srcd/gitbase:v0.17.1"
image: "srcd/gitbase:v0.18.0"
environment:
BBLFSH_ENDPOINT: bblfsh:9432
GITBASE_UNSTABLE_SQUASH_ENABLE: "true"
Expand Down
8 changes: 6 additions & 2 deletions docs/rest-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ curl -X POST \

## POST /parse

Receives a file content and returns UAST.
Receives a file content and returns UAST parsed by the bblfsh server.

```bash
curl -X POST \
Expand All @@ -221,6 +221,7 @@ curl -X POST \
-d '{
"language": "javascript",
"content": "console.log(test)"
"mode": "annotated"
}'
```

Expand All @@ -243,8 +244,11 @@ curl -X POST \
}
```

The endpoint also receives additional parameters:
The endpoint accepts these parameters:

- `language`: Language name.
- `content`: The file contents to parse.
- `mode`: Transformation mode. Can be one of `native`, `annotated`, `semantic`. The default is `semantic`.
- `serverUrl` - allows to override bblfsh server URL.
- `filename` - can be used instead of language. Then the bblfsh server would try to guess the language.
- `filter` - [xpath query](https://doc.bblf.sh/user/uast-querying.html) to filter the results.
Expand Down
4 changes: 3 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"react-split-pane": "^0.1.77",
"react-switch": "^3.0.4",
"react-table": "^6.8.2",
"uast-viewer": "^0.0.8"
"uast-viewer": "^0.2.0"
},
"scripts": {
"start": "react-app-rewired start",
Expand All @@ -28,6 +28,8 @@
"format": "eslint --fix 'src/**/*.js'"
},
"devDependencies": {
"enzyme": "^3.7.0",
"enzyme-adapter-react-16": "^1.7.0",
"eslint-config-airbnb-base": "^12.1.0",
"eslint-config-prettier": "^2.9.0",
"eslint-plugin-jest": "^21.15.1",
Expand Down
12 changes: 9 additions & 3 deletions frontend/src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,21 @@ function detectLang(content, filename) {
}).then(res => res.data);
}

function parseCode(language, content, filter, customServerUrl) {
const defaultUastMode = 'semantic';
const uastModes = ['semantic', 'annotated', 'native'];

function parseCode(language, content, mode, filter, customServerUrl) {
return apiCall('/parse', {
method: 'POST',
body: {
language,
content,
mode,
filter,
serverUrl: customServerUrl
}
}).then(res => {
if (res.data.status !== 0) {
if (res.status !== 200) {
throw normalizeErrors(res.data.errors);
}
return res.data.uast;
Expand Down Expand Up @@ -178,5 +182,7 @@ export default {
parseCode,
getLanguages,
filterUAST,
version
version,
uastModes,
defaultUastMode
};
33 changes: 28 additions & 5 deletions frontend/src/components/CodeViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ function EditorUASTSpitPane({
handleLangChange,
handleShowLocationsChange,
handleFilterChange,
handleSearch
handleSearch,
mode,
handleModeChange
}) {
return (
<SplitPane split="vertical" defaultSize={500} minSize={1} maxSize={-15}>
Expand All @@ -72,6 +74,8 @@ function EditorUASTSpitPane({
handleShowLocationsChange={handleShowLocationsChange}
handleFilterChange={handleFilterChange}
handleSearch={handleSearch}
mode={mode}
handleModeChange={handleModeChange}
/>
</SplitPane>
);
Expand All @@ -87,7 +91,9 @@ EditorUASTSpitPane.propTypes = {
handleLangChange: PropTypes.func.isRequired,
handleShowLocationsChange: PropTypes.func.isRequired,
handleFilterChange: PropTypes.func.isRequired,
handleSearch: PropTypes.func.isRequired
handleSearch: PropTypes.func.isRequired,
mode: PropTypes.string.isRequired,
handleModeChange: PropTypes.func.isRequired
};

const EditorWithUAST = withUASTEditor(EditorUASTSpitPane);
Expand All @@ -104,7 +110,8 @@ class CodeViewer extends Component {
uast: null,
error: null,
showLocations: false,
filter: ''
filter: '',
mode: api.defaultUastMode
};

this.handleLangChange = this.handleLangChange.bind(this);
Expand All @@ -113,6 +120,7 @@ class CodeViewer extends Component {
this.removeError = this.removeError.bind(this);
this.handleShowLocationsChange = this.handleShowLocationsChange.bind(this);
this.handleFilterChange = this.handleFilterChange.bind(this);
this.handleModeChange = this.handleModeChange.bind(this);
}

componentDidMount() {
Expand Down Expand Up @@ -154,7 +162,12 @@ class CodeViewer extends Component {
this.setState({ error: null, uast: null, uastLoading: true });

api
.parseCode(this.state.language, this.props.code, this.state.filter)
.parseCode(
this.state.language,
this.props.code,
this.state.mode,
this.state.filter
)
.then(res => {
this.setState({ uast: res });
})
Expand All @@ -176,6 +189,13 @@ class CodeViewer extends Component {
this.setState({ filter: e.target.value });
}

handleModeChange(mode) {
this.setState({ mode });
if (this.state.showUast) {
this.parseCode();
}
}

render() {
const { showModal, onHide, code, languages } = this.props;
const {
Expand All @@ -186,7 +206,8 @@ class CodeViewer extends Component {
uast,
error,
showLocations,
filter
filter,
mode
} = this.state;

if (loading) {
Expand Down Expand Up @@ -230,6 +251,8 @@ class CodeViewer extends Component {
handleShowLocationsChange={this.handleShowLocationsChange}
handleFilterChange={this.handleFilterChange}
handleSearch={this.parseCode}
mode={mode}
handleModeChange={this.handleModeChange}
/>
{error ? (
<div className="error">
Expand Down
34 changes: 34 additions & 0 deletions frontend/src/components/ParseModeSwitcher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react';
import PropTypes from 'prop-types';
import api from '../api';

function ParseModeSwitcher({ mode, handleModeChange }) {
return (
<div style={{ padding: '20px' }}>
{api.uastModes.map(m => (
<label
key={m}
style={{
marginRight: '20px',
textTransform: 'capitalize'
}}
>
<input
type="radio"
value={m}
checked={mode === m}
onChange={e => handleModeChange(e.target.value)}
/>{' '}
{m}
</label>
))}
</div>
);
}

ParseModeSwitcher.propTypes = {
mode: PropTypes.string.isRequired,
handleModeChange: PropTypes.func.isRequired
};

export default ParseModeSwitcher;
25 changes: 25 additions & 0 deletions frontend/src/components/ParseModeSwitcher.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react';
import { shallow } from 'enzyme';
import renderer from 'react-test-renderer';
import ParseModeSwitcher from './ParseModeSwitcher';

test('it renders correctly', () => {
const tree = renderer
.create(
<ParseModeSwitcher mode={'semantic'} handleModeChange={() => null} />
)
.toJSON();

expect(tree).toMatchSnapshot();
});

test('it calls handleModeChange when the input is clicked', () => {
const spy = jest.fn();
const wrapper = shallow(
<ParseModeSwitcher mode={'semantic'} handleModeChange={spy} />
);
wrapper
.find('[value="annotated"]')
.simulate('change', { target: { value: 'annotated' } });
expect(spy.mock.calls.length).toBe(1);
});
Loading

0 comments on commit 30953f7

Please sign in to comment.