Skip to content

Commit 30953f7

Browse files
authored
Merge pull request #296 from src-d/gitbase-0.18
Update to gitbase v0.18.0
2 parents ea2ecaf + 3b34c13 commit 30953f7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1769
-3509
lines changed

.travis.yml

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,8 @@ language: go
33
services:
44
- docker
55

6-
addons:
7-
apt:
8-
sources:
9-
- ubuntu-toolchain-r-test
10-
packages:
11-
- gcc-6
12-
- g++-6
13-
146
go:
15-
- "1.10.x"
7+
- "1.11.x"
168

179
before_install:
1810
- . $HOME/.nvm/nvm.sh
@@ -21,8 +13,6 @@ before_install:
2113
- npm install -g yarn
2214

2315
install:
24-
- sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-6 90
25-
- sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 90
2616
- make dependencies
2717

2818
stages:
@@ -48,7 +38,7 @@ jobs:
4838
- docker exec -it bblfshd bblfshctl driver install --force javascript docker://bblfsh/javascript-driver:latest
4939
- mkdir $HOME/repos
5040
- git clone https://github.com/src-d/gitbase-web.git $HOME/repos/gitbase-web
51-
- docker run -d --name gitbase -p "3367:3306" -e "BBLFSH_ENDPOINT=bblfshd:9432" --volume $HOME/repos:/opt/repos --link bblfshd srcd/gitbase
41+
- 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
5242
- sleep 15
5343
- GITBASEPG_DB_CONNECTION='root@tcp(localhost:3367)/none' GITBASEPG_INTEGRATION_TESTS=true make test
5444
- script:

Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ FROM debian:stretch-slim
33
RUN apt-get update && \
44
apt-get install -y --no-install-recommends --no-install-suggests \
55
ca-certificates \
6-
libxml2 \
76
&& apt-get clean
87

98
ADD ./build/bin /bin

Gopkg.lock

Lines changed: 13 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
unused-packages = true
77
non-go = true
88

9-
[[prune.project]]
10-
name = "gopkg.in/bblfsh/client-go.v2"
11-
non-go = false
12-
139
[[constraint]]
1410
name = "github.com/go-chi/chi"
1511
version = "3.3.2"
@@ -39,12 +35,16 @@
3935
version = "1.2.2"
4036

4137
[[constraint]]
38+
name = "gopkg.in/bblfsh/client-go.v3"
39+
version = "3.1.0"
40+
41+
[[override]]
4242
name = "gopkg.in/bblfsh/sdk.v1"
4343
version = "1.16.0"
4444

4545
[[constraint]]
46-
name = "gopkg.in/bblfsh/client-go.v2"
47-
version = "2.8.4"
46+
name = "gopkg.in/bblfsh/sdk.v2"
47+
version = "2.3.0"
4848

4949
[[constraint]]
5050
name = "gopkg.in/DATA-DOG/go-sqlmock.v1"

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ services:
1111
depends_on:
1212
- gitbase
1313
gitbase:
14-
image: "srcd/gitbase:v0.17.1"
14+
image: "srcd/gitbase:v0.18.0"
1515
environment:
1616
BBLFSH_ENDPOINT: bblfsh:9432
1717
GITBASE_UNSTABLE_SQUASH_ENABLE: "true"

docs/rest-api.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ curl -X POST \
212212

213213
## POST /parse
214214

215-
Receives a file content and returns UAST.
215+
Receives a file content and returns UAST parsed by the bblfsh server.
216216

217217
```bash
218218
curl -X POST \
@@ -221,6 +221,7 @@ curl -X POST \
221221
-d '{
222222
"language": "javascript",
223223
"content": "console.log(test)"
224+
"mode": "annotated"
224225
}'
225226
```
226227

