2016-02-21 12:05:14 +00:00
|
|
|
import React from 'react-native';
|
2016-02-23 23:12:32 +00:00
|
|
|
import GlobalStyles from '../../settings/styles';
|
|
|
|
import { getProjectRecentBuilds } from '../../api/CircleCI';
|
2016-02-21 12:05:14 +00:00
|
|
|
|
2016-02-23 23:12:32 +00:00
|
|
|
const {
|
2016-02-21 12:05:14 +00:00
|
|
|
View,
|
|
|
|
Text,
|
2016-02-24 22:23:44 +00:00
|
|
|
StyleSheet,
|
|
|
|
TouchableHighlight
|
2016-02-21 12:05:14 +00:00
|
|
|
} = React;
|
|
|
|
|
2016-02-23 23:12:32 +00:00
|
|
|
const styles = StyleSheet.create({
|
|
|
|
container: {
|
|
|
|
flex: 1,
|
|
|
|
height: 70,
|
|
|
|
alignItems: 'stretch',
|
|
|
|
backgroundColor: GlobalStyles.get('CIRCLE_ITEM_BG'),
|
|
|
|
borderBottomColor: GlobalStyles.get('CIRCLE_ITEM_BORDER'),
|
2016-02-24 18:00:50 +00:00
|
|
|
borderBottomWidth: 2,
|
|
|
|
flexDirection: 'row',
|
2016-02-23 23:12:32 +00:00
|
|
|
},
|
2016-02-24 22:23:44 +00:00
|
|
|
button: {
|
|
|
|
marginVertical: 2.5,
|
|
|
|
},
|
2016-02-24 18:00:50 +00:00
|
|
|
repoCell: {
|
2016-02-23 23:12:32 +00:00
|
|
|
paddingHorizontal: 4,
|
2016-02-24 18:00:50 +00:00
|
|
|
paddingVertical: 3,
|
2016-02-24 21:59:55 +00:00
|
|
|
flex: 0.84
|
2016-02-23 23:12:32 +00:00
|
|
|
},
|
2016-02-24 18:00:50 +00:00
|
|
|
buildCell: {
|
2016-02-24 21:59:55 +00:00
|
|
|
flex: 0.25,
|
2016-02-24 22:23:44 +00:00
|
|
|
padding: 4,
|
2016-02-24 18:10:26 +00:00
|
|
|
borderLeftColor: GlobalStyles.get('CIRCLE_ITEM_BORDER'),
|
|
|
|
borderLeftWidth: 1
|
2016-02-24 18:00:50 +00:00
|
|
|
},
|
|
|
|
colourPanel: {
|
|
|
|
flex: 0.02
|
2016-02-23 23:12:32 +00:00
|
|
|
},
|
|
|
|
repoName: {
|
2016-02-24 18:00:50 +00:00
|
|
|
fontSize: 15,
|
2016-02-23 23:12:32 +00:00
|
|
|
fontWeight: '500'
|
2016-02-24 18:00:50 +00:00
|
|
|
},
|
|
|
|
details: {
|
2016-02-24 22:23:44 +00:00
|
|
|
fontSize: 12.5,
|
|
|
|
fontWeight: '300',
|
|
|
|
marginLeft: 3
|
2016-02-23 23:12:32 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-02-21 12:05:14 +00:00
|
|
|
export default class ProjectItem extends React.Component {
|
2016-02-23 23:12:32 +00:00
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.state = {
|
|
|
|
recentBuild: false
|
|
|
|
};
|
|
|
|
this._displayMoreInfo = this._displayMoreInfo.bind(this);
|
2016-02-24 22:23:44 +00:00
|
|
|
this._viewBuildDetails = this._viewBuildDetails.bind(this);
|
2016-02-23 23:12:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
getProjectRecentBuilds(this.props.project.username, this.props.project.reponame).then(function (recentBuild) {
|
|
|
|
this.setState({ recentBuild: recentBuild[0] });
|
|
|
|
}.bind(this));
|
|
|
|
}
|
|
|
|
|
2016-02-24 22:23:44 +00:00
|
|
|
_viewBuildDetails() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-02-23 23:12:32 +00:00
|
|
|
_displayMoreInfo(mostRecentBuild) {
|
|
|
|
let seconds = Math.floor(mostRecentBuild.build_time_millis / 1000);
|
|
|
|
const minutes = Math.floor(seconds / 60);
|
|
|
|
seconds = seconds - (minutes * 60);
|
2016-02-24 18:00:50 +00:00
|
|
|
const buildTime = minutes + ':' + seconds;
|
|
|
|
const commit = mostRecentBuild.all_commit_details[0];
|
2016-02-23 23:12:32 +00:00
|
|
|
return (
|
2016-02-24 21:59:55 +00:00
|
|
|
<View style={styles.buildCell}>
|
2016-02-24 22:23:44 +00:00
|
|
|
<Text style={styles.details}>#{ mostRecentBuild.build_num }</Text>
|
|
|
|
<Text style={styles.details}>D: { buildTime }</Text>
|
|
|
|
<Text style={styles.details}>C: { commit.commit.substring(0, 6) }</Text>
|
2016-02-24 18:00:50 +00:00
|
|
|
</View>
|
2016-02-23 23:12:32 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-02-21 12:05:14 +00:00
|
|
|
render() {
|
2016-02-23 23:12:32 +00:00
|
|
|
console.log(this.props.userDetails);
|
|
|
|
const project = this.props.project;
|
|
|
|
const mostRecentBuild = this.state.recentBuild;
|
2016-02-24 21:59:55 +00:00
|
|
|
const master = project.branches[project.default_branch].recent_builds[0];
|
|
|
|
const statusColour = master.outcome === 'failed' ?
|
2016-02-24 18:10:16 +00:00
|
|
|
GlobalStyles.get('CIRCLE_TEST_FAIL') :
|
|
|
|
GlobalStyles.get('CIRCLE_TEST_PASS');
|
2016-02-24 21:59:55 +00:00
|
|
|
const username = this.props.userDetails && this.props.userDetails.login !== project.username ?
|
2016-02-24 22:23:44 +00:00
|
|
|
(<Text style={styles.details}>U: {project.username}</Text>) : null;
|
2016-02-24 21:59:55 +00:00
|
|
|
|
|
|
|
const language = project.language ?
|
2016-02-24 22:23:44 +00:00
|
|
|
(<Text style={styles.details}>L: {project.language}</Text>) : null;
|
2016-02-24 21:59:55 +00:00
|
|
|
|
2016-02-23 23:12:32 +00:00
|
|
|
const buildDetails = mostRecentBuild ? this._displayMoreInfo(mostRecentBuild) : null;
|
|
|
|
|
2016-02-21 12:05:14 +00:00
|
|
|
return (
|
2016-02-24 22:23:44 +00:00
|
|
|
<TouchableHighlight
|
|
|
|
style={styles.button}
|
|
|
|
underlayColor={GlobalStyles.get('CIRCLE_BG')}
|
|
|
|
onPress={this._viewBuildDetails}>
|
|
|
|
<View style={styles.container}>
|
|
|
|
<View style={styles.repoCell}>
|
|
|
|
<Text style={styles.repoName}>{project.reponame}</Text>
|
|
|
|
{ username }
|
|
|
|
{ language }
|
|
|
|
</View>
|
|
|
|
{ buildDetails }
|
|
|
|
<View style={[styles.colourPanel, {backgroundColor: statusColour}]} />
|
2016-02-23 23:12:32 +00:00
|
|
|
</View>
|
2016-02-24 22:23:44 +00:00
|
|
|
</TouchableHighlight>
|
2016-02-21 12:05:14 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|