|
| 1 | +/* |
| 2 | + Copyright 2016 Aviral Dasgupta |
| 3 | +
|
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + you may not use this file except in compliance with the License. |
| 6 | + You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | + Unless required by applicable law or agreed to in writing, software |
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + See the License for the specific language governing permissions and |
| 14 | + limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import React from 'react'; |
| 18 | +import sdk from 'matrix-react-sdk'; |
| 19 | +import 'whatwg-fetch'; |
| 20 | +import request from 'browser-request'; |
| 21 | + |
| 22 | +const REPOS = ['vector-im/vector-web', 'matrix-org/matrix-react-sdk', 'matrix-org/matrix-js-sdk']; |
| 23 | + |
| 24 | +export default class ChangelogDialog extends React.Component { |
| 25 | + constructor(props) { |
| 26 | + super(props); |
| 27 | + |
| 28 | + this.state = {}; |
| 29 | + } |
| 30 | + |
| 31 | + componentDidMount() { |
| 32 | + const version = this.props.newVersion.split('-'); |
| 33 | + const version2 = this.props.version.split('-'); |
| 34 | + if(version == null || version2 == null) return; |
| 35 | + for(let i=0; i<REPOS.length; i++) { |
| 36 | + const oldVersion = version2[2*i+1]; |
| 37 | + const newVersion = version[2*i+1]; |
| 38 | + request(`https://api.github.com/repos/${REPOS[i]}/compare/${oldVersion}...${newVersion}`, (a, b, body) => { |
| 39 | + if(body == null) return; |
| 40 | + this.setState({[REPOS[i]]: JSON.parse(body).commits}); |
| 41 | + }); |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + render() { |
| 46 | + const Spinner = sdk.getComponent('views.elements.Spinner'); |
| 47 | + const QuestionDialog = sdk.getComponent('dialogs.QuestionDialog'); |
| 48 | + |
| 49 | + const logs = REPOS.map(repo => { |
| 50 | + if (this.state[repo] == null) return <Spinner key={repo} />; |
| 51 | + return ( |
| 52 | + <div key={repo}> |
| 53 | + <h2>{repo}</h2> |
| 54 | + {this.state[repo].map(commit => |
| 55 | + <div key={commit.commit.url}><a href={commit.commit.url}>{commit.commit.message}</a></div> |
| 56 | + )} |
| 57 | + </div> |
| 58 | + ) |
| 59 | + }); |
| 60 | + |
| 61 | + const content = ( |
| 62 | + <div className="mx_ChangelogDialog_content"> |
| 63 | + {this.props.version == null || this.props.newVersion == null ? <h2>Unavailable</h2> : logs} |
| 64 | + </div> |
| 65 | + ); |
| 66 | + |
| 67 | + |
| 68 | + return ( |
| 69 | + <QuestionDialog |
| 70 | + title="Changelog" |
| 71 | + description={content} |
| 72 | + button="Update" |
| 73 | + onFinished={this.props.onFinished} |
| 74 | + /> |
| 75 | + ) |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | +ChangelogDialog.propTypes = { |
| 80 | + version: React.PropTypes.string.isRequired, |
| 81 | + newVersion: React.PropTypes.string.isRequired, |
| 82 | + onFinished: React.PropTypes.func.isRequired, |
| 83 | +}; |
0 commit comments