@@ -243,8 +244,11 @@ curl -X POST \
243244
}
244245
```
245246

246-
The endpoint also receives additional parameters:
247+
The endpoint accepts these parameters:
247248

249+
- `language`: Language name.
250+
- `content`: The file contents to parse.
251+
- `mode`: Transformation mode. Can be one of `native`, `annotated`, `semantic`. The default is `semantic`.
248252
- `serverUrl` - allows to override bblfsh server URL.
249253
- `filename` - can be used instead of language. Then the bblfsh server would try to guess the language.
250254
- `filter` - [xpath query](https://doc.bblf.sh/user/uast-querying.html) to filter the results.

frontend/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"react-split-pane": "^0.1.77",
1818
"react-switch": "^3.0.4",
1919
"react-table": "^6.8.2",
20-
"uast-viewer": "^0.0.8"
20+
"uast-viewer": "^0.2.0"
2121
},
2222
"scripts": {
2323
"start": "react-app-rewired start",
@@ -28,6 +28,8 @@
2828
"format": "eslint --fix 'src/**/*.js'"
2929
},
3030
"devDependencies": {
31+
"enzyme": "^3.7.0",
32+
"enzyme-adapter-react-16": "^1.7.0",
3133
"eslint-config-airbnb-base": "^12.1.0",
3234
"eslint-config-prettier": "^2.9.0",
3335
"eslint-plugin-jest": "^21.15.1",

frontend/src/api.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,21 @@ function detectLang(content, filename) {
135135
}).then(res => res.data);
136136
}
137137

138-
function parseCode(language, content, filter, customServerUrl) {
138+
const defaultUastMode = 'semantic';
139+
const uastModes = ['semantic', 'annotated', 'native'];
140+
141+
function parseCode(language, content, mode, filter, customServerUrl) {
139142
return apiCall('/parse', {
140143
method: 'POST',
141144
body: {
142145
language,
143146
content,
147+
mode,
144148
filter,
145149
serverUrl: customServerUrl
146150
}
147151
}).then(res => {
148-
if (res.data.status !== 0) {
152+
if (res.status !== 200) {
149153
throw normalizeErrors(res.data.errors);
150154
}
151155
return res.data.uast;
@@ -178,5 +182,7 @@ export default {
178182
parseCode,
179183
getLanguages,
180184
filterUAST,
181-
version
185+
version,
186+
uastModes,
187+
defaultUastMode
182188
};

frontend/src/components/CodeViewer.js

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ function EditorUASTSpitPane({
5454
handleLangChange,
5555
handleShowLocationsChange,
5656
handleFilterChange,
57-
handleSearch
57+
handleSearch,
58+
mode,
59+
handleModeChange
5860
}) {
5961
return (
6062
<SplitPane split="vertical" defaultSize={500} minSize={1} maxSize={-15}>
@@ -72,6 +74,8 @@ function EditorUASTSpitPane({
7274
handleShowLocationsChange={handleShowLocationsChange}
7375
handleFilterChange={handleFilterChange}
7476
handleSearch={handleSearch}
77+
mode={mode}
78+
handleModeChange={handleModeChange}
7579
/>
7680
</SplitPane>
7781
);
@@ -87,7 +91,9 @@ EditorUASTSpitPane.propTypes = {
8791
handleLangChange: PropTypes.func.isRequired,
8892
handleShowLocationsChange: PropTypes.func.isRequired,
8993
handleFilterChange: PropTypes.func.isRequired,
90-
handleSearch: PropTypes.func.isRequired
94+
handleSearch: PropTypes.func.isRequired,
95+
mode: PropTypes.string.isRequired,
96+
handleModeChange: PropTypes.func.isRequired
9197
};
9298

9399
const EditorWithUAST = withUASTEditor(EditorUASTSpitPane);
@@ -104,7 +110,8 @@ class CodeViewer extends Component {
104110
uast: null,
105111
error: null,
106112
showLocations: false,
107-
filter: ''
113+
filter: '',
114+
mode: api.defaultUastMode
108115
};
109116

110117
this.handleLangChange = this.handleLangChange.bind(this);
@@ -113,6 +120,7 @@ class CodeViewer extends Component {
113120
this.removeError = this.removeError.bind(this);
114121
this.handleShowLocationsChange = this.handleShowLocationsChange.bind(this);
115122
this.handleFilterChange = this.handleFilterChange.bind(this);
123+
this.handleModeChange = this.handleModeChange.bind(this);
116124
}
117125

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

156164
api
157-
.parseCode(this.state.language, this.props.code, this.state.filter)
165+
.parseCode(
166+
this.state.language,
167+
this.props.code,
168+
this.state.mode,
169+
this.state.filter
170+
)
158171
.then(res => {
159172
this.setState({ uast: res });
160173
})
@@ -176,6 +189,13 @@ class CodeViewer extends Component {
176189
this.setState({ filter: e.target.value });
177190
}
178191

192+
handleModeChange(mode) {
193+
this.setState({ mode });
194+
if (this.state.showUast) {
195+
this.parseCode();
196+
}
197+
}
198+
179199
render() {
180200
const { showModal, onHide, code, languages } = this.props;
181201
const {
@@ -186,7 +206,8 @@ class CodeViewer extends Component {
186206
uast,
187207
error,
188208
showLocations,
189-
filter
209+
filter,
210+
mode
190211
} = this.state;
191212

192213
if (loading) {
@@ -230,6 +251,8 @@ class CodeViewer extends Component {
230251
handleShowLocationsChange={this.handleShowLocationsChange}
231252
handleFilterChange={this.handleFilterChange}
232253
handleSearch={this.parseCode}
254+
mode={mode}
255+
handleModeChange={this.handleModeChange}
233256
/>
234257
{error ? (
235258
<div className="error">
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import api from '../api';
4+
5+
function ParseModeSwitcher({ mode, handleModeChange }) {
6+
return (
7+
<div style={{ padding: '20px' }}>
8+
{api.uastModes.map(m => (
9+
<label
10+
key={m}
11+
style={{
12+
marginRight: '20px',
13+
textTransform: 'capitalize'
14+
}}
15+
>
16+
<input
17+
type="radio"
18+
value={m}
19+
checked={mode === m}
20+
onChange={e => handleModeChange(e.target.value)}
21+
/>{' '}
22+
{m}
23+
</label>
24+
))}
25+
</div>
26+
);
27+
}
28+
29+
ParseModeSwitcher.propTypes = {
30+
mode: PropTypes.string.isRequired,
31+
handleModeChange: PropTypes.func.isRequired
32+
};
33+
34+
export default ParseModeSwitcher;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React from 'react';
2+
import { shallow } from 'enzyme';
3+
import renderer from 'react-test-renderer';
4+
import ParseModeSwitcher from './ParseModeSwitcher';
5+
6+
test('it renders correctly', () => {
7+
const tree = renderer
8+
.create(
9+
<ParseModeSwitcher mode={'semantic'} handleModeChange={() => null} />
10+
)
11+
.toJSON();
12+
13+
expect(tree).toMatchSnapshot();
14+
});
15+
16+
test('it calls handleModeChange when the input is clicked', () => {
17+
const spy = jest.fn();
18+
const wrapper = shallow(
19+
<ParseModeSwitcher mode={'semantic'} handleModeChange={spy} />
20+
);
21+
wrapper
22+
.find('[value="annotated"]')
23+
.simulate('change', { target: { value: 'annotated' } });
24+
expect(spy.mock.calls.length).toBe(1);
25+
});

0 commit comments

Comments
 (0)